private WorldPosition GetBestDefensiveKaijuPosition(Region targetRegion)
    {
        Region[] neighbourRegionsWithCityOfEmpire = this.worldPositionningService.GetNeighbourRegionsWithCityOfEmpire(targetRegion, this.MajorEmpire, false);
        if (neighbourRegionsWithCityOfEmpire.Length == 0)
        {
            return(KaijuCouncil.GetValidKaijuPosition(targetRegion, false));
        }
        List <WorldPosition> list = (from position in targetRegion.WorldPositions
                                     where KaijuCouncil.IsPositionValidForSettleKaiju(position, null)
                                     select position).ToList <WorldPosition>();

        if (list.Count == 0)
        {
            return(WorldPosition.Invalid);
        }
        int num   = -1;
        int index = -1;

        for (int i = 0; i < list.Count; i++)
        {
            int num2 = 0;
            foreach (Region region in neighbourRegionsWithCityOfEmpire)
            {
                int distance = this.worldPositionningService.GetDistance(list[i], region.City.WorldPosition);
                num2 += ((distance > 5) ? Mathf.Max(15 - distance, 0) : ((15 - distance) * 3));
            }
            if (num2 > num)
            {
                num   = num2;
                index = i;
            }
        }
        return(list[index]);
    }
    private WorldPosition GetValidKaijuSupportPosition(Region targetRegion, Army ArmyToSupport)
    {
        List <WorldPosition> list = (from position in targetRegion.WorldPositions
                                     where KaijuCouncil.IsPositionValidForSettleKaiju(position, null)
                                     select position).ToList <WorldPosition>();

        if (list.Count == 0)
        {
            return(WorldPosition.Invalid);
        }
        list.Sort((WorldPosition left, WorldPosition right) => this.worldPositionningService.GetDistance(left, ArmyToSupport.WorldPosition).CompareTo(this.worldPositionningService.GetDistance(right, ArmyToSupport.WorldPosition)));
        return(list[0]);
    }
Esempio n. 3
0
    public static WorldPosition GetValidKaijuPosition(Region targetRegion, bool randomFallback = false)
    {
        IGameService service = Services.GetService <IGameService>();
        IWorldPositionningService service3 = service.Game.Services.GetService <IWorldPositionningService>();

        KaijuCouncil.attractivenessMap = (KaijuCouncil.world.Atlas.GetMap(WorldAtlas.Maps.KaijuAttractiveness) as GridMap <bool>);
        WorldPosition[] array = (from position in targetRegion.WorldPositions
                                 where KaijuCouncil.IsPositionValidForSettleKaiju(position, null)
                                 select position).ToArray <WorldPosition>();
        WorldPosition result = WorldPosition.Invalid;

        if (array.Length != 0)
        {
            result = array[KaijuCouncil.random.Next(0, array.Length)];
            if (!ELCPUtilities.UseELCPSymbiosisBuffs)
            {
                goto IL_185;
            }
            List <WorldPosition>   list  = array.ToList <WorldPosition>().Randomize(KaijuCouncil.random);
            List <PointOfInterest> list2 = targetRegion.PointOfInterests.ToList <PointOfInterest>().FindAll((PointOfInterest PointOfInterest) => PointOfInterest.Type == ELCPUtilities.QuestLocation);
            if (list2 == null || list2.Count <= 0)
            {
                goto IL_185;
            }
            using (List <WorldPosition> .Enumerator enumerator = list.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    WorldPosition position = enumerator.Current;
                    if (list2.Any((PointOfInterest poi) => service3.GetDistance(poi.WorldPosition, position) == 1))
                    {
                        result = position;
                        break;
                    }
                }
                goto IL_185;
            }
        }
        if (randomFallback)
        {
            Diagnostics.LogError("Could not find suitable position in starting region!... Picking a random one...");
            result = targetRegion.WorldPositions[KaijuCouncil.random.Next(0, targetRegion.WorldPositions.Length)];
        }
IL_185:
        if (!result.IsValid)
        {
            Diagnostics.LogError("Could not find a valid kaiju position!");
        }
        return(result);
    }
    private bool IsRelocationMessageValid(KaijuRelocationMessage message)
    {
        Kaiju kaiju = null;

        if (!this.gameEntityRepositoryService.TryGetValue <Kaiju>(message.KaijuGUID, out kaiju) || !this.MajorEmpire.TamedKaijus.Contains(kaiju))
        {
            return(false);
        }
        if (kaiju.OnArmyMode())
        {
            return(false);
        }
        WorldPosition targetPosition = message.TargetPosition;

        if (!targetPosition.IsValid || !KaijuCouncil.IsPositionValidForSettleKaiju(targetPosition, null))
        {
            return(false);
        }
        Region region = this.worldPositionningService.GetRegion(message.TargetPosition);

        if (region == null || !KaijuCouncil.IsRegionValidForSettleKaiju(region))
        {
            return(false);
        }
        for (int i = 0; i < this.validatedRelocationMessages.Count; i++)
        {
            KaijuRelocationMessage kaijuRelocationMessage = this.validatedRelocationMessages[i];
            GameEntityGUID         kaijuGUID  = message.KaijuGUID;
            GameEntityGUID         kaijuGUID2 = kaijuRelocationMessage.KaijuGUID;
            if (kaijuGUID == kaijuGUID2)
            {
                return(false);
            }
            int regionIndex  = (int)this.worldPositionningService.GetRegionIndex(message.TargetPosition);
            int regionIndex2 = (int)this.worldPositionningService.GetRegionIndex(kaijuRelocationMessage.TargetPosition);
            if (regionIndex == regionIndex2)
            {
                return(false);
            }
        }
        return(true);
    }
 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);
         }
         if (!(army is KaijuArmy))
         {
             return(State.Failure);
         }
         Kaiju kaiju = (army as KaijuArmy).Kaiju;
         if (kaiju == null || !(army.Empire is MajorEmpire) || kaiju.OnGarrisonMode() || !KaijuCouncil.IsPositionValidForSettleKaiju(army.WorldPosition, kaiju))
         {
             return(State.Failure);
         }
         this.failuresFlags.Clear();
         if (!this.armyAction_SettleKaiju.CanExecute(army, ref this.failuresFlags, new object[0]))
         {
             return(State.Failure);
         }
         this.orderExecuted = false;
         this.armyAction_SettleKaiju.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised), new object[0]);
         return(State.Running);
     }
 }