protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null || !(service.Game is global::Game))
        {
            Diagnostics.LogError("Unable to retrieve the game service.");
            return(false);
        }
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();

        if (service2 == null)
        {
            Diagnostics.LogError("Unable to retrieve the game entity repository service.");
            return(false);
        }
        if (!this.TryResolveTarget(questBehaviour))
        {
            return(false);
        }
        if (this.QuestMarkerGUID == 0UL)
        {
            this.QuestMarkerGUID = service2.GenerateGUID();
        }
        QuestVariable questVariable = questBehaviour.GetQuestVariableByName(this.Output_QuestMarkerVarName);

        if (questVariable == null)
        {
            questVariable = new QuestVariable(this.Output_QuestMarkerVarName);
            questBehaviour.QuestVariables.Add(questVariable);
        }
        questVariable.Object = this.QuestMarkerGUID;
        return(base.Initialize(questBehaviour));
    }
    private bool TryResolveTarget(QuestBehaviour questBehaviour)
    {
        if (this.TargetEntityGUID != 0UL)
        {
            return(true);
        }
        QuestVariable questVariableByName = questBehaviour.GetQuestVariableByName(this.TargetEntityVarName);

        if (questVariableByName == null)
        {
            Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        if (questVariableByName.Object == null)
        {
            Diagnostics.LogError("Quest variable object is null (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        try
        {
            IGameEntity gameEntity;
            if (questVariableByName.Object is IEnumerable <object> )
            {
                gameEntity = ((questVariableByName.Object as IEnumerable <object>).ElementAt(0) as IGameEntity);
            }
            else
            {
                gameEntity = (questVariableByName.Object as IGameEntity);
            }
            if (gameEntity == null)
            {
                Diagnostics.LogWarning("Quest variable object is not a game entity (varname: '{0}')", new object[]
                {
                    this.TargetEntityVarName
                });
            }
            else
            {
                this.TargetEntityGUID = gameEntity.GUID;
            }
        }
        catch
        {
            Diagnostics.LogError("Quest variable object is not a game entity (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        return(true);
    }
Esempio n. 3
0
 private void UpdateQuestVariable(QuestBehaviour questBehaviour, string name, object value)
 {
     if (!string.IsNullOrEmpty(name))
     {
         QuestVariable questVariable = questBehaviour.GetQuestVariableByName(name);
         if (questVariable == null)
         {
             questVariable = new QuestVariable(name);
             questBehaviour.QuestVariables.Add(questVariable);
         }
         questVariable.Object = value;
     }
 }
Esempio n. 4
0
    protected int ComputeEleapsedTurn(QuestBehaviour questBehaviour)
    {
        QuestVariable questVariableByName = questBehaviour.GetQuestVariableByName(this.TimerVarName);

        if (questVariableByName == null)
        {
            return(-1);
        }
        int num  = (int)questVariableByName.Object;
        int turn = this.game.Turn;

        return(turn - num);
    }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();
        global::Game game    = service.Game as global::Game;

        if (service == null || service.Game == null || !(service.Game is global::Game))
        {
            Diagnostics.LogError("Unable to retrieve the game service.");
            return(false);
        }
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();

        if (service2 == null)
        {
            Diagnostics.LogError("Unable to retrieve the game entity repository service.");
            return(false);
        }
        IEnumerable <WorldPosition> source;

        if (this.DevicePositions == null && questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.DevicePositionVarName, out source))
        {
            this.DevicePositions = source.ToArray <WorldPosition>();
        }
        if (this.EntityGUID == 0UL)
        {
            this.EntityGUID = service2.GenerateGUID();
        }
        QuestVariable questVariable = questBehaviour.GetQuestVariableByName(this.Output_EntityVarName);

        if (questVariable == null)
        {
            questVariable = new QuestVariable(this.Output_EntityVarName);
            questBehaviour.QuestVariables.Add(questVariable);
            IQuestManagementService service3 = game.Services.GetService <IQuestManagementService>();
            if (service3 != null)
            {
                QuestVariable questVariable2 = new QuestVariable(this.Output_EntityVarName, this.EntityGUID);
                service3.State.AddGlobalVariable(questBehaviour.Initiator.Index, questVariable2);
            }
        }
        questVariable.Object = this.EntityGUID;
        return(base.Initialize(questBehaviour));
    }
Esempio n. 6
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null)
        {
            Diagnostics.LogError("Failed to retrieve the game service.");
            return(false);
        }
        global::Game game = service.Game as global::Game;

        if (game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        this.gameEntityRepositoryService = game.Services.GetService <IGameEntityRepositoryService>();
        if (this.gameEntityRepositoryService == null)
        {
            Diagnostics.LogError("Failed to retrieve the game entity repository service.");
            return(false);
        }
        IEnumerable <WorldPosition> source;

        if (this.SpawnLocations == null && questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.SpawnLocationVarName, out source))
        {
            this.SpawnLocations = source.ToArray <WorldPosition>();
        }
        if (!string.IsNullOrEmpty(this.ForbiddenSpawnLocationVarName) && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.ForbiddenSpawnLocationVarName))
        {
            QuestVariable questVariable = new QuestVariable(this.ForbiddenSpawnLocationVarName);
            questVariable.Object = new List <WorldPosition>();
            questBehaviour.QuestVariables.Add(questVariable);
        }
        if (this.ArmyGUID != GameEntityGUID.Zero && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.OutputEnemyArmyGUIDVarName))
        {
            QuestVariable questVariable2 = new QuestVariable(this.OutputEnemyArmyGUIDVarName);
            questVariable2.Object = this.ArmyGUID;
            questBehaviour.QuestVariables.Add(questVariable2);
        }
        if (this.EmpireArmyOwnerIndex == -1)
        {
            if (!string.IsNullOrEmpty(this.EmpireArmyOwnerVarName))
            {
                global::Empire empireArmyOwner;
                if (!questBehaviour.TryGetQuestVariableValueByName <global::Empire>(this.EmpireArmyOwnerVarName, out empireArmyOwner))
                {
                    Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[]
                    {
                        this.EmpireArmyOwnerVarName
                    });
                    return(false);
                }
                this.EmpireArmyOwner = empireArmyOwner;
            }
            if (this.EmpireArmyOwner == null)
            {
                this.EmpireArmyOwner = game.Empires.FirstOrDefault((global::Empire match) => match.Name == "LesserEmpire#0");
                if (this.EmpireArmyOwner == null)
                {
                    Diagnostics.LogError("Failed to retrieve the (lesser) quest empire.");
                    return(false);
                }
            }
            this.EmpireArmyOwnerIndex = this.EmpireArmyOwner.Index;
        }
        else
        {
            this.EmpireArmyOwner = game.Empires[this.EmpireArmyOwnerIndex];
        }
        if (this.ArmyDroplistSuffixVarName != string.Empty && this.ArmyDroplistSuffix == string.Empty)
        {
            string text;
            if (!questBehaviour.TryGetQuestVariableValueByName <string>(this.ArmyDroplistSuffixVarName, out text))
            {
                Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}', are you sure it is a string?)", new object[]
                {
                    this.ArmyDroplistSuffixVarName
                });
                return(false);
            }
            if (text == string.Empty)
            {
                Diagnostics.LogError("The suffix is an empty string (varname: '{0}')", new object[]
                {
                    this.ArmyDroplistSuffixVarName
                });
                return(false);
            }
            this.ArmyDroplistSuffix = text;
        }
        if (this.ArmyGUID == 0UL && !string.IsNullOrEmpty(this.OutputEnemyArmyGUIDVarName))
        {
            QuestVariable questVariable3 = questBehaviour.GetQuestVariableByName(this.OutputEnemyArmyGUIDVarName);
            if (questVariable3 == null)
            {
                questVariable3 = new QuestVariable(this.OutputEnemyArmyGUIDVarName);
                questBehaviour.QuestVariables.Add(questVariable3);
            }
            this.ArmyGUID         = this.gameEntityRepositoryService.GenerateGUID();
            questVariable3.Object = this.ArmyGUID;
            if (this.OutputEnemyArmyGUIDIsGlobal)
            {
                IQuestManagementService service2 = game.Services.GetService <IQuestManagementService>();
                if (service2 != null)
                {
                    QuestVariable questVariable4 = new QuestVariable(this.OutputEnemyArmyGUIDVarName, this.ArmyGUID);
                    service2.State.AddGlobalVariable(questBehaviour.Initiator.Index, questVariable4);
                }
            }
        }
        return(base.Initialize(questBehaviour));
    }
    protected override State Execute(QuestBehaviour questBehaviour, EventArmyTransferred e, params object[] parameters)
    {
        bool flag;

        switch (this.DestinationType)
        {
        case QuestBehaviourTreeNode_Decorator_ArmyTransferred.QuestTransferOption.Army:
            flag = e.IsDestinationArmy;
            break;

        case QuestBehaviourTreeNode_Decorator_ArmyTransferred.QuestTransferOption.Camp:
            flag = e.IsDestinationCamp;
            break;

        case QuestBehaviourTreeNode_Decorator_ArmyTransferred.QuestTransferOption.City:
            flag = e.IsDestinationCity;
            break;

        case QuestBehaviourTreeNode_Decorator_ArmyTransferred.QuestTransferOption.Village:
            flag = e.IsDestinationVillage;
            break;

        default:
            flag = true;
            break;
        }
        if (!flag)
        {
            return(State.Running);
        }
        bool flag2 = false;

        if (string.IsNullOrEmpty(this.ArmyGUID))
        {
            Diagnostics.LogError("The argument ArmyGUID is required.");
            return(State.Failure);
        }
        object obj;

        if (!questBehaviour.TryGetQuestVariableValueByName <object>(this.ArmyGUID, out obj))
        {
            Diagnostics.LogError("Failed to retrieve the variable {0}.", new object[]
            {
                this.ArmyGUID
            });
            return(State.Failure);
        }
        if (obj is GameEntityGUID)
        {
            flag2 = (e.Source == (GameEntityGUID)obj);
        }
        else if (obj is ulong)
        {
            flag2 = (e.Source == (ulong)obj);
        }
        if (!flag2)
        {
            return(State.Running);
        }
        bool flag3 = false;

        if (string.IsNullOrEmpty(this.DestinationGUID))
        {
            flag3 = true;
        }
        else
        {
            object obj2;
            if (!questBehaviour.TryGetQuestVariableValueByName <object>(this.DestinationGUID, out obj2))
            {
                Diagnostics.LogError("Failed to retrieve the variable {0}.", new object[]
                {
                    this.DestinationGUID
                });
                return(State.Failure);
            }
            if (obj2 is GameEntityGUID)
            {
                flag3 = (e.Destination.GUID == (GameEntityGUID)obj2);
            }
            else if (obj2 is ulong)
            {
                flag3 = (e.Destination.GUID == (ulong)obj2);
            }
            else if (obj2 is IGarrison)
            {
                flag3 = (e.Destination.GUID == ((IGarrison)obj2).GUID);
            }
        }
        if (!((!this.OtherThanDestination) ? flag3 : (!flag3)))
        {
            return(State.Running);
        }
        if (!string.IsNullOrEmpty(this.Output_DestinationGUID))
        {
            if (this.DestinationType != QuestBehaviourTreeNode_Decorator_ArmyTransferred.QuestTransferOption.Army)
            {
                Diagnostics.LogError("The argument Output_DestinationGUID is valid only when DestinationType is Army.");
                return(State.Failure);
            }
            QuestVariable questVariable = questBehaviour.GetQuestVariableByName(this.Output_DestinationGUID);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_DestinationGUID);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object   = e.Destination.GUID;
            this.StoredDestination = e.Destination.GUID;
            if (!string.IsNullOrEmpty(this.Output_SourceGUID))
            {
                questVariable = questBehaviour.GetQuestVariableByName(this.Output_SourceGUID);
                if (questVariable == null)
                {
                    questVariable = new QuestVariable(this.Output_SourceGUID);
                    questBehaviour.QuestVariables.Add(questVariable);
                }
                questVariable.Object = obj;
            }
        }
        return(State.Success);
    }