private void UpdatePillageProgress(Army army, PointOfInterest pointOfInterest) { if (!DepartmentOfDefense.CanStartPillage(army, pointOfInterest, true)) { DepartmentOfDefense.StopPillage(army, pointOfInterest); return; } float propertyValue = army.GetPropertyValue(SimulationProperties.PillagePower); float num = pointOfInterest.GetPropertyValue(SimulationProperties.PillageDefense); num -= propertyValue; pointOfInterest.SetPropertyBaseValue(SimulationProperties.PillageDefense, Mathf.Max(0f, num)); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { DepartmentOfScience agency = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>(); if (agency != null && !agency.CanPillage()) { return(State.Failure); } if (!this.downloadableContentService.IsShared(DownloadableContent11.ReadOnlyName)) { return(State.Failure); } Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName)) { return(State.Failure); } if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName)) { this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName]; } List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>; if (list == null) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } if (list.Count == 0) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); float num = 0.1f; float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumMovement); PointOfInterest pointOfInterest = null; for (int i = 0; i < list.Count; i++) { PointOfInterest pointOfInterest2 = list[i] as PointOfInterest; if (pointOfInterest2 != null && pointOfInterest2.Region.City != null && pointOfInterest2.PointOfInterestImprovement != null && DepartmentOfDefense.CanStartPillage(army, pointOfInterest2, false)) { float num2 = 0.5f; if (entity != null) { num2 = this.ComputePillageInterest(pointOfInterest2, entity, army) * 0.5f; } if (num2 >= 0f) { float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest2.WorldPosition) / propertyValue; if (num3 <= this.MaximumTurnDistance) { float num4 = 0.5f - num3 / this.MaximumTurnDistance; num2 = AILayer.Boost(num2, num4 * 0.5f); float propertyValue2 = pointOfInterest2.GetPropertyValue(SimulationProperties.PillageDefense); float propertyValue3 = pointOfInterest2.GetPropertyValue(SimulationProperties.MaximumPillageDefense); num2 = AILayer.Boost(num2, (1f - propertyValue2 / propertyValue3) * 0.2f); if (num2 > num) { num = num2; pointOfInterest = pointOfInterest2; } } } } } if (pointOfInterest != null) { if (this.OpportunityMaximumTurn > 0f) { int num5 = 0; int num6 = 0; if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition)) { WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition]; if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, pointOfInterest.WorldPosition, mainTargetPosition, out num6, out num5)) { return(State.Failure); } } int remainingTurnToPillage = DepartmentOfDefense.GetRemainingTurnToPillage(army, pointOfInterest); IAIDataRepositoryAIHelper service = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>(); Diagnostics.Assert(service != null); float num7 = 1f; AIData_Army aidata_Army; if (service.TryGetAIData <AIData_Army>(army.GUID, out aidata_Army)) { num7 = aiBehaviorTree.AICommander.GetPillageModifier(aidata_Army.CommanderMission); } if ((float)(num5 - num6 + remainingTurnToPillage) > this.OpportunityMaximumTurn * num7) { return(State.Failure); } } if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName)) { aiBehaviorTree.Variables[this.Output_TargetVarName] = pointOfInterest; } else { aiBehaviorTree.Variables.Add(this.Output_TargetVarName, pointOfInterest); } return(State.Success); } return(State.Failure); }