NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.DefenderPrepare.cs

119 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using Framework;
using Framework.Wrapper;
using Gameplay;
using Gameplay.Common;
using Gameplay.Level;
using Gameplay.Net;
using Gameplay.SubSystems;
using PhxhSDK;
using TGS;
using UnityEngine;
using UnityEngine.SceneManagement;
//防守方布阵
public partial class PVPManager
{
private string _scenePath;
public async void EnterDefendPrepare()
{
await LoadingManager.Instance.ExecuteLoading(new PVPDefendLoadingExecutor(), 0f, 0f);
}
public async void ExitDefendPrepare(List<PVPUnitInfo> unitInfosAfterEdit)
{
SetPVPDefenderPrepareData(unitInfosAfterEdit);
PrepareTeamManager.Instance.Dispose();
await CommonUtils.CloseUIWithScene(UINameConst.UI_PVPDefendPrepare);
}
public async void ExitDefendPrepare()
{
PrepareTeamManager.Instance.Dispose();
//await GameSceneHelper.Instance.UnloadSceneForUIView();
await CommonUtils.CloseUIWithScene(UINameConst.UI_PVPDefendPrepare);
}
public void SavePvPDefenderPrepareData(List<PVPUnitInfo> unitInfosAfterEdit)
{
SetPVPDefenderPrepareData(unitInfosAfterEdit);
}
private void SetPVPDefenderPrepareData(List<PVPUnitInfo> unitInfos)
{
if (unitInfos.Count == 0)
return;
unitInfos.Sort((a, b) => a.type.CompareTo(b.type));
//uint vehicleID = 0;//unitInfos[^1].type == Unit.UnitType.Vehicle ? unitInfos[^1].unitID : 0;
var buildingList = new List<uint>();
var characterIDList = new List<uint>();
var vehicleIDList = new List<uint>();
foreach (var unitInfo in unitInfos)
{
if (unitInfo.type == Unit.UnitType.Charactor)
{
characterIDList.Add(unitInfo.unitID);
}
if (unitInfo.type == Unit.UnitType.Vehicle)
{
vehicleIDList.Add(unitInfo.unitID);
}
if (unitInfo.type == Unit.UnitType.Building)
{
buildingList.Add(unitInfo.unitID);
}
}
uint[] characterIDs = characterIDList.ToArray();//new uint[vehicleID == 0 ? unitInfos.Count : unitInfos.Count - 1];
uint[] buildingIDs = buildingList.ToArray();
uint[] vehicleIDs = vehicleIDList.ToArray();
// for (int i = 0; i < characterIDs.Length; i++)
// {
// characterIDs[i] = unitInfos[i].unitID;
// }
if (characterIDs.Length > GLConfig.Inst.data.PvpFightCharacterLimit)
{
DebugUtil.LogError("保存的CharacterID长度有误length:" + characterIDs.Length);
return;
}
for (int i = 0; i < characterIDs.Length; i++)
{
var curIdx = characterIDs[i];
int j = 0;
while (j < characterIDs.Length)
{
if (j == i)
{
++j;
continue;
}
if (curIdx == characterIDs[j])
{
DebugUtil.LogError("保存的CharacterID有重复ID:" + curIdx);
return;
}
++j;
}
}
if (buildingIDs.Length > GLConfig.Inst.data.PvpFightBuildLimit)
{
DebugUtil.LogError("保存的BuildingID长度有误length:" + characterIDs.Length);
return;
}
byte[] teamData = PVPUnitInfo.Serialize(unitInfos);
NetHelper.SetDefenceTeamForPvp(characterIDs, vehicleIDs, buildingIDs, teamData);
}
}