private IState CreateDelayState(TimeSpan delay)
        {
            var timer = new TimeTracker(delay);

            return(AnonymousState.Create(t =>
            {
                timer.Update(t);

                if (!timer.Expired)
                {
                    return;
                }

                _fsm.Pop();
            }));
        }
        private IState CreatePortalState()
        {
            var first = true;

            return(AnonymousState.Create(t =>
            {
                if (!first)
                {
                    return;
                }

                first = false;

                var portal = (Portal)Unit.CreateUnitWithRandomEID(DefinitionNames.RANDOM_RIFT_PORTAL);
                portal.SetDespawnTime(TimeSpan.FromMinutes(5));
                portal.AddToZone(Zone, DynamicPosition);
            }));
        }
        private IState CreateWaveState(IEnumerable <RandomFlockInfo> flockInfos, bool isLastWave)
        {
            var first = true;

            return(AnonymousState.Create(t =>
            {
                if (!first)
                {
                    return;
                }

                first = false;

                Task.Run(() =>
                {
                    foreach (var flockInfo in flockInfos)
                    {
                        var f = SpawnFlock(flockInfo.flockID);
                        f.AllMembersDead += flock =>
                        {
                            var membersCount = Flocks.MembersCount();
                            if (membersCount > 0)
                            {
                                return;
                            }

                            _fsm.Pop();

                            if (!isLastWave)
                            {
                                _fsm.Push(CreateDelayState(TimeSpan.FromSeconds(5)));
                            }
                        };

                        Logger.DebugInfo($"Flock spawned: {f}");
                    }
                });
            }));
        }