78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using GeometryTD.CustomEvent;
|
|
using GeometryTD.DataTable;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
public partial class CombatScheduler
|
|
{
|
|
private sealed class CombatRunningPhaseState : CombatStateBase
|
|
{
|
|
private readonly DRLevelPhase _phase;
|
|
private readonly IReadOnlyList<DRLevelSpawnEntry> _spawnEntries;
|
|
|
|
public CombatRunningPhaseState(
|
|
CombatScheduler scheduler,
|
|
DRLevelPhase phase,
|
|
IReadOnlyList<DRLevelSpawnEntry> spawnEntries) : base(scheduler)
|
|
{
|
|
_phase = phase;
|
|
_spawnEntries = spawnEntries;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
Scheduler._enemyManager.BeginPhase(_phase, _spawnEntries);
|
|
GameEntry.Event.Fire(
|
|
Scheduler,
|
|
CombatProcessEventArgs.Create(
|
|
Scheduler._phaseLoopRuntime.DisplayPhaseIndex,
|
|
Scheduler._phaseLoopRuntime.PhaseCount));
|
|
GameEntry.Event.Fire(
|
|
Scheduler,
|
|
CombatEnemyHpRateChangedEventArgs.Create(
|
|
ResolveEnemyHpRateMultiplier(
|
|
Scheduler._phaseLoopRuntime.DisplayPhaseIndex,
|
|
Scheduler._phaseLoopRuntime.PhaseCount)));
|
|
|
|
if (!Scheduler._nodeEnterFired)
|
|
{
|
|
Scheduler._nodeEnterFired = true;
|
|
GameEntry.Event.Fire(Scheduler, NodeEnterEventArgs.Create());
|
|
}
|
|
|
|
Log.Info(
|
|
"CombatScheduler phase started. Level={0}, Phase={1}, EndType={2}, Entries={3}.",
|
|
Scheduler._currentLevel != null ? Scheduler._currentLevel.Id : 0,
|
|
Scheduler._phaseLoopRuntime.DisplayPhaseIndex,
|
|
_phase.EndType,
|
|
_spawnEntries != null ? _spawnEntries.Count : 0);
|
|
}
|
|
|
|
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
|
{
|
|
if (Scheduler._phaseLoopRuntime.CurrentPhase == null)
|
|
{
|
|
Scheduler.EnterFailureFallback("CombatScheduler update failed. Current phase is null.");
|
|
return;
|
|
}
|
|
|
|
Scheduler._phaseLoopRuntime.AdvancePhaseElapsed(elapseSeconds);
|
|
Scheduler._enemyManager.OnUpdate(elapseSeconds, realElapseSeconds);
|
|
|
|
if (Scheduler.ShouldEnterSettlementFromActiveState(out string reason, out bool isVictory))
|
|
{
|
|
Scheduler.ChangeState(new CombatSettlementState(Scheduler, reason, isVictory));
|
|
return;
|
|
}
|
|
|
|
if (Scheduler._enemyManager.IsPhaseSpawnCompleted)
|
|
{
|
|
Scheduler.EnterWaitingForPhaseEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|