Пример #1
0
    private void AddWinnerToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.Empire == questBehaviour.Initiator && match.ContenderState == ContenderState.Survived);

        if (contender != null)
        {
            this.WinnerArmyGUID = contender.GUID;
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_WinnerVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_WinnerVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            DepartmentOfDefense agency = questBehaviour.Initiator.GetAgency <DepartmentOfDefense>();
            Diagnostics.Assert(agency != null);
            Army army = agency.Armies.FirstOrDefault((Army match) => match.GUID == this.WinnerArmyGUID);
            if (army == null)
            {
                Diagnostics.LogError("Decorator_KillArmy: the army (GUID:'{0}') cannot be found in the empire (index:'{1}') armies", new object[]
                {
                    this.WinnerArmyGUID,
                    questBehaviour.Initiator.Index
                });
            }
            questVariable.Object = army;
        }
    }
    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));
    }
Пример #3
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        Diagnostics.Log("UpdateVariable.Initialize");
        global::Game game = Services.GetService <IGameService>().Game as global::Game;

        if (game == null)
        {
            Diagnostics.LogError("Cannot retrieve game service, Action_uptateVariable");
        }
        if (this.EmpireIndex != -1)
        {
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.EmpireVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.EmpireVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = game.Empires[this.EmpireIndex];
        }
        MajorEmpire majorEmpire;

        if (this.EmpireIndex == -1 && this.EmpireVarName != string.Empty && questBehaviour.TryGetQuestVariableValueByName <MajorEmpire>(this.EmpireVarName, out majorEmpire))
        {
            this.EmpireIndex = majorEmpire.Index;
        }
        return(true);
    }
    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);
        }
        this.Game = (service.Game as global::Game);
        if (this.Game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        if (this.ArmyGUID == 0UL)
        {
            ulong armyGUID;
            if (!string.IsNullOrEmpty(this.ArmyGUIDVarName) && questBehaviour.TryGetQuestVariableValueByName <ulong>(this.ArmyGUIDVarName, out armyGUID))
            {
                this.ArmyGUID = armyGUID;
            }
        }
        else
        {
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.ArmyGUIDVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.ArmyGUIDVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = this.ArmyGUID;
        }
        return(base.Initialize(questBehaviour));
    }
Пример #5
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        if (this.WinnerArmyGUID != GameEntityGUID.Zero && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_WinnerVarName))
        {
            QuestVariable questVariable = new QuestVariable(this.Output_WinnerVarName);
            questVariable.Object = this.WinnerArmyGUID;
            questBehaviour.QuestVariables.Add(questVariable);
        }
        this.SaveEnemyArmyGUIDs(questBehaviour);
        MajorEmpire majorEmpire;

        if (this.FocusedEmpireVarName != string.Empty && questBehaviour.TryGetQuestVariableValueByName <MajorEmpire>(this.FocusedEmpireVarName, out majorEmpire))
        {
            this.FocusedEmpireIndex = majorEmpire.Index;
        }
        if (this.UpdateVarName)
        {
            this.UpdateVars = true;
        }
        else
        {
            this.UpdateVars = false;
        }
        IGameService service = Services.GetService <IGameService>();

        this.gameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>();
        return(base.Initialize(questBehaviour));
    }
    protected override State Execute(QuestBehaviour questBehaviour, EventTerraformDeviceEntityCreated e, params object[] parameters)
    {
        global::Game game = Services.GetService <IGameService>().Game as global::Game;

        if (this.DevicePositionVarName == string.Empty)
        {
            return(State.Success);
        }
        IEnumerable <WorldPosition> source;

        if (this.DevicePositionVarName != null && questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.DevicePositionVarName, out source))
        {
            this.DevicePositions = source.ToArray <WorldPosition>();
        }
        if (this.DevicePositions != null && this.DevicePositions[0] == e.TerraformDevice.WorldPosition)
        {
            IQuestManagementService service = game.Services.GetService <IQuestManagementService>();
            if (service != null)
            {
                this.EntityGUID = e.TerraformDevice.GUID;
                QuestVariable questVariable = new QuestVariable(this.Output_EntityVarName, e.TerraformDevice);
                service.State.AddGlobalVariable(questBehaviour.Initiator.Index, questVariable);
            }
            return(State.Success);
        }
        return(State.Running);
    }
