Example #1
0
        protected void CheckInputsOnActivation(BaseQuestObject obj)
        {
            // all objects except quests get activated when all their input pins are active
            bool allActive = true;

            GameDebugger.Log(LogLevel.Debug, "QS: Checking inputs of {0} '0x{1:X16}'", obj.GetType().Name, obj.Id);
            foreach (QuestPin pin in obj.Inputs)
            {
                QuestObjectState state = GetState(pin);
                if (state.Active != QuestObjectState.ActivationState.Active)
                {
                    allActive = false;
                    break;
                }
            }
            if (allActive)
            {
                GameDebugger.Log(LogLevel.Debug, "QS: SUCCESS");
                Activate((BaseQuestObject)obj);
            }
            else
            {
                GameDebugger.Log(LogLevel.Debug, "QS: FAIL");
            }
        }
Example #2
0
        protected void Activate(BaseQuestObject obj)
        {
            QuestObjectState state = GetState(obj);

            if (state.Locked || state.Active != QuestObjectState.ActivationState.Inactive)
            {
                return;
            }
            state.Active = QuestObjectState.ActivationState.Active;
            GameDebugger.Log(LogLevel.Debug, "QS: Activated {0} '0x{1:X16}'", obj.GetType().Name, obj.Id);
            if (obj is QuestCondition)
            {
                // conditions must be actively checked every quest system tick
                GameDebugger.Log(LogLevel.Debug, "QS: Adding {0} '0x{1:X16}' to the list of actively checked objects", obj.GetType().Name, obj.Id);
                m_ActivelyChecked.Add(obj.Id, obj);
            }
            else if (obj is QuestObjective)
            {
                // quest objectives must be actively checked every quest system tick, but only when there is at least one output that has a script assigned
                bool hasScriptsOnOutputs = false;
                foreach (QuestPin pin in obj.Outputs)
                {
                    if (pin.Script != null)
                    {
                        hasScriptsOnOutputs = true;
                        break;
                    }
                }
                if (hasScriptsOnOutputs)
                {
                    GameDebugger.Log(LogLevel.Debug, "QS: Adding {0} '0x{1:X16}' to the list of actively checked objects due to existing scripts on one or more outputs", obj.GetType().Name, obj.Id);
                    m_ActivelyChecked.Add(obj.Id, obj);
                }
                GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestObjectiveActivated");
                if (OnQuestObjectiveActivated != null)
                {
                    OnQuestObjectiveActivated.Invoke(new QuestObjectiveActivatedEventArgs((QuestObjective)obj));
                }
            }
            else if (obj is Quest)
            {
                GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestActivated");
                if (OnQuestActivated != null)
                {
                    OnQuestActivated.Invoke(new QuestActivatedEventArgs((Quest)obj));
                }
            }
            else
            {
                if (obj is QuestInstruction)
                {
                    ExecuteScript((QuestInstruction)obj);
                }
                foreach (QuestPin pin in obj.Outputs)
                {
                    Activate(pin);
                }
            }
            // when quest gets activated it does nothing since objectives actually get activated by quest's active input pins
        }
Example #3
0
        private static bool ImportArticyPins(ArticyFlowObject source, BaseQuestObject target, bool compileInputScripts, bool compileOutputScripts, Dictionary <ulong, QuestPin> pinIndex)
        {
            FlowObjectPin articyPin;
            QuestPin      pin;
            bool          badScripts = false;

            foreach (GraphPin graphPin in source.Inputs)
            {
                articyPin = (FlowObjectPin)graphPin;
                pin       = new QuestPin(articyPin.Type, articyPin.Id);
                if (compileInputScripts && !string.IsNullOrWhiteSpace(articyPin.Script))
                {
                    if ((pin.Script = CompileScript(articyPin.Script, Quests.InputPinScriptEnvironment, "input pin", articyPin.Id)) == null)
                    {
                        badScripts = true;
                    }
                }
                if (string.IsNullOrEmpty(target.Key))
                {
                    GameDebugger.Log(LogLevel.Debug, "Adding intput pin to '0x{0:X16}'", target.Id);
                }
                else
                {
                    GameDebugger.Log(LogLevel.Debug, "Adding intput pin to '{0}'", target.Key);
                }
                pinIndex.Add(articyPin.Id, pin);
                target.AddInput(pin);
            }

            foreach (GraphPin graphPin in source.Outputs)
            {
                articyPin = (FlowObjectPin)graphPin;
                pin       = new QuestPin(articyPin.Type, articyPin.Id);
                if (compileOutputScripts && !string.IsNullOrWhiteSpace(articyPin.Script))
                {
                    QuestSystemScriptEnvironment env;
                    env = (target is QuestObjective) ? (QuestSystemScriptEnvironment)Quests.OutputPinScriptEnvironment : (QuestSystemScriptEnvironment)Quests.InstructionScriptEnvironment;
                    if ((pin.Script = CompileScript(articyPin.Script, env, "output pin", articyPin.Id)) == null)
                    {
                        badScripts = true;
                    }
                }
                if (string.IsNullOrEmpty(target.Key))
                {
                    GameDebugger.Log(LogLevel.Debug, "Adding output pin to '0x{0:X16}'", target.Id);
                }
                else
                {
                    GameDebugger.Log(LogLevel.Debug, "Adding output pin to '{0}'", target.Key);
                }
                pinIndex.Add(articyPin.Id, pin);
                target.AddOutput(pin);
            }

            return(badScripts);
        }
