protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        this.aiBehaviorTree = aiBehaviorTree;
        if (this.ticket != null)
        {
            return(State.Running);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            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);
        }
        AICommanderWithObjective commanderObjective = aiBehaviorTree.AICommander as AICommanderWithObjective;

        if (commanderObjective == null)
        {
            return(State.Failure);
        }
        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.MilitaryAccountName);

        if (evaluableMessage_VillageAction == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
        {
            this.aiBehaviorTree.ErrorCode = 31;
            return(State.Failure);
        }
        if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtained)
        {
            return(State.Success);
        }
        if (evaluableMessage_VillageAction.ChosenBuyEvaluation == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
        {
            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);
            }
        }
        Village village = target as Village;

        if (village == null)
        {
            aiBehaviorTree.ErrorCode = 2;
            return(State.Failure);
        }
        Diagnostics.Assert(AIScheduler.Services != null);
        if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, (target as IWorldPositionable).WorldPosition) != 1)
        {
            aiBehaviorTree.ErrorCode = 12;
            return(State.Failure);
        }
        if (village.HasBeenPacified || village.HasBeenConverted || village.HasBeenInfected)
        {
            return(State.Failure);
        }
        OrderBribeVillage order = new OrderBribeVillage(army.Empire.Index, army.GUID, (target as IWorldPositionable).WorldPosition, ArmyAction_Bribe.ReadOnlyName);

        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderBribeVillage_TicketRaised));
        return(State.Running);
    }
    public override void Begin(params object[] parameters)
    {
        base.Begin(parameters);
        bool canceled = false;

        if (parameters.Length >= 1 && parameters[0] is bool)
        {
            canceled = (bool)parameters[0];
        }
        global::PlayerController playerController = base.BattleEncounter.PlayerController;

        if (playerController != null)
        {
            OrderLockEncounterExternalArmies order = new OrderLockEncounterExternalArmies(base.BattleEncounter.EncounterGUID, base.BattleEncounter.ExternalArmies, false);
            playerController.PostOrder(order);
            for (int i = 0; i < base.BattleEncounter.BattleContenders.Count; i++)
            {
                BattleContender battleContender = base.BattleEncounter.BattleContenders[i];
                if (battleContender.DeadParasitesCount > 0)
                {
                    BattleContender enemyContenderWithAbilityFromContender = base.BattleEncounter.GetEnemyContenderWithAbilityFromContender(battleContender, UnitAbility.ReadonlyParasite);
                    if (enemyContenderWithAbilityFromContender != null)
                    {
                        enemyContenderWithAbilityFromContender.UndeadUnitsToCreateCount += battleContender.DeadParasitesCount;
                    }
                }
            }
            for (int j = 0; j < base.BattleEncounter.BattleContenders.Count; j++)
            {
                BattleContender battleContender2 = base.BattleEncounter.BattleContenders[j];
                if (battleContender2.Garrison != null && battleContender2.UndeadUnitsToCreateCount > 0)
                {
                    OrderCreateUndeadUnits order2 = new OrderCreateUndeadUnits(battleContender2.Garrison.Empire.Index, battleContender2.UndeadUnitsToCreateCount, battleContender2.Garrison.GUID, base.BattleEncounter.EncounterGUID);
                    playerController.PostOrder(order2);
                }
            }
            OrderEndEncounter orderEndEncounter = new OrderEndEncounter(base.BattleEncounter.EncounterGUID, canceled);
            IGameService      service           = Services.GetService <IGameService>();
            Diagnostics.Assert(service != null);
            if (ELCPUtilities.UseELCPFortificationPointRuleset)
            {
                Diagnostics.Assert(service != null);
                IEncounterRepositoryService service2 = service.Game.Services.GetService <IEncounterRepositoryService>();
                Diagnostics.Assert(service2 != null);
                Encounter encounter = null;
                if (service2.TryGetValue(base.BattleEncounter.EncounterGUID, out encounter))
                {
                    List <ulong> list = new List <ulong>();
                    foreach (Contender contender in encounter.Contenders)
                    {
                        if (contender.IsTakingPartInBattle)
                        {
                            foreach (EncounterUnit encounterUnit in contender.EncounterUnits)
                            {
                                if (encounterUnit.IsOnBattlefield)
                                {
                                    list.Add(encounterUnit.Unit.GUID);
                                }
                            }
                        }
                    }
                    orderEndEncounter.GUIDsOnBattlefield = list.ToArray();
                }
            }
            if (base.BattleEncounter is BattleCityAssaultEncounter)
            {
                orderEndEncounter.DoNotSubtractActionPoints = (base.BattleEncounter as BattleCityAssaultEncounter).IsCityRipeForTheTaking;
            }
            playerController.PostOrder(orderEndEncounter);
            if (base.BattleEncounter is BattleCityAssaultEncounter && base.BattleEncounter.BattleContenders.Count >= 1)
            {
                BattleCityAssaultEncounter   battleCityAssaultEncounter = base.BattleEncounter as BattleCityAssaultEncounter;
                IGameEntityRepositoryService service3 = service.Game.Services.GetService <IGameEntityRepositoryService>();
                Diagnostics.Assert(service3 != null);
                IGameEntity gameEntity = null;
                City        city       = null;
                if (service3.TryGetValue(battleCityAssaultEncounter.CityGuid, out gameEntity) && gameEntity is City)
                {
                    city = (gameEntity as City);
                }
                bool flag  = false;
                bool flag2 = false;
                for (int k = 0; k < base.BattleEncounter.BattleContenders.Count; k++)
                {
                    BattleContender battleContender3 = base.BattleEncounter.BattleContenders[k];
                    if (battleContender3.IsTakingPartInBattle && !battleContender3.IsDead)
                    {
                        if (battleContender3.Garrison.Empire == city.Empire)
                        {
                            flag = true;
                        }
                        else
                        {
                            flag2 = true;
                        }
                    }
                    else if (!battleContender3.IsTakingPartInBattle && battleContender3.Garrison.GUID == city.GUID && battleContender3.Garrison.UnitsCount > 0)
                    {
                        flag = true;
                    }
                }
                flag |= !flag2;
                OrderCityEncounterEnd order3 = new OrderCityEncounterEnd(base.BattleEncounter.BattleContenders[0].Garrison.Empire.Index, base.BattleEncounter.BattleContenders[0].Garrison.GUID, battleCityAssaultEncounter.CityGuid, flag);
                playerController.PostOrder(order3);
            }
        }
    }
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.ticket != null)
     {
         if (!this.orderExecuted)
         {
             return(State.Running);
         }
         if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
         {
             this.orderExecuted       = false;
             this.ticket              = null;
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         this.orderExecuted = false;
         this.ticket        = null;
         return(State.Success);
     }
     else
     {
         Army army;
         if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
         {
             return(State.Failure);
         }
         if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
         {
             aiBehaviorTree.LogError("${0} not set", new object[]
             {
                 this.TargetVarName
             });
             return(State.Failure);
         }
         Army army2 = aiBehaviorTree.Variables[this.TargetVarName] as Army;
         if (army2 == null)
         {
             return(State.Failure);
         }
         List <StaticString> list = new List <StaticString>();
         if (!this.armyActionHeal.CanExecute(army, ref list, new object[]
         {
             army2
         }))
         {
             return(State.Failure);
         }
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         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)))
             {
                 return(State.Running);
             }
         }
         this.orderExecuted = false;
         this.armyActionHeal.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised), new object[]
         {
             army2
         });
         return(State.Running);
     }
 }
