Example #1
0
    public void Bind(Army army, ArmyAction armyAction, GameObject client, int index, IWorldPositionable target, IEnumerable <Unit> unitsSelection)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null || this.Army != null || this.ArmyAction != null)
        {
            this.Unbind();
        }
        this.Army           = army;
        this.ArmyAction     = armyAction;
        this.Client         = client;
        this.Target         = target;
        this.UnitsSelection = unitsSelection;
        this.ActionButton.OnActivateObject = this.Client;
        IGuiPanelHelper guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper;

        Diagnostics.Assert(guiPanelHelper != null, "Unable to access GuiPanelHelper");
        GuiElement guiElement;

        if (guiPanelHelper.TryGetGuiElement(armyAction.Name, out guiElement))
        {
            this.ActionTitle.Text       = guiElement.Title;
            this.ActionDescription.Text = guiElement.Description;
            Texture2D image;
            if (guiPanelHelper.TryGetTextureFromIcon(guiElement, global::GuiPanel.IconSize.Large, out image))
            {
                this.ActionImage.Image = image;
            }
        }
        this.AgeTransform.AgeTooltip.Anchor = this.AgeTransform;
        this.RefreshCosts();
        this.RefreshCanExecute();
    }
    private static bool ValidateTarget(Army myArmy, IGameEntity gameEntity, DepartmentOfForeignAffairs departmentOfForeignAffairs, bool canAttack, IGameEntityRepositoryService gameEntityRepositoryService, IWorldPositionningService worldPositionningService)
    {
        if (gameEntity == null)
        {
            return(false);
        }
        if (!gameEntityRepositoryService.Contains(gameEntity.GUID))
        {
            return(false);
        }
        if (departmentOfForeignAffairs != null)
        {
            IGarrison garrison = gameEntity as IGarrison;
            if (gameEntity is Kaiju)
            {
                garrison   = (gameEntity as Kaiju).GetActiveTroops();
                gameEntity = garrison;
            }
            IWorldPositionable worldPositionable = gameEntity as IWorldPositionable;
            Region             region            = worldPositionningService.GetRegion(worldPositionable.WorldPosition);
            if (garrison == null || worldPositionable == null)
            {
                return(false);
            }
            if (canAttack)
            {
                if (!departmentOfForeignAffairs.CanAttack(gameEntity) || garrison.Empire.Index == myArmy.Empire.Index)
                {
                    return(false);
                }
            }
            else if (!departmentOfForeignAffairs.IsEnnemy(garrison.Empire))
            {
                return(false);
            }
            if ((garrison.Empire is MinorEmpire || garrison is Village) && region != null && region.IsRegionColonized() && departmentOfForeignAffairs != null && departmentOfForeignAffairs.IsEnnemy(region.Owner))
            {
                return(false);
            }
        }
        Army army = gameEntity as Army;

        if (army != null)
        {
            if (myArmy.Empire is LesserEmpire && !(army.Empire is MajorEmpire))
            {
                return(false);
            }
            District district = worldPositionningService.GetDistrict(army.WorldPosition);
            if (district != null && district.Type != DistrictType.Exploitation && army.Empire == district.Empire)
            {
                return(false);
            }
            if (!myArmy.HasSeafaringUnits() && army.IsNaval)
            {
                return(false);
            }
        }
        return(true);
    }