Example #4
0
        protected void Deactivate(BaseQuestObject obj)
        {
            QuestObjectState state = GetState(obj);

            if (state.Locked || state.Active == QuestObjectState.ActivationState.Inactive)
            {
                return;
            }
            state.Active = QuestObjectState.ActivationState.Inactive;
            GameDebugger.Log(LogLevel.Debug, "QS: {0} '0x{1:X16}' deactivated", obj.GetType().Name, obj.Id);

            if (m_ActivelyChecked.ContainsKey(obj.Id))
            {
                GameDebugger.Log(LogLevel.Debug, "QS: Removing {0} '0x{1:X16}' from the list of actively checked objects", obj.GetType().Name, obj.Id);
                m_ActivelyChecked.Remove(obj.Id);
            }

            if (obj is Quest)
            {
                GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestDeactivated");
                if (OnQuestDeactivated != null)
                {
                    OnQuestDeactivated.Invoke(new QuestDeactivatedEventArgs((Quest)obj));
                }
                if (state.Completion != QuestObjectState.CompletionState.Incomplete)
                {
                    state.Completion = QuestObjectState.CompletionState.Incomplete;
                    // NOTE: This most probably will never happen since quests are locked right after getting complete,
                    // but might need to invoke OnQuestIncomplete event in case this happens after all.
                }
            }
            else if (obj is QuestObjective)
            {
                GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestObjectiveDeactivated");
                if (OnQuestObjectiveDeactivated != null)
                {
                    OnQuestObjectiveDeactivated.Invoke(new QuestObjectiveDeactivatedEventArgs((QuestObjective)obj));
                }
                if (state.Completion != QuestObjectState.CompletionState.Incomplete)
                {
                    state.Completion = QuestObjectState.CompletionState.Incomplete;
                    GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestObjectiveIncomplete");
                    if (OnQuestObjectiveIncomplete != null)
                    {
                        OnQuestObjectiveIncomplete.Invoke(new QuestObjectiveIncompleteEventArgs((QuestObjective)obj));
                    }
                }
            }

            foreach (QuestPin pin in obj.Outputs)
            {
                Deactivate(pin);
            }
        }
Example #5
0
 public static void Add(BaseQuestObject obj)
 {
     m_Objects.Add(obj.Id, obj);
     if (obj is Quest)
     {
         m_Quests.Add(obj.Id, (Quest)obj);
     }
     if (!string.IsNullOrWhiteSpace(obj.Key))
     {
         GameDebugger.Log(LogLevel.Debug, "Added {0} '{1}' to quest system", obj.GetType().Name, obj.Key);
         m_ObjectIndex.Add(obj.Key, obj);
         if (obj is Quest)
         {
             m_QuestIndex.Add(obj.Key, (Quest)obj);
         }
     }
     else
     {
         GameDebugger.Log(LogLevel.Debug, "Added {0} '0x{1:X16}' to quest system", obj.GetType().Name, obj.Id);
     }
 }
Example #6
0
        protected void Lock(BaseQuestObject obj)
        {
            QuestObjectState state = GetState(obj);

            if (state.Locked)
            {
                return;
            }
            state.Locked = true;
            GameDebugger.Log(LogLevel.Debug, "QS: {0} '0x{1:X16}' locked", obj.GetType().Name, obj.Id);

            if (m_ActivelyChecked.ContainsKey(obj.Id))
            {
                GameDebugger.Log(LogLevel.Debug, "QS: Removing {0} '0x{1:X16}' from the list of actively checked objects", obj.GetType().Name, obj.Id);
                m_ActivelyChecked.Remove(obj.Id);
            }

            foreach (QuestPin pin in obj.Inputs)
            {
                Lock(pin, true);
            }
        }