Пример #1
0
        public override void LoadProperties(IDictionary <string, string> properties)
        {
            cityId            = uint.Parse(properties["troop_city_id"]);
            troopObjectId     = uint.Parse(properties["troop_object_id"]);
            groupId           = uint.Parse(properties["group_id"]);
            originalUnitCount = int.Parse(properties["original_count"]);

            targetObjectId = uint.Parse(properties["target_object_id"]);

            IBarbarianTribe targetBarbarianTribe;

            gameObjectLocator.TryGetObjects(targetObjectId, out targetBarbarianTribe);
            RegisterBattleListeners(targetBarbarianTribe);

            var          combatGroup = targetBarbarianTribe.Battle.GetCombatGroup(groupId);
            ITroopObject troopObject;
            ICity        city;

            gameObjectLocator.TryGetObjects(cityId, troopObjectId, out city, out troopObject);

            StaminaMonitor = staminaMonitorFactory.CreateStaminaMonitor(targetBarbarianTribe.Battle, combatGroup, short.Parse(properties["stamina"]));
            StaminaMonitor.PropertyChanged += (sender, args) => dbManager.Save(this);

            AttackModeMonitor = new AttackModeMonitor(targetBarbarianTribe.Battle, combatGroup, troopObject.Stub);
        }
Пример #2
0
        public override Error Execute()
        {
            ICity        city;
            ICity        targetCity;
            ITroopObject troopObject;

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

            // Save original unit count to know when to bail out of battle
            originalUnitCount = troopObject.Stub.TotalCount;

            // Create the group in the battle
            uint         battleId;
            ICombatGroup combatGroup;

            cityBattleProcedure.JoinOrCreateCityBattle(targetCity, troopObject, dbManager, out combatGroup, out battleId);
            groupId = combatGroup.Id;

            // Register the battle listeners
            RegisterBattleListeners(targetCity);

            // Create stamina monitor
            StaminaMonitor = staminaMonitorFactory.CreateStaminaMonitor(targetCity.Battle,
                                                                        combatGroup,
                                                                        battleFormula.GetStamina(troopObject.Stub, targetCity));
            StaminaMonitor.PropertyChanged += (sender, args) => dbManager.Save(this);

            // Create attack mode monitor
            AttackModeMonitor = new AttackModeMonitor(targetCity.Battle, combatGroup, troopObject.Stub);

            // Set the attacking troop object to the correct state and stamina
            troopObject.BeginUpdate();
            troopObject.State = GameObjectStateFactory.BattleState(battleId);
            troopObject.EndUpdate();

            // Set the troop stub to the correct state
            troopObject.Stub.BeginUpdate();
            troopObject.Stub.State = TroopState.Battle;
            troopObject.Stub.EndUpdate();

            return(Error.Ok);
        }
Пример #3
0
        public override Error Execute()
        {
            ICity        city;
            ITroopObject troopObject;
            IStronghold  targetStronghold;

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

            // Create the group in the battle
            uint         battleId;
            ICombatGroup combatGroup;

            strongholdBattleProcedure.JoinOrCreateStrongholdMainBattle(targetStronghold,
                                                                       troopObject,
                                                                       out combatGroup,
                                                                       out battleId);
            groupId = combatGroup.Id;

            // Create attack mode monitor
            originalUnitCount = troopObject.Stub.TotalCount;
            AttackModeMonitor = new AttackModeMonitor(targetStronghold.MainBattle, combatGroup, troopObject.Stub);

            // Register the battle listeners
            RegisterBattleListeners(targetStronghold);

            // Set the attacking troop object to the correct state and stamina
            troopObject.BeginUpdate();
            troopObject.State = GameObjectStateFactory.BattleState(battleId);
            troopObject.EndUpdate();

            // Set the troop stub to the correct state
            troopObject.Stub.BeginUpdate();
            troopObject.Stub.State = TroopState.Battle;
            troopObject.Stub.EndUpdate();

            return(Error.Ok);
        }
Пример #4
0
        public override void LoadProperties(IDictionary <string, string> properties)
        {
            cityId            = uint.Parse(properties["troop_city_id"]);
            troopObjectId     = uint.Parse(properties["troop_object_id"]);
            groupId           = uint.Parse(properties["group_id"]);
            originalUnitCount = int.Parse(properties["original_count"]);

            targetStrongholdId = uint.Parse(properties["target_stronghold_id"]);

            IStronghold targetStronghold;

            gameObjectLocator.TryGetObjects(targetStrongholdId, out targetStronghold);
            RegisterBattleListeners(targetStronghold);

            var          combatGroup = targetStronghold.MainBattle.GetCombatGroup(groupId);
            ITroopObject troopObject;
            ICity        city;

            gameObjectLocator.TryGetObjects(cityId, troopObjectId, out city, out troopObject);
            AttackModeMonitor = new AttackModeMonitor(targetStronghold.MainBattle, combatGroup, troopObject.Stub);
        }