/// <summary> /// Called on every tick of the game. Allows AiEntityManagers to perform actions and respawns /// removed Entities. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnGameTick(object sender, GameTickEventArgs args) { Ticks++; if (Ticks >= _ticksPerSecond) { Ticks = 0; foreach (var manager in _managers) { manager.OnGameTick(); } RespawnEntity(); } }
private void OnGameTick(object sender, GameTickEventArgs args) { _ticks++; if (_ticks < 1000 / _MovementsPerSecond / GameplayConstants.GameTicksPerSecond) { return; } _ticks = 0; bool success = false; bool isMovementStopped = false; // Don't move if wrong state if (_stateManager.GetPlayerState(PlayerId) != PlayerStateConstants.Free) { return; } lock (_lock) { while (!success && _movementQueue.Count > 0) { success = TryMoveEntity(_movementQueue.Dequeue()); } isMovementStopped = _movementQueue.Count <= 0; if (isMovementStopped) { PerformAction(); } } if (isMovementStopped && _canInvokeMovementStopped) { Task.Run(() => OnMovementStopped?.Invoke(this, new System.EventArgs())); _canInvokeMovementStopped = false; } }