Beispiel #1
0
        private void AfterTroopMoved(ActionState state)
        {
            if (state == ActionState.Fired)
            {
                IBarbarianTribe targetBarbarianTribe;
                // Verify the target is still good, otherwise we walk back immediately
                if (!gameObjectLocator.TryGetObjects(targetObjectId, out targetBarbarianTribe) || targetBarbarianTribe.CampRemains == 0)
                {
                    CancelCurrentChain();
                }

                return;
            }

            if (state == ActionState.Failed)
            {
                // If TroopMove failed it's because we cancelled it and the target is invalid. Walk back home
                ICity        city;
                ITroopObject troopObject;

                locker.Lock(cityId, troopObjectId, out city, out troopObject).Do(() =>
                {
                    TroopMovePassiveAction tma = actionFactory.CreateTroopMovePassiveAction(city.Id, troopObject.ObjectId, city.PrimaryPosition.X, city.PrimaryPosition.Y, true, true);
                    ExecuteChainAndWait(tma, AfterTroopMovedHome);
                });

                return;
            }

            if (state == ActionState.Completed)
            {
                ICity           city;
                IBarbarianTribe targetBarbarianTribe;
                ITroopObject    troopObject;

                if (!gameObjectLocator.TryGetObjects(cityId, troopObjectId, out city, out troopObject))
                {
                    throw new Exception("City or troop object is missing");
                }

                if (!gameObjectLocator.TryGetObjects(targetObjectId, out targetBarbarianTribe))
                {
                    //If the target is missing, walk back
                    locker.Lock(city).Do(() =>
                    {
                        TroopMovePassiveAction tma = actionFactory.CreateTroopMovePassiveAction(city.Id,
                                                                                                troopObject.ObjectId,
                                                                                                city.PrimaryPosition.X,
                                                                                                city.PrimaryPosition.Y,
                                                                                                true,
                                                                                                true);
                        ExecuteChainAndWait(tma, AfterTroopMovedHome);
                    });

                    return;
                }

                locker.Lock(city, targetBarbarianTribe).Do(() =>
                {
                    var bea = actionFactory.CreateBarbarianTribeEngageAttackPassiveAction(cityId, troopObject.ObjectId, targetObjectId);
                    ExecuteChainAndWait(bea, AfterBattle);
                });
            }
        }