Пример #7
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        if (string.IsNullOrEmpty(this.ConstructionName))
        {
            if (string.IsNullOrEmpty(this.ConstructionNameVarName))
            {
                Diagnostics.LogError("Missing attribute 'ConstructionNameVarName'");
                return(false);
            }
            string text;
            if (!questBehaviour.TryGetQuestVariableValueByName <string>(this.ConstructionNameVarName, out text))
            {
                Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[]
                {
                    this.ConstructionNameVarName
                });
                return(false);
            }
            if (string.IsNullOrEmpty(text))
            {
                Diagnostics.LogError("Construction name is null or empty (varname: '{0}')", new object[]
                {
                    this.ConstructionNameVarName
                });
                return(false);
            }
            this.ConstructionName = text;
        }
        if (this.CityGUID != GameEntityGUID.Zero && !string.IsNullOrEmpty(this.Output_CityVarName) && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_CityVarName))
        {
            IGameService service = Services.GetService <IGameService>();
            if (service == null)
            {
                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);
            }
            City @object;
            if (service2.TryGetValue <City>(this.CityGUID, out @object))
            {
                QuestVariable questVariable = new QuestVariable(this.Output_CityVarName);
                questVariable.Object = @object;
                questBehaviour.QuestVariables.Add(questVariable);
            }
        }
        City city = null;

        if (this.CityGUID == GameEntityGUID.Zero && !string.IsNullOrEmpty(this.TargetCityVarName) && questBehaviour.TryGetQuestVariableValueByName <City>(this.TargetCityVarName, out city))
        {
            this.CityGUID = city.GUID;
        }
        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);
    }
Пример #9
0
 protected void AddPositionToForbiddenSpawnPosition(QuestBehaviour questBehaviour, WorldPosition position)
 {
     if (!string.IsNullOrEmpty(this.ForbiddenSpawnLocationVarName))
     {
         QuestVariable        questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.ForbiddenSpawnLocationVarName);
         List <WorldPosition> list          = questVariable.Object as List <WorldPosition>;
         if (!list.Contains(position))
         {
             list.Add(position);
         }
     }
 }
Пример #10
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;
     }
 }
Пример #11
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);
    }
Пример #12
0
    public string GetValue(QuestVariable var)
    {
        QuestVarContainer cont = FindContainer(var);

        if (cont == null)
        {
            cont = new QuestVarContainer()
            {
                name = var.name, var = var, value = var.value
            };
            vars.Add(cont);
        }

        return(cont.value);
    }
Пример #13
0
    private void AddWinnerEmpireToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.ContenderState == ContenderState.Survived);

        if (contender != null)
        {
            this.WinnerEmpireIndex = contender.Empire.Index;
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_WinnerEmpire);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_WinnerEmpire);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = this.WinnerEmpireIndex;
        }
    }
Пример #14
0
    private void AddPositionToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.ContenderState == ContenderState.Defeated);

        if (contender != null)
        {
            this.BattlePosition = contender.WorldPosition;
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_Position);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_Position);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = this.BattlePosition;
        }
    }
Пример #15
0
    public void SetValue(QuestVariable var, string value)
    {
        QuestVarContainer cont = FindContainer(var);

        if (cont == null)
        {
            cont = new QuestVarContainer()
            {
                name = var.name, var = var, value = value
            };
            vars.Add(cont);
        }
        else
        {
            cont.value = value;
        }
    }
    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));
    }
