public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters) { ticket = null; IGameEntity gameEntity = null; ArmyAction.FailureFlags.Clear(); for (int i = 0; i < parameters.Length; i++) { if (parameters[i] is IGameEntity) { gameEntity = (parameters[i] as IGameEntity); break; } if (parameters[i] is List <IGameEntity> ) { List <IGameEntity> list = parameters[i] as List <IGameEntity>; bool flag = false; for (int j = 0; j < list.Count; j++) { if (this.CanAttackGameEntity(army, list[j], ref flag, ref ArmyAction.FailureFlags)) { gameEntity = list[j]; break; } } break; } } if (gameEntity != null) { DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); if (agency.CanAttack(gameEntity) || army.IsPrivateers) { OrderAttack orderAttack = new OrderAttack(army.Empire.Index, army.GUID, gameEntity.GUID); orderAttack.NumberOfActionPointsToSpend = base.GetCostInActionPoints(); Diagnostics.Assert(playerController != null); playerController.PostOrder(orderAttack, out ticket, ticketRaisedEventHandler); } } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (this.ticket != null) { if (!this.orderExecuted) { return(State.Running); } if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed) { this.orderExecuted = false; this.ticket = null; aiBehaviorTree.ErrorCode = 1; return(State.Failure); } this.orderExecuted = false; this.ticket = null; return(State.Success); } else { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints); float propertyValue2 = army.GetPropertyValue(SimulationProperties.ActionPointsSpent); if (propertyValue <= propertyValue2) { aiBehaviorTree.ErrorCode = 33; return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName)) { aiBehaviorTree.LogError("${0} not set", new object[] { this.TargetVarName }); return(State.Failure); } IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity; if (!(target is IWorldPositionable)) { return(State.Failure); } IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(target.GUID)) { return(State.Success); } IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); IEnumerable <Encounter> service3 = service.Game.Services.GetService <IEncounterRepositoryService>(); if (service3 != null && service3.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false) || encounter.IsGarrisonInEncounter(target.GUID, false))) { return(State.Running); } IGarrison garrison; if (target is Kaiju) { Kaiju kaiju = target as Kaiju; garrison = kaiju.GetActiveTroops(); if (kaiju.IsStunned()) { return(State.Failure); } } else { if (target is KaijuArmy) { KaijuArmy kaijuArmy = target as KaijuArmy; if (kaijuArmy != null && kaijuArmy.Kaiju.IsStunned()) { return(State.Failure); } } else if (target is KaijuGarrison) { KaijuGarrison kaijuGarrison = target as KaijuGarrison; if (kaijuGarrison != null && kaijuGarrison.Kaiju.IsStunned()) { return(State.Failure); } } garrison = (target as IGarrison); if (garrison == null) { return(State.Failure); } } if ((army.Empire is MinorEmpire || army.Empire is NavalEmpire) && garrison.Hero != null && garrison.Hero.IsSkillUnlocked("HeroSkillLeaderMap07")) { return(State.Failure); } if (garrison.Empire.Index == aiBehaviorTree.AICommander.Empire.Index) { return(State.Failure); } this.orderExecuted = false; GameEntityGUID guid = target.GUID; if (target is City) { Diagnostics.Assert(AIScheduler.Services != null); IEntityInfoAIHelper service4 = AIScheduler.Services.GetService <IEntityInfoAIHelper>(); Diagnostics.Assert(service4 != null); City city = target as City; if (city.BesiegingEmpire != null && city.BesiegingEmpire != aiBehaviorTree.AICommander.Empire) { return(State.Failure); } District districtToAttackFrom = service4.GetDistrictToAttackFrom(army, city); if (districtToAttackFrom == null) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } guid = districtToAttackFrom.GUID; } else if (target is Camp) { Camp camp = target as Camp; IWorldPositionable worldPositionable = target as IWorldPositionable; if (worldPositionable == null) { return(State.Failure); } if (service2.GetDistance(army.WorldPosition, worldPositionable.WorldPosition) != 1) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } guid = camp.GUID; } else if (target is Fortress) { guid = target.GUID; } else { Village village = target as Village; if (village != null && (village.HasBeenPacified || (village.HasBeenConverted && village.Converter == aiBehaviorTree.AICommander.Empire) || village.HasBeenInfected)) { return(State.Failure); } Diagnostics.Assert(AIScheduler.Services != null); IWorldPositionable worldPositionable2 = target as IWorldPositionable; if (worldPositionable2 == null) { return(State.Failure); } District district = service2.GetDistrict(worldPositionable2.WorldPosition); if (district != null && District.IsACityTile(district) && district.City.Empire == garrison.Empire) { worldPositionable2 = district; guid = district.GUID; } if (service2.GetDistance(army.WorldPosition, worldPositionable2.WorldPosition) != 1) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } } OrderAttack order = new OrderAttack(army.Empire.Index, army.GUID, guid); aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised)); return(State.Running); } }
private void ValidatePath() { IGuiService service = Services.GetService <IGuiService>(); IAudioEventService service2 = Services.GetService <IAudioEventService>(); Diagnostics.Assert(service2 != null); bool flag = base.SelectedUnits.Length == 0 || base.SelectedUnits.Length == this.Army.StandardUnits.Count || (this.Garrison.UnitsCount == 1 && this.Garrison.Hero != null); if (!base.IsTransferable(WorldCursor.HighlightedWorldPosition) && flag) { global::Empire empire = this.WorldArmy.Army.Empire; if (this.battleTarget is Army) { Army army = this.battleTarget as Army; if (army.Empire.Index == this.Army.Empire.Index) { int num = Mathf.Max(army.MaximumUnitSlot - army.CurrentUnitSlot, 0); if (this.Army.HasCatspaw || army.HasCatspaw) { QuickWarningPanel.Show("%UnitsTransferImpossibleWithCatsPawArmy"); } else if (this.Army.StandardUnits.Count > num) { QuickWarningPanel.Show(string.Format(AgeLocalizer.Instance.LocalizeString("%UnitsTransferNotEnoughSlotsInTargetArmy"), num)); } else if (this.Army.GetPropertyValue(SimulationProperties.Movement) <= 0f && base.WorldPositionningService.GetDistance(this.Army.WorldPosition, army.WorldPosition) == 1) { QuickWarningPanel.Show(AgeLocalizer.Instance.LocalizeString("%" + ArmyAction_TransferUnits.NotEnoughMovementToTransfer + "Description")); } else if (this.TemporaryWorldPath != null && this.TemporaryWorldPath.Length > 1 && !this.Army.HasCatspaw && !army.HasCatspaw) { OrderGoToAndMerge order = new OrderGoToAndMerge(empire.Index, this.WorldArmy.Army.GUID, this.battleTarget.GUID, (from unit in base.SelectedUnits select unit.GUID).ToArray <GameEntityGUID>(), this.TemporaryWorldPath); this.PlayerControllerRepositoryService.ActivePlayerController.PostOrder(order); } } else { DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); bool flag2 = this.Army.IsNaval == army.IsNaval; if ((agency.CanAttack(this.battleTarget) || this.WorldArmy.Army.IsPrivateers) && flag2) { ArmyAction armyAction = null; IDatabase <ArmyAction> database = Databases.GetDatabase <ArmyAction>(false); float cost = 0f; if (database != null && database.TryGetValue(ArmyAction_Attack.ReadOnlyName, out armyAction)) { cost = armyAction.GetCostInActionPoints(); } if (!this.Army.HasEnoughActionPoint(cost)) { QuickWarningPanel.Show(AgeLocalizer.Instance.LocalizeString("%ArmyNotEnoughActionPointsDescription")); } else if (this.TemporaryWorldPath != null && this.TemporaryWorldPath.Length > 1) { OrderGoToAndAttack order2 = new OrderGoToAndAttack(empire.Index, this.WorldArmy.Army.GUID, this.battleTarget.GUID, this.TemporaryWorldPath); this.PlayerControllerRepositoryService.ActivePlayerController.PostOrder(order2); } else { OrderAttack order3 = new OrderAttack(empire.Index, this.WorldArmy.Army.GUID, this.battleTarget.GUID); this.PlayerControllerRepositoryService.ActivePlayerController.PostOrder(order3); } service2.Play2DEvent("Gui/Interface/InGame/OrderAttack"); } else if (army.Empire is MajorEmpire && flag2) { global::Empire empire2 = army.Empire; service.GetGuiPanel <WarDeclarationModalPanel>().Show(new object[] { empire2, "AttackTarget" }); } } } else { bool flag3 = false; if (this.battleTarget != null) { if (this.TemporaryWorldPath != null && this.TemporaryWorldPath.Length > 1) { flag3 = (this.TemporaryWorldPath.ControlPoints.Length == 0); flag3 |= (this.TemporaryWorldPath.ControlPoints.Length == 1 && (int)this.TemporaryWorldPath.ControlPoints[0] == this.TemporaryWorldPath.Length - 1); } else { flag3 = base.PathfindingService.IsTransitionPassable(this.Army.WorldPosition, this.battleTarget.WorldPosition, this.Army, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreOtherEmpireDistrict | PathfindingFlags.IgnoreDiplomacy | PathfindingFlags.IgnorePOI | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null); } } if (flag3 || this.battleTarget is Fortress || this.battleTarget is KaijuGarrison) { flag3 = false; bool flag4 = true; if (this.battleTarget is KaijuGarrison) { KaijuGarrison kaijuGarrison = this.battleTarget as KaijuGarrison; DepartmentOfForeignAffairs agency2 = empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency2 != null); if (!agency2.CanAttack(this.battleTarget)) { flag4 = false; global::Empire empire3 = kaijuGarrison.Empire; service.GetGuiPanel <WarDeclarationModalPanel>().Show(new object[] { empire3, "AttackTarget" }); } } if (flag4) { ArmyActionModalPanel guiPanel = service.GetGuiPanel <ArmyActionModalPanel>(); if (guiPanel != null) { WorldPosition destination = (this.TemporaryWorldPath == null || this.TemporaryWorldPath.Length <= 1) ? WorldPosition.Invalid : this.TemporaryWorldPath.Destination; if (guiPanel.CheckForArmyActionsAvailability(this.Army, this.battleTarget, destination).Count > 0) { flag3 = true; } } } } if (flag3 && this.battleTarget != null && !this.Army.IsPrivateers) { MajorEmpire majorEmpire = null; if (this.battleTarget is Garrison) { majorEmpire = ((this.battleTarget as Garrison).Empire as MajorEmpire); } else if (this.battleTarget is District) { majorEmpire = ((this.battleTarget as District).Empire as MajorEmpire); } if (majorEmpire != null && majorEmpire.Index != this.Army.Empire.Index) { flag3 = this.Army.Empire.GetAgency <DepartmentOfForeignAffairs>().IsSymetricallyDiscovered(majorEmpire); } } if (flag3) { WorldPosition worldPosition = (this.TemporaryWorldPath == null || this.TemporaryWorldPath.Length <= 1) ? WorldPosition.Invalid : this.TemporaryWorldPath.Destination; service.Show(typeof(ArmyActionModalPanel), new object[] { this.Army, this.battleTarget, base.SelectedUnits, worldPosition }); } else if (this.TemporaryWorldPath != null && this.TemporaryWorldPath.Destination != WorldPosition.Invalid) { OrderGoTo order4 = new OrderGoTo(empire.Index, this.WorldArmy.Army.GUID, this.TemporaryWorldPath.Destination); this.PlayerControllerRepositoryService.ActivePlayerController.PostOrder(order4); service2.Play2DEvent("Gui/Interface/InGame/OrderGoTo"); } else if (WorldCursor.HighlightedWorldPosition != WorldPosition.Invalid) { Region region = base.WorldPositionningService.GetRegion(WorldCursor.HighlightedWorldPosition); if (region != null && region.City != null && region.City.Empire != null) { DepartmentOfForeignAffairs agency3 = this.Army.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency3 != null); if (!agency3.CanMoveOn(WorldCursor.HighlightedWorldPosition, this.WorldArmy.Army.IsPrivateers, this.WorldArmy.Army.IsCamouflaged)) { District district = base.WorldPositionningService.GetDistrict(WorldCursor.HighlightedWorldPosition); if ((district == null || district.Type == DistrictType.Exploitation) && region.City.Empire is MajorEmpire) { service.GetGuiPanel <WarDeclarationModalPanel>().Show(new object[] { region.City.Empire, "BreakCloseBorder" }); } } } } } } this.LastHighlightedWorldPosition = WorldPosition.Invalid; this.LastUnpathableWorldPosition = WorldPosition.Invalid; this.SelectTarget(); this.UpdateBattlegroundVisibility(); if (this.TemporaryWorldPath != null) { this.PathRendererService.RemovePath(this.TemporaryWorldPath); this.TemporaryWorldPath = null; } }