Beispiel #1
0
        public override Error Execute()
        {
            ICity city;

            if (!gameObjectLocator.TryGetObjects(cityId, out city))
            {
                return(Error.ObjectNotFound);
            }

            world.Add(city.Battle);
            dbManager.Save(city.Battle);

            //Add local troop
            cityBattleProcedure.AddLocalUnitsToBattle(city.Battle, city);

            //Add reinforcement
            foreach (
                var stub in
                city.Troops.Where(
                    stub =>
                    stub != city.DefaultTroop && stub.State == TroopState.Stationed &&
                    stub.Station == city))
            {
                stub.BeginUpdate();
                stub.State = TroopState.BattleStationed;
                stub.EndUpdate();

                battleProcedure.AddReinforcementToBattle(city.Battle, stub, FormationType.Defense);
            }

            beginTime = SystemClock.Now;
            endTime   = SystemClock.Now.Add(formula.GetBattleDelayStartInterval());

            return(Error.Ok);
        }
Beispiel #2
0
        public override Error Execute()
        {
            ICity city;

            ITroopObject troopObject;

            if (!gameObjectLocator.TryGetObjects(cityId, troopObjectId, out city, out troopObject))
            {
                return(Error.ObjectNotFound);
            }

            if (city.Battle == null)
            {
                StateChange(ActionState.Completed);
                return(Error.Ok);
            }

            RegisterBattleListeners(city);

            troopObject.BeginUpdate();
            troopObject.State = GameObjectStateFactory.BattleState(city.Battle.BattleId);
            troopObject.EndUpdate();
            troopObject.Stub.BeginUpdate();
            troopObject.Stub.State = TroopState.Battle;
            troopObject.Stub.EndUpdate();

            // Add units to battle
            groupId = battleProcedure.AddReinforcementToBattle(city.Battle, troopObject.Stub, formationType);
            cityBattleProcedure.AddLocalUnitsToBattle(city.Battle, city);

            return(Error.Ok);
        }