Exemplo n.º 1
0
        private void ProcessTurn()
        {
            while (true)
            {
                Command command;
                if (gameState.Scheduler.Current().Conditions.Any(c => c is StunnedCondition))
                {
                    command = new WaitCommand(gameState.Scheduler.Current());
                }
                else
                {
                    command = gameState.Scheduler.Current().Act(gameState);
                }

                var turnEnded = CommandProcessor.ProcessCommand(command, gameState);

                if (turnEnded)
                {
                    var currentActor = gameState.Scheduler.Current();
                    currentActor.Conditions.ForEach(c => c.TimePasses());
                    currentActor.Conditions.RemoveAll(c => c.TimeLeft <= 0);
                    gameState.Scheduler.Next();
                    if (gameState.Scheduler.Current().Role == ActorRole.Inflirtator)
                    {
                        CheckForAlertLevel    = true;
                        gameState.CurrentTime = gameState.CurrentTime.AddSeconds(1);
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private IEnumerator <WaitCommand> PunchTimeoutCleanup()
        {
            var cancellableRegistrations = new List <ConnectionId>();

            while (true)
            {
                cancellableRegistrations.Clear();
                var connectionAttemptRegistrations = _punchAttempts.Values.ToListOptimized();
                for (int i = 0; i < connectionAttemptRegistrations.Count; i++)
                {
                    var registration = connectionAttemptRegistrations[i];
                    if (registration.Instance.Timestamp + _connectionAttemptTimeout < Time.realtimeSinceStartup ||
                        IsCancelled(registration.Instance))
                    {
                        registration.Instance.OnConnectionFailure(registration.Instance.PublicEndpoint, exception: null);
                        cancellableRegistrations.Add(registration.Instance.ConnectionId);
                    }
                }

                for (int i = 0; i < cancellableRegistrations.Count; i++)
                {
                    var connectionId = cancellableRegistrations[i];
                    CancelConnectionAttempt(connectionId);
                }

                yield return(WaitCommand.WaitSeconds(_connectionAttemptTimeout));
            }
        }
        public void OnWaitCommand(WaitCommand command)
        {
            if (insideLoop)
            {
                loopCommands.Add(command);
                return;
            }

            string time = command.Time.Replace(LOOPSTRING, currentRep.ToString());

            if (int.TryParse(time, out int sleepTime))
            {
                Console.WriteLine(
                    "[{0}] Waiting {1}",
                    DateTime.Now.ToString("HH:mm:ss"),
                    time);
                Thread.Sleep(sleepTime);
            }
            else
            {
                Console.WriteLine(
                    "[{0}] Error parsing time",
                    DateTime.Now.ToString("HH:mm:ss"));
            }
        }
Exemplo n.º 4
0
        IEnumerator <WaitCommand> OnExit()
        {
            _closeListener.Dispose();
            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeOut(_data.CameraManager.Rig.ScreenFader, _data.Clock, _data.FaderSettings)));

            _data.CourseEditor.enabled = false;
        }
Exemplo n.º 5
0
        private IEnumerator <WaitCommand> LogoFadeIn()
        {
            yield return(WaitCommand.WaitSeconds(_data.LogoDelayInS));

            _data.Logo.Show(true);
            _logoFadeIn = Disposables.Empty;
        }
Exemplo n.º 6
0
        public static IEnumerator ToUnity(this WaitCommand waitCommand, StartRoutine startRoutine)
        {
            if (waitCommand.IsRoutine)
            {
                var runningRoutines = new UnityEngine.Coroutine[waitCommand.RoutineCount];
                for (int i = 0; i < waitCommand.RoutineCount; i++)
                {
                    var routine        = waitCommand.GetRoutine(i).ToUnity(startRoutine);
                    var runningRoutine = startRoutine(routine);
                    runningRoutines[i] = runningRoutine;
                }

                for (int i = 0; i < runningRoutines.Length; i++)
                {
                    var runningRoutine = runningRoutines[i];
                    yield return(runningRoutine);
                }
            }
            else
            {
                if (waitCommand.Duration.Value.Seconds > 0f)
                {
                    yield return(new WaitForSeconds(waitCommand.Duration.Value.Seconds));
                }
                else
                {
                    for (int i = 0; i < waitCommand.Duration.Value.FrameCount; i++)
                    {
                        yield return(null);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public FluentSessionRecorder Wait(TimeSpan duration)
        {
            var command = new WaitCommand(duration);

            _performer.Perform(command);

            return(this);
        }
Exemplo n.º 8
0
 static IEnumerator <WaitCommand> InterleaveTest()
 {
     yield return(WaitCommand.Interleave(
                      WaitSeconds("z", 5),
                      InterleaveTest("a"),
                      InterleaveTest("b"),
                      InterleaveTest("c")));
 }
Exemplo n.º 9
0
        public void Wait(
            string Trig, string Next,
            double Time
            )
        {
            WaitCommand cmd = new WaitCommand(inWaitTimeSec: Time, inNext: Next);

            PublicController.Instance.Register(Trig, cmd);
        }
Exemplo n.º 10
0
 public EventCommandWait(WaitCommand refCommand, FrmEvent editor)
 {
     InitializeComponent();
     mMyCommand   = refCommand;
     mEventEditor = editor;
     InitLocalization();
     nudWait.Value = mMyCommand.Time;
     lblWait.Text  = Strings.EventWait.label;
 }
Exemplo n.º 11
0
        IEnumerator <WaitCommand> NotifyAboutParachute()
        {
            yield return(WaitCommand.Wait(30.Seconds()));

            if (_unfoldParachuteMappingStr != null)
            {
                _data.NotificationList.AddTimedNotification("Did you know you can press <i>" + _unfoldParachuteMappingStr + "</i> to open your parachute?", 10.Seconds());
                _openParachuteNotification = Disposables.Empty;
            }
        }
        public void WaitCommandNoArguments()
        {
            var command = ParseCommand("wait");

            Assert.IsTrue(command is WaitCommand);
            WaitCommand waitCommand = (WaitCommand)command;

            Assert.AreEqual(1, CastNumber(waitCommand.waitInterval.GetValue()).GetNumericValue());
            Assert.AreEqual(UnitType.TICKS, waitCommand.units);
        }
        public void WaitCommandInterval()
        {
            var command = ParseCommand("wait 3");

            Assert.IsTrue(command is WaitCommand);
            WaitCommand waitCommand = (WaitCommand)command;

            Assert.AreEqual(3, CastNumber(waitCommand.waitInterval.GetValue()).GetNumericValue());
            Assert.AreEqual(UnitType.SECONDS, waitCommand.units);
        }
Exemplo n.º 14
0
    private IEnumerator <WaitCommand> RegisterAtMasterServer(string hostName)
    {
        while (!_ramnet.NatFacilitatorConnection.ExternalEndpoint.IsResultAvailable)
        {
            yield return(WaitCommand.WaitForNextFrame);
        }
        var externalEndpoint = _ramnet.NatFacilitatorConnection.ExternalEndpoint.Result;

        var isRegistrationSuccessful = false;

        while (true)
        {
            while (!isRegistrationSuccessful)
            {
                var registrationConfirmation = Coroutine.FromCallback <HttpStatusCode>(callback => {
                    Debug.Log("External endpoint is: " + externalEndpoint);
                    var request = new HostRegistrationRequest(hostName,
                                                              new PeerInfo(externalEndpoint, _transporter.InternalEndpoint),
                                                              shouldAdvertise: true,
                                                              version: VersionInfo.VersionNumber);
                    _masterServerClient.Client.RegisterHost(_authToken, request, callback);
                });
                while (!registrationConfirmation.IsResultAvailable)
                {
                    yield return(WaitCommand.WaitForNextFrame);
                }

                if (registrationConfirmation.Result != HttpStatusCode.OK)
                {
                    Debug.LogWarning("Failed to register at the master server due to: " + registrationConfirmation.Result);
                }
                else
                {
                    isRegistrationSuccessful = true;
                    Debug.Log("Successfully registered at master server");
                }

                yield return(WaitCommand.WaitSeconds(3f));
            }

            while (isRegistrationSuccessful)
            {
                yield return(WaitCommand.WaitSeconds(30f));

                var asyncResult = Coroutine.FromCallback <HttpStatusCode>(callback => {
                    _masterServerClient.Client.Ping(_authToken, externalEndpoint, callback);
                });
                while (!asyncResult.IsResultAvailable)
                {
                    yield return(WaitCommand.WaitForNextFrame);
                }
                isRegistrationSuccessful = asyncResult.Result == HttpStatusCode.OK;
            }
        }
    }
        public void WaitCommandIntervalUnits()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("wait 3 ticks");

            Assert.IsTrue(command is WaitCommand);
            WaitCommand waitCommand = (WaitCommand)command;

            Assert.AreEqual(3, CastNumber(waitCommand.waitInterval.GetValue()).GetTypedValue());
            Assert.AreEqual(Unit.TICKS, waitCommand.units);
        }
Exemplo n.º 16
0
 private IEnumerator <WaitCommand> ExitOldState()
 {
     _isTransitioning = true;
     while (_stack.Count > 0)
     {
         var state = _stack.Pop();
         UnsubscribeToStateMethods(state);
         yield return(WaitCommand.WaitRoutine(InvokeStateLifeCycleMethod(state.OnExit)));
     }
     _isTransitioning = false;
 }
Exemplo n.º 17
0
        IEnumerator <WaitCommand> OnExit()
        {
            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeOut(_data.CameraManager.Rig.ScreenFader, _data.MenuClock, _data.FaderSettings)));

            _playingStateMachine.Transition(PlayingStates.Initial);

            yield return(_data.PlayerPilotSpawner.Despawn().AsWaitCommand());

            _data.ChallengeAnnouncerUi.enabled        = false;
            _data.JoystickActivator.enabled           = true;
            _data.ThirdPersonCameraController.enabled = false;
        }
Exemplo n.º 18
0
        IEnumerator <WaitCommand> OnExit()
        {
            OnSuspend();

            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeOut(_data.CameraManager.Rig.ScreenFader, _data.MenuClock, _data.FaderSettings)));

            _data.CameraAnimator.enabled = false;
            var spawnpointBillboards = _uiState.To(s => s.SpawnpointUIList).To(s => s.Items).Get();

            for (int i = 0; i < spawnpointBillboards.Count; i++)
            {
                spawnpointBillboards[i].SetActive(false);
            }
        }
Exemplo n.º 19
0
        static IEnumerator <WaitCommand> Subroutine(bool hasSubroutine, string prefix)
        {
            yield return(WaitCommand.Wait(5f.Seconds()));

            if (hasSubroutine)
            {
                yield return(WaitCommand.Interleave(
                                 Subroutine(false, prefix + prefix),
                                 Subroutine(false, prefix + prefix + "2")));
            }
            yield return(WaitCommand.DontWait);

            Console.WriteLine(prefix + " subroutine");
        }
Exemplo n.º 20
0
        // When exiting always transition to spawnpoint selection
        // Allow options menu to be enabled

        IEnumerator <WaitCommand> OnEnter()
        {
            _data.CourseEditor.enabled = true;

            var currentCameraTransform = _data.CameraManager.Rig.transform.MakeImmutable();

            _data.Mount.transform.Set(currentCameraTransform);
            _data.CameraManager.SwitchMount(_data.Mount);

            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeIn(_data.CameraManager.Rig.ScreenFader, _data.Clock, _data.FaderSettings)));

            _closeListener = _data.CourseEditor.CloseEditor.Subscribe(_ => {
                Machine.Transition(VoloStateMachine.States.SpawnScreen);
            });
        }