Example #4
0
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.ticket != null)
     {
         if (!this.ticket.Raised)
         {
             return(State.Running);
         }
         if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
         {
             this.ticket = null;
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         this.ticket = null;
         return(State.Success);
     }
     else
     {
         Army army;
         if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
         {
             return(State.Failure);
         }
         if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
         {
             aiBehaviorTree.LogError("${0} not set", new object[]
             {
                 this.TargetVarName
             });
             return(State.Failure);
         }
         IGameEntity gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
         if (!(gameEntity is IWorldPositionable))
         {
             return(State.Failure);
         }
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(gameEntity.GUID))
         {
             return(State.Success);
         }
         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)))
             {
                 return(State.Running);
             }
         }
         IGarrison garrison = gameEntity as IGarrison;
         if (gameEntity is Kaiju)
         {
             garrison = (gameEntity as Kaiju).GetActiveTroops();
         }
         if (garrison == null)
         {
             return(State.Failure);
         }
         if (garrison.Empire.Index == aiBehaviorTree.AICommander.Empire.Index)
         {
             return(State.Failure);
         }
         GameEntityGUID guid = gameEntity.GUID;
         if (!aiBehaviorTree.Variables.ContainsKey(this.PathVarName))
         {
             aiBehaviorTree.LogError("{0} not set", new object[]
             {
                 this.PathVarName
             });
             return(State.Failure);
         }
         WorldPath worldPath = aiBehaviorTree.Variables[this.PathVarName] as WorldPath;
         if (worldPath == null || worldPath.Length < 2)
         {
             aiBehaviorTree.LogError("Path is null.", new object[0]);
             aiBehaviorTree.ErrorCode = 3;
             return(State.Failure);
         }
         if (!worldPath.IsValid)
         {
             aiBehaviorTree.ErrorCode = 3;
             return(State.Failure);
         }
         if (!aiBehaviorTree.Variables.ContainsKey(this.ArmyActionVarName))
         {
             aiBehaviorTree.LogError("${0} not set", new object[]
             {
                 this.ArmyActionVarName
             });
             return(State.Failure);
         }
         OrderGoToAndExecute orderGoToAndExecute = new OrderGoToAndExecute(army.Empire.Index, army.GUID, this.ArmyActionVarName, worldPath.Destination, guid);
         orderGoToAndExecute.Flags = (PathfindingFlags)0;
         aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderGoToAndExecute, out this.ticket, null);
         return(State.Running);
     }
 }
