Exemplo n.º 1
0
    public override State Execute(BehaviourTree behaviourTree, params object[] parameters)
    {
        QuestBehaviour questBehaviour = behaviourTree as QuestBehaviour;

        if (questBehaviour != null)
        {
            if (parameters == null)
            {
                return(State.Running);
            }
            if (parameters.Length == 0)
            {
                return(State.Running);
            }
            T t = parameters[0] as T;
            if (t != null)
            {
                GameEvent gameEvent = t as GameEvent;
                if (gameEvent != null && !this.CheckAgainstQuestInitiatorFilter(questBehaviour, gameEvent, this.QuestInitiatorFilter))
                {
                    return(State.Running);
                }
                if (this.questRepositoryService == null || this.questManagementService == null)
                {
                    IGameService service = Services.GetService <IGameService>();
                    Diagnostics.Assert(service != null && service.Game != null);
                    this.questManagementService = service.Game.Services.GetService <IQuestManagementService>();
                    Diagnostics.Assert(this.questManagementService != null);
                    this.questRepositoryService = service.Game.Services.GetService <IQuestRepositoryService>();
                    Diagnostics.Assert(this.questRepositoryService != null);
                }
                State state = this.Execute(questBehaviour, t, new object[0]);
                if (state == State.Success)
                {
                    state = this.CheckConditions(questBehaviour, gameEvent, parameters);
                    if (state == State.Success)
                    {
                        this.IncrementProgression(questBehaviour, t as GameEvent);
                        if (!string.IsNullOrEmpty(this.PrerequisiteVerifiedMessage) && gameEvent.Empire.Index == questBehaviour.Initiator.Index)
                        {
                            QuestInstruction_ShowMessagePanel questInstruction = new QuestInstruction_ShowMessagePanel(this.PrerequisiteVerifiedMessage);
                            questBehaviour.Push(questInstruction);
                        }
                    }
                    else if (!string.IsNullOrEmpty(this.PrerequisiteNotVerifiedMessage) && gameEvent.Empire.Index == questBehaviour.Initiator.Index)
                    {
                        QuestInstruction_ShowMessagePanel questInstruction2 = new QuestInstruction_ShowMessagePanel(this.PrerequisiteNotVerifiedMessage);
                        questBehaviour.Push(questInstruction2);
                    }
                }
                return(state);
            }
        }
        return(State.Running);
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        if (this.Tags.IsNullOrEmpty)
        {
            Diagnostics.LogWarning("Marker was added without any tags in quest {0} : abort.", new object[]
            {
                questBehaviour.Quest.QuestDefinition.XmlSerializableName
            });
            return(State.Success);
        }
        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(State.Running);
        }
        if (!this.TryResolveTarget(questBehaviour))
        {
            return(State.Running);
        }
        questBehaviour.Push(new QuestInstruction_UpdateQuestMarker
        {
            BoundTargetGUID         = this.TargetEntityGUID,
            MarkerGUID              = this.QuestMarkerGUID,
            Tags                    = this.Tags,
            Empire                  = questBehaviour.Initiator,
            RevealUnexploredLand    = this.RevealUnexploredLand,
            MarkerVisibleInFogOfWar = this.MarkerVisibleInFogOfWar,
            MarkerTypeName          = this.MarkerTypeName,
            IgnoreInteraction       = this.IgnoreInteraction
        });
        return(State.Success);
    }
Exemplo n.º 3
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);
        }
        this.game = (service.Game as global::Game);
        if (this.game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        if (!string.IsNullOrEmpty(this.TimerLocalizationKey))
        {
            int num = this.ComputeEleapsedTurn(questBehaviour);
            if (num != -1)
            {
                int num2 = this.TurnCountBeforeTimeOut;
                if (this.ScaleWithGameSpeed)
                {
                    num2 = Mathf.CeilToInt((float)this.TurnCountBeforeTimeOut * questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier));
                }
                int num3 = num2 - num;
                if (num3 >= 0)
                {
                    QuestInstruction_UpdateLocalizationVariable questInstruction = new QuestInstruction_UpdateLocalizationVariable(this.TimerLocalizationKey, num3.ToString());
                    questBehaviour.Push(questInstruction);
                }
            }
        }
        return(true);
    }