Example #3
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
        {
            return(State.Failure);
        }
        Garrison garrison = aiBehaviorTree.Variables[this.TargetVarName] as Garrison;

        if (aiBehaviorTree.Variables[this.TargetVarName] is Kaiju)
        {
            garrison = (aiBehaviorTree.Variables[this.TargetVarName] as Kaiju).GetActiveTroops();
        }
        if (garrison == null)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        if (garrison == army)
        {
            return(State.Failure);
        }
        IWorldPositionable worldPositionable = garrison as IWorldPositionable;

        if (worldPositionable == null)
        {
            return(State.Failure);
        }
        if (this.worldPositionningService.GetDistance(army.WorldPosition, worldPositionable.WorldPosition) > 1)
        {
            return(State.Failure);
        }
        if (army.GetPropertyValue(SimulationProperties.Movement) <= 0f)
        {
            return(State.Failure);
        }
        WorldPosition bestAttackPosition = this.GetBestAttackPosition(army, garrison, worldPositionable);

        if (bestAttackPosition != army.WorldPosition)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_BestAttackPositionVarName))
            {
                aiBehaviorTree.Variables[this.Output_BestAttackPositionVarName] = bestAttackPosition;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_BestAttackPositionVarName, bestAttackPosition);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
    private float GetTargetPower(IWorldPositionable worldPositionable, int size, global::Empire myEmpire, IGameService service)
    {
        DepartmentOfForeignAffairs agency = myEmpire.GetAgency <DepartmentOfForeignAffairs>();
        float num = 0f;

        if (worldPositionable is KaijuGarrison)
        {
            num += (worldPositionable as KaijuGarrison).GetPropertyValue(SimulationProperties.MilitaryPower);
        }
        else if (worldPositionable is Kaiju && (worldPositionable as Kaiju).OnGarrisonMode())
        {
            num += (worldPositionable as Kaiju).GetActiveTroops().GetPropertyValue(SimulationProperties.MilitaryPower);
        }
        if (size > 0)
        {
            foreach (global::Empire empire in (service.Game as global::Game).Empires)
            {
                if (empire is KaijuEmpire)
                {
                    KaijuEmpire kaijuEmpire = empire as KaijuEmpire;
                    if (kaijuEmpire != null && kaijuEmpire.Region != null)
                    {
                        KaijuCouncil agency2 = kaijuEmpire.GetAgency <KaijuCouncil>();
                        if (agency2 != null && agency2.Kaiju != null && agency2.Kaiju.IsTamed() && agency2.Kaiju.OnGarrisonMode() && this.worldPositionningService.GetDistance(worldPositionable.WorldPosition, agency2.Kaiju.WorldPosition) <= size && agency.IsEnnemy(agency2.Kaiju.MajorEmpire))
                        {
                            num += agency2.Kaiju.KaijuGarrison.GetPropertyValue(SimulationProperties.MilitaryPower);
                        }
                    }
                }
            }
            List <City> list = new List <City>();
            foreach (WorldPosition worldPosition in new WorldCircle(worldPositionable.WorldPosition, size).GetWorldPositions(this.worldPositionningService.World.WorldParameters))
            {
                Army armyAtPosition = this.worldPositionningService.GetArmyAtPosition(worldPosition);
                if (armyAtPosition != null && !armyAtPosition.IsFomorian && agency.IsEnnemy(armyAtPosition.Empire))
                {
                    num += armyAtPosition.GetPropertyValue(SimulationProperties.MilitaryPower);
                }
                District district = this.worldPositionningService.GetDistrict(worldPosition);
                if (district != null && district.Empire != null && district.City != null && agency.IsEnnemy(district.Empire))
                {
                    if (district.Type == DistrictType.Camp)
                    {
                        num += district.City.Camp.GetPropertyValue(SimulationProperties.MilitaryPower);
                    }
                    else if (!list.Contains(district.City))
                    {
                        num += district.City.GetPropertyValue(SimulationProperties.MilitaryPower);
                        list.Add(district.City);
                    }
                }
            }
        }
        return(num);
    }
Example #5
0
    private WorldPosition GetBestAttackPosition(Army army, Garrison target, IWorldPositionable targetWorldPositionable)
    {
        bool          flag          = this.worldPositionningService.IsWaterTile(targetWorldPositionable.WorldPosition);
        WorldPosition worldPosition = army.WorldPosition;
        float         num           = 0f;
        float         num2          = 0f;

        this.intelligenceAiHelper.EstimateMPInBattleground(army, worldPosition, target, ref num2, ref num);
        if (num == 0f)
        {
            num = 1f;
        }
        float            num3          = num2 / num;
        float            num4          = 0f;
        float            num5          = 0f;
        WorldOrientation orientation   = this.worldPositionningService.GetOrientation(targetWorldPositionable.WorldPosition, army.WorldPosition);
        WorldOrientation direction     = orientation.Rotate(-1);
        WorldPosition    neighbourTile = this.worldPositionningService.GetNeighbourTile(targetWorldPositionable.WorldPosition, direction, 1);

        if (neighbourTile.IsValid && this.worldPositionningService.IsWaterTile(neighbourTile) == flag && this.pathfindingService.IsTransitionPassable(neighbourTile, targetWorldPositionable.WorldPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null) && this.pathfindingService.IsTransitionPassable(neighbourTile, army.WorldPosition, army, OrderAttack.AttackFlags, null))
        {
            this.intelligenceAiHelper.EstimateMPInBattleground(army, neighbourTile, target, ref num5, ref num4);
            if (num5 == 0f)
            {
                num5 = 1f;
            }
            float num6 = num5 / num4;
            if (num3 < num6)
            {
                num3          = num6;
                num2          = num5;
                num           = num4;
                worldPosition = neighbourTile;
            }
        }
        WorldOrientation direction2     = orientation.Rotate(1);
        WorldPosition    neighbourTile2 = this.worldPositionningService.GetNeighbourTile(targetWorldPositionable.WorldPosition, direction2, 1);

        if (neighbourTile2.IsValid && this.worldPositionningService.IsWaterTile(neighbourTile2) == flag && this.pathfindingService.IsTransitionPassable(neighbourTile2, targetWorldPositionable.WorldPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile2, army, PathfindingFlags.IgnoreFogOfWar, null) && this.pathfindingService.IsTransitionPassable(neighbourTile2, army.WorldPosition, army, OrderAttack.AttackFlags, null))
        {
            this.intelligenceAiHelper.EstimateMPInBattleground(army, neighbourTile2, target, ref num5, ref num4);
            if (num5 == 0f)
            {
                num5 = 1f;
            }
            float num7 = num5 / num4;
            if (num3 < num7)
            {
                num2          = num5;
                num           = num4;
                worldPosition = neighbourTile2;
            }
        }
        return(worldPosition);
    }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (!this.downloadableContentService.IsShared(DownloadableContent13.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
        if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!(army.Empire is MajorEmpire))
        {
            return(State.Failure);
        }
        MantaZone mantaZone = null;

        if (!string.IsNullOrEmpty(this.MantaZoneVarName) && aiBehaviorTree.Variables.ContainsKey(this.MantaZoneVarName))
        {
            mantaZone = (aiBehaviorTree.Variables[this.MantaZoneVarName] as MantaZone);
        }
        if (mantaZone == null)
        {
            return(State.Failure);
        }
        float num = 0f;
        IWorldPositionable worldPositionable = null;

        this.GoThrought <OrbSpawnInfo>(mantaZone.Orbs, army, new Func <OrbSpawnInfo, Army, float>(this.ComputeOrbCollectingScore), ref num, ref worldPositionable);
        this.GoThrought <PointOfInterest>(mantaZone.Ruins, army, new Func <PointOfInterest, Army, float>(this.ComputeRuinScore), ref num, ref worldPositionable);
        this.GoThrought <PointOfInterest>(mantaZone.Resources, army, new Func <PointOfInterest, Army, float>(this.ComputeResourceScore), ref num, ref worldPositionable);
        if (worldPositionable != null)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = worldPositionable;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, worldPositionable);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
