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
 public ShutdownActor(IPlayerActor playerActor, ILogger <ShutdownActor> logger, IBassActor bassActor)
 {
     _playerActor  = playerActor;
     _logger       = logger;
     _bassActor    = bassActor;
     _appDirectory = AppDomain.CurrentDomain.BaseDirectory;
 }
Esempio n. 3
0
        public async Task <int> CalculateScore(IPlayerActor winner, ICollection <IPlayerActor> loosers)
        {
            var tasks = loosers.Select(looser => looser.GetState());
            var sizes = await Task.WhenAll(tasks);

            return(sizes.Select(x => x.SpriteSize).Sum());
        }
Esempio n. 4
0
        public void StartLoop(GameLoopType startType)
        {
            _playerActor         = GetPlayerActor();
            _bananaTreeGenerator = new BananaTreeGenerator(_playerActor.GameObject.transform, _gameSettings, _audioPlayer);

            // HACK. 面倒なので全オブジェクト拾ってきてinterfaceを対象に初期化していく.
            var objs = Object.FindObjectsOfType <GameObject>();

            foreach (var obj in objs)
            {
                // Presenterを初期化.
                foreach (var presenter in obj.GetComponents <IPresenter>())
                {
                    presenter.Initialize(this);
                }

                // ECS利用箇所にPresenterを流し込む
                foreach (var usable in obj.GetComponents <IECSProviderUsable>())
                {
                    usable.SetProvider(_ecsProvider);
                }
            }

            SetLoop(startType);
        }
Esempio n. 5
0
 public PushButtonMonitor(IPlayerActor playerActor, ILogger <PushButtonMonitor> logger, IBassActor bassActor, IShutdownActor shutdownActor)
 {
     this.playerActor  = playerActor;
     this.logger       = logger;
     this.bassActor    = bassActor;
     this.AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
     _shutdownActor    = shutdownActor;
 }
Esempio n. 6
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();
            }
        }
 public MorningAlarmWorker(IPlayerActor playerActor, ILogger <MorningAlarmWorker> logger, ILibraryActor libraryActor)
 {
     this.playerActor        = playerActor;
     this.logger             = logger;
     this.libraryActor       = libraryActor;
     this.previousVolume     = playerActor.BassActor.CurrentVolume;
     this.AlarmConfiguration = new AlarmConfiguration()
     {
         AlarmTime                 = TimeSpan.FromHours(6),
         AlarmMissThreshold        = TimeSpan.FromMinutes(20),
         AlarmAutoTurnOffCheckTime = TimeSpan.FromHours(8),
         Enabled     = true,
         MediaItemId = 1
     };
 }
        public async Task <CollisionResult> DetectCollision(IPlayerActor player, ICollection <IPlayerActor> opponents)
        {
            var collissionChecks = await Task.WhenAll(opponents
                                                      .Select(opponent => IsCollidedWith(player, opponent)));

            var collided = collissionChecks
                           .Where(x => x.IsCollided)
                           .Select(x => x.Target);

            var sortedDictionary = new SortedDictionary <int, List <IPlayerActor> >();

            foreach (var grain in collided.Append(player))
            {
                var info = await grain.GetState();

                if (!sortedDictionary.ContainsKey(info.SpriteSize))
                {
                    sortedDictionary.Add(info.SpriteSize, new List <IPlayerActor>());
                }

                sortedDictionary[info.SpriteSize].Add(grain);
            }

            var loosers = sortedDictionary
                          .Take(sortedDictionary.Count - 1)
                          .SelectMany(k => k.Value)
                          .ToList();

            var winner = sortedDictionary.Count > 1 ? sortedDictionary.LastOrDefault().Value?.LastOrDefault() : null;

            var result = new CollisionResult
            {
                Loosers = loosers,
                Winner  = winner,
            };

            return(result);
        }
        private static async Task <CollissionCheck> IsCollidedWith(IPlayerActor player, IPlayerActor targetPlayer)
        {
            var playerInfo = await player.GetState();

            var targetInfo = await targetPlayer.GetState();

            var position       = playerInfo.Position;
            var targetPosition = targetInfo.Position;

            var dx = position.X - targetPosition.X;
            var dy = position.Y - targetPosition.Y;

            var distance = Math.Sqrt(dx * dx + dy * dy);

            var radius       = playerInfo.SpriteSize;
            var tartedRadius = targetInfo.SpriteSize;

            return(new CollissionCheck
            {
                Target = targetPlayer,
                IsCollided = distance < radius + tartedRadius
            });
        }
Esempio n. 10
0
 public async Task RoutePlayerMovement(IPlayerActor player)
 {
     await RegisterPlayerIfRequired(player);
     await HandleColissionsAsync(player);
 }
Esempio n. 11
0
 public LibraryStatusHub(IPlayerActor playerActor)
 {
     PlayerActor = playerActor;
 }
Esempio n. 12
0
 public PlayerController(IPlayerActor actor) => _playerActor = actor;
Esempio n. 13
0
 public PlayerController()
 {
     player       = DependencyActor.Container.Resolve <IPlayerActor>();
     libraryActor = DependencyActor.Container.Resolve <ILibraryActor>();
 }
Esempio n. 14
0
 public StatusNotificationWorker(IHubContext <PlayerStatusHub, IPlayerStatusHub> playerHub, IPlayerActor playerActor)
 {
     PlayerStatusHub = playerHub;
     PlayerActor     = playerActor;
 }
Esempio n. 15
0
 public PlayerStatusHub(IPlayerActor playerActor, ILibraryActor libraryActor)
 {
     PlayerActor  = playerActor;
     LibraryActor = libraryActor;
 }