Exemplo n.º 21
0
        private IEnumerator <WaitCommand> PingRepeatedly(ConnectionId hostId)
        {
            while (true)
            {
                var pingMessage = _networkSystems.MessagePool.GetMessage <BasicMessage.Ping>();
                pingMessage.Content.FrameId = _frameId;

                //Debug.Log("sending ping in frame " + Time.frameCount + " with frame id " + _frameId + " current time " + _localRealtimeClock.CurrentTime);
                _outstandingPings.Add(new OutstandingPing(_frameId, _localRealtimeClock.CurrentTime));
                _frameId++;

                _networkSystems.MessageSender.Send(hostId, pingMessage);
                yield return(WaitCommand.WaitSeconds(1f));
            }
        }
Exemplo n.º 22
0
        private IEnumerator <WaitCommand> BeginChallenge(IChallenge challenge, FlightStatistics player)
        {
            if (_isChallengeStarting)
            {
                Debug.LogError("Challenge '" + challenge.Name + "' start is triggered while another challenge '" +
                               _activeChallenge.Value.Name + "' is already starting");
                yield break;
            }
            _isChallengeStarting = true;
            Debug.Log("Starting challenge: " + challenge.Name);
            yield return(WaitCommand.Interleave(
                             challenge.Begin(player),
                             _challengeAnnouncerUi.Introduce(challenge.ChallengeType.PrettyString(), Color.white, challenge.Name)));

            _isChallengeStarting = false;
        }