Example #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);
    }
Example #6
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        IGameService service = Services.GetService <IGameService>();

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

        if (this.orderTicket != null)
        {
            if (!this.orderTicket.Raised)
            {
                return(State.Running);
            }
            if (this.orderTicket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
            {
                this.orderTicket         = null;
                aiBehaviorTree.ErrorCode = 1;
                return(State.Failure);
            }
            this.orderTicket = null;
            return(State.Success);
        }
        else
        {
            Army army;
            if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
            {
                return(State.Failure);
            }
            if (army.IsDismantlingDevice)
            {
                aiBehaviorTree.ErrorCode = 37;
                return(State.Failure);
            }
            if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
            {
                aiBehaviorTree.LogError("${0} not set", new object[]
                {
                    this.TargetVarName
                });
                return(State.Failure);
            }
            IGameEntity gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
            if (!(gameEntity is IWorldPositionable) || !(gameEntity is TerraformDevice))
            {
                aiBehaviorTree.ErrorCode = 10;
                return(State.Failure);
            }
            if (!service2.Contains(gameEntity.GUID))
            {
                return(State.Success);
            }
            if ((gameEntity as TerraformDevice).TurnsToActivate() < 1999)
            {
                return(State.Success);
            }
            if ((gameEntity as TerraformDevice).DismantlingArmy != null)
            {
                aiBehaviorTree.ErrorCode = 37;
                return(State.Failure);
            }
            Diagnostics.Assert(AIScheduler.Services != null);
            if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, (gameEntity as IWorldPositionable).WorldPosition) != 1)
            {
                aiBehaviorTree.ErrorCode = 12;
                return(State.Failure);
            }
            IEncounterRepositoryService service3 = service.Game.Services.GetService <IEncounterRepositoryService>();
            if (service3 != null)
            {
                IEnumerable <Encounter> enumerable = service3;
                if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false)))
                {
                    return(State.Running);
                }
            }
            OrderToggleDismantleDevice order = new OrderToggleDismantleDevice(army.Empire.Index, army.GUID, gameEntity.GUID, true);
            aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.orderTicket, null);
            return(State.Running);
        }
    }
Example #7
0
    public static bool CanTeleportToCity(City city, Army army, Region originRegion, IWorldPositionningService worldPositionningService, IEncounterRepositoryService encounterRepositoryService)
    {
        WorldPosition position;

        return(city != null && city.GUID.IsValid && originRegion.City != null && city.Empire.Index == army.Empire.Index && city != originRegion.City && (encounterRepositoryService == null || !encounterRepositoryService.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(city.GUID, false))) && army.Empire.GetAgency <DepartmentOfTransportation>().TryGetFirstCityTileAvailableForTeleport(city, out position) && position.IsValid && !worldPositionningService.IsWaterTile(position));
    }
