public QuestObjectState GetState(IQuestSystemObject obj) { QuestObjectState state; if (m_States.TryGetValue(obj.Id, out state)) { return(state); } state = new QuestObjectState(); m_States.Add(obj.Id, state); return(state); }
public void Tick() { QuestObjectState state; bool result; var values = m_ActivelyChecked.Values; IQuestSystemObject[] objects = new IQuestSystemObject[values.Count]; values.CopyTo(objects, 0); GameDebugger.Log(LogLevel.Debug, "QS: TICK"); foreach (IQuestSystemObject obj in objects) { state = GetState(obj); if (state.Locked) { GameDebugger.Log(LogLevel.Warning, "QS: {0} '0x{1:X16}' is in the list of actively checked objects while being locked", obj.GetType().Name, obj.Id); m_ActivelyChecked.Remove(obj.Id); continue; } GameDebugger.Log(LogLevel.Debug, "QS: Checking {0} '0x{1:X16}'", obj.GetType().Name, obj.Id); if (obj is QuestPin) { QuestPin pin = (QuestPin)obj; result = CheckCondition(pin, true); if (result && state.Active == QuestObjectState.ActivationState.PartiallyActive) { state.Active = QuestObjectState.ActivationState.Active; GameDebugger.Log(LogLevel.Debug, "QS: Switched {0} '0x{1:X16}' from partially activated to activated", obj.GetType().Name, obj.Id); if (pin.Node is Quest) { Activate((BaseQuestObject)pin.Node); } else { CheckInputsOnActivation((BaseQuestObject)pin.Node); } foreach (QuestConnection connection in pin.Connections) { if (connection.Source == pin) { Activate(connection); } } } else if (!result && state.Active == QuestObjectState.ActivationState.Active) { state.Active = QuestObjectState.ActivationState.PartiallyActive; GameDebugger.Log(LogLevel.Debug, "QS: Switched {0} '0x{1:X16}' from activated to partially activated", obj.GetType().Name, obj.Id); Deactivate((BaseQuestObject)pin.Node); foreach (QuestConnection connection in pin.Connections) { if (connection.Source == pin) { Deactivate(connection); } } } } else if (obj is QuestCondition) { // every tick depending on it's script execution result it switches active either output[0] or output[1] active QuestCondition condition = (QuestCondition)obj; result = CheckCondition(condition, true); if (result) { if (state.CompletionOutput != 0 || state.Completion == QuestObjectState.CompletionState.Incomplete) { if (state.Completion != QuestObjectState.CompletionState.Incomplete) { Deactivate((QuestPin)condition.Outputs[1]); GameDebugger.Log(LogLevel.Debug, "QS: Switching {0} '0x{1:X16}' output from FALSE to TRUE", obj.GetType().Name, obj.Id); } else { GameDebugger.Log(LogLevel.Debug, "QS: Setting {0} '0x{1:X16}' output to TRUE", obj.GetType().Name, obj.Id); } Activate((QuestPin)condition.Outputs[0]); state.CompletionOutput = 0; } } else { if (state.CompletionOutput != 1 || state.Completion == QuestObjectState.CompletionState.Incomplete) { if (state.Completion != QuestObjectState.CompletionState.Incomplete) { Deactivate((QuestPin)condition.Outputs[0]); GameDebugger.Log(LogLevel.Debug, "QS: Switching {0} '0x{1:X16}' output from TRUE to FALSE", obj.GetType().Name, obj.Id); } else { GameDebugger.Log(LogLevel.Debug, "QS: Setting {0} '0x{1:X16}' output to FALSE", obj.GetType().Name, obj.Id); } Activate((QuestPin)condition.Outputs[1]); state.CompletionOutput = 1; } } state.Completion = QuestObjectState.CompletionState.Successful; } else if (obj is QuestObjective) { // every tick rechecks all conditions on output pins QuestObjective objective = (QuestObjective)obj; int pinIndex = 0; foreach (QuestPin pin in objective.Outputs) { if (pin.Script == null) { pinIndex++; continue; } result = CheckCondition(pin, false); if (result) { Activate(pin); // this will also deactivate previously active pin break; // Just in case when there is more than one output that passes the check. We don't want lots of unneeded events, right? } if (pinIndex == state.CompletionOutput && state.Completion != QuestObjectState.CompletionState.Incomplete) { state.Completion = QuestObjectState.CompletionState.Incomplete; GameDebugger.Log(LogLevel.Debug, "QS: event: OnQuestObjectiveIncomplete"); if (OnQuestObjectiveIncomplete != null) { OnQuestObjectiveIncomplete.Invoke(new QuestObjectiveIncompleteEventArgs(objective)); } } Deactivate(pin); pinIndex++; } } else { GameDebugger.Log(LogLevel.Warning, "QS: {0} '0x{1:X16}' is not supposed to be in the list of actively checked objects", obj.GetType().Name, obj.Id); } } }