Exemplo n.º 23
0
        public void Execute_WaitOneSecond_DelayOfOnesecond()
        {
            var waitArgs = Mock.Of <IWaitCommandArgs>
                           (
                c => c.MilliSeconds == new LiteralScalarResolver <int>("1000")
                           );
            var command = new WaitCommand(waitArgs);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            command.Execute();
            stopWatch.Stop();
            Console.WriteLine($"Visible wait equal to { stopWatch.ElapsedMilliseconds} ms");
            Assert.That(stopWatch.ElapsedMilliseconds, Is.GreaterThanOrEqualTo(1000));
        }
Exemplo n.º 24
0
        public override bool Evaluate(GameContext context, Actor actor, IEnumerable <GameCell> choices)
        {
            var walkable = context.Level.GetCellAndAdjacent(actor.Pos);
            var option   = walkable.Where(o => !o.HasNonActorObstacle).GetRandomElement(context.Randomizer);

            if (option.Pos == actor.Pos)
            {
                WaitCommand.Execute(context, actor, actor.Pos, false);
            }
            else
            {
                MoveCommand.Execute(context, actor, option.Pos, false);
            }

            return(true);
        }
Exemplo n.º 25
0
        IEnumerator <WaitCommand> OnEnter()
        {
            _data.CameraManager.SwitchMount(_data.CameraMount.GetComponent <ICameraMount>());

            var spawnpointBillboards = _uiState.To(s => s.SpawnpointUIList).To(s => s.Items).Get();

            for (int i = 0; i < _spawnpoints.Count; i++)
            {
                var spawnpoint = _spawnpoints[i];
                spawnpointBillboards[i].SetActive(spawnpoint.IsDiscovered);
            }

            OnResume();

            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeIn(_data.CameraManager.Rig.ScreenFader, _data.MenuClock, _data.FaderSettings)));
        }
