Пример #1
0
    private void SendConvertVillageAction(Village village)
    {
        EvaluableMessage_VillageAction evaluableMessage_VillageAction = base.AIPlayer.Blackboard.FindFirst <EvaluableMessage_VillageAction>(BlackboardLayerID.Empire, (EvaluableMessage_VillageAction match) => match.RegionIndex == base.RegionIndex && match.VillageGUID == base.SubObjectiveGuid && match.AccountTag == AILayer_AccountManager.ConversionAccountName);

        if (evaluableMessage_VillageAction == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
        {
            evaluableMessage_VillageAction     = new EvaluableMessage_VillageAction(base.RegionIndex, base.SubObjectiveGuid, AILayer_AccountManager.ConversionAccountName);
            this.villageConvertActionMessageId = base.AIPlayer.Blackboard.AddMessage(evaluableMessage_VillageAction);
        }
        else
        {
            this.villageConvertActionMessageId = evaluableMessage_VillageAction.ID;
        }
        evaluableMessage_VillageAction.TimeOut = 1;
        evaluableMessage_VillageAction.SetInterest(base.GlobalPriority, base.LocalPriority);
        evaluableMessage_VillageAction.UpdateBuyEvaluation("ConvertVillage", 0UL, AILayer_Village.GetVillageConversionCost(base.Empire as MajorEmpire, village), (int)BuyEvaluation.MaxTurnGain, 0f, 0UL);
    }
    private List <IWorldPositionable> Execute_GetVillages(AIBehaviorTree aiBehaviorTree, Army army, IGameService gameService, List <IWorldPositionable> unfilteredTargetList)
    {
        List <IWorldPositionable> list = new List <IWorldPositionable>();

        for (int i = 0; i < unfilteredTargetList.Count; i++)
        {
            PointOfInterest pointOfInterest = unfilteredTargetList[i] as PointOfInterest;
            if (pointOfInterest != null && !(pointOfInterest.Type != "Village") && pointOfInterest.Region != null && pointOfInterest.Region.MinorEmpire != null)
            {
                BarbarianCouncil agency = pointOfInterest.Region.MinorEmpire.GetAgency <BarbarianCouncil>();
                if (agency != null)
                {
                    Village villageAt = agency.GetVillageAt(pointOfInterest.WorldPosition);
                    if (villageAt != null && !villageAt.HasBeenPacified && this.TypeOfDiplomaticRelation != "VillageConvert" && pointOfInterest.PointOfInterestImprovement != null && !villageAt.HasBeenInfected)
                    {
                        list.Add(villageAt);
                    }
                    else if (this.TypeOfDiplomaticRelation == "VillageConvert" && army.Empire is MajorEmpire && army.Empire.SimulationObject.Tags.Contains(AILayer_Village.TagConversionTrait) && villageAt.HasBeenPacified && DepartmentOfTheInterior.IsArmyAbleToConvert(army, true) && !villageAt.HasBeenConverted && !villageAt.HasBeenInfected)
                    {
                        DepartmentOfForeignAffairs agency2 = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
                        City city = villageAt.Region.City;
                        if (city != null && city.Empire != aiBehaviorTree.AICommander.Empire)
                        {
                            DiplomaticRelation diplomaticRelation = agency2.GetDiplomaticRelation(city.Empire);
                            if (diplomaticRelation == null || diplomaticRelation.State.Name != DiplomaticRelationState.Names.War || (diplomaticRelation.State.Name == DiplomaticRelationState.Names.War && pointOfInterest.PointOfInterestImprovement == null))
                            {
                                goto IL_1FB;
                            }
                        }
                        float num;
                        army.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false);
                        if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, villageAt) * 2f < num)
                        {
                            list.Add(villageAt);
                        }
                    }
                }
            }
            IL_1FB :;
        }
        return(list);
    }
    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
    public override void PopulateMission()
    {
        Tags tags = new Tags();

        tags.AddTag(base.Category.ToString());
        tags.AddTag("Village");
        IGameEntity gameEntity;

        if (this.gameEntityRepositoryService.TryGetValue(base.SubObjectiveGuid, out gameEntity) && gameEntity is Village)
        {
            Village village = gameEntity as Village;
            bool    flag    = base.Empire.SimulationObject.Tags.Contains(AILayer_Village.TagConversionTrait);
            bool    flag2   = this.departmentOfScience.CanBribe() && !village.HasBeenConverted && !village.HasBeenPacified;
            if (flag)
            {
                this.SendConvertVillageAction(village);
            }
            if (flag2)
            {
                this.SendBribeVillageAction(village);
            }
            bool flag3 = false;
            bool flag4 = false;
            if (this.villageBribeActionMessageId > 0UL)
            {
                EvaluableMessage_VillageAction evaluableMessage_VillageAction = base.AIPlayer.Blackboard.GetMessage(this.villageBribeActionMessageId) as EvaluableMessage_VillageAction;
                if (evaluableMessage_VillageAction != null && evaluableMessage_VillageAction.ChosenBuyEvaluation != null)
                {
                    flag4 = true;
                }
            }
            if (village.HasBeenPacified && flag2 && !flag4)
            {
                flag4 = true;
            }
            if (this.villageConvertActionMessageId > 0UL)
            {
                EvaluableMessage_VillageAction evaluableMessage_VillageAction2 = base.AIPlayer.Blackboard.GetMessage(this.villageConvertActionMessageId) as EvaluableMessage_VillageAction;
                if (evaluableMessage_VillageAction2 != null && evaluableMessage_VillageAction2.ChosenBuyEvaluation != null)
                {
                    flag3 = true;
                }
            }
            if (flag && !flag3)
            {
                float num;
                base.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(base.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false);
                if (AILayer_Village.GetVillageConversionCost(base.Empire as MajorEmpire, village) * 2f < num)
                {
                    flag3 = true;
                }
            }
            if (flag)
            {
                tags.AddTag("Convert");
                if (village.HasBeenConverted)
                {
                    tags.AddTag("Hardway");
                }
                else if (village.HasBeenPacified)
                {
                    if (!flag3)
                    {
                        return;
                    }
                }
                else if (flag2)
                {
                    if (!flag3 || !flag4)
                    {
                        return;
                    }
                    tags.AddTag("Bribe");
                }
                else
                {
                    tags.AddTag("Hardway");
                }
            }
            for (int i = base.Missions.Count - 1; i >= 0; i--)
            {
                if (base.Missions[i].MissionDefinition.Category.Contains(tags))
                {
                    return;
                }
                this.CancelMission(base.Missions[i]);
            }
            base.PopulationFirstMissionFromCategory(tags, new object[]
            {
                this.RegionTarget,
                base.SubObjectiveGuid
            });
        }
    }
