118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
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 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);
|
||
}
|
||
} |