Exemplo n.º 26
0
 IEnumerator <WaitCommand> EmitParticles(FlightStatistics player)
 {
     using (var ps = _particleSystemPool.Take()) {
         var velocity = player.WorldVelocity * 2f;
         Debug.Log("player velocty " + player.WorldVelocity);
         var psVelocity = ps.Instance.velocityOverLifetime;
         psVelocity.xMultiplier         = velocity.x;
         psVelocity.yMultiplier         = velocity.y;
         psVelocity.zMultiplier         = velocity.z;
         ps.Instance.transform.position = _transform.position;
         ps.Instance.Play();
         // Wait until the last particle is emitted before disposing it
         yield return(WaitCommand.WaitSeconds(
                          ps.Instance.main.duration +
                          ps.Instance.main.startLifetime.constant));
     }
 }
Exemplo n.º 27
0
        IEnumerator <WaitCommand> OnEnter(SpawnpointLocation spawnpoint)
        {
            _data.ChallengeAnnouncerUi.enabled        = true;
            _data.JoystickActivator.enabled           = false;
            _data.ThirdPersonCameraController.enabled = true;

            // TODO Don't spawn the player this is now the responsisiblity of the wingsuit state
            //yield return _data.PlayerPilotSpawner.Respawn(spawnpoint).AsWaitCommand();

            var environment = new PlayingEnvironment(
                spawnpoint: spawnpoint,
                pilot: null,
                parachuteConfig: _activeParachuteConfig.Get());

            _playingStateMachine.Transition(PlayingStates.FlyingWingsuit, environment, Maybe.Just(new RespawnRequest()));
            yield return(WaitCommand.WaitRoutine(CameraTransitions.FadeIn(_data.CameraManager.Rig.ScreenFader, _data.MenuClock, _data.FaderSettings)));
        }
