using System.Collections.Generic;
|
using UnityEngine;
|
|
public class BattleField
|
{
|
public BattleObjMgr battleObjMgr;
|
|
public RecordPlayer recordPlayer;
|
|
public IOperationAgent operationAgent;
|
|
public int round = 0;
|
|
public bool IsActive
|
{
|
get;
|
protected set;
|
}
|
|
public bool IsBattleFinish
|
{
|
get;
|
protected set;
|
}
|
|
public virtual bool IsPvp
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
private bool m_IsPause = false;
|
|
public bool IsPause
|
{
|
get
|
{
|
return m_IsPause;
|
}
|
protected set
|
{
|
m_IsPause = value;
|
|
if (m_IsPause)
|
{
|
PauseGame();
|
}
|
else
|
{
|
ResumeGame();
|
}
|
}
|
}
|
|
public BattleRootNode battleRootNode;
|
|
private BattleMode battleMode;
|
|
public virtual void Init(TeamBase _redTeam, TeamBase _blueTeam)
|
{
|
GameObject go = ResManager.Instance.LoadAsset<GameObject>("Battle/Prefabs", "BattleRootNode");
|
GameObject battleRootNodeGO = GameObject.Instantiate(go);
|
battleRootNode = battleRootNodeGO.GetComponent<BattleRootNode>();
|
battleRootNodeGO.name = this.GetType().Name;
|
|
battleObjMgr = new BattleObjMgr();
|
battleObjMgr.Init(this, _redTeam, _blueTeam);
|
|
recordPlayer = new RecordPlayer();
|
recordPlayer.Init(this);
|
}
|
|
// 在Run之前要设置完毕 要创建Agent
|
public void SetBattleMode(BattleMode _battleMode)
|
{
|
battleMode = _battleMode;
|
CreateAgent();
|
}
|
|
public virtual void Release()
|
{
|
battleObjMgr.Release();
|
}
|
|
public virtual void Run()
|
{
|
if (IsPause)
|
return;
|
|
if (IsRoundReachLimit())
|
{
|
return;
|
}
|
|
recordPlayer.Run();
|
battleObjMgr.Run();
|
|
if (operationAgent == null)
|
{
|
Debug.LogError("you should SetBattleMode before Run");
|
return;
|
}
|
|
operationAgent.Run();
|
}
|
|
|
protected virtual void CreateAgent()
|
{
|
// Hand,//手动战斗
|
// Auto,//自动战斗
|
// Record,//战报
|
switch (battleMode)
|
{
|
case BattleMode.Hand:
|
operationAgent = new HandModeOperationAgent(this);
|
break;
|
case BattleMode.Auto:
|
operationAgent = new AutoModeOperationAgent(this);
|
break;
|
case BattleMode.Record:
|
operationAgent = new RecordModeOperationAgent(this);
|
break;
|
default:
|
operationAgent = new HandModeOperationAgent(this);
|
break;
|
}
|
}
|
|
public virtual void PlayRecord(RecordAction recordAction)
|
{
|
recordPlayer.PlayRecord(recordAction);
|
}
|
|
public virtual void PlayRecord(List<RecordAction> recordList)
|
{
|
recordPlayer.PlayRecord(recordList);
|
}
|
|
protected virtual void ResumeGame()
|
{
|
battleObjMgr.ResumeGame();
|
recordPlayer.ResumeGame();
|
}
|
|
protected virtual void PauseGame()
|
{
|
battleObjMgr.PauseGame();
|
recordPlayer.PauseGame();
|
}
|
|
public bool IsRoundReachLimit()
|
{
|
// return round > xxx;
|
return false;
|
}
|
}
|