using System.Collections.Generic;
|
using UnityEngine;
|
using LitJson;
|
|
|
public class BattleManager : GameSystemManager<BattleManager>
|
{
|
public StoryBattleField storyBattleField = null;
|
|
// 同时只能有一场战斗在进行 guid, battlefield
|
protected Dictionary<string, BattleField> battleFields = new Dictionary<string, BattleField>();
|
|
protected LogicUpdate logicUpdate = new LogicUpdate();
|
|
public override void Init()
|
{
|
base.Init();
|
// StartStoryBattle();
|
logicUpdate.Start(Run);
|
}
|
|
public override void Release()
|
{
|
base.Release();
|
logicUpdate.Destroy();
|
}
|
|
public void CreateStoryBattle(int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
|
{
|
if (null == storyBattleField)
|
{
|
storyBattleField = new StoryBattleField();
|
}
|
|
storyBattleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
|
}
|
|
|
|
public void OnBattleClose(BattleField _battleField)
|
{
|
|
}
|
|
|
#region 截断网络派发包 只收入当前包的后续
|
private bool allow = true;
|
|
private Queue<GameNetPackBasic> packQueue = new Queue<GameNetPackBasic>();
|
|
public bool IsCanDistributePackage(GameNetPackBasic _package)
|
{
|
if (_package is HB425_tagSCTurnFightReportSign)
|
{
|
HB425_tagSCTurnFightReportSign pkg = _package as HB425_tagSCTurnFightReportSign;
|
|
// 0-战报片段开始;1-战报片段结束;
|
if (pkg.Sign == 0)
|
{
|
allow = false;
|
}
|
else
|
{
|
allow = true;
|
}
|
}
|
else
|
{
|
if (!allow)
|
{
|
packQueue.Enqueue(_package);
|
}
|
}
|
|
return allow;
|
}
|
|
public bool DistributeNextPackage()
|
{
|
if (packQueue.Count > 0)
|
{
|
GameNetPackBasic pack = packQueue.Dequeue();
|
PackageRegedit.Distribute(pack);
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
public void OnConnected()
|
{
|
if (!allow)
|
{
|
allow = true;
|
packQueue.Clear();
|
|
// 重新发送要上一组战斗包的请求
|
// TODO YYL
|
}
|
}
|
|
#endregion
|
|
#region 战报部分
|
|
protected Dictionary<string, Queue<GameNetPackBasic>> battleReportDict = new Dictionary<string, Queue<GameNetPackBasic>>();
|
|
protected Dictionary<string, List<ulong>> battlePackRelationList = new Dictionary<string, List<ulong>>();
|
|
public void PushPackage(string guid, GameNetPackBasic vNetPack)
|
{
|
Queue<GameNetPackBasic> queue = null;
|
|
if (!battleReportDict.TryGetValue(guid, out queue))
|
{
|
queue = new Queue<GameNetPackBasic>();
|
}
|
|
queue.Enqueue(vNetPack);
|
|
List<ulong> uidList = null;
|
|
if (!battlePackRelationList.TryGetValue(guid, out uidList))
|
{
|
uidList = new List<ulong>();
|
}
|
|
uidList.Add(vNetPack.packUID);
|
}
|
|
public BattleField GetBattleField(ulong packUID)
|
{
|
return GetBattleField(GetGUID(packUID));
|
}
|
|
public BattleField GetBattleField(string guid)
|
{
|
BattleField battleField = null;
|
battleFields.TryGetValue(guid, out battleField);
|
if (battleField == null)
|
{
|
battleField = storyBattleField;
|
}
|
return battleField;
|
}
|
|
|
|
public string GetGUID(ulong packUID)
|
{
|
foreach (var kv in battlePackRelationList)
|
{
|
if (kv.Value.Contains(packUID))
|
{
|
return kv.Key;
|
}
|
}
|
return string.Empty;
|
}
|
|
|
public void DistributeNextReportPackage(string guid)
|
{
|
Queue<GameNetPackBasic> queue = null;
|
|
if (!battleReportDict.TryGetValue(guid, out queue))
|
{
|
Debug.LogError("DistributeNextReportPackage could not find queue for guid : " + guid);
|
return;
|
}
|
|
PackageRegedit.Distribute(queue.Dequeue());
|
|
if (queue.Count <= 0)
|
{
|
battleReportDict.Remove(guid);
|
battlePackRelationList.Remove(guid);
|
}
|
}
|
#endregion
|
|
public BattleField CreateBattleField(string guid, int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
|
{
|
BattleField battleField = null;
|
|
if (battleFields.TryGetValue(guid, out battleField))
|
{
|
Debug.LogError("战场已存在 先进行销毁");
|
battleField.Destroy();
|
}
|
|
|
battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
|
|
battleFields.Add(guid, battleField);
|
|
if (string.Empty == guid)
|
{
|
storyBattleField = battleField as StoryBattleField;
|
}
|
|
return battleField;
|
}
|
|
|
// public void OnTurnFightObjAction(battleType, vNetData.TurnNum, (int)vNetData.ObjID)
|
|
|
public void Run()
|
{
|
if (null != storyBattleField)
|
{
|
storyBattleField.Run();
|
}
|
|
foreach (var battleField in battleFields)
|
{
|
battleField.Value?.Run();
|
}
|
}
|
|
}
|