| | |
| | | private int ShapeType; |
| | | public int ServerShapeType { get; private set; } |
| | | |
| | | public TeamHero[] teamHeros = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | public TeamHero[] tempHeroes = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | |
| | | public TeamHero[] serverData { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | public TeamHero[] serverHeroes { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | |
| | | public TeamBase(TeamType _teamType) |
| | | { |
| | |
| | | |
| | | for (int i = 0; i < lineUp.ObjCnt; i++) |
| | | { |
| | | if (i < teamHeros.Length) |
| | | if (i < tempHeroes.Length) |
| | | { |
| | | var fightObj = lineUp.ObjList[i]; |
| | | TeamHero hero = new TeamHero(fightObj, this); |
| | | teamHeros[fightObj.PosNum] = hero; |
| | | serverData[fightObj.PosNum] = hero; |
| | | tempHeroes[fightObj.PosNum] = hero; |
| | | serverHeroes[fightObj.PosNum] = hero; |
| | | } |
| | | else |
| | | { |
| | |
| | | public int GetTeamHeroCount() |
| | | { |
| | | int count = 0; |
| | | for (int i = 0; i < teamHeros.Length; i++) |
| | | for (int i = 0; i < tempHeroes.Length; i++) |
| | | { |
| | | if (teamHeros[i] != null) |
| | | if (tempHeroes[i] != null) |
| | | { |
| | | count++; |
| | | } |
| | |
| | | |
| | | public bool IsFull() |
| | | { |
| | | return GetTeamHeroCount() >= teamHeros.Length; |
| | | return GetTeamHeroCount() >= tempHeroes.Length; |
| | | } |
| | | |
| | | public bool IsEmpty() |
| | |
| | | savePack.PosCnt = (byte)GetTeamHeroCount(); |
| | | savePack.HeroPosList = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos[savePack.PosCnt]; |
| | | |
| | | foreach (var hero in teamHeros) |
| | | foreach (var hero in tempHeroes) |
| | | { |
| | | if (hero != null) |
| | | { |
| | |
| | | |
| | | for (int i = 0; i < heroInfos.Count; i++) |
| | | { |
| | | if (i < teamHeros.Length) |
| | | if (i < tempHeroes.Length) |
| | | { |
| | | var heroInfo = heroInfos[i]; |
| | | TeamHero hero = new TeamHero(heroInfo, i, this); |
| | |
| | | |
| | | public TeamHero GetHero(string guid) |
| | | { |
| | | foreach (var hero in teamHeros) |
| | | foreach (var hero in tempHeroes) |
| | | { |
| | | if (hero != null && hero.guid == guid) |
| | | { |
| | |
| | | |
| | | public TeamHero GetServerHero(string guid) |
| | | { |
| | | foreach (var hero in serverData) |
| | | foreach (var hero in serverHeroes) |
| | | { |
| | | if (hero != null && hero.guid == guid) |
| | | { |
| | |
| | | // 布阵接口 |
| | | public bool HasHero(string guid) |
| | | { |
| | | foreach (var hero in teamHeros) |
| | | foreach (var hero in tempHeroes) |
| | | { |
| | | if (hero != null && hero.guid == guid) |
| | | { |
| | |
| | | |
| | | public int GetEmptyPosition() |
| | | { |
| | | for (int i = 0; i < teamHeros.Length; i++) |
| | | for (int i = 0; i < tempHeroes.Length; i++) |
| | | { |
| | | if (teamHeros[i] == null) |
| | | if (tempHeroes[i] == null) |
| | | { |
| | | return i; |
| | | } |
| | |
| | | // 布阵接口 |
| | | public void SetTeamHero(int posNum, TeamHero hero) |
| | | { |
| | | teamHeros[posNum] = hero; |
| | | tempHeroes[posNum] = hero; |
| | | } |
| | | |
| | | // 布阵接口 |
| | | public void SetServerTeamHero(int posNum, TeamHero hero) |
| | | { |
| | | serverData[posNum] = hero; |
| | | teamHeros[posNum] = hero; |
| | | serverHeroes[posNum] = hero; |
| | | tempHeroes[posNum] = hero; |
| | | } |
| | | |
| | | public void AddHero(HeroInfo heroInfo, int targetPosition) |
| | | { |
| | | if (targetPosition < 0 || targetPosition >= teamHeros.Length) |
| | | if (targetPosition < 0 || targetPosition >= tempHeroes.Length) |
| | | { |
| | | Debug.LogError("Invalid target position for adding hero."); |
| | | return; |
| | | } |
| | | |
| | | TeamHero targetHero = teamHeros[targetPosition]; |
| | | TeamHero targetHero = tempHeroes[targetPosition]; |
| | | |
| | | if (null == targetHero) |
| | | { |
| | |
| | | { |
| | | if (teamHero == null) return false; |
| | | |
| | | for (int i = 0; i < teamHeros.Length; i++) |
| | | for (int i = 0; i < tempHeroes.Length; i++) |
| | | { |
| | | if (teamHeros[i] != null && teamHeros[i].guid == teamHero.guid) |
| | | if (tempHeroes[i] != null && tempHeroes[i].guid == teamHero.guid) |
| | | { |
| | | SetTeamHero(i, null); |
| | | return true; // Hero removed successfully |
| | |
| | | |
| | | public void SwapPosition(int index1, int index2) |
| | | { |
| | | if (index1 < 0 || index1 >= teamHeros.Length || index2 < 0 || index2 >= teamHeros.Length) |
| | | if (index1 < 0 || index1 >= tempHeroes.Length || index2 < 0 || index2 >= tempHeroes.Length) |
| | | { |
| | | Debug.LogError("Invalid indices for swapping positions."); |
| | | return; |
| | | } |
| | | |
| | | TeamHero temp = teamHeros[index1]; |
| | | teamHeros[index1] = teamHeros[index2]; |
| | | teamHeros[index2] = temp; |
| | | TeamHero temp = tempHeroes[index1]; |
| | | tempHeroes[index1] = tempHeroes[index2]; |
| | | tempHeroes[index2] = temp; |
| | | |
| | | // 更新位置编号 |
| | | if (teamHeros[index1] != null) teamHeros[index1].positionNum = index1; |
| | | if (teamHeros[index2] != null) teamHeros[index2].positionNum = index2; |
| | | if (tempHeroes[index1] != null) tempHeroes[index1].positionNum = index1; |
| | | if (tempHeroes[index2] != null) tempHeroes[index2].positionNum = index2; |
| | | } |
| | | |
| | | } |