Пример #1
0
        private void AfterTroopMovedHome(ActionState state)
        {
            if (state != ActionState.Completed)
            {
                return;
            }
            ICity        city;
            ITroopObject troopObject;

            locker.Lock(cityId, troopObjectId, out city, out troopObject).Do(() =>
            {
                // If city is not in battle then add back to city otherwise join local battle
                if (city.Battle == null)
                {
                    city.References.Remove(troopObject, this);
                    city.Notifications.Remove(this);
                    procedure.TroopObjectDelete(troopObject, true);
                    StateChange(ActionState.Completed);
                }
                else
                {
                    var eda = actionFactory.CreateCityEngageDefensePassiveAction(cityId, troopObject.ObjectId, FormationType.Attack);
                    ExecuteChainAndWait(eda, AfterEngageDefense);
                }
            });
        }
Пример #2
0
        private void AfterTroopMoved(ActionState state)
        {
            if (state == ActionState.Completed)
            {
                ICity city;
                locker.Lock(cityId, out city).Do(() =>
                {
                    ITroopObject troopObject;
                    if (!city.TryGetTroop(troopObjectId, out troopObject))
                    {
                        throw new Exception();
                    }

                    city.Notifications.Remove(this);

                    if (city.Battle == null)
                    {
                        city.References.Remove(troopObject, this);
                        procedure.TroopObjectDelete(troopObject, true);
                        StateChange(ActionState.Completed);
                    }
                    else
                    {
                        var eda = actionFactory.CreateCityEngageDefensePassiveAction(cityId, troopObjectId, FormationType.Defense);
                        ExecuteChainAndWait(eda, AfterEngageDefense);
                    }
                });

                return;
            }

            if (state == ActionState.Failed)
            {
                ICity city;
                locker.Lock(cityId, out city).Do(() =>
                {
                    ITroopObject troopObject;
                    if (!city.TryGetTroop(troopObjectId, out troopObject))
                    {
                        throw new Exception();
                    }

                    procedure.TroopObjectStation(troopObject, city);
                });
            }
        }