| | |
| | | private int ShapeType; |
| | | public int ServerShapeType { get; private set; } |
| | | |
| | | public TeamHero[] tempHeroes = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | public TeamHero[] tempHeroes { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | |
| | | public TeamHero[] serverHeroes { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | |
| | |
| | | { |
| | | if (IsEmpty()) |
| | | { |
| | | Debug.LogError("Cannot save an empty team. You should at least have one hero in the team."); |
| | | SysNotifyMgr.Instance.ShowTip("HeroFunc3"); |
| | | return; |
| | | } |
| | | |
| | |
| | | savePack.PosCnt = (byte)GetTeamHeroCount(); |
| | | savePack.HeroPosList = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos[savePack.PosCnt]; |
| | | |
| | | int index = 0; |
| | | foreach (var hero in tempHeroes) |
| | | { |
| | | if (hero != null) |
| | |
| | | continue; |
| | | } |
| | | |
| | | savePack.HeroPosList[posNum] = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos |
| | | savePack.HeroPosList[index] = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos |
| | | { |
| | | ItemIndex = (ushort)heroInfo.itemHero.gridIndex, |
| | | PosNum = (byte)posNum |
| | | PosNum = (byte)(posNum + 1) |
| | | }; |
| | | index++; |
| | | } |
| | | } |
| | | |
| | | GameNetSystem.Instance.SendInfo(savePack); |
| | | SysNotifyMgr.Instance.ShowTip("HeroFunc4"); |
| | | //非主线阵容客户端自己做战力变化,主线阵容服务端战力变更会同步推送 |
| | | } |
| | | |
| | | public void OnChangeShapeType(int newShapeType) |
| | |
| | | ShapeType = newShapeType; |
| | | } |
| | | |
| | | // hero info could be null if the hero is removed from the team |
| | | |
| | | public void RefreshServerData(int shapeType, int positionIndex, HeroInfo heroInfo) |
| | | { |
| | | TeamHero teamHero = heroInfo == null ? null : new TeamHero(heroInfo, positionIndex, this); |
| | |
| | | return null; |
| | | } |
| | | |
| | | public TeamHero GetHeroByHeroID(int heroId) |
| | | { |
| | | foreach (var hero in tempHeroes) |
| | | { |
| | | if (hero != null && hero.heroId == heroId) |
| | | { |
| | | return hero; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public TeamHero GetServerHero(string guid) |
| | | { |
| | | foreach (var hero in serverHeroes) |
| | |
| | | return false; |
| | | } |
| | | |
| | | //客户端从0开始,服务端从1开始 |
| | | public int GetEmptyPosition() |
| | | { |
| | | for (int i = 0; i < tempHeroes.Length; i++) |
| | |
| | | } |
| | | |
| | | // 布阵接口 |
| | | public void SetTeamHero(int posNum, TeamHero hero) |
| | | private void SetTeamHero(int posNum, TeamHero hero) |
| | | { |
| | | tempHeroes[posNum] = hero; |
| | | } |
| | | |
| | | // 布阵接口 |
| | | public void SetServerTeamHero(int posNum, TeamHero hero) |
| | | private void SetServerTeamHero(int posNum, TeamHero hero) |
| | | { |
| | | serverHeroes[posNum] = hero; |
| | | tempHeroes[posNum] = hero; |
| | |
| | | |
| | | |
| | | // add只可能是点下面卡牌 |
| | | public bool AddHero(HeroInfo heroInfo) |
| | | public bool AddHero(HeroInfo heroInfo, out int pos) |
| | | { |
| | | pos = -1; |
| | | if (heroInfo == null || heroInfo.itemHero == null) return false; |
| | | |
| | | |
| | | // 如果当前英雄已经在队伍里了 就不处理了 |
| | | if (GetHero(heroInfo.itemHero.guid) != null) |
| | | // 同一英雄 只能上阵一个 |
| | | if (GetHeroByHeroID(heroInfo.heroId) != null) |
| | | { |
| | | return false; // Hero already in team |
| | | SysNotifyMgr.Instance.ShowTip("HeroFunc2"); |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | int emptyPosition = GetEmptyPosition(); |
| | | pos = GetEmptyPosition(); |
| | | |
| | | if (emptyPosition < 0) |
| | | if (pos < 0) |
| | | { |
| | | Debug.LogError("No empty position available in the team."); |
| | | SysNotifyMgr.Instance.ShowTip("HeroFunc1"); |
| | | return false; // No empty position available |
| | | } |
| | | |
| | | TeamHero teamHero = new TeamHero(heroInfo, GetEmptyPosition(), this); |
| | | TeamHero teamHero = new TeamHero(heroInfo, pos, this); |
| | | SetTeamHero(teamHero.positionNum, teamHero); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | |
| | | public bool RemoveHero(HeroInfo heroInfo) |
| | | public bool RemoveHero(HeroInfo heroInfo, out int pos) |
| | | { |
| | | pos = -1; |
| | | if (heroInfo == null || heroInfo.itemHero == null) return false; |
| | | |
| | | TeamHero teamHero = GetHero(heroInfo.itemHero.guid); |
| | | |
| | | if (teamHero != null) |
| | | { |
| | | pos = teamHero.positionNum; |
| | | // 从当前队伍里移除该英雄 |
| | | SetTeamHero(teamHero.positionNum, null); |
| | | return true; |
| | |
| | | return false; // Hero not found |
| | | } |
| | | |
| | | public bool RemoveHero(int pos) |
| | | { |
| | | SetTeamHero(pos, null); |
| | | return true; |
| | | } |
| | | |
| | | public void RemoveAllHeroes() |
| | | { |
| | | tempHeroes = new TeamHero[TeamConst.MaxTeamHeroCount]; |
| | | } |
| | | |
| | | |
| | | public void SwapPosition(int index1, int index2) |
| | | { |
| | | if (index1 < 0 || index1 >= tempHeroes.Length || index2 < 0 || index2 >= tempHeroes.Length) |