protected override void ExecuteNeeds(StaticString context, StaticString pass) { base.ExecuteNeeds(context, pass); ISynchronousJobRepositoryAIHelper service = AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>(); if (this.availableNodes.Count > 0 && this.nodesPerPopulation > 0f) { service.RegisterSynchronousJob(new SynchronousJob(this.SyncrhronousJob_QueueNode)); } List <CreepingNodeBuyoutMessage> list = new List <CreepingNodeBuyoutMessage>(base.AIEntity.AIPlayer.Blackboard.GetMessages <CreepingNodeBuyoutMessage>(BlackboardLayerID.Empire, (CreepingNodeBuyoutMessage match) => match.State != BlackboardMessage.StateValue.Message_Canceled)); for (int i = list.Count - 1; i >= 0; i--) { CreepingNodeBuyoutMessage message = list[i]; if (!this.IsMessageValid(message)) { base.AIEntity.AIPlayer.Blackboard.CancelMessage(message); list.RemoveAt(i); } } if (list.Count > 0) { this.validatedBuyoutMessages = list; service.RegisterSynchronousJob(new SynchronousJob(this.SyncrhronousJob_BuyoutNode)); } }
private bool IsMessageValid(CreepingNodeBuyoutMessage message) { IGameEntity gameEntity = null; if (!this.gameEntityRepositoryService.TryGetValue(message.NodeGUID, out gameEntity)) { return(false); } CreepingNode creepingNode = gameEntity as CreepingNode; return(creepingNode != null && creepingNode.IsUnderConstruction); }
protected override void CreateLocalNeeds(StaticString context, StaticString pass) { base.CreateLocalNeeds(context, pass); this.availableNodes.Clear(); CreepingNode[] array = this.departmentOfCreepingNodes.GetNodesUnderConstruction(); this.nodesPerPopulation = this.GetNodesPerPopulation(); this.nodesPerPopulation -= (float)array.Length; this.availableNodes = this.GetAvailableNodes(); this.ResetNodesScore(); this.ScoreAvailableNodes(); int num = 0; if (array.Length == 0) { num = 1; } for (int i = num; i < this.availableNodes.Count; i++) { if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools && ELCPUtilities.ELCPVerboseMode) { Diagnostics.Log("ELCP: {0} availableNodes {1} {2} {3}", new object[] { base.AIEntity.Empire, this.availableNodes[i].nodeDefinition.Name, this.availableNodes[i].pointOfInterest.WorldPosition, this.availableNodes[i].score }); } if (this.availableNodes[i].score < this.MinScoreToQueueNode) { this.availableNodes.RemoveAt(i); i--; } } if (this.IsMadSeason) { array = (from node in array orderby node.GetBuyoutCost() descending select node).ToArray <CreepingNode>(); for (int j = 0; j < array.Length; j++) { float num2 = -array[j].GetBuyoutCost(); if (this.departmentOfTheTreasury.IsTransferOfResourcePossible(base.AIEntity.Empire, DepartmentOfTheTreasury.Resources.EmpireMoney, ref num2)) { CreepingNodeBuyoutMessage message = new CreepingNodeBuyoutMessage(base.AIEntity.Empire.Index, array[j].GUID); base.AIEntity.AIPlayer.Blackboard.AddMessage(message); return; } } } }
private SynchronousJobState SyncrhronousJob_BuyoutNode() { if (base.AIEntity == null || (base.AIEntity.Empire as MajorEmpire).ELCPIsEliminated || this.departmentOfTheInterior.MainCity == null || this.departmentOfTheInterior.MainCity.SimulationObject.Tags.Contains(City.TagCityStatusRazed)) { return(SynchronousJobState.Failure); } if (this.validatedBuyoutMessages.Count > 0) { for (int i = this.validatedBuyoutMessages.Count - 1; i >= 0; i--) { CreepingNodeBuyoutMessage creepingNodeBuyoutMessage = this.validatedBuyoutMessages[i]; this.validatedBuyoutMessages.RemoveAt(i); OrderBuyoutCreepingNode order = new OrderBuyoutCreepingNode(creepingNodeBuyoutMessage.EmpireIndex, creepingNodeBuyoutMessage.NodeGUID); base.AIEntity.Empire.PlayerControllers.AI.PostOrder(order); base.AIEntity.AIPlayer.Blackboard.CancelMessage(creepingNodeBuyoutMessage); } return(SynchronousJobState.Success); } return(SynchronousJobState.Failure); }