コード例 #1
0
        public void BattleEncounterListener(BattleEncounterEvent battleEncounterEvent)
        {
            var battleRunner = new SimpleBattleRunner(battleEncounterEvent.Attacker.GetComponent <Army>(),
                                                      battleEncounterEvent.Defender.GetComponent <Army>());

            battleRunner.Run();

            if (battleRunner.BattleWinner == SimpleBattleRunner.Winner.Attacker)
            {
                ArmyLoseEvent armyLoseEvent =
                    new ArmyLoseEvent(battleEncounterEvent.Defender, battleEncounterEvent.Position);
                _eventBus.Post(armyLoseEvent);
            }
            else if (battleRunner.BattleWinner == SimpleBattleRunner.Winner.Defender)
            {
                ArmyLoseEvent armyLoseEvent =
                    new ArmyLoseEvent(battleEncounterEvent.Attacker, battleEncounterEvent.Position);
                _eventBus.Post(armyLoseEvent);
            }
            else
            {
                ArmyLoseEvent armyLoseEvent =
                    new ArmyLoseEvent(battleEncounterEvent.Attacker, battleEncounterEvent.Position);
                _eventBus.Post(armyLoseEvent);

                armyLoseEvent =
                    new ArmyLoseEvent(battleEncounterEvent.Defender, battleEncounterEvent.Position);
                _eventBus.Post(armyLoseEvent);
            }
        }
コード例 #2
0
        public void MoveInListener(MoveInEvent moveInEvent)
        {
            FindArmyInArea findArmyInArea = new FindArmyInArea(moveInEvent.Current, 1);

            FindArmyInAreaListener(findArmyInArea);

            if (findArmyInArea.Results.Count < 2)
            {
                return;
            }

            Army attacker = findArmyInArea.Results[0].GetComponent <Army>();
            Army defender = findArmyInArea.Results[1].GetComponent <Army>();

            Debug.WriteLine($"BATTLE ENCOUNTER {attacker} VS {defender}");
            BattleEncounterEvent battleEncounterEvent = new BattleEncounterEvent(findArmyInArea.Results[0],
                                                                                 findArmyInArea.Results[1], moveInEvent.Current);

            _eventBus.Post(battleEncounterEvent);
        }