| | |
| | | private Dictionary<int, BattleObject> redCampDict = new Dictionary<int, BattleObject>(); |
| | | private Dictionary<int, BattleObject> blueCampDict = new Dictionary<int, BattleObject>(); |
| | | |
| | | protected Dictionary<int, BattleObject> allBattleObjDict = new Dictionary<int, BattleObject>(); |
| | | public Dictionary<int, BattleObject> allBattleObjDict = new Dictionary<int, BattleObject>(); |
| | | |
| | | protected BattleField battleField; |
| | | |
| | | public void Init(BattleField _battleField, TeamBase _redTeam, TeamBase _blueTeam) |
| | | { |
| | | Release(); |
| | | battleField = _battleField; |
| | | CreateTeam(battleField.battleRootNode.redTeamNodeList, redCampDict, _redTeam, BattleCamp.Red); |
| | | CreateTeam(battleField.battleRootNode.blueTeamNodeList, blueCampDict, _blueTeam, BattleCamp.Blue); |
| | | } |
| | | ReloadTeam(_redTeam, BattleCamp.Red); |
| | | ReloadTeam(_blueTeam, BattleCamp.Blue, false); |
| | | } |
| | | |
| | | protected void CreateTeam(List<GameObject> posNodeList, Dictionary<int, BattleObject> campDict, TeamBase teamBase, BattleCamp _Camp) |
| | | public void ReloadTeam(TeamBase teamBase, BattleCamp _camp, bool active = true) |
| | | { |
| | | var posNodeList = _camp == BattleCamp.Red ? battleField.battleRootNode.redTeamNodeList : battleField.battleRootNode.blueTeamNodeList; |
| | | var campDict = _camp == BattleCamp.Red ? redCampDict : blueCampDict; |
| | | CreateTeam(posNodeList, campDict, teamBase, _camp, active); |
| | | } |
| | | |
| | | protected void CreateTeam(List<GameObject> posNodeList, Dictionary<int, BattleObject> campDict, TeamBase teamBase, BattleCamp _Camp, bool active) |
| | | { |
| | | DestroyTeam(campDict); |
| | | for (int i = 0; i < teamBase.teamHeros.Length; i++) |
| | | if (teamBase == null) |
| | | { |
| | | TeamHero teamHero = teamBase.teamHeros[i]; |
| | | return; |
| | | } |
| | | |
| | | |
| | | for (int i = 0; i < teamBase.serverHeroes.Length; i++) |
| | | { |
| | | TeamHero teamHero = teamBase.serverHeroes[i]; |
| | | if (teamHero != null) |
| | | { |
| | | BattleObject battleObj = BattleObjectFactory.CreateBattleObject(battleField, posNodeList, teamHero, _Camp); |
| | | allBattleObjDict.Add(battleObj.BattleObjectId, battleObj); |
| | | campDict.Add(teamHero.heroIndex, battleObj); |
| | | battleObj.heroGo.SetActive(active); |
| | | allBattleObjDict.Add(battleObj.ObjID, battleObj); |
| | | campDict.Add(teamHero.positionNum, battleObj); |
| | | battleObj.SetSpeedRatio(battleField.speedRatio); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public BattleObject GetBattleObject(int battleObjId) |
| | | public BattleObject GetBattleObject(int objId) |
| | | { |
| | | if (allBattleObjDict.TryGetValue(battleObjId, out BattleObject battleObj)) |
| | | if (allBattleObjDict.TryGetValue(objId, out BattleObject battleObj)) |
| | | { |
| | | return battleObj; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<BattleObject> GetBattleObjList(BattleCamp _Camp) |
| | | { |
| | | if (_Camp == BattleCamp.Red) |
| | | { |
| | | return redCampList; |
| | | } |
| | | else |
| | | { |
| | | return blueCampList; |
| | | } |
| | | } |
| | | |
| | | public List<BattleObject> GetBattleObjList(HB427_tagSCUseSkill tagUseSkillAttack) |
| | | { |
| | | List<BattleObject> retList = new List<BattleObject>(); |
| | | foreach (var hurt in tagUseSkillAttack.HurtList) |
| | | { |
| | | BattleObject obj = GetBattleObject((int)hurt.ObjID); |
| | | if (null != obj) |
| | | { |
| | | retList.Add(obj); |
| | | } |
| | | } |
| | | |
| | | return retList; |
| | | } |
| | | |
| | | public void DestroyTeam(BattleCamp battleCamp) |
| | | { |
| | | Dictionary<int, BattleObject> campDict = battleCamp == BattleCamp.Red ? redCampDict : blueCampDict; |
| | | if (campDict == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | DestroyTeam(campDict); |
| | | } |
| | | |
| | | public void DestroyObjIds(uint[] objIDs) |
| | | { |
| | | if (objIDs == null || objIDs.Length == 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | foreach (var objID in objIDs) |
| | | { |
| | | if (allBattleObjDict.TryGetValue((int)objID, out BattleObject battleObj)) |
| | | { |
| | | if (battleObj.Camp == BattleCamp.Red) |
| | | { |
| | | redCampDict.Remove(battleObj.teamHero.positionNum); |
| | | } |
| | | else |
| | | { |
| | | blueCampDict.Remove(battleObj.teamHero.positionNum); |
| | | } |
| | | allBattleObjDict.Remove((int)objID); |
| | | BattleObjectFactory.DestroyBattleObject((int)objID, battleObj); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void DestroyTeam(Dictionary<int, BattleObject> campDict) |
| | |
| | | foreach (var item in campDict) |
| | | { |
| | | BattleObject battleObj = item.Value; |
| | | var positionNum = item.Key; |
| | | if (battleObj != null) |
| | | { |
| | | allBattleObjDict.Remove(battleObj.BattleObjectId); |
| | | BattleObjectFactory.DestroyBattleObject(item.Key, battleObj); |
| | | allBattleObjDict.Remove(battleObj.ObjID); |
| | | BattleObjectFactory.DestroyBattleObject(battleObj.ObjID, battleObj); |
| | | } |
| | | } |
| | | campDict.Clear(); |
| | | |
| | | } |
| | | |
| | | public void Release() |
| | | // 空闲状态 |
| | | public virtual void HaveRest(BattleCamp _Camp) |
| | | { |
| | | // 休息状态 |
| | | if (_Camp == BattleCamp.Red) |
| | | { |
| | | foreach (var item in redCampDict.Values) |
| | | { |
| | | item.HaveRest(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | foreach (var item in blueCampDict.Values) |
| | | { |
| | | item.HaveRest(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public virtual void Release() |
| | | { |
| | | DestroyTeam(redCampDict); |
| | | DestroyTeam(blueCampDict); |
| | | allBattleObjDict.Clear(); |
| | | } |
| | | |
| | | public void Run() |
| | |
| | | return blueCampList; |
| | | } |
| | | |
| | | #if UNITY_EDITOR |
| | | public BattleObject GetBattleObjectByIndex(BattleCamp camp, int selfIndex) |
| | | { |
| | | if (camp == BattleCamp.Red) |
| | | { |
| | | redCampDict.TryGetValue(selfIndex, out BattleObject battleObj); |
| | | return battleObj; |
| | | } |
| | | else |
| | | { |
| | | blueCampDict.TryGetValue(selfIndex, out BattleObject battleObj); |
| | | return battleObj; |
| | | } |
| | | } |
| | | |
| | | public void SetSpeedRatio(float ratio) |
| | | { |
| | | foreach (var obj in allBattleObjDict.Values) |
| | | { |
| | | obj.SetSpeedRatio(ratio); |
| | | } |
| | | } |
| | | |
| | | #if UNITY_EDITOR_STOP_USING |
| | | public void ReviveAll() |
| | | { |
| | | foreach (var kv in allBattleObjDict) |
| | |
| | | //暂时没有召唤物 |
| | | // 放在第7格的BOSS后排的。。位置放在正中间 |
| | | // a)前排,1、2、3号为前排,前排全部阵亡后,4、5、6号即是前排也是后排 7其实也是后排 |
| | | List<BattleObject> frontList = new List<BattleObject>(from BO in returnList where BO.teamHero.heroIndex < 3 && !BO.IsDead() select BO); |
| | | List<BattleObject> frontList = new List<BattleObject>(from BO in returnList where BO.teamHero.positionNum < 3 && !BO.IsDead() select BO); |
| | | if (frontList.Count == 0) |
| | | { |
| | | frontList.AddRange(returnList); |
| | |
| | | returnList = frontList; |
| | | break; |
| | | case SkillTargetRangeType.Back: |
| | | List<BattleObject> backList = new List<BattleObject>(from BO in returnList where BO.teamHero.heroIndex >= 3 && !BO.IsDead() select BO); |
| | | List<BattleObject> backList = new List<BattleObject>(from BO in returnList where BO.teamHero.positionNum >= 3 && !BO.IsDead() select BO); |
| | | if (backList.Count == 0) |
| | | { |
| | | backList.AddRange(returnList); |