protected override bool TryComputeArmyMissionParameter()
    {
        if (this.RegionTarget == null)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return(false);
        }
        base.ArmyMissionParameters.Clear();
        if (base.AIDataArmyGUID == GameEntityGUID.Zero)
        {
            return(false);
        }
        AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID);

        if (aidata == null)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return(false);
        }
        Army maxHostileArmy = AILayer_Pacification.GetMaxHostileArmy(base.Commander.Empire, this.RegionTarget.Index);

        if (maxHostileArmy != null && aidata.Army.GetPropertyValue(SimulationProperties.MilitaryPower) > 0.8f * maxHostileArmy.GetPropertyValue(SimulationProperties.MilitaryPower))
        {
            return(base.TryCreateArmyMission("MajorFactionAttackArmy", new List <object>
            {
                maxHostileArmy,
                this.RegionTarget.Index
            }));
        }
        return(base.TryCreateArmyMission("MajorFactionRoaming", new List <object>
        {
            this.RegionTarget.Index
        }));
    }
    public override WorldPosition GetTargetPositionForTheArmy()
    {
        Army maxHostileArmy = AILayer_Pacification.GetMaxHostileArmy(base.Commander.Empire, this.RegionTarget.Index);

        if (maxHostileArmy != null)
        {
            return(maxHostileArmy.WorldPosition);
        }
        if (this.RegionTarget != null)
        {
            return(this.RegionTarget.Barycenter);
        }
        return(WorldPosition.Invalid);
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        if (!this.TryInitializingTargets(questBehaviour, this.ForceUpdate))
        {
            Diagnostics.LogError("ELCP {0} {2} {1} QuestBehaviourTreeNode_Action_SendAICommand TryInitializingTargets failed!", new object[]
            {
                questBehaviour.Initiator,
                this.Type,
                questBehaviour.Quest.QuestDefinition.Name
            });
            return(State.Success);
        }
        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            Diagnostics.Log("ELCP {0} QuestBehaviourTreeNode_Action_SendAICommand {2} {1}, Target {3}, RequiredMilitaryPower {4}, Cancel {5}, Region {6}, ForceArmyGUID {7}, {8}, {9}", new object[]
            {
                questBehaviour.Initiator,
                this.Type,
                questBehaviour.Quest.QuestDefinition.Name,
                this.TargetEntityGUID,
                this.RequiredMilitaryPower,
                this.CancelOrder,
                this.TargetRegionIndex,
                this.ForceArmyGUID,
                this.ResourceName,
                this.WantedAmount
            });
        }
        ISessionService service = Services.GetService <ISessionService>();

        if (service == null || service.Session == null || !service.Session.IsHosting)
        {
            return(State.Success);
        }
        GameServer           gameServer = (service.Session as global::Session).GameServer as GameServer;
        AIPlayer_MajorEmpire aiplayer_MajorEmpire;

        if (gameServer != null && gameServer.AIScheduler != null && gameServer.AIScheduler.TryGetMajorEmpireAIPlayer(questBehaviour.Initiator as MajorEmpire, out aiplayer_MajorEmpire) && aiplayer_MajorEmpire.AIState != AIPlayer.PlayerState.EmpireControlledByHuman)
        {
            AIEntity entity = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
            if (entity != null)
            {
                if (this.Type == QuestBehaviourTreeNode_Action_SendAICommand.CommandType.VisitTarget && this.TargetEntityGUID > 0UL)
                {
                    if (this.ForceArmyGUID > 0UL)
                    {
                        AILayer_QuestSolver layer = entity.GetLayer <AILayer_QuestSolver>();
                        if (!this.CancelOrder)
                        {
                            layer.AddQuestSolverOrder(questBehaviour.Quest.QuestDefinition.Name, new GameEntityGUID(this.TargetEntityGUID), new GameEntityGUID(this.ForceArmyGUID));
                        }
                        else
                        {
                            layer.RemoveQuestSolverOrder(questBehaviour.Quest.QuestDefinition.Name, new GameEntityGUID(this.ForceArmyGUID));
                        }
                    }
                    else
                    {
                        AILayer_QuestBTController layer2 = entity.GetLayer <AILayer_QuestBTController>();
                        if (!this.CancelOrder)
                        {
                            if (!string.IsNullOrEmpty(this.ResourceName))
                            {
                                layer2.AddQuestBTOrder(questBehaviour.Quest.QuestDefinition.Name, new GameEntityGUID(this.TargetEntityGUID), this.RequiredMilitaryPower, this.ResourceName, this.WantedAmount);
                            }
                            else
                            {
                                layer2.AddQuestBTOrder(questBehaviour.Quest.QuestDefinition.Name, new GameEntityGUID(this.TargetEntityGUID), this.RequiredMilitaryPower);
                            }
                        }
                        else
                        {
                            layer2.RemoveQuestBTOrder(questBehaviour.Quest.QuestDefinition.Name, new GameEntityGUID(this.TargetEntityGUID));
                        }
                    }
                }
                else if (this.Type == QuestBehaviourTreeNode_Action_SendAICommand.CommandType.SuspendPacification)
                {
                    AILayer_Village layer3 = entity.GetLayer <AILayer_Village>();
                    if (!this.CancelOrder)
                    {
                        layer3.SuspendPacifications(questBehaviour.Quest.QuestDefinition.Name);
                    }
                    else
                    {
                        layer3.ResumePacifications(questBehaviour.Quest.QuestDefinition.Name);
                    }
                }
                else if (this.Type == QuestBehaviourTreeNode_Action_SendAICommand.CommandType.PacifyVillage && this.TargetEntityGUID > 0UL)
                {
                    AILayer_Village layer4 = entity.GetLayer <AILayer_Village>();
                    if (!this.CancelOrder)
                    {
                        layer4.AddQuestVillageToPrioritize(questBehaviour.Quest.QuestDefinition.Name, this.TargetEntityGUID);
                    }
                    else
                    {
                        layer4.RemoveQuestVillageToPrioritize(questBehaviour.Quest.QuestDefinition.Name, this.TargetEntityGUID);
                    }
                }
                else if (this.Type == QuestBehaviourTreeNode_Action_SendAICommand.CommandType.PacifyRegion && this.TargetRegionIndex >= 0)
                {
                    AILayer_Pacification layer5 = entity.GetLayer <AILayer_Pacification>();
                    if (!this.CancelOrder)
                    {
                        layer5.AddQuestBTPacification(questBehaviour.Quest.QuestDefinition.Name, this.TargetRegionIndex);
                    }
                    else
                    {
                        layer5.RemoveQuestBTPacification(questBehaviour.Quest.QuestDefinition.Name, this.TargetRegionIndex);
                    }
                }
            }
        }
        return(State.Success);
    }
