geometry-tower-defense/Assets/GameMain/Scripts/CustomComponent/CombatNode/CombatScheduler/CombatStates/CombatRunningPhaseState.cs

76 lines
2.7 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(
CombatSchedulerRuntimeContext context,
CombatSchedulerFlowCoordinator flow,
DRLevelPhase phase,
IReadOnlyList<DRLevelSpawnEntry> spawnEntries) : base(context, flow)
{
_phase = phase;
_spawnEntries = spawnEntries;
}
public override void OnEnter()
{
Context.EnemyManager.BeginPhase(_phase, _spawnEntries);
GameEntry.Event.Fire(
Flow,
CombatProcessEventArgs.Create(
Context.PhaseLoopRuntime.DisplayPhaseIndex,
Context.PhaseLoopRuntime.PhaseCount));
GameEntry.Event.Fire(
Flow,
CombatEnemyHpRateChangedEventArgs.Create(
Flow.ResolveEnemyHpRateMultiplier(
Context.PhaseLoopRuntime.DisplayPhaseIndex,
Context.PhaseLoopRuntime.PhaseCount)));
if (!Context.NodeEnterFired)
{
Context.NodeEnterFired = true;
GameEntry.Event.Fire(Flow, NodeEnterEventArgs.Create());
}
Log.Info(
"CombatScheduler phase started. Level={0}, Phase={1}, EndType={2}, Entries={3}.",
Context.CurrentLevel != null ? Context.CurrentLevel.Id : 0,
Context.PhaseLoopRuntime.DisplayPhaseIndex,
_phase.EndType,
_spawnEntries != null ? _spawnEntries.Count : 0);
}
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
if (Context.PhaseLoopRuntime.CurrentPhase == null)
{
Flow.EnterFailureFallback("CombatScheduler update failed. Current phase is null.");
return;
}
Context.PhaseLoopRuntime.AdvancePhaseElapsed(elapseSeconds);
Context.EnemyManager.OnUpdate(elapseSeconds, realElapseSeconds);
if (Flow.ShouldEnterSettlementFromActiveState(out string reason, out bool isVictory))
{
Flow.Scheduler.ChangeState(new CombatSettlementState(Context, Flow, reason, isVictory));
return;
}
if (Context.EnemyManager.IsPhaseSpawnCompleted)
{
Flow.EnterWaitingForPhaseEnd();
}
}
}
}