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);
    }
Esempio n. 3
0
    protected override void ShowTooltip(WorldPosition worldPosition)
    {
        if (this.guiTooltipService == null)
        {
            return;
        }
        if (AgeManager.IsMouseCovered)
        {
            return;
        }
        IWorldPositionningService service = base.GameService.Game.Services.GetService <IWorldPositionningService>();

        if (worldPosition.IsValid)
        {
            if (service != null)
            {
                if (service == null)
                {
                    this.guiTooltipService.HideTooltip();
                    return;
                }
                if ((service.GetExplorationBits(worldPosition) & base.EmpireBits) == 0)
                {
                    this.guiTooltipService.HideTooltip();
                    return;
                }
                AgeTransform         cursorTooltipAnchor = this.guiTooltipService.GetCursorTooltipAnchor();
                AgeTooltipAnchorMode anchorMode          = AgeTooltipAnchorMode.FREE;
                global::CursorTarget cursorTarget        = null;
                if (base.CursorTargetService.HighlightedCursorTargets.Count > 0)
                {
                    for (int i = 0; i < base.CursorTargetService.HighlightedCursorTargets.Count; i++)
                    {
                        Diagnostics.Log("Cursortarget {0} at {1} is {2} and has tooltipclass {3}", new object[]
                        {
                            i,
                            worldPosition,
                            base.CursorTargetService.HighlightedCursorTargets[i].GetType(),
                            (base.CursorTargetService.HighlightedCursorTargets[i] as global::CursorTarget).TooltipClass
                        });
                        Diagnostics.Log("Conten: {0}", new object[]
                        {
                            (base.CursorTargetService.HighlightedCursorTargets[i] as global::CursorTarget).TooltipContent
                        });
                        Diagnostics.Log("Context: {0}", new object[]
                        {
                            (base.CursorTargetService.HighlightedCursorTargets[i] as global::CursorTarget).TooltipContext.GetType()
                        });
                        if (cursorTarget == null)
                        {
                            cursorTarget = (base.CursorTargetService.HighlightedCursorTargets[i] as global::CursorTarget);
                        }
                        else if (StaticString.IsNullOrEmpty(cursorTarget.TooltipClass))
                        {
                            cursorTarget = (base.CursorTargetService.HighlightedCursorTargets[i] as global::CursorTarget);
                        }
                    }
                }
                string          text            = string.Format("Worldposition: {0} {1}", worldPosition.Row, worldPosition.Column);
                PointOfInterest pointOfInterest = service.GetPointOfInterest(worldPosition);
                if (pointOfInterest != null)
                {
                    text += "\nhas POI!";
                    IQuestManagementService service2 = base.GameService.Game.Services.GetService <IQuestManagementService>();
                    IQuestRepositoryService service3 = base.GameService.Game.Services.GetService <IQuestRepositoryService>();
                    global::Empire          empire   = base.GameService.Game.Services.GetService <IPlayerControllerRepositoryService>().ActivePlayerController.Empire as global::Empire;
                    if (empire != null)
                    {
                        text += string.Concat(new object[]
                        {
                            "\n",
                            pointOfInterest.Type,
                            ", ",
                            pointOfInterest.Interaction.IsLocked(empire.Index, "ArmyActionSearch").ToString(),
                            ", ",
                            pointOfInterest.Interaction.Bits,
                            ", ",
                            empire.Bits,
                            ", ",
                            (pointOfInterest.Interaction.Bits & empire.Bits) == empire.Bits,
                            ", ",
                            pointOfInterest.UntappedDustDeposits.ToString(),
                            ", ",
                            SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag).ToString()
                        }).ToString();
                        foreach (QuestMarker questMarker in service2.GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
                        {
                            Quest quest;
                            if (service3.TryGetValue(questMarker.QuestGUID, out quest))
                            {
                                text = text + "\nhas Questmarker for quest" + quest.QuestDefinition.Name;
                                QuestBehaviour questBehaviour = service3.GetQuestBehaviour(quest.Name, empire.Index);
                                if (questBehaviour != null)
                                {
                                    QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount questBehaviourTreeNode_ConditionCheck_HasResourceAmount;
                                    if (quest.QuestDefinition.Variables.First((QuestVariableDefinition p) => p.VarName == "$NameOfStrategicResourceToGather1") != null && this.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_HasResourceAmount))
                                    {
                                        string resourceName = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                        int    wantedAmount = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                        text = text + "\nResource: " + resourceName;
                                        text = text + "\nAmount: " + wantedAmount;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!(cursorTarget != null) || StaticString.IsNullOrEmpty(cursorTarget.TooltipClass))
                {
                    if (base.TooltipFilters != null)
                    {
                        if (!Array.Exists <StaticString>(base.TooltipFilters, (StaticString match) => match == "Terrain"))
                        {
                            this.guiTooltipService.HideTooltip();
                            return;
                        }
                    }
                    this.guiTooltipService.ShowTooltip(string.Empty, text, worldPosition, cursorTooltipAnchor, anchorMode, 0f, false);
                    return;
                }
                if (base.TooltipFilters == null || Array.Exists <StaticString>(base.TooltipFilters, (StaticString match) => match == cursorTarget.TooltipClass))
                {
                    this.guiTooltipService.ShowTooltip(string.Empty, text, worldPosition, cursorTooltipAnchor, anchorMode, 0f, false);
                    return;
                }
                this.guiTooltipService.HideTooltip();
                return;
            }
        }
        else
        {
            this.guiTooltipService.HideTooltip();
        }
    }
Esempio n. 4
0
    private void SelectTarget()
    {
        this.battleTarget = null;
        if (this.LastHighlightedWorldPosition == WorldPosition.Invalid)
        {
            return;
        }
        if (!base.VisibilityService.IsWorldPositionVisibleFor(this.LastHighlightedWorldPosition, this.Army.Empire))
        {
            return;
        }
        Region region = base.WorldPositionningService.GetRegion(this.LastHighlightedWorldPosition);

        if (region == null || this.battleTarget != null)
        {
            return;
        }
        PointOfInterest pointOfInterest = region.PointOfInterests.FirstOrDefault((PointOfInterest match) => match.WorldPosition == this.LastHighlightedWorldPosition);

        if (pointOfInterest != null && (pointOfInterest.Type == Fortress.Citadel || pointOfInterest.Type == Fortress.Facility))
        {
            Fortress fortressAt = region.NavalEmpire.GetAgency <PirateCouncil>().GetFortressAt(pointOfInterest.WorldPosition);
            this.battleTarget = fortressAt;
        }
        if (region != null)
        {
            District district = null;
            if (region.City != null && region.City.Empire != this.Army.Empire)
            {
                district = region.City.Districts.FirstOrDefault((District match) => match.WorldPosition == this.LastHighlightedWorldPosition);
            }
            if (district != null && district.Type != DistrictType.Exploitation)
            {
                this.battleTarget = district;
            }
        }
        if (this.battleTarget == null && region != null && region.City != null && region.City.Camp != null && region.City.Camp.WorldPosition == this.LastHighlightedWorldPosition && region.City.Empire != this.Army.Empire)
        {
            this.battleTarget = region.City.Camp;
        }
        if (this.battleTarget == null)
        {
            Army armyAtPosition = base.WorldPositionningService.GetArmyAtPosition(this.LastHighlightedWorldPosition);
            if (armyAtPosition != null && (!armyAtPosition.IsCamouflaged || base.VisibilityService.IsWorldPositionDetectedFor(this.LastHighlightedWorldPosition, this.Army.Empire)))
            {
                this.battleTarget = armyAtPosition;
            }
        }
        if (region != null && this.battleTarget == null)
        {
            pointOfInterest = region.PointOfInterests.FirstOrDefault((PointOfInterest match) => match.WorldPosition == this.LastHighlightedWorldPosition);
            if (pointOfInterest != null)
            {
                if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero)
                {
                    CreepingNode creepingNode = null;
                    base.GameEntityRepositoryService.TryGetValue <CreepingNode>(pointOfInterest.CreepingNodeGUID, out creepingNode);
                    if (creepingNode != null)
                    {
                        if (creepingNode.Empire.Index != this.Army.Empire.Index)
                        {
                            if (ELCPUtilities.UseELCPPeacefulCreepingNodes)
                            {
                                DepartmentOfForeignAffairs agency = this.Army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                                if (agency != null && agency.IsFriend(creepingNode.Empire))
                                {
                                    if (pointOfInterest.Type == "QuestLocation")
                                    {
                                        this.battleTarget = pointOfInterest;
                                    }
                                    else if (pointOfInterest.Type == "Village")
                                    {
                                        IQuestManagementService   service  = base.GameService.Game.Services.GetService <IQuestManagementService>();
                                        IQuestRepositoryService   service2 = base.GameService.Game.Services.GetService <IQuestRepositoryService>();
                                        IEnumerable <QuestMarker> markersByBoundTargetGUID = service.GetMarkersByBoundTargetGUID(pointOfInterest.GUID);
                                        bool flag = false;
                                        foreach (QuestMarker questMarker in markersByBoundTargetGUID)
                                        {
                                            Quest quest;
                                            if (service2.TryGetValue(questMarker.QuestGUID, out quest) && quest.EmpireBits == this.Army.Empire.Bits)
                                            {
                                                Village villageAt = region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(pointOfInterest.WorldPosition);
                                                this.battleTarget = villageAt;
                                                flag = true;
                                                break;
                                            }
                                        }
                                        if (!flag)
                                        {
                                            this.battleTarget = creepingNode;
                                        }
                                    }
                                    else
                                    {
                                        this.battleTarget = creepingNode;
                                    }
                                }
                            }
                            else
                            {
                                this.battleTarget = creepingNode;
                            }
                        }
                        else if (pointOfInterest.Type == "QuestLocation" || pointOfInterest.Type == "NavalQuestLocation")
                        {
                            this.battleTarget = pointOfInterest;
                        }
                    }
                }
                else if (pointOfInterest.Type == "Village")
                {
                    Village villageAt2 = region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(pointOfInterest.WorldPosition);
                    this.battleTarget = villageAt2;
                }
                else if (pointOfInterest.Type == "QuestLocation" || pointOfInterest.Type == "NavalQuestLocation")
                {
                    this.battleTarget = pointOfInterest;
                }
            }
        }
        if (region != null && this.battleTarget == null && region.KaijuEmpire != null && region.Kaiju != null)
        {
            KaijuGarrison kaijuGarrison = region.Kaiju.KaijuGarrison;
            if (kaijuGarrison.WorldPosition == this.LastHighlightedWorldPosition)
            {
                this.battleTarget = kaijuGarrison;
            }
        }
        if (this.battleTarget == null)
        {
            TerraformDevice deviceAtPosition = (base.GameService.Game as global::Game).GetService <ITerraformDeviceService>().GetDeviceAtPosition(this.LastHighlightedWorldPosition);
            if (deviceAtPosition != null)
            {
                this.battleTarget = deviceAtPosition;
            }
        }
    }
Esempio n. 5
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army2;

        base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army2);
        IGameService service = Services.GetService <IGameService>();

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

        if (this.orderTicket != null)
        {
            if (!this.orderTicket.Raised)
            {
                result = State.Running;
            }
            else
            {
                OrderInteractWith orderInteractWith = this.orderTicket.Order as OrderInteractWith;
                IGameEntity       gameEntity        = null;
                if (this.orderTicket.PostOrderResponse != PostOrderResponse.Processed)
                {
                    if (service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity))
                    {
                        PointOfInterest pointOfInterest;
                        if (gameEntity is Village)
                        {
                            pointOfInterest = (gameEntity as Village).PointOfInterest;
                        }
                        else
                        {
                            pointOfInterest = (gameEntity as PointOfInterest);
                        }
                        if (pointOfInterest != null)
                        {
                            IQuestRepositoryService service3 = service.Game.Services.GetService <IQuestRepositoryService>();
                            foreach (QuestMarker questMarker in service.Game.Services.GetService <IQuestManagementService>().GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
                            {
                                Quest quest;
                                if (service3.TryGetValue(questMarker.QuestGUID, out quest) && quest.QuestDefinition.Name == "GlobalQuestCoop#0004" && quest.EmpireBits == army2.Empire.Bits && questMarker.IsVisibleFor(army2.Empire))
                                {
                                    this.orderTicket = null;
                                    QuestBehaviour questBehaviour = service3.GetQuestBehaviour(quest.Name, army2.Empire.Index);
                                    if (questBehaviour != null)
                                    {
                                        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))
                                            {
                                                break;
                                            }
                                            string resourceName            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                            int    wantedAmount            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                            DepartmentOfTheTreasury agency = army2.Empire.GetAgency <DepartmentOfTheTreasury>();
                                            if (agency == null)
                                            {
                                                break;
                                            }
                                            float num;
                                            if (agency != null && agency.TryGetResourceStockValue(army2.Empire.SimulationObject, resourceName, out num, false) && num >= (float)wantedAmount)
                                            {
                                                return(State.Running);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            if ((pointOfInterest.Interaction.Bits & aiBehaviorTree.AICommander.Empire.Bits) != aiBehaviorTree.AICommander.Empire.Bits)
                            {
                                pointOfInterest.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                            }
                        }
                    }
                    aiBehaviorTree.ErrorCode = 30;
                    this.orderTicket         = null;
                    result = State.Failure;
                }
                else
                {
                    if (this.orderTicket.PostOrderResponse == PostOrderResponse.Processed && service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity) && gameEntity is PointOfInterest && orderInteractWith.Tags.Contains("Talk") && orderInteractWith.QuestRewards == null)
                    {
                        PointOfInterest pointOfInterest2 = gameEntity as PointOfInterest;
                        Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin parley order without quest reward: {1} ", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire.ToString(),
                            pointOfInterest2.WorldPosition
                        });
                        if (pointOfInterest2 != null)
                        {
                            pointOfInterest2.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                        }
                    }
                    this.orderTicket = null;
                    result           = State.Success;
                }
            }
        }
        else
        {
            Army army;
            if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
            {
                result = State.Failure;
            }
            else
            {
                if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
                {
                    aiBehaviorTree.LogError("${0} not set", new object[]
                    {
                        this.TargetVarName
                    });
                    return(State.Failure);
                }
                IGameEntity gameEntity2 = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
                if (!(gameEntity2 is IWorldPositionable) || (!(gameEntity2 is PointOfInterest) && !(gameEntity2 is Village)))
                {
                    aiBehaviorTree.ErrorCode = 10;
                    return(State.Failure);
                }
                if (gameEntity2 is Village)
                {
                    Village village = gameEntity2 as Village;
                    Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin village {2} {3}", new object[]
                    {
                        aiBehaviorTree.AICommander.Empire,
                        army.LocalizedName,
                        village.WorldPosition,
                        this.QuestVillage
                    });
                    PointOfInterest pointOfInterest3 = village.PointOfInterest;
                    if (pointOfInterest3 == null)
                    {
                        return(State.Failure);
                    }
                    if (!this.QuestVillage)
                    {
                        if (village.HasBeenConverted || village.HasBeenPacified || village.IsInEncounter || village.PointOfInterest.PointOfInterestImprovement == null)
                        {
                            return(State.Failure);
                        }
                        if (!aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley())
                        {
                            return(State.Failure);
                        }
                        if (pointOfInterest3.SimulationObject.Tags.Contains(Village.DissentedVillage))
                        {
                            return(State.Failure);
                        }
                        if ((pointOfInterest3.Interaction.Bits & army.Empire.Bits) != 0)
                        {
                            Diagnostics.Log("fail");
                            return(State.Failure);
                        }
                        QuestMarker questMarker2;
                        if (service.Game.Services.GetService <IQuestManagementService>().TryGetMarkerByGUID(pointOfInterest3.GUID, out questMarker2))
                        {
                            Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin Questmarker active", new object[]
                            {
                                aiBehaviorTree.AICommander.Empire.ToString()
                            });
                            return(State.Failure);
                        }
                    }
                }
                Diagnostics.Assert(AIScheduler.Services != null);
                if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, (gameEntity2 as IWorldPositionable).WorldPosition) != 1)
                {
                    aiBehaviorTree.ErrorCode = 12;
                    result = State.Failure;
                }
                else
                {
                    IEncounterRepositoryService service4 = service.Game.Services.GetService <IEncounterRepositoryService>();
                    if (service4 != null)
                    {
                        IEnumerable <Encounter> enumerable = service4;
                        if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false)))
                        {
                            return(State.Running);
                        }
                    }
                    if (gameEntity2 is Village)
                    {
                        Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin2 village", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire,
                            army.LocalizedName
                        });
                        PointOfInterest   pointOfInterest4   = (gameEntity2 as Village).PointOfInterest;
                        OrderInteractWith orderInteractWith2 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionParley");
                        orderInteractWith2.WorldPosition = army.WorldPosition;
                        orderInteractWith2.Tags.AddTag("Talk");
                        orderInteractWith2.TargetGUID     = pointOfInterest4.GUID;
                        orderInteractWith2.ArmyActionName = "ArmyActionParley";
                        orderInteractWith2.NumberOfActionPointsToSpend = 0f;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith2, out this.orderTicket, null);
                    }
                    else
                    {
                        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
                        {
                            Diagnostics.Log("~~~~~ ELCP: {0}/{1} ArmyActionSearch at {2}, {3} {4} ~~~~~", new object[]
                            {
                                army.LocalizedName,
                                army.Empire,
                                (gameEntity2 as PointOfInterest).WorldPosition,
                                ((gameEntity2 as PointOfInterest).Interaction.Bits & army.Empire.Bits) == army.Empire.Bits,
                                (gameEntity2 as PointOfInterest).UntappedDustDeposits
                            });
                        }
                        OrderInteractWith orderInteractWith3 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionSearch");
                        orderInteractWith3.WorldPosition = army.WorldPosition;
                        orderInteractWith3.Tags.AddTag("Interact");
                        orderInteractWith3.TargetGUID = gameEntity2.GUID;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith3, out this.orderTicket, null);
                    }
                    result = State.Running;
                }
            }
        }
        return(result);
    }