Exemplo n.º 28
0
        public static IEnumerator <WaitCommand> OnSendRate(float sendRate, MonoBehaviour c, Action send)
        {
            yield return(WaitCommand.WaitForNextFrame);

            while (c != null)
            {
                if (c.enabled)
                {
                    send();
                    yield return(WaitCommand.WaitSeconds(1f / sendRate));
                }
                else
                {
                    yield return(WaitCommand.WaitForNextFrame);
                }
            }
        }
Exemplo n.º 29
0
        public override DronesOutput GetResultFromReader(DronesInput input, TextReader reader)
        {
            var commands     = new List <CommandBase>();
            var commandCount = int.Parse(reader.ReadLine());

            for (int i = 0; i < commandCount; i++)
            {
                var line  = reader.ReadLine();
                var spl   = line.Split(' ');
                var drone = input.Drones[int.Parse(spl[0])];

                var others = spl.Skip(2).Select(int.Parse).ToList();

                CommandBase newCommand;
                switch (spl[1])
                {
                case "D":
                    newCommand = new DeliverCommand(drone, input.Orders[others[0]], input.Products[others[1]], others[2]);
                    break;

                case "W":
                    newCommand = new WaitCommand(drone, (uint)others[0]);
                    break;

                case "U":
                    newCommand = new UnloadCommand(drone, input.WareHouses[others[0]], input.Products[others[1]], others[2]);
                    break;

                case "L":
                    newCommand = new LoadCommand(drone, input.WareHouses[others[0]], input.Products[others[1]], others[2]);
                    break;

                default:
                    throw new ArgumentException(string.Format("Unknown command {0}", spl[1]));
                }

                commands.Add(newCommand);
            }

            return(new DronesOutput {
                Commands = commands
            });
        }
    public IEnumerator <WaitCommand> Animate(Transform mount, Predicate isRunning)
    {
        var pathSelection = _cameraPaths.Paths;
        var selectedPath  = pathSelection.RandomElement();
        var isFirst       = true;

        while (isRunning())
        {
            selectedPath = pathSelection.GetNext(selectedPath);

            if (_gameSettingsProvider.IsVrActive)
            {
                selectedPath = new StaticCameraPath(
                    Routines.LinearAnimation,
                    selectedPath.Duration,
                    selectedPath.To,
                    to: selectedPath.To);
            }

            IEnumerator <WaitCommand> fadeIn;
            if (isFirst)
            {
                fadeIn  = WaitCommand.DontWait.AsRoutine;
                isFirst = false;
            }
            else
            {
                fadeIn = _rig.ScreenFader.FadeIn(_clock, _faderSettings);
            }

            var fadeOut = WaitCommand.Wait(selectedPath.Duration - _faderSettings.FadeOutDuration)
                          .AndThen(_rig.ScreenFader.FadeOut(_clock, _faderSettings));

            var cameraAnimation = CameraAnimator.Animate(mount, selectedPath, _clock);

            yield return(WaitCommand
                         .Interleave(fadeIn, cameraAnimation, fadeOut)
                         .RunWhile(isRunning)
                         .AsWaitCommand());
        }
        _rig.ScreenFader.Opacity = 0f;
    }