Пример #17
0
 protected void IncrementProgression(QuestBehaviour questBehaviour, GameEvent e)
 {
     if (!StaticString.IsNullOrEmpty(this.LinkedStepProgression))
     {
         QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.LinkedStepProgression);
         if (questVariable != null)
         {
             QuestRegisterVariable questRegisterVariable = questVariable.Object as QuestRegisterVariable;
             if (questRegisterVariable != null)
             {
                 questRegisterVariable.Value += this.ProgressionIncrement;
                 questBehaviour.Push(new QuestInstruction_UpdateRegisterVariable(this.LinkedStepProgression, questRegisterVariable.Value));
                 if (e != null && questBehaviour.Quest.QuestDefinition.IsGlobal && questBehaviour.Initiator.Index == 0)
                 {
                     QuestBehaviour questBehaviour2 = this.questRepositoryService.GetQuestBehaviour(questBehaviour.Quest.Name, e.Empire.Index);
                     if (questBehaviour2 != null)
                     {
                         QuestVariable questVariable2 = questBehaviour2.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.PersonnalLinkedStepProgression);
                         if (questVariable2 != null)
                         {
                             QuestRegisterVariable questRegisterVariable2 = questVariable2.Object as QuestRegisterVariable;
                             if (questRegisterVariable2 != null)
                             {
                                 questRegisterVariable2.Value += this.ProgressionIncrement;
                                 questBehaviour2.Push(new QuestInstruction_UpdateRegisterVariable(this.PersonnalLinkedStepProgression, questRegisterVariable2.Value));
                                 this.questManagementService.SendPendingInstructions(questBehaviour2);
                                 return;
                             }
                         }
                     }
                     else
                     {
                         Diagnostics.LogError("Cannot find quest behaviour of global quest '{0}' for empire {1}", new object[]
                         {
                             questBehaviour.Quest.Name,
                             e.Empire.Index
                         });
                     }
                 }
             }
         }
     }
 }
