From 3b2a6bb9047cfce9f501593b3669a9c1af6c5df4 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期三, 05 十一月 2025 17:40:23 +0800
Subject: [PATCH] 130 战斗修改回合样式
---
Main/System/Team/TeamBase.cs | 513 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 449 insertions(+), 64 deletions(-)
diff --git a/Main/System/Team/TeamBase.cs b/Main/System/Team/TeamBase.cs
index 65f0538..13f0f91 100644
--- a/Main/System/Team/TeamBase.cs
+++ b/Main/System/Team/TeamBase.cs
@@ -1,87 +1,94 @@
using System;
using System.Collections.Generic;
+using UnityEngine;
// 闃靛瀷鍩虹
public partial class TeamBase
{
- public TeamHero[] teamHeros = new TeamHero[TeamConst.MaxTeamHeroCount];
+ // 璇ラ樀瀹瑰湪鏈樀钀ョ殑缂栧彿锛屼笉鍚岄樀钀ョ殑闃靛缂栧彿鍙兘鐩稿悓锛岄兘鏄粠1寮�濮嬶紝涓�鑸�1V1鏃舵瘡涓樀钀ヤ负1涓樀瀹癸紝澶歏澶氭椂鍒欐瘡涓樀钀ヤ负澶氫釜闃靛
+ private int teamIndex = 0;
+ private uint playerId = 0;
+
+ // 鏈湴鍙彉闃靛瀷
+
+ public bool IsPlayer
+ {
+ get { return playerId == 0; }
+ }
+
+
+ // 鏈嶅姟鍣ㄤ笅鍙戠殑闃靛瀷鍜岄樀瀹癸紝鍙兘閫氳繃缃戠粶鍗忚璧嬪�硷紝澶栭儴鍙
+ public TeamType teamType
+ {
+ get;
+ private set;
+ }
+
+ private int ShapeType;
+ public int ServerShapeType { get; private set; }
+
+ public TeamHero[] tempHeroes { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount];
+
+ public TeamHero[] serverHeroes { get; private set; } = new TeamHero[TeamConst.MaxTeamHeroCount];
+
+ public TeamBase(TeamType _teamType)
+ {
+ teamType = _teamType;
+ teamIndex = 0;
+ playerId = PlayerDatas.Instance.baseData.PlayerID;
+ }
+
+ // 杩欒竟鏉ョ殑鍙互娌℃湁闃熶紞绫诲瀷
+ public TeamBase(HB424_tagSCTurnFightInit.tagSCTurnFightLineup lineUp, bool isBoss = false)
+ {
+ if (isBoss)
+ {
+ tempHeroes = new TeamHero[TeamConst.MaxTeamSlotCount];
+ serverHeroes = new TeamHero[TeamConst.MaxTeamSlotCount];
+ }
+ teamIndex = lineUp.Num;
+ playerId = lineUp.OwnerID;
+ ShapeType = lineUp.ShapeType;
+ ServerShapeType = lineUp.ShapeType;
+
+ for (int i = 0; i < lineUp.ObjCnt; i++)
+ {
+ if (i < tempHeroes.Length)
+ {
+ var fightObj = lineUp.ObjList[i];
+ TeamHero hero = new TeamHero(fightObj, this);
+ tempHeroes[hero.positionNum] = hero;
+ serverHeroes[hero.positionNum] = hero;
+ }
+ else
+ {
+ Debug.LogError("TeamBase: Too many heroes in lineup, exceeding MaxTeamHeroCount.");
+ }
+ }
+
+ // 鍒锋柊鏈嶅姟鍣ㄦ暟鎹�
+ UpdateProperties();
+ }
+
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++;
}
}
-
return count;
- }
-
- public bool SwapTeamHero(int index1, int index2)
- {
- if (index1 < 0 || index1 >= teamHeros.Length || index2 < 0 || index2 >= teamHeros.Length)
- {
- return false;
- }
-
- TeamHero temp = teamHeros[index1];
- teamHeros[index1] = teamHeros[index2];
- teamHeros[index2] = temp;
- temp.heroIndex = index2;
- teamHeros[index1].heroIndex = index1;
-
- return true;
}
- public void AddTeamHeros(List<HeroInfo> heroInfos)
- {
- for (int i = 0; i < heroInfos.Count; i++)
- {
- AddTeamHero(heroInfos[i]);
- }
-
- UpdateProperties();
- }
-
- public bool AddTeamHero(HeroInfo heroInfo)
- {
- if (heroInfo == null)
- {
- return false;
- }
-
- for (int i = 0; i < teamHeros.Length; i++)
- {
- if (teamHeros[i] == null)
- {
- teamHeros[i] = new TeamHero();
- teamHeros[i].heroInfo = heroInfo;
- teamHeros[i].heroIndex = i;
- UpdateProperties();
- return true;
- }
- }
- return false;
- }
-
- public bool RemoveTeamHero(int index)
- {
- if (index < 0 || index >= teamHeros.Length)
- {
- return false;
- }
-
- teamHeros[index] = null;
- return true;
- }
public bool IsFull()
{
- return GetTeamHeroCount() >= teamHeros.Length;
+ return GetTeamHeroCount() >= tempHeroes.Length;
}
public bool IsEmpty()
@@ -89,8 +96,386 @@
return GetTeamHeroCount() == 0;
}
- public void InitByLevelId(int levelId)
+
+ /// <summary>
+ /// 淇濆瓨闃靛锛堥鐣欐帴鍙o級
+ /// </summary>
+ public void SaveTeam()
{
-
+ if (IsEmpty())
+ {
+ SysNotifyMgr.Instance.ShowTip("HeroFunc3");
+ return;
+ }
+
+ CB412_tagCSHeroLineupSave savePack = new CB412_tagCSHeroLineupSave();
+ savePack.LineupID = (byte)teamType;
+ savePack.ShapeType = (byte)ShapeType;
+ savePack.PosCnt = (byte)GetTeamHeroCount();
+ savePack.HeroPosList = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos[savePack.PosCnt];
+
+ int index = 0;
+ foreach (var hero in tempHeroes)
+ {
+ if (hero != null)
+ {
+ int posNum = hero.positionNum;
+ var heroInfo = HeroManager.Instance.GetHero(hero.guid);
+
+ if (heroInfo == null)
+ {
+ Debug.LogError($"Hero with GUID {hero.guid} not found in HeroManager.");
+ continue;
+ }
+
+ savePack.HeroPosList[index] = new CB412_tagCSHeroLineupSave.tagCSHeroLineupPos
+ {
+ ItemIndex = (ushort)heroInfo.itemHero.gridIndex,
+ PosNum = (byte)(posNum + 1)
+ };
+ index++;
+ }
+ }
+ GameNetSystem.Instance.SendInfo(savePack);
+ SysNotifyMgr.Instance.ShowTip("HeroFunc4");
+ //闈炰富绾块樀瀹瑰鎴风鑷繁鍋氭垬鍔涘彉鍖栵紝涓荤嚎闃靛鏈嶅姟绔垬鍔涘彉鏇翠細鍚屾鎺ㄩ��
}
+
+ public void OnChangeShapeType(int newShapeType)
+ {
+ ShapeType = newShapeType;
+ }
+
+ public void OnServerChangeShapeType(int newShapeType)
+ {
+ ServerShapeType = newShapeType;
+ ShapeType = newShapeType;
+ }
+
+
+ public void RefreshServerData(int shapeType, int positionIndex, HeroInfo heroInfo)
+ {
+ TeamHero teamHero = heroInfo == null ? null : new TeamHero(heroInfo, positionIndex, this);
+ SetServerTeamHero(positionIndex, teamHero);
+ OnServerChangeShapeType(shapeType);
+ }
+
+ public void CreateDefault(List<HeroInfo> heroInfos)
+ {
+ teamIndex = 0;
+ playerId = PlayerDatas.Instance.baseData.PlayerID;
+ OnServerChangeShapeType(0);
+
+ for (int i = 0; i < heroInfos.Count; i++)
+ {
+ if (i < tempHeroes.Length)
+ {
+ var heroInfo = heroInfos[i];
+ TeamHero hero = new TeamHero(heroInfo, i, this);
+ SetServerTeamHero(i, hero);
+ }
+ else
+ {
+ Debug.LogError("TeamBase: Too many heroes in lineup");
+ }
+ }
+ }
+
+ public TeamHero GetHero(string guid)
+ {
+ foreach (var hero in tempHeroes)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ return hero;
+ }
+ }
+ 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)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ return hero;
+ }
+ }
+ return null;
+ }
+
+ // 甯冮樀鎺ュ彛
+ public bool HasHero(string guid)
+ {
+ foreach (var hero in tempHeroes)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public bool HasHeroInServer(string guid)
+ {
+ foreach (var hero in serverHeroes)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public TeamHero GetServerHeroByIndex(int index)
+ {
+ if (index < 0 || index >= serverHeroes.Length)
+ {
+ return null;
+ }
+ return serverHeroes[index];
+ }
+
+
+ //鑾峰彇鎵�鏈変笂闃电殑姝﹀皢
+ public List<TeamHero> GetHerosOnTeam()
+ {
+ List<TeamHero> tmpHeros = new List<TeamHero>();
+ foreach (var hero in tempHeroes)
+ {
+ if (hero != null)
+ {
+ tmpHeros.Add(hero);
+ }
+ }
+ return tmpHeros;
+ }
+
+ public TeamHero GetNextServerHero(string guid)
+ {
+ if (string.IsNullOrEmpty(guid))
+ {
+ //鍙栫涓�涓�
+ foreach (var hero in serverHeroes)
+ {
+ if (hero != null)
+ {
+ return hero;
+ }
+ }
+ return null;
+ }
+ else
+ {
+ //鍙栦笅涓�涓�
+ bool findNext = false;
+ foreach (var hero in serverHeroes)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ findNext = true;
+ }
+ else if (findNext && hero != null)
+ {
+ return hero;
+ }
+ }
+ //娌℃壘鍒� 鍙栫涓�涓�
+ return GetNextServerHero("");
+ }
+ }
+
+ //瀹㈡埛绔粠0寮�濮嬶紝鏈嶅姟绔粠1寮�濮�
+ public int GetEmptyPosition()
+ {
+ for (int i = 0; i < tempHeroes.Length; i++)
+ {
+ if (tempHeroes[i] == null)
+ {
+ return i;
+ }
+ }
+ return -1; // No empty position
+ }
+
+ public int GetPosition(string guid)
+ {
+ foreach (var hero in serverHeroes)
+ {
+ if (hero != null && hero.guid == guid)
+ {
+ return hero.positionNum;
+ }
+ }
+ return -1;
+ }
+
+ // 甯冮樀鎺ュ彛
+ private void SetTeamHero(int posNum, TeamHero hero)
+ {
+ tempHeroes[posNum] = hero;
+ }
+
+ // 甯冮樀鎺ュ彛
+ private void SetServerTeamHero(int posNum, TeamHero hero)
+ {
+ serverHeroes[posNum] = hero;
+ tempHeroes[posNum] = hero;
+ }
+
+ // 甯冮樀鎺ュ彛: 鎭㈠闃靛
+ public void RestoreTeam()
+ {
+ for (int i = 0; i < tempHeroes.Length; i++)
+ {
+ tempHeroes[i] = serverHeroes[i];
+ }
+ }
+
+ //checkLock 锛氭槸鍚﹂獙璇佷笂闃典汉鏁伴檺鍒�
+ //targetPosition 浠�0寮�濮�
+ public void AddHero(HeroInfo heroInfo, int targetPosition, bool checkLock)
+ {
+ if (targetPosition < 0 || targetPosition >= tempHeroes.Length)
+ {
+ Debug.LogError("Invalid target position for adding hero.");
+ return;
+ }
+
+ if (checkLock)
+ {
+ var lockCnt = HeroUIManager.Instance.lockIndexList.Count;
+ if (lockCnt > 0 && TeamConst.MaxTeamHeroCount - GetHerosOnTeam().Count <= lockCnt)
+ {
+ HeroUIManager.Instance.ShowUnLockTip(HeroUIManager.Instance.lockIndexList[0]);
+ return;
+ }
+ }
+
+ SetTeamHero(targetPosition, new TeamHero(heroInfo, targetPosition, this));
+ }
+
+
+ //checkLock 锛氭槸鍚﹂獙璇佷笂闃典汉鏁伴檺鍒�
+ // add鍙彲鑳芥槸鐐逛笅闈㈠崱鐗�
+ public bool AddHero(HeroInfo heroInfo, out int pos, bool checkLock)
+ {
+ pos = -1;
+ if (heroInfo == null || heroInfo.itemHero == null) return false;
+
+ if (checkLock)
+ {
+ var lockCnt = HeroUIManager.Instance.lockIndexList.Count;
+ if (lockCnt > 0 && TeamConst.MaxTeamHeroCount - GetHerosOnTeam().Count <= lockCnt)
+ {
+ HeroUIManager.Instance.ShowUnLockTip(HeroUIManager.Instance.lockIndexList[0]);
+ return false;
+ }
+ }
+
+
+ // 鍚屼竴鑻遍泟 鍙兘涓婇樀涓�涓�
+ if (GetHeroByHeroID(heroInfo.heroId) != null)
+ {
+ SysNotifyMgr.Instance.ShowTip("HeroFunc2");
+ return false;
+ }
+ else
+ {
+ pos = GetEmptyPosition();
+
+ if (pos < 0)
+ {
+ SysNotifyMgr.Instance.ShowTip("HeroFunc1");
+ return false; // No empty position available
+ }
+
+ TeamHero teamHero = new TeamHero(heroInfo, pos, this);
+ SetTeamHero(teamHero.positionNum, teamHero);
+ return true;
+ }
+ }
+
+
+ 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;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool RemoveHero(TeamHero teamHero)
+ {
+ if (teamHero == null) return false;
+
+ for (int i = 0; i < tempHeroes.Length; i++)
+ {
+ if (tempHeroes[i] != null && tempHeroes[i].guid == teamHero.guid)
+ {
+ SetTeamHero(i, null);
+ return true; // Hero removed successfully
+ }
+ }
+ 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)
+ {
+ Debug.LogError("Invalid indices for swapping positions.");
+ return;
+ }
+
+ TeamHero temp = tempHeroes[index1];
+ tempHeroes[index1] = tempHeroes[index2];
+ tempHeroes[index2] = temp;
+
+ // 鏇存柊浣嶇疆缂栧彿
+ if (tempHeroes[index1] != null) tempHeroes[index1].positionNum = index1;
+ if (tempHeroes[index2] != null) tempHeroes[index2].positionNum = index2;
+ }
+
}
\ No newline at end of file
--
Gitblit v1.8.0