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; } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (this.ticket != null) { if (!this.ticket.Raised) { return(State.Running); } if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed) { this.ticket = null; aiBehaviorTree.ErrorCode = 1; return(State.Failure); } 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 gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity; if (!(gameEntity is IWorldPositionable)) { return(State.Failure); } IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(gameEntity.GUID)) { return(State.Success); } IEncounterRepositoryService service2 = service.Game.Services.GetService <IEncounterRepositoryService>(); if (service2 != null) { IEnumerable <Encounter> enumerable = service2; if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false))) { return(State.Running); } } IGarrison garrison; if (gameEntity is Kaiju) { Kaiju kaiju = gameEntity as Kaiju; garrison = kaiju.GetActiveTroops(); if (kaiju.IsStunned()) { return(State.Failure); } } else { if (gameEntity is KaijuArmy) { KaijuArmy kaijuArmy = gameEntity as KaijuArmy; if (kaijuArmy != null && kaijuArmy.Kaiju.IsStunned()) { return(State.Failure); } } else if (gameEntity is KaijuGarrison) { KaijuGarrison kaijuGarrison = gameEntity as KaijuGarrison; if (kaijuGarrison != null && kaijuGarrison.Kaiju.IsStunned()) { return(State.Failure); } } garrison = (gameEntity 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); } GameEntityGUID guid = gameEntity.GUID; if (!aiBehaviorTree.Variables.ContainsKey(this.PathVarName)) { aiBehaviorTree.LogError("{0} not set", new object[] { this.PathVarName }); return(State.Failure); } WorldPath worldPath = aiBehaviorTree.Variables[this.PathVarName] as WorldPath; if (worldPath == null || worldPath.Length < 2) { aiBehaviorTree.LogError("Path is null.", new object[0]); aiBehaviorTree.ErrorCode = 3; return(State.Failure); } if (!worldPath.IsValid) { aiBehaviorTree.ErrorCode = 3; return(State.Failure); } OrderGoToAndAttack orderGoToAndAttack = new OrderGoToAndAttack(army.Empire.Index, army.GUID, guid, worldPath); orderGoToAndAttack.Flags = PathfindingFlags.IgnoreFogOfWar; aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderGoToAndAttack, out this.ticket, null); return(State.Running); } }