Esempio n. 6
0
    private bool CanSearch(Army army, PointOfInterest pointOfInterest, IQuestManagementService questManagementService, IQuestRepositoryService questRepositoryService, ref bool available)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null)
        {
            return(false);
        }
        global::Game game = service.Game as global::Game;

        if (game == null)
        {
            return(false);
        }
        if (pointOfInterest == null)
        {
            return(false);
        }
        if (pointOfInterest.Type != ELCPUtilities.QuestLocation)
        {
            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);
        }
        bool flag = false;

        foreach (QuestMarker questMarker in questManagementService.GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
        {
            Quest quest;
            if (!questMarker.IgnoreInteraction && questRepositoryService.TryGetValue(questMarker.QuestGUID, out quest) && quest.EmpireBits == army.Empire.Bits)
            {
                if (!quest.QuestDefinition.SkipLockedQuestTarget)
                {
                    available = true;
                    return(true);
                }
                flag = true;
            }
        }
        if (pointOfInterest.UntappedDustDeposits && SimulationGlobal.GlobalTagsContains(SeasonManager.RuinDustDepositsTag))
        {
            return(true);
        }
        if (pointOfInterest.Interaction.IsLocked(army.Empire.Index, this.Name))
        {
            return(false);
        }
        IWorldPositionningService service2 = game.Services.GetService <IWorldPositionningService>();

        if (service2 != null && service2.IsWaterTile(pointOfInterest.WorldPosition))
        {
            return(false);
        }
        global::Empire[] empires = game.Empires;
        for (int i = 0; i < empires.Length; i++)
        {
            using (IEnumerator <Army> enumerator2 = empires[i].GetAgency <DepartmentOfDefense>().Armies.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    if (enumerator2.Current.WorldPosition == pointOfInterest.WorldPosition)
                    {
                        return(false);
                    }
                }
            }
        }
        if ((pointOfInterest.Interaction.Bits & army.Empire.Bits) == 0)
        {
            return(true);
        }
        available = true;
        if (flag)
        {
            available = true;
            return(true);
        }
        return(false);
    }