Example #7
0
 private bool CanPathToObjective(IWorldPositionable target)
 {
     if (target == null || this.departmentOfTheInterior.Cities.Count == 0)
     {
         return(false);
     }
     foreach (Army army in this.departmentOfDefense.Armies)
     {
         if (!army.IsSeafaring)
         {
             if (this.pathfindingService.FindPath(army, this.departmentOfTheInterior.Cities[0].WorldPosition, target.WorldPosition, PathfindingManager.RequestMode.Default, null, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreTerraformDevices | PathfindingFlags.IgnoreKaijuGarrisons, null) == null)
             {
                 return(false);
             }
             return(true);
         }
     }
     return(true);
 }
Example #8
0
    protected BehaviorNodeReturnCode ChoosePositionAwayFromMain(CatspawArmy army)
    {
        IWorldPositionable mainAttackableTarget = army.MainAttackableTarget;

        if (mainAttackableTarget == null)
        {
            return(BehaviorNodeReturnCode.Failure);
        }
        army.RoamingPosition = mainAttackableTarget.WorldPosition;
        if (this.worldPositionService.GetDistance(army.RoamingPosition, army.Garrison.WorldPosition) < 2)
        {
            WorldPosition validTileToAttack = base.GetValidTileToAttack(army, army.Garrison);
            if (validTileToAttack.IsValid)
            {
                army.RoamingPosition = validTileToAttack;
            }
        }
        return(BehaviorNodeReturnCode.Success);
    }
    private void ComputeScoreWithDistance(IWorldPositionable target, Army army, ref float score)
    {
        float propertyValue  = army.GetPropertyValue(SimulationProperties.MaximumMovement);
        float propertyValue2 = army.GetPropertyValue(SimulationProperties.Movement);
        float num            = (float)this.worldPositionningService.GetDistance(army.WorldPosition, target.WorldPosition);
        float num2           = num / propertyValue;

        if (num > propertyValue2)
        {
            num2 += 1f;
        }
        if (num2 > this.MaximumTurnDistance)
        {
            score = -1f;
            return;
        }
        float num3 = 1f;
        float num4 = 1f + num3 * num2;

        score /= num4;
    }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        global::Empire empire = aiBehaviorTree.AICommander.Empire;

        if (empire == null || !(empire is MajorEmpire))
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (string.IsNullOrEmpty(this.TargetVarName))
        {
            return(State.Failure);
        }
        if (army.GetPropertyValue(SimulationProperties.Movement) < 0.001f)
        {
            aiBehaviorTree.ErrorCode = 24;
            return(State.Failure);
        }
        IGameEntity gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;

        if (!(gameEntity is IWorldPositionable))
        {
            aiBehaviorTree.LogError("${0} is not a IWorldPositionable", new object[]
            {
                this.TargetVarName
            });
            return(State.Failure);
        }
        IWorldPositionable worldPositionable = gameEntity as IWorldPositionable;
        IGameService       service           = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        service.Game.Services.GetService <IGameEntityRepositoryService>();
        if (!worldPositionable.WorldPosition.IsValid)
        {
            aiBehaviorTree.LogError("${0} doesn't exists", new object[]
            {
                this.TargetVarName
            });
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        if (aiBehaviorTree.AICommander.TargetPower < 0f)
        {
            aiBehaviorTree.AICommander.TargetPower = this.GetTargetPower(worldPositionable, 6, army.Empire, service);
            Diagnostics.Log("ELCP {0} AIBehaviorTreeNode_Decorator_WaitForAllies TargetPower for {1} is {2}", new object[]
            {
                army.Empire,
                worldPositionable.WorldPosition,
                aiBehaviorTree.AICommander.TargetPower
            });
        }
        float propertyValue = army.GetPropertyValue(SimulationProperties.MilitaryPower);

        if (propertyValue > aiBehaviorTree.AICommander.TargetPower * 1.5f)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_LeaderVarName))
            {
                aiBehaviorTree.Variables.Remove(this.Output_LeaderVarName);
            }
            return(State.Failure);
        }
        List <AIBehaviorTreeNode_Decorator_WaitForAllies.ArmyDistance> list = new List <AIBehaviorTreeNode_Decorator_WaitForAllies.ArmyDistance>();

        foreach (AICommanderMission aicommanderMission in aiBehaviorTree.AICommander.Missions)
        {
            IGameEntity gameEntity2 = null;
            if (aicommanderMission.AIDataArmyGUID.IsValid && this.gameEntityRepositoryService.TryGetValue(aicommanderMission.AIDataArmyGUID, out gameEntity2) && gameEntity2 is Army)
            {
                Army army2 = gameEntity2 as Army;
                if (army2.GUID.IsValid)
                {
                    int distance = this.worldPositionningService.GetDistance(worldPositionable.WorldPosition, army2.WorldPosition);
                    list.Add(new AIBehaviorTreeNode_Decorator_WaitForAllies.ArmyDistance(army2, distance));
                }
            }
        }
        list.Sort(delegate(AIBehaviorTreeNode_Decorator_WaitForAllies.ArmyDistance leftarmy, AIBehaviorTreeNode_Decorator_WaitForAllies.ArmyDistance rightarmy)
        {
            if (leftarmy.distanceToObjective != rightarmy.distanceToObjective)
            {
                return(leftarmy.distanceToObjective.CompareTo(rightarmy.distanceToObjective));
            }
            return(leftarmy.army.GUID.CompareTo(rightarmy.army.GUID));
        });
        int  i     = 0;
        Army army3 = null;
        bool flag  = false;

        while (i < list.Count)
        {
            if (list[i].army == army)
            {
                float num = 0f;
                if (i > 0)
                {
                    num = list[0].army.GetPropertyValue(SimulationProperties.MilitaryPower);
                }
                float propertyValue2 = army.GetPropertyValue(SimulationProperties.Movement);
                float propertyValue3 = army.GetPropertyValue(SimulationProperties.MaximumMovement);
                int   distance2      = this.worldPositionningService.GetDistance(army.WorldPosition, list[0].army.WorldPosition);
                flag = (i == 0 || this.worldPositionningService.IsWaterTile(list[0].army.WorldPosition) || (float)distance2 > Mathf.Max(propertyValue2 + propertyValue3, 6f) || list[i].distanceToObjective <= distance2 || distance2 < 4);
                if (i == list.Count - 1 || (float)list[i].distanceToObjective <= Mathf.Max(propertyValue2, 6f) || this.worldPositionningService.IsWaterTile(army.WorldPosition))
                {
                    if (i == list.Count - 1 && (float)list[i].distanceToObjective > Mathf.Max(propertyValue2, 6f) && !this.worldPositionningService.IsWaterTile(army.WorldPosition))
                    {
                        army3 = list[0].army;
                        break;
                    }
                    break;
                }
                else if ((float)(list[i + 1].distanceToObjective - list[i].distanceToObjective) > list[i + 1].army.GetPropertyValue(SimulationProperties.MaximumMovement) + list[i + 1].army.GetPropertyValue(SimulationProperties.Movement))
                {
                    if (i > 0)
                    {
                        army3 = list[0].army;
                        break;
                    }
                    break;
                }
                else
                {
                    if (propertyValue + num > 1.5f * aiBehaviorTree.AICommander.TargetPower || list[0].army.IsNaval)
                    {
                        army3 = list[0].army;
                        break;
                    }
                    if (i == 0)
                    {
                        if (this.worldPositionningService.GetDistance(army.WorldPosition, list[i + 1].army.WorldPosition) > 2 && list[i + 1].distanceToObjective - list[i].distanceToObjective > 0)
                        {
                            return(State.Success);
                        }
                        break;
                    }
                    else
                    {
                        if ((float)(list[i + 1].distanceToObjective - list[i].distanceToObjective) > list[i + 1].army.GetPropertyValue(SimulationProperties.Movement))
                        {
                            return(State.Success);
                        }
                        break;
                    }
                }
            }
            else
            {
                i++;
            }
        }
        if (army3 != null && !flag)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_LeaderVarName))
            {
                aiBehaviorTree.Variables[this.Output_LeaderVarName] = army3;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_LeaderVarName, army3);
            }
        }
        else if (aiBehaviorTree.Variables.ContainsKey(this.Output_LeaderVarName))
        {
            aiBehaviorTree.Variables.Remove(this.Output_LeaderVarName);
        }
        return(State.Failure);
    }
