예제 #1
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
                         });
                     }
                 }
             }
         }
     }
 }
    private void DisplayQuestFailed()
    {
        this.WriteSummaryDescription();
        int       failedStepRank = (this.guiNotification as GuiNotificationQuestFailed).FailedStepRank;
        QuestStep step;

        if (failedStepRank >= 0 && failedStepRank < this.Quest.QuestDefinition.Steps.Length)
        {
            step = this.Quest.QuestDefinition.Steps[failedStepRank];
        }
        else
        {
            step = null;
        }
        Diagnostics.Assert(failedStepRank != -1, "There wasn't any step in progress when the quest failed");
        this.LeftTitleLabel.Text = "%NotificationQuestFailedObjectiveTitle";
        this.LeftSummary.Hide();
        this.LeftStepItem.Show(this.Quest, step, failedStepRank, this.empire);
        string arg = this.Quest.QuestDefinition.Name;

        if (this.questGuiElement != null)
        {
            arg = AgeLocalizer.Instance.LocalizeString(this.questGuiElement.Title);
        }
        string text = string.Empty;
        bool   flag = false;

        if (this.Quest.QuestDefinition.IsGlobal && this.Quest.QuestDefinition.GlobalWinner == GlobalQuestWinner.First && this.Quest.QuestState == QuestState.Failed)
        {
            flag = true;
            QuestRegisterVariable questRegisterVariable = null;
            if (this.Quest.QuestVariables.TryGetValue(QuestDefinition.WinnerVariableName, out questRegisterVariable) && questRegisterVariable != null)
            {
                if (this.game == null)
                {
                    IGameService service = Services.GetService <IGameService>();
                    Diagnostics.Assert(service != null && service.Game != null && service.Game is global::Game);
                    this.game = (service.Game as global::Game);
                }
                int value = questRegisterVariable.Value;
                if (this.departmentOfForeignAffairs.GetDiplomaticRelation(this.game.Empires[value]).State.Name == DiplomaticRelationState.Names.Unknown)
                {
                    text = AgeLocalizer.Instance.LocalizeString("%UnknownEmpire");
                }
                else
                {
                    text = new GuiEmpire(this.game.Empires[value]).GetColorizedLocalizedNameAndFaction(this.empire, false);
                }
            }
        }
        string text2;

        if (flag)
        {
            text2 = string.Format(AgeLocalizer.Instance.LocalizeString("%NotificationQuestFailedCompetitiveDescription"), arg);
            if (!string.IsNullOrEmpty(text.Trim()))
            {
                text2 = text2 + "\n" + string.Format(AgeLocalizer.Instance.LocalizeString("%NotificationQuestFailedCompetitiveWinnerDescription"), text);
            }
        }
        else
        {
            text2 = string.Format(AgeLocalizer.Instance.LocalizeString("%NotificationQuestFailedDescription"), arg);
        }
        this.RightSummary.Show(this.Quest, "%QuestOutcomeTitle", text2);
        this.RightStepItem.Hide();
    }
    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);
    }