1149 lines
31 KiB
C#
1149 lines
31 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using cfg.CharacterCfg;
|
||
using cfg.FightCfg;
|
||
using cfg.MonsterCfg;
|
||
using cfg.VehicleCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using UnityEngine;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.Area;
|
||
using Gameplay.Area.Ready;
|
||
using Gameplay.Character;
|
||
using Gameplay.Level;
|
||
using Gameplay.Level.Data;
|
||
using Gameplay.Unit;
|
||
using Gameplay.Unit.Data;
|
||
using PhxhSDK;
|
||
using Constants = Framework.Constants;
|
||
using EventManager = Framework.EventManager;
|
||
|
||
//队伍管理器
|
||
public partial class TeamManager
|
||
{
|
||
private static TeamManager m_instance;
|
||
private TeamManager()
|
||
{
|
||
|
||
}
|
||
|
||
public int TotalLimit
|
||
{
|
||
get
|
||
{
|
||
return 7;
|
||
}
|
||
}
|
||
private const int FIGHT_LIMIT = 5;
|
||
private const int VEHICLE_FIGHT_LIMIT = 3;
|
||
private const int WAIT_LIMIT = 7;
|
||
public const int TOTAL_LIMIT = 6;
|
||
|
||
//指挥官技能
|
||
private CommandSkillManager _commonSkillMgr;
|
||
public CommandSkillManager CommonSkillMgr => _commonSkillMgr;
|
||
|
||
private bool _isFightStory = true;
|
||
|
||
//进入时初始队列,队伍信息池
|
||
private Dictionary<uint, TeamUnitInfo> m_allCharactersMap;
|
||
private List<uint> m_allIDList;
|
||
//上阵角色ID队列
|
||
private List<uint> m_onFightIDList;
|
||
//下阵角色ID队列
|
||
private List<uint> m_waitFightIDList;
|
||
//死亡角色ID队列
|
||
private List<uint> m_deadIDList;
|
||
//敌方NPCID列表
|
||
private List<uint> m_enemyIDList;
|
||
//载具上的成员
|
||
private List<uint> _inVehicleIDList;
|
||
|
||
private List<uint> _npcIDList;
|
||
|
||
private int _lastVehicleCellIdx = Constants.INVALID_ID;
|
||
|
||
//当前选择ID
|
||
private uint m_selectID = Constants.INVALID_UINT_ID;
|
||
//战斗进行时间,战斗开始时开始计时
|
||
private float m_fightPastTimeCount = 0;
|
||
|
||
private bool _isChanging = false;
|
||
|
||
private static bool _isHideAllUI = false;
|
||
|
||
public static bool IsHideAllUI
|
||
{
|
||
get
|
||
{
|
||
return _isHideAllUI;
|
||
}
|
||
|
||
set
|
||
{
|
||
_isHideAllUI = value;
|
||
if (_isHideAllUI)
|
||
{
|
||
UIManager.Instance.HideAllUI(UINameConst.UIFightScene, UINameConst.UI_Guide, UINameConst.UI_GuideTip, UINameConst.UISkillPut);
|
||
}
|
||
else
|
||
{
|
||
UIManager.Instance.ShowAllUI();
|
||
}
|
||
}
|
||
}
|
||
|
||
public uint SelectID
|
||
{
|
||
get { return m_selectID; }
|
||
}
|
||
|
||
public static TeamManager Instance
|
||
{
|
||
get
|
||
{
|
||
if (m_instance == null)
|
||
{
|
||
m_instance = new TeamManager();
|
||
}
|
||
return m_instance;
|
||
}
|
||
}
|
||
|
||
#region Init
|
||
|
||
public async void Init()
|
||
{
|
||
await _Init();
|
||
}
|
||
private async UniTask _Init()
|
||
{
|
||
_isFightStory = false;
|
||
Team team = TeamEditManager.Instance.GetSelectTeam();
|
||
if (null == team)
|
||
_commonSkillMgr = new CommandSkillManager();
|
||
else
|
||
_commonSkillMgr = new CommandSkillManager(team.GetPlayerSkillIDs());
|
||
|
||
FightTeamManager.Instance.InitCommandSkillMgr();
|
||
_npcIDList = new List<uint>();
|
||
var curLevel = LevelManager.Instance.CurrentLevel;
|
||
if (curLevel != null)
|
||
{
|
||
if (curLevel.GetLevelInfo().fightStoryData != null)
|
||
{
|
||
_isFightStory = true;
|
||
}
|
||
}
|
||
var selectList = await GetSelectList(_isFightStory);
|
||
|
||
m_allIDList = new List<uint>();
|
||
m_waitFightIDList = new List<uint>();
|
||
m_allCharactersMap = new Dictionary<uint, TeamUnitInfo>();
|
||
m_onFightIDList = new List<uint>();
|
||
m_deadIDList = new List<uint>();
|
||
m_enemyIDList = new List<uint>();
|
||
_inVehicleIDList = new List<uint>();
|
||
|
||
if (_isFightStory)
|
||
{
|
||
for (int i = 0; i < selectList.Count; i++)
|
||
{
|
||
uint uid = selectList[i].Uid;
|
||
m_allIDList.Add(uid);
|
||
m_allCharactersMap.Add(uid, selectList[i]);
|
||
if (selectList[i].IsVehicle())
|
||
{
|
||
m_onFightIDList.Insert(0, uid);
|
||
}
|
||
else
|
||
{
|
||
m_onFightIDList.Add(uid);
|
||
}
|
||
}
|
||
|
||
m_onFightIDList.Reverse();
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < selectList.Count; i++)
|
||
{
|
||
uint uid = selectList[i].Uid;
|
||
m_allIDList.Add(uid);
|
||
m_allCharactersMap.Add(uid, selectList[i]);
|
||
if (selectList[i].IsVehicle())
|
||
{
|
||
m_waitFightIDList.Insert(0, uid);
|
||
}
|
||
else
|
||
{
|
||
m_waitFightIDList.Add(uid);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
private async UniTask<List<TeamUnitInfo>> GetSelectList(bool isFightStory = false)
|
||
{
|
||
//测试数据
|
||
//AllCharacterInfo allChaInfo = AllCharacterInfo.Instance;
|
||
|
||
Team defaultTeam = TeamEditManager.Instance.GetSelectTeam();
|
||
|
||
var cIDs = defaultTeam.GetAllCharacters();
|
||
|
||
var vInfos = new List<VehicleCultivateData>();
|
||
|
||
foreach (var vehicleID in defaultTeam.GetVehicleIDs())
|
||
{
|
||
if (ValueValidator.IsIdValid(vehicleID))
|
||
{
|
||
var vInfo = VehicleCultivateDataManager.Instance.DataDic[vehicleID];
|
||
vInfos.Add(vInfo);
|
||
}
|
||
}
|
||
|
||
List<TeamUnitInfo> selectList = new List<TeamUnitInfo>();
|
||
if (isFightStory)
|
||
{
|
||
|
||
_SetTeamUnitListFightStory(selectList);
|
||
return selectList;
|
||
}
|
||
|
||
_SetNpcList();
|
||
int allCount = cIDs.Count + vInfos.Count;
|
||
var count = allCount > WAIT_LIMIT ? WAIT_LIMIT : allCount;
|
||
|
||
var workUIIndex = 1;
|
||
//Test
|
||
for (int i = 0; i < cIDs.Count; i++)
|
||
{
|
||
if (i < cIDs.Count)
|
||
{
|
||
var id = cIDs[i];
|
||
if (id > 0)
|
||
{
|
||
TeamUnitInfo info;
|
||
var charInfo = CharacterDataInfoManager.Instance.DataDic[id];
|
||
var unit = await GameUnitManager.instance.PrepareCharacter(charInfo, ETroopsId.Self);
|
||
if (unit == null)
|
||
{
|
||
DebugUtil.LogError("创建角色失败!!!");
|
||
continue;
|
||
}
|
||
info = new TeamUnitInfo(CharacterDataInfoManager.Instance.DataDic[id], unit.GetID());
|
||
unit.unitUIData.uiIndex = defaultTeam.GetCharacterIdxInAllUnits(id);
|
||
unit.unitUIData.isNPC = false;
|
||
workUIIndex++;
|
||
selectList.Add(info);
|
||
}
|
||
}
|
||
}
|
||
|
||
for (int i = 0; i < vInfos.Count; i++)
|
||
{
|
||
if (i < vInfos.Count)
|
||
{
|
||
TeamUnitInfo info;
|
||
var unit = await GameUnitManager.instance.PrepareVehicle(vInfos[i], ETroopsId.Self);
|
||
info = new TeamUnitInfo(unit.GetID(), vInfos[i]);
|
||
unit.unitUIData.uiIndex = defaultTeam.GetVehicleIdxInAllUnits(vInfos[i].nID);
|
||
unit.unitUIData.isNPC = false;
|
||
workUIIndex++;
|
||
selectList.Add(info);
|
||
}
|
||
}
|
||
|
||
return selectList;
|
||
}
|
||
|
||
private void InitData()
|
||
{
|
||
Release();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 剧情战斗关卡设置队伍
|
||
/// </summary>
|
||
/// <param name="selectList"></param>
|
||
private void _SetTeamUnitListFightStory(List<TeamUnitInfo> selectList)
|
||
{
|
||
selectList.Clear();
|
||
var level = LevelManager.Instance.CurrentLevel;
|
||
if (level == null)
|
||
{
|
||
DebugUtil.LogError("当前剧情战斗关卡为空!!!无法获取上阵NPC列表");
|
||
return;
|
||
}
|
||
|
||
var levelInfo = level.GetLevelInfo();
|
||
if (levelInfo == null)
|
||
{
|
||
DebugUtil.LogError("当前剧情战斗关卡的关卡信息为空!!!无法获取上阵NPC列表");
|
||
return;
|
||
}
|
||
|
||
var fightStoryData = levelInfo.fightStoryData;
|
||
if (fightStoryData == null)
|
||
{
|
||
DebugUtil.LogError("当前剧情战斗关卡的剧情战斗相关数据为空!!!无法获取上阵NPC列表");
|
||
return;
|
||
}
|
||
|
||
var playerTeamData = fightStoryData.playerTeamData;
|
||
var memberList = playerTeamData.memberList;
|
||
var infightUnits = GameUnitManager.instance.infightUnits;
|
||
|
||
for (int i = 0; i < memberList.Count; i++)
|
||
{
|
||
var memberData = memberList[i];
|
||
var monsterID = memberData.monsterId;
|
||
if (monsterID == 0)
|
||
{
|
||
continue;
|
||
}
|
||
var npcMonsterData = TableManager.Instance.Tables.Monster.Get(monsterID);
|
||
if (npcMonsterData == null)
|
||
{
|
||
DebugUtil.LogError($"Monster表无法获取,monsterID:{monsterID}");
|
||
continue;
|
||
}
|
||
|
||
var unit = infightUnits.SearchByLocalId(memberData.unitLocalId);
|
||
if (unit != null)
|
||
{
|
||
var teamUnitInfo = new TeamUnitInfo(npcMonsterData, unit.GetID());
|
||
teamUnitInfo.SetVehicleNID((uint)npcMonsterData.MonsterClassID);
|
||
unit.unitUIData.isNPC = true;
|
||
selectList.Add(teamUnitInfo);
|
||
}
|
||
|
||
//var teamUnitInfo = new TeamUnitInfo()
|
||
}
|
||
}
|
||
|
||
private void _SetNpcList()
|
||
{
|
||
var inFightUnits = GameUnitManager.instance.infightUnits;
|
||
foreach (var unit in inFightUnits.unitList)
|
||
{
|
||
if (unit.commonData.troopId == ETroopsId.Self && unit.commonData.canControl == false)
|
||
{
|
||
unit.unitUIData.isNPC = true;
|
||
_npcIDList.Add(unit.GetID());
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
bool IsDead(uint uid)
|
||
{
|
||
if (!m_allCharactersMap.ContainsKey(uid))
|
||
{
|
||
DebugUtil.LogError("传入ID有误!!!");
|
||
return false;
|
||
}
|
||
return m_allCharactersMap[uid].GetIsDead();
|
||
}
|
||
|
||
private List<uint> GetCharacterIDs()
|
||
{
|
||
List<uint> retList = new List<uint>();
|
||
for (int i = 0; i < m_allIDList.Count; i++)
|
||
{
|
||
var id = m_allIDList[i];
|
||
if (GetUnitType(id) == TeamUnitInfo.CharacType.Hero)
|
||
{
|
||
retList.Add(id);
|
||
}
|
||
}
|
||
|
||
return retList;
|
||
}
|
||
|
||
private List<uint> GetVehicleIDs()
|
||
{
|
||
List<uint> retList = new List<uint>();
|
||
for (int i = 0; i < m_allIDList.Count; i++)
|
||
{
|
||
var id = m_allIDList[i];
|
||
if (GetUnitType(id) == TeamUnitInfo.CharacType.Vehicle)
|
||
{
|
||
retList.Add(id);
|
||
}
|
||
}
|
||
|
||
return retList;
|
||
}
|
||
|
||
//战前上阵队列变化
|
||
void SendWaitToFightBefore(uint toFightUId)
|
||
{
|
||
foreach (var uid in m_waitFightIDList)
|
||
{
|
||
if (toFightUId == uid)
|
||
{
|
||
if (GetCharacterDataInfo(uid).IsVehicle())
|
||
{
|
||
m_onFightIDList.Insert(0, uid);
|
||
}
|
||
else
|
||
{
|
||
m_onFightIDList.Add(toFightUId);
|
||
}
|
||
m_waitFightIDList.Remove(toFightUId);
|
||
EventManager.Instance.Send(EventManager.EventName.LevelFightStartChange);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
//战斗中上阵
|
||
void SendWaitToFightFighting(uint toFightUId)
|
||
{
|
||
if (!m_allCharactersMap.ContainsKey(toFightUId))
|
||
{
|
||
return;
|
||
}
|
||
if (IsDead(toFightUId))
|
||
{
|
||
return;
|
||
}
|
||
|
||
foreach (var uid in m_waitFightIDList)
|
||
{
|
||
if (toFightUId == uid)
|
||
{
|
||
if (GetCharacterDataInfo(uid).IsVehicle())
|
||
{
|
||
m_onFightIDList.Insert(0, uid);
|
||
}
|
||
else
|
||
{
|
||
m_onFightIDList.Add(toFightUId);
|
||
}
|
||
m_waitFightIDList.Remove(toFightUId);
|
||
//EventSystem.Instance.Send(EventSystem.EventName.LevelFightStartChange);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
//战前下阵队列变化
|
||
void SendFightToWaitBefore(uint toWaitUid,
|
||
bool fightDontMove = true)
|
||
{
|
||
foreach (var uid in m_onFightIDList)
|
||
{
|
||
if (toWaitUid == uid)
|
||
{
|
||
if (GetCharacterDataInfo(uid).IsVehicle())
|
||
{
|
||
m_waitFightIDList.Insert(0, uid);
|
||
}
|
||
else
|
||
{
|
||
m_waitFightIDList.Add(toWaitUid);
|
||
}
|
||
m_onFightIDList.Remove(toWaitUid);
|
||
EventManager.Instance.Send(EventManager.EventName.LevelFightStartChange);
|
||
|
||
if (fightDontMove)
|
||
{
|
||
GameUnitManager.instance.MoveUnitToPrepare(toWaitUid);
|
||
}
|
||
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
//战斗中下阵
|
||
void SendFightToWaitFighting(uint toWaitUid)
|
||
{
|
||
//LevelManager.Instance.CurrentLevel.CharacterManager.Remove(toWaitUid);
|
||
if (!m_allCharactersMap.ContainsKey(toWaitUid))
|
||
{
|
||
return;
|
||
}
|
||
bool isDead = false;
|
||
if (IsDead(toWaitUid) && !m_deadIDList.Contains(toWaitUid))
|
||
{
|
||
if (GetCharacterDataInfo(toWaitUid).IsVehicle())
|
||
{
|
||
m_deadIDList.Insert(0, toWaitUid);
|
||
}
|
||
else
|
||
{
|
||
m_deadIDList.Add(toWaitUid);
|
||
}
|
||
|
||
isDead = true;
|
||
}
|
||
|
||
int idx = m_onFightIDList.FindIndex((id) =>
|
||
{
|
||
if (m_deadIDList.Count > 0)
|
||
{
|
||
return m_deadIDList[0] == id;
|
||
}
|
||
return false;
|
||
});
|
||
idx = idx < 0 ? m_waitFightIDList.Count - m_deadIDList.Count : idx;
|
||
|
||
if (isDead)
|
||
{
|
||
if (m_deadIDList.Count > 0)
|
||
{
|
||
if (m_allCharactersMap[toWaitUid].IsVehicle())
|
||
{
|
||
m_waitFightIDList.Insert(idx, toWaitUid);
|
||
m_onFightIDList.Remove(toWaitUid);
|
||
return;
|
||
}
|
||
}
|
||
m_waitFightIDList.Add(toWaitUid);
|
||
}
|
||
else
|
||
{
|
||
m_waitFightIDList.Insert(idx, toWaitUid);
|
||
}
|
||
|
||
m_onFightIDList.Remove(toWaitUid);
|
||
}
|
||
|
||
public void Release()
|
||
{
|
||
UnLoadAllPost();
|
||
|
||
m_allIDList.Clear();
|
||
m_onFightIDList.Clear();
|
||
m_waitFightIDList.Clear();
|
||
m_allCharactersMap.Clear();
|
||
_npcIDList.Clear();
|
||
m_enemyIDList.Clear();
|
||
_inVehicleIDList.Clear();
|
||
if (m_deadIDList != null)
|
||
{
|
||
m_deadIDList.Clear();
|
||
}
|
||
m_instance = null;
|
||
|
||
_isFightStory = false;
|
||
//InputManager.Instance.OnFingerUp -= _OnFingerUp;
|
||
}
|
||
|
||
public void SetSelectID(uint uid = Constants.INVALID_UINT_ID)
|
||
{
|
||
m_selectID = uid;
|
||
|
||
bool isNeedShow = ValueValidator.IsIdValid(m_selectID);
|
||
if (LevelManager.Instance.CurrentLevel.IsPreparing())
|
||
{
|
||
//AreaManager.instance.readyAreaManager.ShowReadyArea();
|
||
// if (!isNeedShow)
|
||
// {
|
||
// AreaManager.instance.readyAreaManager.HideReadyArea();
|
||
// }
|
||
}
|
||
else if (LevelManager.Instance.CurrentLevel.IsInBattle())
|
||
{
|
||
if (m_waitFightIDList.Contains(uid))
|
||
{
|
||
if (GameUnitManager.instance.infightUnits.Contains(uid))
|
||
{
|
||
var unit = GameUnitManager.instance.infightUnits.Search(uid);
|
||
if (unit.statusData.isOnVehicle)
|
||
{
|
||
// 在战斗中
|
||
AreaManager.instance.readyAreaManager.ShowReadyArea(EReadyAreaStatus.AroundVehicle, unit);
|
||
}
|
||
}
|
||
else if (GameUnitManager.instance.prepareUnits.Contains(uid))
|
||
{
|
||
// 备战席
|
||
AreaManager.instance.readyAreaManager.ShowReadyArea();
|
||
}
|
||
else if (GameUnitManager.instance.deadUnits.Contains(uid))
|
||
{
|
||
// 已死亡
|
||
AreaManager.instance.readyAreaManager.HideReadyArea();
|
||
}
|
||
else
|
||
{
|
||
// 未知情况
|
||
DebugUtil.LogError("未知上阵情况!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AreaManager.instance.readyAreaManager.HideReadyArea();
|
||
}
|
||
|
||
// LevelManager.Instance.CurrentLevel.Map.ShowInfo(Map.InfoMask.ShowCells, isNeedShow);
|
||
}
|
||
|
||
if (uid == Constants.INVALID_UINT_ID)
|
||
{
|
||
if (IsHideAllUI)
|
||
{
|
||
IsHideAllUI = false;
|
||
CloseFightPosterUI();
|
||
}
|
||
}
|
||
}
|
||
|
||
//获取某一个角色的信息
|
||
public TeamUnitInfo GetCharacterDataInfo(uint uid)
|
||
{
|
||
if (m_allCharactersMap.TryGetValue(uid, out var result))
|
||
{
|
||
return result;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
//获取各个队列
|
||
public List<uint> GetWaitList()
|
||
{
|
||
return m_waitFightIDList;
|
||
}
|
||
|
||
public List<uint> GetFightList()
|
||
{
|
||
return m_onFightIDList;
|
||
}
|
||
|
||
public List<uint> GetDeadList()
|
||
{
|
||
if (m_deadIDList == null)
|
||
{
|
||
DebugUtil.LogError("Null!");
|
||
}
|
||
return m_deadIDList;
|
||
}
|
||
|
||
public List<uint> GetInVehicleList()
|
||
{
|
||
return _inVehicleIDList;
|
||
}
|
||
|
||
public List<uint> GetEnemyList()
|
||
{
|
||
return m_enemyIDList;
|
||
}
|
||
|
||
public void AddEnemyID(uint uid)
|
||
{
|
||
m_enemyIDList.Add(uid);
|
||
}
|
||
|
||
public void ClearEnemyID(uint uid)
|
||
{
|
||
m_enemyIDList.Remove(uid);
|
||
}
|
||
|
||
public TeamUnitInfo GetTeamUnitInfoByUid(uint uid)
|
||
{
|
||
return m_allCharactersMap[uid];
|
||
}
|
||
|
||
//上下载具
|
||
public void InVehicleAdd(uint id)
|
||
{
|
||
_inVehicleIDList.Add(id);
|
||
}
|
||
|
||
public void InVehicleRemove(uint id)
|
||
{
|
||
_inVehicleIDList.Remove(id);
|
||
}
|
||
|
||
//选中一个准备上阵
|
||
public void SelectToFight(uint selectUid = Constants.INVALID_UINT_ID)
|
||
{
|
||
SetSelectID(selectUid);
|
||
}
|
||
|
||
//从Level中选择的传入到UI层
|
||
public void SelectToWait(uint selectUid = Constants.INVALID_UINT_ID)
|
||
{
|
||
SetSelectID(selectUid);
|
||
}
|
||
|
||
//上阵成功
|
||
public void SendToFight(uint toFightUId)
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel.IsPreparing())
|
||
{
|
||
SendWaitToFightBefore(toFightUId);
|
||
return;
|
||
}
|
||
|
||
SendWaitToFightFighting(toFightUId);
|
||
}
|
||
|
||
//下阵成功
|
||
public void SendToWait(uint toWaitUid,
|
||
bool fightDontMove = true)
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel.IsPreparing())
|
||
{
|
||
SendFightToWaitBefore(toWaitUid, fightDontMove);
|
||
return;
|
||
}
|
||
|
||
// if (LevelManager.Instance.CurrentLevel.IsInBattle())
|
||
// {
|
||
SendFightToWaitFighting(toWaitUid);
|
||
// }
|
||
}
|
||
|
||
//战斗时选中已上阵
|
||
public void SelectCharacterFighting(int uid)
|
||
{
|
||
|
||
}
|
||
|
||
//记录战斗开始时间
|
||
public void StartFightTime()
|
||
{
|
||
//InitFightTime();
|
||
//MonoHelper.instance.AddAction(EActionType.UPDATE, FightPassAddDeltaTime);
|
||
}
|
||
|
||
void FightPassAddDeltaTime()
|
||
{
|
||
bool isPause = LevelManager.Instance.CurrentLevel.IsPause();
|
||
if (!isPause)
|
||
{
|
||
FightPastTimeAddSecond(Time.deltaTime);
|
||
}
|
||
}
|
||
|
||
public void InitFightTime()
|
||
{
|
||
m_fightPastTimeCount = 0;
|
||
}
|
||
|
||
public void SetFightPastTime(float time)
|
||
{
|
||
m_fightPastTimeCount = time;
|
||
}
|
||
|
||
void FightPastTimeAddMs(float ms)
|
||
{
|
||
m_fightPastTimeCount += ms / 1000f;
|
||
}
|
||
|
||
void FightPastTimeAddSecond(float second)
|
||
{
|
||
m_fightPastTimeCount += second;
|
||
}
|
||
|
||
public float GetFightPastTime()
|
||
{
|
||
return m_fightPastTimeCount;
|
||
}
|
||
|
||
public int GetFightPastHour()
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel == null)
|
||
{
|
||
return 0;
|
||
}
|
||
var time = LevelManager.Instance.CurrentLevel.LevelTime;
|
||
int curTimeSecond = Convert.ToInt32(Math.Floor(time));
|
||
int hour = Convert.ToInt32(Math.Floor(curTimeSecond / 3600f));
|
||
|
||
return hour;
|
||
}
|
||
|
||
public int GetFightPastMinute()
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel == null)
|
||
{
|
||
return 0;
|
||
}
|
||
var time = LevelManager.Instance.CurrentLevel.LevelTime;
|
||
int curTimeSecond = Convert.ToInt32(Math.Floor(time));
|
||
int hour = GetFightPastHour();
|
||
int min = Convert.ToInt32(Math.Floor(curTimeSecond / 60f - hour * 60f));
|
||
|
||
return min;
|
||
}
|
||
|
||
public int GetFightPastSecond()
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel == null)
|
||
{
|
||
return 0;
|
||
}
|
||
var time = LevelManager.Instance.CurrentLevel.LevelTime;
|
||
int curTimeSecond = Convert.ToInt32(Math.Floor(time));
|
||
int hour = GetFightPastHour();
|
||
int min = GetFightPastMinute();
|
||
int sec = (curTimeSecond - min * 60 - hour * 3600);
|
||
|
||
return sec;
|
||
}
|
||
|
||
public TeamUnitInfo.CharacType GetUnitType(uint uid)
|
||
{
|
||
if (m_allCharactersMap.ContainsKey(uid))
|
||
{
|
||
return m_allCharactersMap[uid].Type;
|
||
}
|
||
|
||
DebugUtil.LogError("请检查传入对象的类型(载具/角色)!!!uid = {0}", uid);
|
||
return TeamUnitInfo.CharacType.Hero;
|
||
}
|
||
|
||
public bool IsCharacter(uint uid)
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel.IsInBattle())
|
||
{
|
||
return GameUnitManager.instance.totalUnits.Search(uid).gameunitType == EGameUnitType.Character;
|
||
}
|
||
return GetUnitType(uid) == TeamUnitInfo.CharacType.Hero;
|
||
}
|
||
|
||
public bool IsVehicle(uint uid)
|
||
{
|
||
if (LevelManager.Instance.CurrentLevel.IsInBattle())
|
||
{
|
||
return GameUnitManager.instance.infightUnits.Search(uid).gameunitType == EGameUnitType.Vehicle;
|
||
}
|
||
return GetUnitType(uid) == TeamUnitInfo.CharacType.Vehicle;
|
||
}
|
||
|
||
public bool GetIsChanging()
|
||
{
|
||
return _isChanging;
|
||
}
|
||
|
||
public void SetIsChanging(bool state)
|
||
{
|
||
_isChanging = state;
|
||
}
|
||
|
||
public void BornInLevel(uint uid)
|
||
{
|
||
if (!m_allCharactersMap.ContainsKey(uid))
|
||
{
|
||
return;
|
||
}
|
||
m_allCharactersMap[uid].IsInLevel = true;
|
||
}
|
||
|
||
public void RemoveInLevel(uint uid)
|
||
{
|
||
if (!m_allCharactersMap.ContainsKey(uid))
|
||
{
|
||
return;
|
||
}
|
||
m_allCharactersMap[uid].IsInLevel = false;
|
||
}
|
||
|
||
public bool IsInLevel(uint uid)
|
||
{
|
||
if (!m_allCharactersMap.ContainsKey(uid))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
return m_allCharactersMap[uid].IsInLevel;
|
||
}
|
||
|
||
public void SetIDReborn(uint uid)
|
||
{
|
||
if (!m_waitFightIDList.Contains(uid))
|
||
{
|
||
return;
|
||
}
|
||
if (!m_deadIDList.Contains(uid))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_waitFightIDList.Remove(uid);
|
||
m_deadIDList.Remove(uid);
|
||
var idx = m_waitFightIDList.Count - m_deadIDList.Count;
|
||
m_waitFightIDList.Insert(idx, uid);
|
||
BornInLevel(uid);
|
||
var singleUnit = m_allCharactersMap[uid];
|
||
singleUnit.SetIsDead();
|
||
}
|
||
public List<uint> GetAllIDList()
|
||
{
|
||
return m_allIDList;
|
||
}
|
||
|
||
public bool IsFightListLimit(uint uid)
|
||
{
|
||
return false;
|
||
// int totalNum = 0;
|
||
// int vehicleNum = 0;
|
||
// var unitList = GameUnitManager.instance.infightUnits;
|
||
// for (int i = 0; i < unitList.count; i++)
|
||
// {
|
||
// var unit = unitList.GetByIndex(i);
|
||
// if (unit.commonData.troopId == ETroopsId.Self)
|
||
// {
|
||
// if (unit.gameunitType == EGameUnitType.Character)
|
||
// {
|
||
// ++totalNum;
|
||
// }
|
||
// if(unit.gameunitType == EGameUnitType.Vehicle)
|
||
// {
|
||
// ++vehicleNum;
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// if (IsCharacter(uid))
|
||
// {
|
||
// return totalNum >= FIGHT_LIMIT;
|
||
// }
|
||
//
|
||
// return vehicleNum >= VEHICLE_FIGHT_LIMIT;
|
||
}
|
||
|
||
public bool IsInTeam(uint uid)
|
||
{
|
||
return m_allCharactersMap.ContainsKey(uid);
|
||
}
|
||
|
||
public bool CheckIsOnCancel()
|
||
{
|
||
if (UIManager.Instance.GetOpenedWindowByPath(UINameConst.UIFightPoster) is UIPosterAndSkillInfoController window)
|
||
{
|
||
return window.CheckIsInCancel();
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public void SetCancelImageShow()
|
||
{
|
||
// if (UIManager.Instance.GetOpenedWindowByPath(UINameConst.UIFightPoster) is UIPosterAndSkillInfoController window)
|
||
// {
|
||
// window.SetCancelShow();
|
||
// }
|
||
}
|
||
}
|
||
|
||
//单个队列中的角色信息
|
||
public class TeamUnitInfo
|
||
{
|
||
private CharacterDataInfo _characterData;
|
||
private VehicleCultivateData _vConfigData;
|
||
public readonly bool IsNPC = false;
|
||
|
||
|
||
private bool m_isDead;
|
||
private bool _isInLevel = false; //是否被创建到战场中,没有的话不能取到各种值
|
||
|
||
//测试数据
|
||
private uint m_uid; //战场中生成的UID
|
||
private CharacType m_type;
|
||
|
||
public readonly uint OutUid; //养成界面的UID
|
||
public const uint NPC_OUT_UID = 0;
|
||
|
||
public enum CharacType
|
||
{
|
||
Hero,
|
||
Vehicle
|
||
}
|
||
|
||
public bool IsInLevel
|
||
{
|
||
get => _isInLevel;
|
||
set => _isInLevel = value;
|
||
}
|
||
|
||
public TeamUnitInfo(DataMonster monsterData,
|
||
uint uid)
|
||
{
|
||
IsNPC = true;
|
||
if (monsterData.NpcType == ENpcType.SELF_CHARACTER)
|
||
{
|
||
m_type = CharacType.Hero;
|
||
_characterData = _CreateFakeCharacterData(monsterData);
|
||
m_uid = uid;
|
||
OutUid = NPC_OUT_UID;
|
||
}
|
||
|
||
if (monsterData.NpcType == ENpcType.SELF_VEHICLE)
|
||
{
|
||
m_type = CharacType.Vehicle;
|
||
m_uid = uid;
|
||
OutUid = NPC_OUT_UID;
|
||
_vConfigData = _CreateFakeVehicleData(monsterData);
|
||
}
|
||
}
|
||
public TeamUnitInfo(CharacterDataInfo configData,
|
||
uint uid,
|
||
CharacType type = CharacType.Hero)
|
||
{
|
||
_characterData = configData;
|
||
m_uid = uid;
|
||
OutUid = configData.Uid;
|
||
m_type = type;
|
||
}
|
||
|
||
public TeamUnitInfo(uint uid,
|
||
VehicleCultivateData configData,
|
||
CharacType type = CharacType.Vehicle)
|
||
{
|
||
_vConfigData = configData;
|
||
//m_leftBlood = configData.Blood();
|
||
OutUid = configData.nID;
|
||
m_uid = uid;
|
||
m_type = type;
|
||
}
|
||
|
||
private CharacterDataInfo _CreateFakeCharacterData(DataMonster monsterData)
|
||
{
|
||
if (monsterData.NpcType == ENpcType.SELF_CHARACTER)
|
||
{
|
||
var npcData = TableManager.Instance.Tables.FightNPCConfig.Get(monsterData.MonsterClassID);
|
||
CharacterDataInfo characterDataInfo = new CharacterDataInfo();
|
||
characterDataInfo.ID = (uint)npcData.ConfigId; //用NPC表ID覆盖
|
||
characterDataInfo.Level = (uint)monsterData.MonsterLevel;
|
||
characterDataInfo.BreakLevel = 0;
|
||
characterDataInfo.AwakeLevel = 0;
|
||
characterDataInfo.LikelyExp = 0;
|
||
characterDataInfo.LikelyLevel = 0;
|
||
characterDataInfo.UltraSkillLevel = 0;
|
||
characterDataInfo.SkinID = 1;
|
||
|
||
var cfgTemp = TableManager.Instance.Tables.CharacterAttri.DataList[0];
|
||
var cfg = new DataCharacterAttri(
|
||
cfgTemp.RoleID,
|
||
"测试",
|
||
"昵称",
|
||
cfgTemp.BirthDay,
|
||
cfgTemp.StartStar,
|
||
cfgTemp.ExchangePiece,
|
||
cfgTemp.ExchangeCount,
|
||
cfgTemp.EmojiEyeBowsType,
|
||
cfgTemp.EmojiEyesColor,
|
||
cfgTemp.EmojiEyeBowsColor,
|
||
cfgTemp.DefaultEmojiImgId,
|
||
cfgTemp.DefaultDisplayEmojiId,
|
||
npcData.StandCrossLevel,
|
||
npcData.MoveCrossLevel,
|
||
1, //测试用
|
||
cfgTemp.Defence,
|
||
cfgTemp.Hp,
|
||
cfgTemp.HpBase,
|
||
cfgTemp.Shield,
|
||
npcData.WeaponGrasp,
|
||
npcData.WeaponDegree,
|
||
cfgTemp.DefenceNoMoveScale,
|
||
npcData.Speed,
|
||
npcData.NoFightMoveSpeed,
|
||
npcData.RetreatSpeed,
|
||
npcData.MaxMorale,
|
||
npcData.CorrageRecover,
|
||
npcData.CriticalRatio,
|
||
npcData.CriticalDamage,
|
||
npcData.WeaponId,
|
||
cfgTemp.ShootDistanceScale,
|
||
cfgTemp.AttackLoopCount,
|
||
npcData.MoveShootType,
|
||
npcData.Job,
|
||
npcData.ProvideJob,
|
||
cfgTemp.SpendLeadership,
|
||
npcData.Army,
|
||
npcData.Fraction,
|
||
cfgTemp.FacDetail,
|
||
cfgTemp.FacIcon
|
||
);
|
||
|
||
characterDataInfo.ForceSetCfg(cfg);
|
||
return characterDataInfo;
|
||
}
|
||
|
||
DebugUtil.LogError($"创建NPC角色时出现错误!Monster NPCType不为角色!MonsterID:{monsterData.MonsterID}");
|
||
return null;
|
||
}
|
||
|
||
private VehicleCultivateData _CreateFakeVehicleData(DataMonster monsterData)
|
||
{
|
||
if (monsterData.NpcType == ENpcType.SELF_VEHICLE)
|
||
{
|
||
var vehicleData = new VehicleCultivateData();
|
||
var vehicleID = monsterData.MonsterClassID;
|
||
var vehicleCfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault(vehicleID);
|
||
if (vehicleCfg == null)
|
||
{
|
||
DebugUtil.LogError($"创建NPC载具时出现错误,无法获取配置数据!, MonsterClassID:{monsterData.MonsterClassID}");
|
||
return null;
|
||
}
|
||
|
||
vehicleData.Cfg = vehicleCfg;
|
||
return vehicleData;
|
||
}
|
||
|
||
DebugUtil.LogError($"创建NPC载具时出现错误,Monster数据不为载具!, MonsterID:{monsterData.MonsterID}");
|
||
return null;
|
||
}
|
||
|
||
public void SetVehicleNID(uint nID)
|
||
{
|
||
if (m_type == CharacType.Vehicle)
|
||
{
|
||
_vConfigData.nID = nID;
|
||
}
|
||
}
|
||
|
||
|
||
public uint Uid
|
||
{
|
||
get { return m_uid; }
|
||
}
|
||
|
||
public CharacType Type
|
||
{
|
||
get { return m_type; }
|
||
}
|
||
|
||
public bool IsVehicle()
|
||
{
|
||
return m_type == CharacType.Vehicle;
|
||
}
|
||
|
||
public int GetTid()
|
||
{
|
||
return _characterData.Cfg.RoleID;
|
||
}
|
||
|
||
public CharacterDataInfo GetConfigInfo()
|
||
{
|
||
return _characterData;
|
||
}
|
||
|
||
public VehicleCultivateData GetVehicleInfo()
|
||
{
|
||
return _vConfigData;
|
||
}
|
||
|
||
public bool GetIsDead()
|
||
{
|
||
return m_isDead;
|
||
}
|
||
|
||
public void SetIsDead(bool state = false)
|
||
{
|
||
m_isDead = state;
|
||
}
|
||
}
|