public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters) { ticket = null; PointOfInterest pointOfInterest = null; if (parameters != null && parameters.Length != 0 && parameters[0] is PointOfInterest) { pointOfInterest = (parameters[0] as PointOfInterest); } else if (parameters != null && parameters.Length != 0 && parameters[0] is Village) { pointOfInterest = (parameters[0] as Village).PointOfInterest; } DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>(); DiplomaticRelation diplomaticRelation = null; if (pointOfInterest != null && pointOfInterest.Empire != null) { diplomaticRelation = agency.GetDiplomaticRelation(pointOfInterest.Empire); } ArmyAction.FailureFlags.Clear(); if (diplomaticRelation == null || diplomaticRelation.State == null || diplomaticRelation.State.Name != DiplomaticRelationState.Names.Alliance) { OrderConvertVillage orderConvertVillage = new OrderConvertVillage(army.Empire.Index, army.GUID, pointOfInterest.WorldPosition); orderConvertVillage.NumberOfActionPointsToSpend = base.GetCostInActionPoints(); Diagnostics.Assert(playerController != null); playerController.PostOrder(orderConvertVillage, out ticket, ticketRaisedEventHandler); } else if (pointOfInterest != null && pointOfInterest.Empire != null && pointOfInterest.Empire is MajorEmpire) { IGuiService service = Services.GetService <IGuiService>(); service.GetGuiPanel <WarDeclarationModalPanel>().Show(new object[] { pointOfInterest.Empire, "Convert" }); } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { this.aiBehaviorTree = aiBehaviorTree; State result; if (this.ticket != null) { result = State.Running; } else { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None) { result = State.Failure; } else if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName)) { aiBehaviorTree.LogError("${0} not set", new object[] { this.TargetVarName }); result = State.Failure; } else { IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity; if (!(target is IWorldPositionable)) { result = State.Failure; } else { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(target.GUID)) { result = State.Success; } else { AICommanderWithObjective commanderObjective = aiBehaviorTree.AICommander as AICommanderWithObjective; if (commanderObjective == null) { result = State.Failure; } else if (!(target is Village)) { aiBehaviorTree.ErrorCode = 2; result = State.Failure; } else { Village village = target as Village; if (village.HasBeenConverted) { if (village.HasBeenConvertedByIndex == aiBehaviorTree.AICommander.Empire.Index) { return(State.Success); } this.aiBehaviorTree.ErrorCode = 32; return(State.Failure); } else { EvaluableMessage_VillageAction evaluableMessage_VillageAction = aiBehaviorTree.AICommander.AIPlayer.Blackboard.FindFirst <EvaluableMessage_VillageAction>(BlackboardLayerID.Empire, (EvaluableMessage_VillageAction match) => match.RegionIndex == commanderObjective.RegionIndex && match.VillageGUID == target.GUID && match.AccountTag == AILayer_AccountManager.ConversionAccountName); if (evaluableMessage_VillageAction == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtained) { float num; army.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false); if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, village) > num) { if (evaluableMessage_VillageAction == null) { this.aiBehaviorTree.ErrorCode = 32; return(State.Failure); } return(State.Success); } } else { if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel) { this.aiBehaviorTree.ErrorCode = 32; return(State.Failure); } if (evaluableMessage_VillageAction.ChosenBuyEvaluation == null || evaluableMessage_VillageAction.ChosenBuyEvaluation.State != BuyEvaluation.EvaluationState.Purchased || evaluableMessage_VillageAction.EvaluationState != EvaluableMessage.EvaluableMessageState.Validate) { return(State.Failure); } } 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) || encounter.IsGarrisonInEncounter(target.GUID, false))) { return(State.Running); } } Diagnostics.Assert(AIScheduler.Services != null); if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, village.WorldPosition) != 1) { aiBehaviorTree.ErrorCode = 12; result = State.Failure; } else { OrderConvertVillage order = new OrderConvertVillage(army.Empire.Index, army.GUID, village.WorldPosition); aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderConvertVillage_TicketRaised)); result = State.Running; } } } } } } } return(result); }