Пример #18
0
    private void AddLooserToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        if (this.SelectLooserWithTag != string.Empty)
        {
            using (IEnumerator <Contender> enumerator = (from match in e.EventArgs.Encounter.Contenders
                                                         where match.ContenderState == ContenderState.Defeated
                                                         select match).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Contender contender = enumerator.Current;
                    if (contender.Garrison.HasTag(this.SelectLooserWithTag))
                    {
                        this.LooserArmyGUID = contender.GUID;
                        QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_LooserVarName);
                        if (questVariable == null)
                        {
                            questVariable = new QuestVariable(this.Output_LooserVarName);
                            questBehaviour.QuestVariables.Add(questVariable);
                        }
                        questVariable.Object = contender.Garrison;
                    }
                }
                return;
            }
        }
        Contender contender2 = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.ContenderState == ContenderState.Defeated);

        if (contender2 != null)
        {
            this.LooserArmyGUID = contender2.GUID;
            QuestVariable questVariable2 = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_LooserVarName);
            if (questVariable2 == null)
            {
                questVariable2 = new QuestVariable(this.Output_LooserVarName);
                questBehaviour.QuestVariables.Add(questVariable2);
            }
            questVariable2.Object = contender2.Garrison;
        }
    }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null)
        {
            Diagnostics.LogError("Unable to retrieve the game service.");
            return(false);
        }
        this.GameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>();
        if (this.GameEntityRepositoryService == null)
        {
            Diagnostics.LogError("Unable to retrieve the game entity repository service.");
            return(false);
        }
        District @object;

        if (this.DistrictGUID != GameEntityGUID.Zero && !string.IsNullOrEmpty(this.Output_DistrictSimObjectVarName) && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_DistrictSimObjectVarName) && this.GameEntityRepositoryService.TryGetValue <District>(this.DistrictGUID, out @object))
        {
            QuestVariable questVariable = new QuestVariable(this.Output_DistrictSimObjectVarName);
            questVariable.Object = @object;
            questBehaviour.QuestVariables.Add(questVariable);
        }
        City object2;

        if (this.CityGUID != GameEntityGUID.Zero && !string.IsNullOrEmpty(this.Output_CityVarName) && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_CityVarName) && this.GameEntityRepositoryService.TryGetValue <City>(this.CityGUID, out object2))
        {
            QuestVariable questVariable2 = new QuestVariable(this.Output_CityVarName);
            questVariable2.Object = object2;
            questBehaviour.QuestVariables.Add(questVariable2);
        }
        City city = null;

        if (this.CityGUID == GameEntityGUID.Zero && !string.IsNullOrEmpty(this.TargetCityVarName) && questBehaviour.TryGetQuestVariableValueByName <City>(this.TargetCityVarName, out city) && city != null)
        {
            this.CityGUID = city.GUID;
        }
        return(base.Initialize(questBehaviour));
    }
    public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
    {
        if (!StaticString.IsNullOrEmpty(this.StepName))
        {
            int num = -1;
            if (!string.IsNullOrEmpty(this.InterpretedValue))
            {
                if (this.compiledExpression == null)
                {
                    this.compiledExpression = Interpreter.InfixTransform(this.InterpretedValue);
                }
                SimulationObject simulationObject;
                if (this.EmpireIndex >= 0)
                {
                    simulationObject = (Services.GetService <IGameService>().Game as global::Game).Empires[this.EmpireIndex].SimulationObject;
                }
                else if (gameEvent != null)
                {
                    simulationObject = gameEvent.Empire.SimulationObject;
                }
                else
                {
                    simulationObject = questBehaviour.Initiator.SimulationObject;
                }
                using (InterpreterContext.InterpreterSession interpreterSession = new InterpreterContext.InterpreterSession(simulationObject))
                {
                    foreach (QuestVariable questVariable in questBehaviour.QuestVariables)
                    {
                        if (questVariable.Object is float)
                        {
                            interpreterSession.Context.Register(questVariable.Name, (float)Convert.ChangeType(questVariable.Object, typeof(float)));
                        }
                    }
                    object obj = Interpreter.Execute(this.compiledExpression, interpreterSession.Context);
                    if (obj is float)
                    {
                        num = Mathf.FloorToInt((float)Convert.ChangeType(obj, typeof(float)));
                    }
                    else
                    {
                        if (!(obj is int))
                        {
                            if (global::GameManager.Preferences.QuestVerboseMode)
                            {
                                Diagnostics.LogWarning("[Quest] IsStepProgressionComplete expression or variable '{0}' returned {1} wich is not a number (in quest {2} of empire {3}).", new object[]
                                {
                                    string.IsNullOrEmpty(this.InterpretedValue) ? this.InterpretedVarName : this.InterpretedValue,
                                    obj ?? "null",
                                    questBehaviour.Quest.QuestDefinition.Name,
                                    questBehaviour.Initiator.Index
                                });
                            }
                            return(State.Failure);
                        }
                        num = (int)Convert.ChangeType(obj, typeof(int));
                    }
                    QuestVariable questVariable2 = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.StepName);
                    if (questVariable2 != null)
                    {
                        QuestRegisterVariable questRegisterVariable = questVariable2.Object as QuestRegisterVariable;
                        if (questRegisterVariable != null)
                        {
                            questRegisterVariable.Value = num;
                            questBehaviour.Push(new QuestInstruction_UpdateRegisterVariable(this.StepName, questRegisterVariable.Value));
                        }
                        if (questBehaviour.Quest.QuestDefinition.IsGlobal)
                        {
                            StaticString personnalStepName = this.StepName + Quest.PersonnalProgressStepSuffix;
                            questVariable2 = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == personnalStepName);
                            if (questVariable2 != null)
                            {
                                questRegisterVariable = (questVariable2.Object as QuestRegisterVariable);
                                if (questRegisterVariable != null)
                                {
                                    questRegisterVariable.Value = num;
                                    questBehaviour.Push(new QuestInstruction_UpdateRegisterVariable(personnalStepName, questRegisterVariable.Value));
                                }
                            }
                        }
                    }
                    goto IL_2DB;
                }
            }
            num = questBehaviour.Quest.GetStepProgressionValueByName(this.StepName);
IL_2DB:
            QuestStepProgressionRange stepProgressionRangeByName = questBehaviour.Quest.GetStepProgressionRangeByName(this.StepName);
            if (stepProgressionRangeByName == null)
            {
                Diagnostics.LogError("[Quest] ConditionCheck_IsStepProgressionComplete: step '{0}' doesn't have a progression range. (in quest {1})", new object[]
                {
                    this.StepName,
                    questBehaviour.Quest.Name
                });
                return(State.Failure);
            }
            if (stepProgressionRangeByName.EndValueVarName != string.Empty)
            {
                questBehaviour.UpdateProgressionVariables();
                stepProgressionRangeByName = questBehaviour.Quest.GetStepProgressionRangeByName(this.StepName);
            }
            if (num >= stepProgressionRangeByName.EndValue)
            {
                return(State.Success);
            }
        }
        return(State.Failure);
    }
