|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class CustomHB426CombinePack : GameNetPackBasic
|
{
|
|
public HB426_tagSCTurnFightTag startTag;
|
|
public HB426_tagSCTurnFightTag endTag;
|
|
public int fromIndex;
|
|
public int toIndex;
|
|
public string guid;
|
|
public List<GameNetPackBasic> packList = new List<GameNetPackBasic>();
|
|
public override void ReadFromBytes(byte[] vBytes)
|
{
|
base.ReadFromBytes(vBytes);
|
}
|
|
public void SetHB426End(int _toIndex, HB426_tagSCTurnFightTag _endTag)
|
{
|
if (_endTag.Sign != 1)
|
{
|
Debug.LogError("HB426_tagSCTurnFightTag Sign must be 1 for end tag, but got: " + _endTag.Sign);
|
return;
|
}
|
endTag = _endTag;
|
toIndex = _toIndex;
|
PrintAllPack();
|
}
|
|
|
public void SetHB426Start(int _fromIndex, HB426_tagSCTurnFightTag tag)
|
{
|
if (tag.Sign != 0)
|
{
|
Debug.LogError("HB426_tagSCTurnFightTag Sign must be 0 for start tag, but got: " + tag.Sign);
|
return;
|
}
|
fromIndex = _fromIndex;
|
startTag = tag;
|
|
|
}
|
|
public void PrintAllPack()
|
{
|
string temp = "CustomHB426CombinePack startTag: " + (startTag != null ? startTag.Tag : "null") + " fromIndex: " + fromIndex + " toIndex: " + toIndex + "\n";
|
for (int i = 0; i < packList.Count; i++)
|
{
|
var pack = packList[i];
|
if (pack is CustomHB426CombinePack b426Pack)
|
{
|
temp += " pack type is " + pack.GetType().Name + " tag is " + (b426Pack.startTag != null ? b426Pack.startTag.Tag : "null") + "\n";
|
}
|
else
|
{
|
temp += " pack type is " + pack.GetType().Name + "\n";
|
}
|
}
|
BattleDebug.LogError(temp);
|
}
|
|
public void AddPack(GameNetPackBasic pack)
|
{
|
if (startTag == null)
|
{
|
Debug.LogError("startTag is null, please set it first.");
|
return;
|
}
|
|
packList.Add(pack);
|
}
|
|
public bool IsEndPack(HB426_tagSCTurnFightTag tag)
|
{
|
if (tag == null)
|
{
|
return false;
|
}
|
|
if (startTag == null)
|
{
|
Debug.LogError("startTag is null, please set it first.");
|
return false;
|
}
|
|
return startTag.Tag == tag.Tag && tag.Sign == 1;
|
}
|
|
public static List<GameNetPackBasic> CombineToSkillPackFromList(string _guid, List<GameNetPackBasic> b421SeriesPackList)
|
{
|
Dictionary<string, CustomHB426CombinePack> combineDict = new Dictionary<string, CustomHB426CombinePack>();
|
|
Dictionary<int, GameNetPackBasic> indexDict = new Dictionary<int, GameNetPackBasic>();
|
|
for (int i = 0; i < b421SeriesPackList.Count; i++)
|
{
|
var pack = b421SeriesPackList[i];
|
|
if (pack is HB426_tagSCTurnFightTag)
|
{
|
var tag = pack as HB426_tagSCTurnFightTag;
|
CustomHB426CombinePack combinePack;
|
|
if (!combineDict.TryGetValue(tag.Tag, out combinePack))
|
{
|
combinePack = new CustomHB426CombinePack();
|
combinePack.guid = _guid;
|
combineDict.Add(tag.Tag, combinePack);
|
|
indexDict.Add(i, combinePack);
|
}
|
|
if (tag.Sign == 0)
|
{
|
combinePack.SetHB426Start(i, tag);
|
continue;
|
}
|
// 找到对应的开始标签
|
if (combinePack.IsEndPack(tag))
|
{
|
combinePack.SetHB426End(i, tag);
|
continue;
|
}
|
|
Debug.LogError("No matching start tag or end tag found: " + tag.Tag);
|
continue;
|
}
|
else
|
{
|
indexDict.Add(i, pack);
|
}
|
}
|
|
|
// 嵌套包内的包合并
|
foreach (var combinePack in combineDict.Values)
|
{
|
for (int i = combinePack.fromIndex + 1; i < combinePack.toIndex; i++)
|
{
|
if (indexDict.TryGetValue(i, out var pack))
|
{
|
indexDict.Remove(i);
|
combinePack.AddPack(pack);
|
if (pack is CustomHB426CombinePack)
|
{
|
// 如果是嵌套的包 加入之后 调整i
|
i = (pack as CustomHB426CombinePack).toIndex;
|
}
|
}
|
}
|
}
|
|
List<GameNetPackBasic> newPackList = new List<GameNetPackBasic>();
|
|
// string temp = string.Empty;
|
|
for (int i = 0; i < b421SeriesPackList.Count; i++)
|
{
|
if (indexDict.TryGetValue(i, out var pack))
|
{
|
newPackList.Add(pack);
|
if (pack is CustomHB426CombinePack)
|
{
|
var cbpack = pack as CustomHB426CombinePack;
|
// temp += "pack type is " + pack.GetType().Name + " tag is " + cbpack.startTag.Tag + "\n";
|
}
|
else
|
{
|
// temp += "pack type is " + pack.GetType().Name + "\n";
|
}
|
}
|
}
|
|
// newPackList = BattleManager.ParseBattlePackList(_guid, newPackList);
|
|
// Debug.LogError(temp);
|
|
return newPackList;
|
}
|
|
public void Distribute()
|
{
|
BattleField battleField = BattleManager.Instance.GetBattleField(guid);
|
|
if (null == battleField)
|
{
|
Debug.LogError("BattleField not found for guid: " + guid);
|
return;
|
}
|
|
var skillAction = CreateSkillAction();
|
if (null != skillAction)
|
{
|
battleField.PlayRecord(skillAction);
|
}
|
|
}
|
|
public SkillRecordAction CreateSkillAction()
|
{
|
BattleField battleField = BattleManager.Instance.GetBattleField(guid);
|
|
if (null == battleField)
|
{
|
Debug.LogError("BattleField not found for guid: " + guid);
|
return null;
|
}
|
|
if (startTag.Tag.StartsWith("Skill_"))
|
{
|
HB427_tagSCUseSkill skill = packList[0] as HB427_tagSCUseSkill;
|
packList.Remove(skill);
|
BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
|
|
// BattleDebug.LogError("_caster == null : " + (_caster == null) + " skill.ObjID : " + skill.ObjID);
|
|
SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, packList);
|
return skillAction;
|
}
|
|
return null;
|
}
|
|
#if UNITY_EDITOR
|
public static CustomHB426CombinePack CreateCustomPack(string _guid, HB427_tagSCUseSkill skill)
|
{
|
CustomHB426CombinePack pack = new CustomHB426CombinePack();
|
pack.guid = string.Empty;
|
|
pack.startTag = new HB426_tagSCTurnFightTag
|
{
|
Tag = "Skill_Start",
|
Sign = 0
|
};
|
|
pack.packList.Add(skill);
|
|
return pack;
|
}
|
#endif
|
}
|