예제 #4
0
    protected override void RefreshObjectives(StaticString context, StaticString pass)
    {
        base.RefreshObjectives(context, pass);
        base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Pacification.ToString(), false, ref this.globalObjectiveMessages);
        base.ValidateMessages(ref this.globalObjectiveMessages);
        base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Colonization.ToString(), ref this.colonizationObjectives);
        this.colonizationObjectives.Sort((GlobalObjectiveMessage left, GlobalObjectiveMessage right) => - 1 * left.LocalPriority.CompareTo(right.LocalPriority));
        List <int> list = new List <int>();

        for (int l = 0; l < this.colonizationObjectives.Count; l++)
        {
            int regionIndex = this.colonizationObjectives[l].RegionIndex;
            list.Add(this.colonizationObjectives[l].RegionIndex);
            if (this.globalObjectiveMessages.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex) == null && AILayer_Pacification.RegionContainsHostileArmies(base.AIEntity.Empire, regionIndex))
            {
                GlobalObjectiveMessage item = base.GenerateObjective(regionIndex);
                this.globalObjectiveMessages.Add(item);
            }
        }
        for (int j = 0; j < this.departmentOfTheInterior.Cities.Count; j++)
        {
            int regionIndex = this.departmentOfTheInterior.Cities[j].Region.Index;
            list.AddOnce(this.departmentOfTheInterior.Cities[j].Region.Index);
            if (this.globalObjectiveMessages.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex) == null && AILayer_Pacification.RegionContainsHostileArmies(base.AIEntity.Empire, regionIndex))
            {
                GlobalObjectiveMessage item2 = base.GenerateObjective(regionIndex);
                this.globalObjectiveMessages.Add(item2);
            }
        }
        this.ComputeObjectivePriority();
        if (this.questManagementService.IsQuestRunningForEmpire("VictoryQuest-Chapter2", base.AIEntity.Empire))
        {
            QuestBehaviour questBehaviour = this.questRepositoryService.GetQuestBehaviour("VictoryQuest-Chapter2", base.AIEntity.Empire.Index);
            QuestBehaviourTreeNode_Action_SpawnArmy questBehaviourTreeNode_Action_SpawnArmy;
            if (questBehaviour != null && ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_Action_SpawnArmy>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_Action_SpawnArmy))
            {
                Region region      = this.worldPositionningService.GetRegion(questBehaviourTreeNode_Action_SpawnArmy.SpawnLocations[0]);
                int    regionIndex = region.Index;
                GlobalObjectiveMessage globalObjectiveMessage = this.globalObjectiveMessages.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex);
                list.AddOnce(regionIndex);
                if (globalObjectiveMessage == null && AILayer_Pacification.RegionContainsHostileArmies(base.AIEntity.Empire, regionIndex) && (region.City == null || region.City.Empire == base.AIEntity.Empire))
                {
                    globalObjectiveMessage = base.GenerateObjective(regionIndex);
                    this.globalObjectiveMessages.Add(globalObjectiveMessage);
                }
                if (globalObjectiveMessage != null)
                {
                    globalObjectiveMessage.GlobalPriority.Value = 1f;
                    globalObjectiveMessage.LocalPriority.Value  = 1f;
                }
            }
        }
        float value = 0.9f;

        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            value = 0.7f;
        }
        int i;

        Predicate <GlobalObjectiveMessage> < > 9__4;
        int i2;

        for (i = 0; i < this.QuestBTPacifications.Count; i = i2 + 1)
        {
            if (!this.questManagementService.IsQuestRunningForEmpire(this.QuestBTPacifications[i].questName, base.AIEntity.Empire))
            {
                this.QuestBTPacifications.RemoveAt(i);
                i2 = i;
                i  = i2 - 1;
            }
            else if (!list.Contains(this.QuestBTPacifications[i].regionIndex))
            {
                Region region2 = this.worldPositionningService.GetRegion(this.QuestBTPacifications[i].regionIndex);
                if (region2.Owner == null || !(region2.Owner is MajorEmpire))
                {
                    list.AddOnce(this.QuestBTPacifications[i].regionIndex);
                    if (this.CanPathToObjective(region2))
                    {
                        List <GlobalObjectiveMessage>      globalObjectiveMessages = this.globalObjectiveMessages;
                        Predicate <GlobalObjectiveMessage> match2;
                        if ((match2 = < > 9__4) == null)
                        {
                            match2 = (< > 9__4 = ((GlobalObjectiveMessage match) => match.RegionIndex == this.QuestBTPacifications[i].regionIndex));
                        }
                        GlobalObjectiveMessage globalObjectiveMessage2 = globalObjectiveMessages.Find(match2);
                        if (globalObjectiveMessage2 != null)
                        {
                            globalObjectiveMessage2.GlobalPriority.Value = value;
                            globalObjectiveMessage2.LocalPriority.Value  = value;
                        }
                        else if (AILayer_Pacification.RegionContainsHostileArmies(base.AIEntity.Empire, this.QuestBTPacifications[i].regionIndex))
                        {
                            globalObjectiveMessage2 = base.GenerateObjective(this.QuestBTPacifications[i].regionIndex);
                            this.globalObjectiveMessages.Add(globalObjectiveMessage2);
                            globalObjectiveMessage2.GlobalPriority.Value = value;
                            globalObjectiveMessage2.LocalPriority.Value  = value;
                        }
                    }
                }
            }
            i2 = i;
        }
        for (int k = 0; k < this.globalObjectiveMessages.Count; k++)
        {
            if ((this.globalObjectiveMessages[k].State == BlackboardMessage.StateValue.Message_None || this.globalObjectiveMessages[k].State == BlackboardMessage.StateValue.Message_InProgress) && !list.Contains(this.globalObjectiveMessages[k].RegionIndex))
            {
                base.AIEntity.AIPlayer.Blackboard.CancelMessage(this.globalObjectiveMessages[k]);
                this.CancelObjective(this.globalObjectiveMessages[k]);
                this.globalObjectiveMessages.RemoveAt(k);
                k--;
            }
        }
    }
예제 #5
0
 protected override bool IsObjectiveValid(StaticString objectiveType, int regionIndex, bool checkLocalPriority = false)
 {
     return(AILayer_Pacification.RegionContainsHostileArmies(base.AIEntity.Empire, regionIndex));
 }
 protected override bool IsMissionCompleted()
 {
     return(this.RegionTarget == null || (this.RegionTarget.City != null && this.RegionTarget.City.Empire != base.Commander.Empire) || !AILayer_Pacification.RegionContainsHostileArmies(base.Commander.Empire, this.RegionTarget.Index));
 }