Esempio n. 1
0
        private async Task HandleColissionsAsync(IPlayerActor currentPlayer)
        {
            var player    = currentPlayer.GetPrimaryKeyString();
            var opponents = State.Players.ExceptOf(player)
                            .Select(opponent => _grainFactory.GetGrain <IPlayerActor>(opponent))
                            .ToList();

            var collissionResult = await _collisionDetector.DetectCollision(currentPlayer, opponents);

            if (collissionResult.IsEmpty())
            {
                return;
            }

            var score = await _scoreCalculator.CalculateScore(collissionResult.Winner, collissionResult.Loosers);

            var winner = collissionResult.Winner.GetPrimaryKeyString();
            await _eventBus.PublishPlayersScoreIncreasedEvent(winner, score);

            foreach (var looser in collissionResult.Loosers)
            {
                var looserName = looser.GetPrimaryKeyString();
                await _eventBus.PublishPlayerDeadEvent(looserName);

                State.Players.Remove(looserName);
            }

            await WriteStateAsync();
        }
Esempio n. 2
0
        private async Task RegisterPlayerIfRequired(IPlayerActor player)
        {
            var playerName      = player.GetPrimaryKeyString();
            var currentlyInZone = State.Players.Contains(playerName);

            if (!currentlyInZone)
            {
                State.Players.Add(playerName);
                await WriteStateAsync();
            }
        }