Example #11
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        global::Empire empire = aiBehaviorTree.AICommander.Empire;

        if (empire == null || !(empire is MajorEmpire))
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        IWorldPositionable worldPositionable = null;

        if (string.IsNullOrEmpty(this.TargetVarName))
        {
            return(State.Failure);
        }
        IGameEntity gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;

        if (!(gameEntity is IWorldPositionable))
        {
            aiBehaviorTree.LogError("${0} is not a IWorldPositionable", new object[]
            {
                this.TargetVarName
            });
            return(State.Failure);
        }
        worldPositionable = (gameEntity as IWorldPositionable);
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        service.Game.Services.GetService <IGameEntityRepositoryService>();
        if (!worldPositionable.WorldPosition.IsValid)
        {
            aiBehaviorTree.LogError("${0} doesn't exists", new object[]
            {
                this.TargetVarName
            });
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        int num = 0;

        foreach (AICommanderMission aicommanderMission in aiBehaviorTree.AICommander.Missions)
        {
            IGameEntity gameEntity2 = null;
            if (aicommanderMission.AIDataArmyGUID.IsValid && this.gameEntityRepositoryService.TryGetValue(aicommanderMission.AIDataArmyGUID, out gameEntity2) && gameEntity2 is Army)
            {
                Army army2 = gameEntity2 as Army;
                if (army != army2 && army2.GUID.IsValid)
                {
                    int distance = this.worldPositionningService.GetDistance(worldPositionable.WorldPosition, army2.WorldPosition);
                    if (distance > num)
                    {
                        num = distance;
                    }
                }
            }
        }
        if (num <= this.worldPositionningService.GetDistance(army.WorldPosition, worldPositionable.WorldPosition))
        {
            return(State.Success);
        }
        return(State.Failure);
    }
 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 CanSearch(Army army, IWorldPositionable item, IQuestManagementService questManagementService, IQuestRepositoryService questRepositoryService)
    {
        if (army.HasCatspaw)
        {
            return(false);
        }
        PointOfInterest pointOfInterest = item as PointOfInterest;

        if (pointOfInterest == null)
        {
            return(false);
        }
        if (pointOfInterest.Type != ELCPUtilities.QuestLocation && pointOfInterest.Type != "NavalQuestLocation")
        {
            return(false);
        }
        if (pointOfInterest.Interaction.IsLocked(army.Empire.Index, "ArmyActionSearch"))
        {
            return(false);
        }
        if (ELCPUtilities.UseELCPPeacefulCreepingNodes)
        {
            if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != army.Empire)
            {
                if (pointOfInterest.Empire == null)
                {
                    return(false);
                }
                if (!(pointOfInterest.Empire is MajorEmpire))
                {
                    return(false);
                }
                DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                if (agency == null)
                {
                    return(false);
                }
                if (!agency.IsFriend(pointOfInterest.Empire))
                {
                    return(false);
                }
            }
        }
        else if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != army.Empire)
        {
            return(false);
        }
        if ((pointOfInterest.Interaction.Bits & army.Empire.Bits) == army.Empire.Bits && !SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag))
        {
            return(false);
        }
        if (SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag) && !pointOfInterest.UntappedDustDeposits && (pointOfInterest.Interaction.Bits & army.Empire.Bits) == army.Empire.Bits)
        {
            return(false);
        }
        if ((pointOfInterest.Interaction.Bits & army.Empire.Bits) != 0)
        {
            using (IEnumerator <QuestMarker> enumerator = questManagementService.GetMarkersByBoundTargetGUID(pointOfInterest.GUID).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Quest quest;
                    if (questRepositoryService.TryGetValue(enumerator.Current.QuestGUID, out quest) && quest.EmpireBits == army.Empire.Bits)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        return(true);
    }
    private bool CanSearchQuest(Army army, IWorldPositionable item, IQuestManagementService questManagementService, IQuestRepositoryService questRepositoryService)
    {
        PointOfInterest pointOfInterest = item as PointOfInterest;

        if (pointOfInterest == null)
        {
            return(false);
        }
        if (pointOfInterest.Type != ELCPUtilities.QuestLocation && pointOfInterest.Type != "NavalQuestLocation")
        {
            return(false);
        }
        if (ELCPUtilities.UseELCPPeacefulCreepingNodes)
        {
            if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != army.Empire)
            {
                if (pointOfInterest.Empire == null)
                {
                    return(false);
                }
                if (!(pointOfInterest.Empire is MajorEmpire))
                {
                    return(false);
                }
                DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                if (agency == null)
                {
                    return(false);
                }
                if (!agency.IsFriend(pointOfInterest.Empire))
                {
                    return(false);
                }
            }
        }
        else if (pointOfInterest.CreepingNodeImprovement != null && pointOfInterest.Empire.Index != army.Empire.Index)
        {
            return(false);
        }
        if (!pointOfInterest.Interaction.IsLocked(army.Empire.Index, "ArmyActionSearch"))
        {
            foreach (QuestMarker questMarker in questManagementService.GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
            {
                Quest quest;
                if (questRepositoryService.TryGetValue(questMarker.QuestGUID, out quest))
                {
                    QuestBehaviour questBehaviour = questRepositoryService.GetQuestBehaviour(quest.Name, army.Empire.Index);
                    if (questBehaviour != null && quest.EmpireBits == army.Empire.Bits && questMarker.IsVisibleFor(army.Empire))
                    {
                        string a = quest.QuestDefinition.Name;
                        if (quest.QuestDefinition.Name == AILayer_QuestSolver.ImportantQuestNames.GlobalQuestACursedBountyName && questMarker.IsVisibleInFogOfWar)
                        {
                            if (this.QuestLayer == null)
                            {
                                GameServer           gameServer = (Services.GetService <ISessionService>().Session as global::Session).GameServer as GameServer;
                                AIPlayer_MajorEmpire aiplayer_MajorEmpire;
                                if (gameServer.AIScheduler != null && gameServer.AIScheduler.TryGetMajorEmpireAIPlayer(army.Empire as MajorEmpire, out aiplayer_MajorEmpire))
                                {
                                    AIEntity entity = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
                                    if (entity != null)
                                    {
                                        this.QuestLayer = entity.GetLayer <AILayer_QuestSolver>();
                                    }
                                }
                            }
                            if (this.QuestLayer.SearchACursedBountyRuin)
                            {
                                return(true);
                            }
                            this.CursedBountyPosition = questMarker.WorldPosition;
                            return(false);
                        }
                        else
                        {
                            if (a == "VictoryQuest-Chapter3" && questMarker.IsVisibleInFogOfWar)
                            {
                                return(true);
                            }
                            if (a == "VictoryQuest-Chapter1Alt" || a == "VictoryQuest-Chapter1")
                            {
                                QuestBehaviourTreeNode_ConditionCheck_Prerequisite questBehaviourTreeNode_ConditionCheck_Prerequisite;
                                if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_Prerequisite>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_Prerequisite))
                                {
                                    return(false);
                                }
                                foreach (QuestBehaviourPrerequisites questBehaviourPrerequisites in questBehaviourTreeNode_ConditionCheck_Prerequisite.Prerequisites)
                                {
                                    for (int j = 0; j < questBehaviourPrerequisites.Prerequisites.Length; j++)
                                    {
                                        InterpreterPrerequisite interpreterPrerequisite = questBehaviourPrerequisites.Prerequisites[j] as InterpreterPrerequisite;
                                        if (interpreterPrerequisite != null && !interpreterPrerequisite.Check(army))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                                return(true);
                            }
                            else if (a == "GlobalQuestCoop#0004")
                            {
                                if (quest.QuestDefinition.Variables.First((QuestVariableDefinition p) => p.VarName == "$NameOfStrategicResourceToGather1") != null)
                                {
                                    QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount questBehaviourTreeNode_ConditionCheck_HasResourceAmount;
                                    if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_HasResourceAmount))
                                    {
                                        return(false);
                                    }
                                    string resourceName             = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                    int    wantedAmount             = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                    DepartmentOfTheTreasury agency2 = army.Empire.GetAgency <DepartmentOfTheTreasury>();
                                    float num;
                                    if (agency2 != null && agency2.TryGetResourceStockValue(army.Empire.SimulationObject, resourceName, out num, false) && num >= (float)(wantedAmount * 3))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        return(false);
    }
 private void GoThrought <T>(List <T> targets, Army army, Func <T, Army, float> scoreFunc, ref float bestScore, ref IWorldPositionable bestTarget) where T : IWorldPositionable
 {
     for (int i = 0; i < targets.Count; i++)
     {
         T     t   = targets[i];
         float num = scoreFunc(t, army);
         if (num >= bestScore)
         {
             this.ComputeScoreWithDistance(t, army, ref num);
             if (num > bestScore)
             {
                 bestScore  = num;
                 bestTarget = t;
             }
         }
     }
 }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        global::Empire empire = aiBehaviorTree.AICommander.Empire;

        if (empire == null || !(empire is MajorEmpire))
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        GameServer             gameServer             = (Services.GetService <ISessionService>().Session as global::Session).GameServer as GameServer;
        AILayer_ArmyManagement ailayer_ArmyManagement = null;
        AIPlayer_MajorEmpire   aiplayer_MajorEmpire;

        if (gameServer.AIScheduler != null && gameServer.AIScheduler.TryGetMajorEmpireAIPlayer(empire as MajorEmpire, out aiplayer_MajorEmpire))
        {
            AIEntity entity = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
            if (entity != null)
            {
                ailayer_ArmyManagement = entity.GetLayer <AILayer_ArmyManagement>();
            }
        }
        if (ailayer_ArmyManagement == null)
        {
            return(State.Failure);
        }
        int         num         = int.MaxValue;
        Army        value       = null;
        AICommander aicommander = null;

        foreach (AICommander aicommander2 in ailayer_ArmyManagement.AICommanders)
        {
            if (aicommander2 is AICommander_WarWithObjective || aicommander2 is AICommander_Victory)
            {
                foreach (AICommanderMission aicommanderMission in aicommander2.Missions)
                {
                    IGameEntity gameEntity = null;
                    if (aicommanderMission.AIDataArmyGUID.IsValid && this.gameEntityRepositoryService.TryGetValue(aicommanderMission.AIDataArmyGUID, out gameEntity) && gameEntity is Army)
                    {
                        Army army2    = gameEntity as Army;
                        int  distance = this.worldPositionningService.GetDistance(army.WorldPosition, army2.WorldPosition);
                        if (distance < num)
                        {
                            num         = distance;
                            value       = army2;
                            aicommander = aicommander2;
                        }
                    }
                }
            }
        }
        if ((float)num > Mathf.Max(army.GetPropertyValue(SimulationProperties.MaximumMovement) * 1.5f, 6f))
        {
            return(State.Failure);
        }
        if (aicommander != null && aicommander is AICommanderWithObjective)
        {
            AICommanderWithObjective aicommanderWithObjective = aicommander as AICommanderWithObjective;
            IWorldPositionable       worldPositionable        = null;
            if (aicommanderWithObjective.SubObjectiveGuid.IsValid)
            {
                IGameEntity gameEntity2 = null;
                if (this.gameEntityRepositoryService.TryGetValue(aicommanderWithObjective.SubObjectiveGuid, out gameEntity2) && gameEntity2 is IWorldPositionable)
                {
                    worldPositionable = (gameEntity2 as IWorldPositionable);
                }
            }
            Region region = this.worldPositionningService.GetRegion(aicommanderWithObjective.RegionIndex);
            if (region.City != null)
            {
                worldPositionable = region.City;
            }
            if (worldPositionable == null)
            {
                if (aiBehaviorTree.Variables.ContainsKey(this.Output_MainTargetVarName))
                {
                    aiBehaviorTree.Variables.Remove(this.Output_MainTargetVarName);
                }
                return(State.Failure);
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_MainTargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_MainTargetVarName] = worldPositionable;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_MainTargetVarName, worldPositionable);
            }
        }
        if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
        {
            aiBehaviorTree.Variables[this.Output_TargetVarName] = value;
        }
        else
        {
            aiBehaviorTree.Variables.Add(this.Output_TargetVarName, value);
        }
        return(State.Success);
    }
Example #17
0
    public static bool CanSearch(global::Empire empire, IWorldPositionable item, IQuestManagementService questManagementService)
    {
        PointOfInterest pointOfInterest = item as PointOfInterest;

        if (pointOfInterest == null)
        {
            return(false);
        }
        if (pointOfInterest.Type != ELCPUtilities.QuestLocation && pointOfInterest.Type != "NavalQuestLocation")
        {
            Diagnostics.Log("fail1 {0}", new object[]
            {
                pointOfInterest.Type
            });
            return(false);
        }
        if (pointOfInterest.Interaction.IsLocked(empire.Index, "ArmyActionSearch"))
        {
            Diagnostics.Log("fail2");
            return(false);
        }
        if (ELCPUtilities.UseELCPPeacefulCreepingNodes)
        {
            if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != empire)
            {
                if (pointOfInterest.Empire == null)
                {
                    return(false);
                }
                if (!(pointOfInterest.Empire is MajorEmpire))
                {
                    return(false);
                }
                DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>();
                if (agency == null)
                {
                    return(false);
                }
                if (!agency.IsFriend(pointOfInterest.Empire))
                {
                    return(false);
                }
            }
        }
        else if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != empire)
        {
            return(false);
        }
        if ((pointOfInterest.Interaction.Bits & empire.Bits) == empire.Bits && !SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag))
        {
            Diagnostics.Log("fail3");
            return(false);
        }
        if (SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag) && !pointOfInterest.UntappedDustDeposits && (pointOfInterest.Interaction.Bits & empire.Bits) == empire.Bits)
        {
            Diagnostics.Log("fail4");
            return(false);
        }
        if ((pointOfInterest.Interaction.Bits & empire.Bits) != 0)
        {
            using (IEnumerator <QuestMarker> enumerator = questManagementService.GetMarkersByBoundTargetGUID(pointOfInterest.GUID).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.IsVisibleFor(empire))
                    {
                        Diagnostics.Log("fail5");
                        return(false);
                    }
                }
            }
            return(true);
        }
        return(true);
    }
