using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
using LitJson;
|
using DG.Tweening;
|
|
public class BattleField
|
{
|
public BattleObjMgr battleObjMgr;
|
|
public BattleEffectMgr battleEffectMgr;
|
|
public BattleTweenMgr battleTweenMgr;
|
|
public RecordPlayer recordPlayer;
|
|
public IOperationAgent operationAgent;
|
|
public int round = 0;
|
|
public string guid = string.Empty;
|
|
public int MapID = 0;
|
|
public int FuncLineID = 0;
|
|
public JsonData extendData;
|
|
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;
|
}
|
set
|
{
|
m_IsPause = value;
|
|
if (m_IsPause)
|
{
|
PauseGame();
|
}
|
else
|
{
|
ResumeGame();
|
}
|
|
OnBattlePause?.Invoke(m_IsPause);
|
}
|
}
|
|
public BattleRootNode battleRootNode;
|
|
private BattleMode battleMode;
|
|
public Action<bool> OnBattlePause;
|
|
protected List<TeamBase> redTeamList = null;
|
|
protected List<TeamBase> blueTeamList = null;
|
|
protected int redTeamIndex = 0;
|
|
protected int blueTeamIndex = 0;
|
|
public BattleField(string _guid)
|
{
|
guid = _guid;
|
}
|
|
public virtual void Init(int _MapID, int _FuncLineID, JsonData _extendData,
|
List<TeamBase> _redTeamList, List<TeamBase> _blueTeamList)
|
{
|
MapID = _MapID;
|
redTeamList = _redTeamList;
|
blueTeamList = _blueTeamList;
|
FuncLineID = _FuncLineID;
|
extendData = _extendData;
|
|
redTeamIndex = 0;
|
blueTeamIndex = 0;
|
|
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, redTeamList[redTeamIndex], blueTeamList[blueTeamIndex]);
|
battleEffectMgr = new BattleEffectMgr();
|
battleEffectMgr.Init(this);
|
battleTweenMgr = new BattleTweenMgr();
|
battleTweenMgr.Init(this);
|
|
// 这里的Init交给各个子类的Init里去实现
|
// 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();
|
battleEffectMgr.ResumeGame();
|
battleTweenMgr.ResumeGame();
|
}
|
|
protected virtual void PauseGame()
|
{
|
// 怎么通知界面暂停了呢?
|
|
battleObjMgr.PauseGame();
|
recordPlayer.PauseGame();
|
battleEffectMgr.PauseGame();
|
battleTweenMgr.PauseGame();
|
}
|
|
public virtual void TurnFightState(int TurnNum, int State,
|
uint FuncLineID, JsonData extendData)
|
{
|
round = TurnNum;
|
}
|
|
public virtual void OnTurnFightObjAction(int turnNum, int ObjID)
|
{
|
|
}
|
|
public virtual void OnTurnFightState(int turnNum, int State, int FuncLineID, JsonData extendData)
|
{
|
|
}
|
|
public void ObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo)
|
{
|
BattleObject battleObj = battleObjMgr.GetBattleObject((int)_refreshInfo.ObjID);
|
|
if (null != battleObj)
|
{
|
battleObj.OnObjInfoRefresh(_refreshInfo);
|
}
|
}
|
|
public void ObjPropertyRefreshView(H0423_tagObjPropertyRefreshView vNetData)
|
{
|
|
}
|
|
public virtual void OnObjDead(int ObjID)
|
{
|
DeathRecordAction recordAction = new DeathRecordAction(this, battleObjMgr.GetBattleObject(ObjID));
|
recordPlayer.PlayRecord(recordAction);
|
}
|
|
public virtual void Destroy()
|
{
|
// 销毁全部内容
|
}
|
|
public void FinishBattleInAdvance(uint[] ObjIDArr)
|
{
|
// 让npc隐藏后 左边播放睡觉动作
|
|
|
}
|
|
public virtual void ProcessUseSkillAttack(H0604_tagUseSkillAttack vNetData)
|
{
|
// H0604_tagUseSkillAttack
|
// public uint ObjID;
|
// public byte ObjType;
|
// public byte BattleType; //物理/魔法
|
// public ushort SkillID;
|
// public uint AttackID; //主攻击目标
|
// public byte AttackObjType; //主攻击目标
|
// public ushort HurtCount; //伤害数目
|
// public tagSkillHurtObj[] HurtList; //size = HurtCount
|
|
// ObjType类型的ObjID使用BattleType类技能SkillID攻击了AttackObjType类型的AttackID 伤害数字是HurtList
|
// SkillAction skillAction = new SkillAction();
|
|
}
|
|
public RectTransform GetTeamNode(BattleCamp battleCamp)
|
{
|
if (battleCamp == BattleCamp.Red)
|
{
|
return battleRootNode.redTeamNode;
|
}
|
else
|
{
|
return battleRootNode.blueTeamNode;
|
}
|
}
|
|
|
public bool IsRoundReachLimit()
|
{
|
// return round > xxx;
|
return false;
|
}
|
|
public void UpdateCanvas(Canvas canvas)
|
{
|
EffectPenetrationBlocker[] blockers = battleRootNode.GetComponentsInChildren<EffectPenetrationBlocker>(true);
|
|
if (null != blockers)
|
{
|
foreach (var blocker in blockers)
|
{
|
blocker.SetParentCanvas(canvas);
|
}
|
}
|
}
|
}
|