public bool IsKaijuValidForSupport(Kaiju kaiju) { if (!this.MajorEmpire.TamedKaijus.Contains(kaiju)) { return(false); } foreach (Unit unit in kaiju.GetActiveTroops().Units) { if (unit.UnitDesign.Tags.Contains(Kaiju.MonsterUnitTag)) { float propertyValue = unit.GetPropertyValue(SimulationProperties.Health); if (propertyValue == unit.GetPropertyValue(SimulationProperties.MaximumHealth)) { return(true); } if (propertyValue > 150f * (float)(this.departmentOfScience.CurrentTechnologyEraNumber - 1) + (float)(this.departmentOfScience.CurrentTechnologyEraNumber * this.departmentOfScience.CurrentTechnologyEraNumber * 10)) { return(true); } return(false); } } return(false); }
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 bool IsKaijuValidForObjective(Kaiju kaiju) { bool flag = false; if (kaiju == null) { return(flag); } int regionIndex = (int)this.worldPositionningService.GetRegionIndex(kaiju.WorldPosition); if (!this.departmentOfForeignAffairs.CanMoveOn(regionIndex, false)) { return(false); } if (kaiju.MajorEmpire != null) { if (!this.departmentOfForeignAffairs.CanAttack(kaiju.GetActiveTroops())) { return(false); } if (kaiju.OnArmyMode()) { District district = this.worldPositionningService.GetDistrict(kaiju.WorldPosition); if (district != null && District.IsACityTile(district)) { return(false); } } if (this.departmentOfForeignAffairs.IsInWarWithSomeone()) { flag = !this.departmentOfForeignAffairs.IsAtWarWith(kaiju.MajorEmpire); } else { flag = this.departmentOfForeignAffairs.IsFriend(kaiju.MajorEmpire); } } if (!flag && kaiju.Empire.Index != base.AIEntity.Empire.Index && this.departmentOfTheInterior.Cities.Count > 0) { if (this.departmentOfCreepingNodes != null) { Region region = this.worldPositionningService.GetRegion(kaiju.WorldPosition); foreach (CreepingNode creepingNode in this.departmentOfCreepingNodes.Nodes) { if (!creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(base.AIEntity.Empire, creepingNode) && creepingNode.Region.Index == region.Index) { return(true); } } } foreach (Army army in this.departmentOfDefense.Armies) { if (!army.IsSeafaring) { if (this.pathfindingService.FindPath(army, this.departmentOfTheInterior.Cities[0].WorldPosition, kaiju.WorldPosition, PathfindingManager.RequestMode.Default, null, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null) == null) { return(false); } return(true); } } return(false); } return(false); }
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); } }