示例#1
0
        public override Error Execute()
        {
            IStronghold stronghold;

            if (!gameObjectLocator.TryGetObjects(strongholdId, out stronghold))
            {
                return(Error.ObjectNotFound);
            }

            world.Add(stronghold.MainBattle);
            dbManager.Save(stronghold.MainBattle);

            if (stronghold.StrongholdState == StrongholdState.Occupied)
            {
                // Add stationed to battle
                foreach (var stub in stronghold.Troops.StationedHere())
                {
                    stub.BeginUpdate();
                    stub.State = TroopState.BattleStationed;
                    stub.EndUpdate();

                    battleProcedure.AddReinforcementToBattle(stronghold.MainBattle, stub, FormationType.Defense);
                }
            }
            else
            {
                var strongholdGroup = strongholdBattleProcedure.AddStrongholdUnitsToBattle(stronghold.MainBattle,
                                                                                           stronghold,
                                                                                           strongholdManager.GenerateNeutralStub(stronghold));

                npcGroupId = strongholdGroup.Id;
            }

            stronghold.BeginUpdate();
            stronghold.State = GameObjectStateFactory.BattleState(stronghold.MainBattle.BattleId);
            stronghold.EndUpdate();

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

            return(Error.Ok);
        }