76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using GeometryTD.Definition;
|
|
using GeometryTD.Entity.EntityData;
|
|
using GeometryTD.UI;
|
|
using UnityEngine;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
public partial class CombatScheduler
|
|
{
|
|
private sealed class CombatLoadingState : CombatStateBase
|
|
{
|
|
public CombatLoadingState(CombatScheduler scheduler) : base(scheduler)
|
|
{
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
if (Scheduler._currentLevel == null)
|
|
{
|
|
Scheduler.EnterFailureFallback("Combat loading failed. Current level is null.");
|
|
return;
|
|
}
|
|
|
|
MapData mapData = BuildMapData();
|
|
if (!Scheduler._loadSession.StartLoading(Scheduler._currentLevel, mapData, Scheduler, out string errorMessage))
|
|
{
|
|
Scheduler.EnterFailureFallback($"Combat loading failed. {errorMessage}");
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
|
{
|
|
_ = elapseSeconds;
|
|
_ = realElapseSeconds;
|
|
|
|
if (!Scheduler._loadSession.IsReady)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Scheduler.TryBeginNextPhase();
|
|
}
|
|
|
|
private MapData BuildMapData()
|
|
{
|
|
List<TowerStatsData> buildTowerStatsSnapshot = new();
|
|
for (int i = 0; i < Scheduler._combatInRunResourceManager.CurrentBuildTowerCount; i++)
|
|
{
|
|
if (Scheduler._combatInRunResourceManager.TryGetBuildTowerStats(i, out TowerStatsData stats) &&
|
|
stats != null)
|
|
{
|
|
buildTowerStatsSnapshot.Add(stats);
|
|
}
|
|
}
|
|
|
|
return new MapData(
|
|
entityId: 0,
|
|
typeId: 0,
|
|
levelId: Scheduler._currentLevel.Id,
|
|
position: Vector3.zero,
|
|
initialCoin: Scheduler._combatInRunResourceManager.CurrentCoin,
|
|
buildTowerStatsSnapshot: buildTowerStatsSnapshot,
|
|
inventorySnapshot: GameEntry.PlayerInventory != null
|
|
? GameEntry.PlayerInventory.GetInventorySnapshot()
|
|
: null,
|
|
participantTowerSnapshot: GameEntry.PlayerInventory != null
|
|
? GameEntry.PlayerInventory.GetParticipantTowerSnapshot()
|
|
: null,
|
|
tryConsumeCoin: Scheduler.TryConsumeCoin,
|
|
addCoin: Scheduler.AddCoin);
|
|
}
|
|
}
|
|
}
|
|
}
|