Exemplo n.º 4
0
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        int num = this.ComputeEleapsedTurn(questBehaviour);

        if (num == -1)
        {
            Diagnostics.LogError("QuestBehaviourTreeNode_Action_UpdateTimerLocalization, Timer '{0}' isn't started, you can't update it.", new object[]
            {
                this.TimerVarName
            });
            return(State.Success);
        }
        int num2 = this.TurnCountBeforeTimeOut;

        if (this.ScaleWithGameSpeed)
        {
            num2 = Mathf.CeilToInt((float)this.TurnCountBeforeTimeOut * questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier));
        }
        int num3 = num2 - num;

        if (!string.IsNullOrEmpty(this.TimerLocalizationKey) && num3 >= 0)
        {
            QuestInstruction_UpdateLocalizationVariable questInstruction = new QuestInstruction_UpdateLocalizationVariable(this.TimerLocalizationKey, num3.ToString());
            questBehaviour.Push(questInstruction);
        }
        return(State.Success);
    }
    private void addQuestMarker(QuestBehaviour questBehaviour, TerraformDevice army)
    {
        QuestInstruction_UpdateQuestMarker questInstruction_UpdateQuestMarker = new QuestInstruction_UpdateQuestMarker();

        questInstruction_UpdateQuestMarker.BoundTargetGUID = army.GUID;
        questInstruction_UpdateQuestMarker.MarkerGUID      = this.EntityGUID;
        questInstruction_UpdateQuestMarker.Tags            = new Tags();
        questInstruction_UpdateQuestMarker.Tags.AddTag("Ruins");
        questInstruction_UpdateQuestMarker.MarkerTypeName          = QuestMarker.DefaultMarkerTypeName;
        questInstruction_UpdateQuestMarker.Empire                  = questBehaviour.Initiator;
        questInstruction_UpdateQuestMarker.RevealUnexploredLand    = true;
        questInstruction_UpdateQuestMarker.MarkerVisibleInFogOfWar = true;
        questInstruction_UpdateQuestMarker.IgnoreInteraction       = false;
        questBehaviour.Push(questInstruction_UpdateQuestMarker);
    }
Exemplo n.º 6
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
                         });
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
    protected override State Execute(QuestBehaviour questBehaviour, EventBeginTurn e, params object[] parameters)
    {
        int num = this.ComputeEleapsedTurn(questBehaviour);

        if (num == -1)
        {
            Diagnostics.LogError("QuestBehaviourTreeNode_Decorator_TimerEnded, Timer '{0}' isn't started, you can't check it.", new object[]
            {
                this.TimerVarName
            });
            return(State.Success);
        }
        int num2 = this.TurnCountBeforeTimeOut;

        if (this.ScaleWithGameSpeed)
        {
            num2 = Mathf.CeilToInt((float)this.TurnCountBeforeTimeOut * questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier));
        }
        int num3 = num2 - num;

        if (!string.IsNullOrEmpty(this.TimerLocalizationKey))
        {
            QuestInstruction_UpdateLocalizationVariable questInstruction = new QuestInstruction_UpdateLocalizationVariable(this.TimerLocalizationKey, num3.ToString());
            questBehaviour.Push(questInstruction);
        }
        Diagnostics.Log("Quest '{0}', Timer '{1}' eleapsedTurn = {2}.", new object[]
        {
            questBehaviour.Quest.QuestDefinition.Name,
            this.TimerVarName,
            num
        });
        if (num >= num2)
        {
            return(State.Success);
        }
        return(State.Running);
    }
    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);
    }