Ejemplo n.º 1
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        State result;
        Army  army;

        if (this.orderPosted)
        {
            if (this.orderExecuted)
            {
                this.orderExecuted = false;
                this.orderPosted   = false;
                result             = State.Success;
            }
            else
            {
                result = State.Running;
            }
        }
        else if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            result = State.Failure;
        }
        else
        {
            bool flag = true;
            for (int i = 0; i < army.StandardUnits.Count; i++)
            {
                if (army.StandardUnits[i].CheckUnitAbility(UnitAbility.ReadonlyResettle, -1))
                {
                    flag = false;
                    break;
                }
            }
            ArmyAction        armyAction = null;
            List <ArmyAction> list       = new List <ArmyAction>();
            if (flag)
            {
                list = new List <ArmyAction>(new List <ArmyAction>(Databases.GetDatabase <ArmyAction>(false).GetValues()).FindAll((ArmyAction match) => match is ArmyAction_Colonization));
            }
            else
            {
                list = new List <ArmyAction>(new List <ArmyAction>(Databases.GetDatabase <ArmyAction>(false).GetValues()).FindAll((ArmyAction match) => match is ArmyAction_Resettle));
            }
            List <StaticString> list2 = new List <StaticString>();
            for (int j = 0; j < list.Count; j++)
            {
                if (list[j].CanExecute(army, ref list2, new object[0]))
                {
                    armyAction = list[j];
                }
            }
            if (armyAction != null)
            {
                this.orderExecuted = false;
                this.orderPosted   = true;
                if (flag)
                {
                    this.CityLocation = army.WorldPosition;
                    this.Empire       = army.Empire;
                    Ticket ticket;
                    armyAction.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out ticket, new EventHandler <TicketRaisedEventArgs>(this.ArmyAction_TicketRaised), new object[0]);
                }
                else
                {
                    OrderResettle order = new OrderResettle(army.Empire.Index, army.GUID, armyAction.Name);
                    Ticket        ticket;
                    aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderResettle_TicketRaised));
                }
                result = State.Running;
            }
            else
            {
                aiBehaviorTree.ErrorCode = 22;
                result = State.Failure;
            }
        }
        return(result);
    }
Ejemplo n.º 2
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (this.currentTicket != null)
        {
            if (!this.currentTicket.Raised)
            {
                return(State.Running);
            }
            bool flag = this.currentTicket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed || this.currentTicket.PostOrderResponse == PostOrderResponse.AuthenticationHasFailed;
            this.currentTicket = null;
            if (flag)
            {
                aiBehaviorTree.ErrorCode = 1;
                return(State.Failure);
            }
            return(State.Success);
        }
        else
        {
            if (!aiBehaviorTree.Variables.ContainsKey(this.DestinationVarName))
            {
                aiBehaviorTree.LogError("{0} not set", new object[]
                {
                    this.DestinationVarName
                });
                return(State.Failure);
            }
            City       city       = (City)aiBehaviorTree.Variables[this.DestinationVarName];
            ArmyAction armyAction = null;
            if (city != null)
            {
                if (!ELCPUtilities.CanTeleportToCity(city, army, this.worldPositionningService.GetRegion(army.WorldPosition), this.worldPositionningService, this.encounterRepositoryService))
                {
                    return(State.Failure);
                }
                List <ArmyAction>   list  = new List <ArmyAction>(new List <ArmyAction>(Databases.GetDatabase <ArmyAction>(false).GetValues()).FindAll((ArmyAction match) => match is ArmyAction_Teleport));
                List <StaticString> list2 = new List <StaticString>();
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].CanExecute(army, ref list2, new object[0]))
                    {
                        armyAction = list[i];
                        break;
                    }
                }
                if (armyAction != null)
                {
                    armyAction.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out this.currentTicket, null, new object[]
                    {
                        city
                    });
                    return(State.Running);
                }
            }
            Diagnostics.LogError("ELCP: AIBehaviorTreeNode_Action_TeleportToCity failed for {0}/{1} {5} -> {6}, {2} {3} {4}", new object[]
            {
                army.LocalizedName,
                army.Empire,
                army.GetPropertyBaseValue(SimulationProperties.Movement),
                city != null,
                armyAction != null,
                army.WorldPosition,
                (city != null) ? city.WorldPosition.ToString() : "null"
            });
            return(State.Failure);
        }
    }