Пример #21
0
 public void RegisterQuestByEvent(QuestVariable addedQuest)
 {
     RegisterQuest(addedQuest.value);
     addedQuest.value = new Quest();
 }
    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);
    }
Пример #23
0
 QuestVarContainer FindContainer(QuestVariable var)
 {
     return(vars.Find(x => x.var == var));
 }
Пример #24
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 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 (string.IsNullOrEmpty(this.ArmyTag))
        {
            Diagnostics.LogError("Spawned armies requires an identifing tag");
            return(false);
        }
        if (string.IsNullOrEmpty(this.ArmyUnitTag))
        {
            Diagnostics.LogError("Spawned armies requires an identifing tag");
            return(false);
        }
        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];
        }
        return(base.Initialize(questBehaviour));
    }
Пример #26
0
    public State CheckConditions(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
    {
        if (this.ConditionChecks == null)
        {
            return(State.Success);
        }
        if (this.InterpretedVarsToUpdate != null && this.InterpretedVarsToUpdate.Length != 0)
        {
            Dictionary <StaticString, IEnumerable <SimulationObjectWrapper> > dictionary = new Dictionary <StaticString, IEnumerable <SimulationObjectWrapper> >();
            dictionary.Add("$(Empire)", new SimulationObjectWrapper[]
            {
                questBehaviour.Initiator
            });
            IGameService service = Services.GetService <IGameService>();
            Diagnostics.Assert(service != null && service.Game != null);
            dictionary.Add("$(Empires)", (from emp in (service.Game as global::Game).Empires
                                          where emp is MajorEmpire && !(emp as MajorEmpire).IsEliminated
                                          select emp).ToArray <global::Empire>());
            string[] interpretedVarsToUpdate = this.InterpretedVarsToUpdate;
            for (int i = 0; i < interpretedVarsToUpdate.Length; i++)
            {
                string variable = interpretedVarsToUpdate[i];
                QuestVariableDefinition questVariableDefinition = questBehaviour.Quest.QuestDefinition.Variables.FirstOrDefault((QuestVariableDefinition varDefinition) => varDefinition is QuestInterpretedVariableDefinition && varDefinition.VarName == variable);
                if (questVariableDefinition != null)
                {
                    QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable questVar) => questVar.Name == variable);
                    if (questVariable != null)
                    {
                        questVariable.Object = (questVariableDefinition as QuestInterpretedVariableDefinition).Evaluate(dictionary, questBehaviour.QuestVariables);
                        if (global::GameManager.Preferences.QuestVerboseMode)
                        {
                            Diagnostics.Log("[Quest] Updated value of '{0}' to '{1}' in quest '{2}'", new object[]
                            {
                                variable,
                                questVariable.Object,
                                questBehaviour.Quest.QuestDefinition.Name
                            });
                        }
                    }
                    else
                    {
                        Diagnostics.LogError("[Quest] InterpretedVarToUpdate '{0}' is not registered in quest behaviour '{1}'", new object[]
                        {
                            variable,
                            questBehaviour.Quest.QuestDefinition.Name
                        });
                    }
                }
                else
                {
                    Diagnostics.LogError("[Quest] Could not find InterpretedVarToUpdate '{0}' in quest '{1}'", new object[]
                    {
                        variable,
                        questBehaviour.Quest.QuestDefinition.Name
                    });
                }
            }
        }
        bool flag = false;

        for (int j = 0; j < this.ConditionChecks.Length; j++)
        {
            QuestBehaviourTreeNode_ConditionCheck questBehaviourTreeNode_ConditionCheck = this.ConditionChecks[j];
            State state = questBehaviourTreeNode_ConditionCheck.CheckCondition(questBehaviour, gameEvent, parameters);
            if (questBehaviourTreeNode_ConditionCheck.Inverted)
            {
                state = base.Inverse(state);
            }
            if (state == State.Failure)
            {
                if (questBehaviourTreeNode_ConditionCheck.IsFailureCondition)
                {
                    return(State.Failure);
                }
                flag = true;
            }
        }
        if (flag)
        {
            return(State.Running);
        }
        return(State.Success);
    }