Example #18
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
        {
            aiBehaviorTree.LogError("$Target not set {0}/{1}", new object[]
            {
                army.Empire,
                army.LocalizedName
            });
            return(State.Failure);
        }
        IWorldPositionable worldPositionable = aiBehaviorTree.Variables[this.TargetVarName] as IWorldPositionable;

        if (worldPositionable == null)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();

        Diagnostics.Assert(service2 != null);
        IPathfindingService service3 = service.Game.Services.GetService <IPathfindingService>();

        Diagnostics.Assert(service3 != null);
        WorldPosition worldPosition;

        if (worldPositionable is City)
        {
            City city = worldPositionable as City;
            if (army.Empire != city.Empire)
            {
                worldPosition = this.NewDistrictToAttackCity(army, city);
            }
            else
            {
                District nearestDistrictToReinforce = this.GetNearestDistrictToReinforce(army, city);
                if (nearestDistrictToReinforce == null)
                {
                    aiBehaviorTree.ErrorCode = 2;
                    return(State.Failure);
                }
                worldPosition = nearestDistrictToReinforce.WorldPosition;
            }
        }
        else if (worldPositionable is Fortress)
        {
            Fortress      fortress       = worldPositionable as Fortress;
            WorldPosition worldPosition2 = worldPositionable.WorldPosition;
            int           num            = service2.GetDistance(army.WorldPosition, worldPosition2);
            foreach (PointOfInterest pointOfInterest in fortress.Facilities)
            {
                int distance = service2.GetDistance(army.WorldPosition, pointOfInterest.WorldPosition);
                if (distance < num)
                {
                    num            = distance;
                    worldPosition2 = pointOfInterest.WorldPosition;
                }
            }
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPosition2, army);
        }
        else if (worldPositionable is Camp)
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
        }
        else if (worldPositionable is Village)
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
        }
        else if (worldPositionable is OrbSpawnInfo)
        {
            worldPosition = worldPositionable.WorldPosition;
        }
        else if (worldPositionable is MapBoostSpawnInfo)
        {
            worldPosition = worldPositionable.WorldPosition;
        }
        else if (worldPositionable is PointOfInterest)
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
        }
        else if (worldPositionable is Kaiju)
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
            if (!worldPosition.IsValid && this.AllowBackupPosition)
            {
                worldPosition = worldPositionable.WorldPosition;
            }
        }
        else if (worldPositionable is Army)
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
            if (!worldPosition.IsValid && this.AllowBackupPosition)
            {
                worldPosition = worldPositionable.WorldPosition;
            }
        }
        else if (service2.IsWaterTile(army.WorldPosition) != service2.IsWaterTile(worldPositionable.WorldPosition))
        {
            worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army);
        }
        else
        {
            worldPosition = worldPositionable.WorldPosition;
        }
        if (worldPosition == WorldPosition.Invalid)
        {
            aiBehaviorTree.ErrorCode = 11;
            return(State.Failure);
        }
        if (aiBehaviorTree.Variables.ContainsKey(this.Output_DestinationVarName))
        {
            aiBehaviorTree.Variables[this.Output_DestinationVarName] = worldPosition;
        }
        else
        {
            aiBehaviorTree.Variables.Add(this.Output_DestinationVarName, worldPosition);
        }
        return(State.Success);
    }