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); }
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.JoinOrCreateStrongholdGateBattle(targetStronghold, troopObject, out combatGroup, out battleId); groupId = combatGroup.Id; // Register the battle listeners RegisterBattleListeners(targetStronghold); // Create stamina monitor StaminaMonitor = staminaMonitorFactory.CreateStaminaMonitor(targetStronghold.GateBattle, combatGroup, battleFormula.GetStamina(troopObject.Stub, targetStronghold)); StaminaMonitor.PropertyChanged += (sender, args) => dbManager.Save(this); // 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); }