Пример #5
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        this.aiBehaviorTree = aiBehaviorTree;
        State result;

        if (this.ticket != null)
        {
            result = State.Running;
        }
        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
                });
                result = State.Failure;
            }
            else
            {
                IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
                if (!(target is IWorldPositionable))
                {
                    result = State.Failure;
                }
                else
                {
                    IGameService service = Services.GetService <IGameService>();
                    Diagnostics.Assert(service != null);
                    if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(target.GUID))
                    {
                        result = State.Success;
                    }
                    else
                    {
                        AICommanderWithObjective commanderObjective = aiBehaviorTree.AICommander as AICommanderWithObjective;
                        if (commanderObjective == null)
                        {
                            result = State.Failure;
                        }
                        else if (!(target is Village))
                        {
                            aiBehaviorTree.ErrorCode = 2;
                            result = State.Failure;
                        }
                        else
                        {
                            Village village = target as Village;
                            if (village.HasBeenConverted)
                            {
                                if (village.HasBeenConvertedByIndex == aiBehaviorTree.AICommander.Empire.Index)
                                {
                                    return(State.Success);
                                }
                                this.aiBehaviorTree.ErrorCode = 32;
                                return(State.Failure);
                            }
                            else
                            {
                                EvaluableMessage_VillageAction evaluableMessage_VillageAction = aiBehaviorTree.AICommander.AIPlayer.Blackboard.FindFirst <EvaluableMessage_VillageAction>(BlackboardLayerID.Empire, (EvaluableMessage_VillageAction match) => match.RegionIndex == commanderObjective.RegionIndex && match.VillageGUID == target.GUID && match.AccountTag == AILayer_AccountManager.ConversionAccountName);
                                if (evaluableMessage_VillageAction == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtained)
                                {
                                    float num;
                                    army.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false);
                                    if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, village) > num)
                                    {
                                        if (evaluableMessage_VillageAction == null)
                                        {
                                            this.aiBehaviorTree.ErrorCode = 32;
                                            return(State.Failure);
                                        }
                                        return(State.Success);
                                    }
                                }
                                else
                                {
                                    if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
                                    {
                                        this.aiBehaviorTree.ErrorCode = 32;
                                        return(State.Failure);
                                    }
                                    if (evaluableMessage_VillageAction.ChosenBuyEvaluation == null || evaluableMessage_VillageAction.ChosenBuyEvaluation.State != BuyEvaluation.EvaluationState.Purchased || evaluableMessage_VillageAction.EvaluationState != EvaluableMessage.EvaluableMessageState.Validate)
                                    {
                                        return(State.Failure);
                                    }
                                }
                                IEncounterRepositoryService service2 = service.Game.Services.GetService <IEncounterRepositoryService>();
                                if (service2 != null)
                                {
                                    IEnumerable <Encounter> enumerable = service2;
                                    if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false) || encounter.IsGarrisonInEncounter(target.GUID, false)))
                                    {
                                        return(State.Running);
                                    }
                                }
                                Diagnostics.Assert(AIScheduler.Services != null);
                                if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, village.WorldPosition) != 1)
                                {
                                    aiBehaviorTree.ErrorCode = 12;
                                    result = State.Failure;
                                }
                                else
                                {
                                    OrderConvertVillage order = new OrderConvertVillage(army.Empire.Index, army.GUID, village.WorldPosition);
                                    aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderConvertVillage_TicketRaised));
                                    result = State.Running;
                                }
                            }
                        }
                    }
                }
            }
        }
        return(result);
    }