using System.Globalization; using GeometryTD.DataTable; using GeometryTD.Definition; namespace GeometryTD.CustomComponent { internal sealed class TimeElapsedPhaseEndCondition : IPhaseEndCondition { public PhaseEndType EndType => PhaseEndType.TimeElapsed; public bool ShouldExit(in PhaseEndConditionContext context) { if (context.Phase == null) { return false; } return context.PhaseElapsedSeconds >= ResolveTimeElapsedThreshold(context.Phase); } private static float ResolveTimeElapsedThreshold(DRLevelPhase phase) { if (!string.IsNullOrWhiteSpace(phase.EndParam) && float.TryParse(phase.EndParam, NumberStyles.Float, CultureInfo.InvariantCulture, out float parsed)) { return parsed; } if (phase.DurationSeconds > 0) { return phase.DurationSeconds; } return 0f; } } }