Example #8
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);
    }
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.ticket != null)
     {
         if (!this.ticket.Raised)
         {
             return(State.Running);
         }
         if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
         {
             this.ticket = null;
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         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 gameEntity = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
         if (!(gameEntity is IWorldPositionable))
         {
             return(State.Failure);
         }
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(gameEntity.GUID))
         {
             return(State.Success);
         }
         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)))
             {
                 return(State.Running);
             }
         }
         IGarrison garrison;
         if (gameEntity is Kaiju)
         {
             Kaiju kaiju = gameEntity as Kaiju;
             garrison = kaiju.GetActiveTroops();
             if (kaiju.IsStunned())
             {
                 return(State.Failure);
             }
         }
         else
         {
             if (gameEntity is KaijuArmy)
             {
                 KaijuArmy kaijuArmy = gameEntity as KaijuArmy;
                 if (kaijuArmy != null && kaijuArmy.Kaiju.IsStunned())
                 {
                     return(State.Failure);
                 }
             }
             else if (gameEntity is KaijuGarrison)
             {
                 KaijuGarrison kaijuGarrison = gameEntity as KaijuGarrison;
                 if (kaijuGarrison != null && kaijuGarrison.Kaiju.IsStunned())
                 {
                     return(State.Failure);
                 }
             }
             garrison = (gameEntity 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);
         }
         GameEntityGUID guid = gameEntity.GUID;
         if (!aiBehaviorTree.Variables.ContainsKey(this.PathVarName))
         {
             aiBehaviorTree.LogError("{0} not set", new object[]
             {
                 this.PathVarName
             });
             return(State.Failure);
         }
         WorldPath worldPath = aiBehaviorTree.Variables[this.PathVarName] as WorldPath;
         if (worldPath == null || worldPath.Length < 2)
         {
             aiBehaviorTree.LogError("Path is null.", new object[0]);
             aiBehaviorTree.ErrorCode = 3;
             return(State.Failure);
         }
         if (!worldPath.IsValid)
         {
             aiBehaviorTree.ErrorCode = 3;
             return(State.Failure);
         }
         OrderGoToAndAttack orderGoToAndAttack = new OrderGoToAndAttack(army.Empire.Index, army.GUID, guid, worldPath);
         orderGoToAndAttack.Flags = PathfindingFlags.IgnoreFogOfWar;
         aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderGoToAndAttack, out this.ticket, null);
         return(State.Running);
     }
 }
Example #10
0
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.ticket != null)
     {
         if (!this.orderExecuted)
         {
             return(State.Running);
         }
         if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
         {
             this.orderExecuted       = false;
             this.ticket              = null;
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         this.orderExecuted = false;
         this.ticket        = null;
         return(State.Success);
     }
     else
     {
         Army army;
         if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
         {
             return(State.Failure);
         }
         if (this.worldPositionningService.IsWaterTile(army.WorldPosition))
         {
             return(State.Failure);
         }
         float propertyValue      = army.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints);
         float propertyValue2     = army.GetPropertyValue(SimulationProperties.ActionPointsSpent);
         float costInActionPoints = this.armyActionFortify.GetCostInActionPoints();
         if (propertyValue < propertyValue2 + costInActionPoints)
         {
             aiBehaviorTree.ErrorCode = 33;
             return(State.Failure);
         }
         City city = null;
         if (this.TargetVarName == string.Empty)
         {
             District district = this.worldPositionningService.GetDistrict(army.WorldPosition);
             if (district == null || !District.IsACityTile(district) || (district.City.Empire.Index != army.Empire.Index && !army.Empire.GetAgency <DepartmentOfForeignAffairs>().IsFriend(district.City.Empire)))
             {
                 return(State.Failure);
             }
             city = district.City;
         }
         else
         {
             if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
             {
                 aiBehaviorTree.LogError("${0} not set", new object[]
                 {
                     this.TargetVarName
                 });
                 return(State.Failure);
             }
             city = (aiBehaviorTree.Variables[this.TargetVarName] as City);
             if (city == null)
             {
                 return(State.Failure);
             }
         }
         if (city.GetPropertyValue(SimulationProperties.CityDefensePoint) < 50f)
         {
             return(State.Failure);
         }
         this.failuresFlags.Clear();
         if (!this.armyActionFortify.CanExecute(army, ref this.failuresFlags, new object[0]))
         {
             return(State.Failure);
         }
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         IEncounterRepositoryService service2 = service.Game.Services.GetService <IEncounterRepositoryService>();
         if (service2 != null)
         {
             IEnumerable <Encounter> enumerable = service2;
             if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(city.GUID, false)))
             {
                 return(State.Running);
             }
         }
         this.orderExecuted = false;
         this.armyActionFortify.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised), new object[]
         {
             city
         });
         return(State.Running);
     }
 }
