public void Update() { var statePushDto = new StatePushDto(); switch (_pushDataState) { case PushDataState.None: return; case PushDataState.First: statePushDto.AddedBlobs = Mapper.Map <BlobDto[]>(_game.Blobs); statePushDto.RemovedBlobs = new BlobDto[] { }; statePushDto.UpdatedBlobs = new BlobDto[] { }; _pushDataState = PushDataState.Continue; break; case PushDataState.Continue: statePushDto.AddedBlobs = Mapper.Map <BlobDto[]>(_stateTracker.AddedBlobs); statePushDto.RemovedBlobs = Mapper.Map <BlobDto[]>(_stateTracker.RemovedBlobs); statePushDto.UpdatedBlobs = Mapper.Map <BlobDto[]>(_stateTracker.UpdatedBlobs); break; } statePushDto.WorldSize = _game.Size; statePushDto.TurnEndTime = _game.TurnEndInstant.ToDateTimeUtc(); statePushDto.GameModeType = GameModeType.Classic; statePushDto.CustomGameModeData = _game.GameMode.GetCustomData().ToJson(); Send(statePushDto); }
private void PublishPlayerEvents(StatePushDto pushData) { var worldSize = pushData.WorldSize; var addedPlayers = pushData.AddedBlobs.Where(b => b.Type == BlobType.Player); var updatedPlayers = pushData.UpdatedBlobs.Where(b => b.Type == BlobType.Player); var removedPlayers = pushData.RemovedBlobs.Where(b => b.Type == BlobType.Player); _executeOnMainThread.Enqueue(() => _eventAggregator.Publish(new PlayersEvent(addedPlayers, BlobEventType.BlobAdded, worldSize))); _executeOnMainThread.Enqueue(() => _eventAggregator.Publish(new PlayersEvent(updatedPlayers, BlobEventType.BlobUpdated, worldSize))); _executeOnMainThread.Enqueue(() => _eventAggregator.Publish(new PlayersEvent(removedPlayers, BlobEventType.BlobRemoved, worldSize))); }
public void Handle(StatePushDto pushData) { var customDataText = pushData.CustomGameModeData; var customData = customDataText.FromJson <ClassicGameModeDataDto>(); var playerStats = customData.PlayerStats; PublishScoreUpdatedEvent(playerStats); PublishFoodEvents(pushData); PublishVirusEvents(pushData); PublishPlayerEvents(pushData); }