82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using GeometryTD.CustomEvent;
|
|
using GeometryTD.DataTable;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
internal sealed class CombatRunningPhaseState : CombatStateBase
|
|
{
|
|
private readonly DRLevelPhase _phase;
|
|
private readonly IReadOnlyList<DRLevelSpawnEntry> _spawnEntries;
|
|
|
|
public CombatRunningPhaseState(
|
|
CombatSchedulerRuntime runtime,
|
|
CombatSchedulerCoordinator coordinator,
|
|
DRLevelPhase phase,
|
|
IReadOnlyList<DRLevelSpawnEntry> spawnEntries) : base(runtime, coordinator)
|
|
{
|
|
_phase = phase;
|
|
_spawnEntries = spawnEntries;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
Runtime.EnemyManager.BeginPhase(_phase, _spawnEntries);
|
|
GameEntry.Event.Fire(
|
|
Coordinator,
|
|
CombatProcessEventArgs.Create(
|
|
Runtime.PhaseLoopRuntime.DisplayPhaseIndex,
|
|
Runtime.PhaseLoopRuntime.PhaseCount));
|
|
GameEntry.Event.Fire(
|
|
Coordinator,
|
|
CombatEnemyHpRateChangedEventArgs.Create(
|
|
Coordinator.ResolveEnemyHpRateMultiplier(
|
|
Runtime.PhaseLoopRuntime.DisplayPhaseIndex,
|
|
Runtime.PhaseLoopRuntime.PhaseCount)));
|
|
|
|
if (!Runtime.NodeEnterFired)
|
|
{
|
|
Runtime.NodeEnterFired = true;
|
|
GameEntry.Event.Fire(
|
|
Coordinator,
|
|
NodeEnterEventArgs.Create(
|
|
Runtime.RunId,
|
|
Runtime.NodeId,
|
|
Runtime.NodeType,
|
|
Runtime.SequenceIndex));
|
|
}
|
|
|
|
Log.Info(
|
|
"CombatScheduler phase started. Level={0}, Phase={1}, EndType={2}, Entries={3}.",
|
|
Runtime.CurrentLevel != null ? Runtime.CurrentLevel.Id : 0,
|
|
Runtime.PhaseLoopRuntime.DisplayPhaseIndex,
|
|
_phase.EndType,
|
|
_spawnEntries != null ? _spawnEntries.Count : 0);
|
|
}
|
|
|
|
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
|
{
|
|
if (Runtime.PhaseLoopRuntime.CurrentPhase == null)
|
|
{
|
|
Coordinator.EnterFailureFallback("CombatScheduler update failed. Current phase is null.");
|
|
return;
|
|
}
|
|
|
|
Runtime.PhaseLoopRuntime.AdvancePhaseElapsed(elapseSeconds);
|
|
Runtime.EnemyManager.OnUpdate(elapseSeconds, realElapseSeconds);
|
|
|
|
if (Coordinator.ShouldEnterSettlementFromActiveState(out bool didCombatWin))
|
|
{
|
|
Coordinator.ChangeState(new CombatSettlementState(Runtime, Coordinator, didCombatWin));
|
|
return;
|
|
}
|
|
|
|
if (Runtime.EnemyManager.IsPhaseSpawnCompleted)
|
|
{
|
|
Coordinator.EnterWaitingForPhaseEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|