Example #11
0
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        Diagnostics.Assert(service.Game != null);
        global::Empire initiator = questBehaviour.Initiator;

        Diagnostics.Assert(initiator.SimulationObject != null);
        if (!initiator.SimulationObject.Tags.Contains(global::Empire.TagEmpireEliminated))
        {
            if (initiator.GetAgency <DepartmentOfDefense>() != null)
            {
                IEncounterRepositoryService service2 = service.Game.Services.GetService <IEncounterRepositoryService>();
                if (service2 != null)
                {
                    IEnumerable <Encounter> enumerable = service2;
                    if (enumerable != null)
                    {
                        List <Encounter> list = new List <Encounter>();
                        foreach (Encounter encounter in enumerable)
                        {
                            if (encounter != null)
                            {
                                for (int i = 0; i < encounter.Empires.Count; i++)
                                {
                                    if (encounter.Empires[i].Index == initiator.Index && encounter.EncounterState != EncounterState.BattleHasEnded)
                                    {
                                        list.Add(encounter);
                                    }
                                }
                            }
                        }
                        global::Empire.PlayerControllersContainer playerControllers = (initiator as MajorEmpire).PlayerControllers;
                        if (playerControllers != null && playerControllers.Server != null)
                        {
                            for (int j = 0; j < list.Count; j++)
                            {
                                Encounter         encounter2 = list[j];
                                OrderEndEncounter order      = new OrderEndEncounter(encounter2.GUID, true);
                                playerControllers.Server.PostOrder(order);
                                OrderDestroyEncounter order2 = new OrderDestroyEncounter(encounter2.GUID);
                                playerControllers.Server.PostOrder(order2);
                            }
                        }
                    }
                }
            }
            SimulationDescriptor             simulationDescriptor = null;
            IDatabase <SimulationDescriptor> database             = Databases.GetDatabase <SimulationDescriptor>(false);
            if (database != null)
            {
                database.TryGetValue("EmpireEliminated", out simulationDescriptor);
            }
            if (simulationDescriptor != null)
            {
                initiator.AddDescriptor(simulationDescriptor, false);
                initiator.Refresh(true);
            }
            else
            {
                initiator.SimulationObject.Tags.AddTag(global::Empire.TagEmpireEliminated);
            }
        }
        ISessionService service3 = Services.GetService <ISessionService>();

        Diagnostics.Assert(service3 != null && service3.Session != null);
        if (service3.Session.IsHosting)
        {
            service3.Session.SetLobbyData(string.Format("Empire{0}Eliminated", initiator.Index), true, true);
        }
        IPlayerControllerRepositoryControl playerControllerRepositoryControl = service.Game.Services.GetService <IPlayerControllerRepositoryService>() as IPlayerControllerRepositoryControl;

        if (playerControllerRepositoryControl != null)
        {
            global::PlayerController playerControllerById = playerControllerRepositoryControl.GetPlayerControllerById("server");
            if (playerControllerById != null)
            {
                if (initiator is MajorEmpire)
                {
                    MajorEmpire majorEmpire = initiator as MajorEmpire;
                    if (majorEmpire.TamedKaijus.Count > 0)
                    {
                        majorEmpire.ServerUntameAllKaijus();
                    }
                }
                OrderEliminateEmpire order3 = new OrderEliminateEmpire(questBehaviour.Initiator.Index);
                playerControllerById.PostOrder(order3);
            }
        }
        return(State.Success);
    }