Exemplo n.º 1
0
        public override void Update(float frameTime)
        {
            base.Update(frameTime);

            if (!RuleStarted)
            {
                return;
            }

            if (_timeUntilNextEvent > 0)
            {
                _timeUntilNextEvent -= frameTime;
                return;
            }

            // No point hammering this trying to find events if none are available
            var stationEvent = FindEvent(AvailableEvents());

            if (stationEvent == null ||
                !_prototype.TryIndex <GameRulePrototype>(stationEvent.Id, out var proto))
            {
                return;
            }

            GameTicker.AddGameRule(proto);
            ResetTimer();
            _sawmill.Info($"Started event {proto.ID}. Next event in {_timeUntilNextEvent} seconds");
        }
Exemplo n.º 2
0
        private bool CanRun(StationEventRuleConfiguration stationEvent, int playerCount, TimeSpan currentTime)
        {
            if (GameTicker.IsGameRuleStarted(stationEvent.Id))
            {
                return(false);
            }

            if (stationEvent.MaxOccurrences.HasValue && GetOccurrences(stationEvent) >= stationEvent.MaxOccurrences.Value)
            {
                return(false);
            }

            if (playerCount < stationEvent.MinimumPlayers)
            {
                return(false);
            }

            if (currentTime != TimeSpan.Zero && currentTime.TotalMinutes < stationEvent.EarliestStart)
            {
                return(false);
            }

            var lastRun = TimeSinceLastEvent(stationEvent);

            if (lastRun != TimeSpan.Zero && currentTime.TotalMinutes <
                stationEvent.ReoccurrenceDelay + lastRun.TotalMinutes)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the events that have met their player count, time-until start, etc.
        /// </summary>
        /// <param name="ignoreEarliestStart"></param>
        /// <returns></returns>
        private List <StationEventRuleConfiguration> AvailableEvents(bool ignoreEarliestStart = false)
        {
            TimeSpan currentTime;
            var      playerCount = _playerManager.PlayerCount;

            // playerCount does a lock so we'll just keep the variable here
            if (!ignoreEarliestStart)
            {
                currentTime = GameTicker.RoundDuration();
            }
            else
            {
                currentTime = TimeSpan.Zero;
            }

            var result = new List <StationEventRuleConfiguration>();

            foreach (var stationEvent in AllEvents())
            {
                if (CanRun(stationEvent, playerCount, currentTime))
                {
                    result.Add(stationEvent);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
    void Awake()
    {
        var state     = Game.GameState;
        var levelData = Resources.Load <GameWorldData>($"LevelDesign/Level{state.Level}");

        Application.targetFrameRate = 60;
        GameTicker.StartTicking(levelData);
    }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Map          map          = new Map();
            Bird         bird         = new Bird(5, 3);
            GameRenderer gameRenderer = new GameRenderer(map, bird);

            System.Timers.Timer timer     = new System.Timers.Timer(200); // Timeris 200ms
            GameRules           gameRules = new GameRules(map, bird, timer);
            GameTicker          game      = new GameTicker(gameRules, gameRenderer, timer);
        }
Exemplo n.º 6
0
 private void PresetSystem()
 {
     AssetUtils.isPlayingMode      = true;
     NativeManager.debugConfigHttp = configHttp;
     FileTools.Start();
     TickerCenter.Init();
     GameTicker.Start();
     NavCpp.Start();
     CppCenter.Start();
     GlobalLogger.writeLogFile = false;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Randomly run a valid event <b>immediately</b>, ignoring earlieststart or whether the event is enabled
        /// </summary>
        /// <returns></returns>
        public string RunRandomEvent()
        {
            var randomEvent = PickRandomEvent();

            if (randomEvent == null ||
                !_prototype.TryIndex <GameRulePrototype>(randomEvent.Id, out var proto))
            {
                return(Loc.GetString("station-event-system-run-random-event-no-valid-events"));
            }

            GameTicker.AddGameRule(proto);
            return(Loc.GetString("station-event-system-run-event", ("eventName", randomEvent.Id)));
        }
Exemplo n.º 8
0
        protected override async Task OnInitializedAsync()
        {
            Api.OnUsersInRoom((users) =>
            {
                usersInGroup.Clear();
                usersInGroup.AddRange(users);
                StateHasChanged();
            });

            Api.OnShuffled(async(onshuffledResponse) => {
                await BoggleBoard.InitializeBoard(onshuffledResponse.Letters);
                OnShuffled(onshuffledResponse.RoomStatus);
            });

            Api.OnTimeLeft((timeRemained) =>
            {
                GameTicker.WriteRemainingTime(int.Parse(timeRemained));
            });


            user = await UserContext.GetUser();

            username = user?.Username;

            if (user == null || string.IsNullOrEmpty(user?.Username))
            {
                NavigationManager.NavigateToIndex();
            }
            else
            {
                if (!Api.IsConnected)
                {
                    await Api.JoinRoom(user.Id, room.Id, true);
                }

                var roomResult = await Api.GetRoom(user.Id, RoomId);

                if (roomResult.IsValid)
                {
                    await InitializeRoom(roomResult.Value);

                    StateHasChanged();
                }
                else
                {
                    NavigationManager.NavigateToIndex();
                }
            }
        }
 public override void OnInspectorGUI()
 {
     //_space.prefab =
     //    (GameObject) EditorGUILayout.ObjectField("Model Prefab", _space.prefab, typeof (GameObject), false);
     base.OnInspectorGUI();
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     if (Application.isPlaying && GUILayout.Button("Play", GUILayout.Width(100)))
     {
         TickerCenter.Init();
         GameTicker.Start();
         _space.Play();
     }
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
 }
        /// <summary>
        ///     Called every tick when this event is running.
        ///     Events are responsible for their own lifetime, so this handles starting and ending after time.
        /// </summary>
        public override void Update(float frameTime)
        {
            if (!RuleAdded || Configuration is not StationEventRuleConfiguration data)
            {
                return;
            }

            Elapsed += frameTime;

            if (!RuleStarted && Elapsed >= data.StartAfter)
            {
                GameTicker.StartGameRule(PrototypeManager.Index <GameRulePrototype>(Prototype));
            }

            if (RuleStarted && Elapsed >= data.EndAfter)
            {
                GameTicker.EndGameRule(PrototypeManager.Index <GameRulePrototype>(Prototype));
            }
        }
 protected void ForceEndSelf()
 {
     GameTicker.EndGameRule(PrototypeManager.Index <GameRulePrototype>(Prototype));
 }
Exemplo n.º 12
0
    public override void Update(float frameTime)
    {
        if (!RuleAdded)
        {
            return;
        }

        // If the restart timer is active, that means the round is ending soon, no need to check for winners.
        // TODO: We probably want a sane, centralized round end thingie in GameTicker, RoundEndSystem is no good...
        if (_restartTimer != null)
        {
            _restartTimer -= frameTime;

            if (_restartTimer > 0f)
            {
                return;
            }

            GameTicker.EndRound();
            GameTicker.RestartRound();
            return;
        }

        if (!_cfg.GetCVar(CCVars.GameLobbyEnableWin) || _deadCheckTimer == null)
        {
            return;
        }

        _deadCheckTimer -= frameTime;

        if (_deadCheckTimer > 0)
        {
            return;
        }

        _deadCheckTimer = null;

        IPlayerSession?winner = null;

        foreach (var playerSession in _playerManager.ServerSessions)
        {
            if (playerSession.AttachedEntity is not {
                Valid: true
            } playerEntity ||
                !TryComp(playerEntity, out MobStateComponent? state))
            {
                continue;
            }

            if (!state.IsAlive())
            {
                continue;
            }

            // Found a second person alive, nothing decided yet!
            if (winner != null)
            {
                return;
            }

            winner = playerSession;
        }

        _chatManager.DispatchServerAnnouncement(winner == null
            ? Loc.GetString("rule-death-match-check-winner-stalemate")
            : Loc.GetString("rule-death-match-check-winner", ("winner", winner)));

        _chatManager.DispatchServerAnnouncement(Loc.GetString("rule-restarting-in-seconds", ("seconds", RestartDelay)));
        _restartTimer = RestartDelay;
    }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new audio effect instance.
 /// </summary>
 /// <param name="minTimeBetweenSoundEffect">The minimum time between two of those audio effects.</param>
 public AudioEffect(float minTimeBetweenSoundEffect)
 {
     minTimeBetweenSoundEffectTimer = new GameTicker(minTimeBetweenSoundEffect);
 }
 public void Start()
 {
     GameTicker.Start();
     TickerCenter.Init();
 }