Class QuestMachine
Hosts quests and manages their execution during play. Quests are instantiated from a source text template. It's possible to have the same quest multiple times (e.g. same fetch quest from two different mage guildhalls). Running quests can perform actions in the world (e.g. spawn enemies and play sounds). Or they can provide data to external systems like the NPC dialog interface (e.g. 'tell me about' and 'rumors'). Quest support is considered to be in very early prototype stages and may change at any time.
Namespace: DaggerfallWorkshop.Game.Questing
Assembly: Assembly-CSharp.dll
Syntax
public class QuestMachine : MonoBehaviour
Fields
| Improve this Doc View SourcequestFoeTag
Declaration
public const string questFoeTag = "QuestFoe"
Field Value
Type | Description |
---|---|
String |
questItemTag
Declaration
public const string questItemTag = "QuestItem"
Field Value
Type | Description |
---|---|
String |
questPersonTag
Declaration
public const string questPersonTag = "QuestPerson"
Field Value
Type | Description |
---|---|
String |
Properties
| Improve this Doc View SourceDiseasesTable
Gets the diseases data table.
Declaration
public Table DiseasesTable { get; }
Property Value
Type | Description |
---|---|
Table |
FactionsTable
Gets the factions data table.
Declaration
public Table FactionsTable { get; }
Property Value
Type | Description |
---|---|
Table |
FoesTable
Gets the foes data table.
Declaration
public Table FoesTable { get; }
Property Value
Type | Description |
---|---|
Table |
GlobalVarsTable
Gets the global variables data table.
Declaration
public Table GlobalVarsTable { get; }
Property Value
Type | Description |
---|---|
Table |
HasInstance
Declaration
public static bool HasInstance { get; }
Property Value
Type | Description |
---|---|
Boolean |
Instance
Declaration
public static QuestMachine Instance { get; }
Property Value
Type | Description |
---|---|
QuestMachine |
InternalSeed
Return a new random seed
Declaration
public int InternalSeed { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsDebugModeEnabled
Returns true if debug mode enabled. This causes original quest source line to be stored and serialized with quests. Always enabled at this stage of development.
Declaration
public bool IsDebugModeEnabled { get; }
Property Value
Type | Description |
---|---|
Boolean |
ItemsTable
Gets the items data table.
Declaration
public Table ItemsTable { get; }
Property Value
Type | Description |
---|---|
Table |
LastNPCClicked
Gets or sets StaticNPC last clicked by player.
Declaration
public StaticNPC LastNPCClicked { get; set; }
Property Value
Type | Description |
---|---|
StaticNPC |
PlacesTable
Gets the places data table.
Declaration
public Table PlacesTable { get; }
Property Value
Type | Description |
---|---|
Table |
QuestCount
Gets count of all quests running at this time.
Declaration
public int QuestCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
QuestSourceFolder
Gets Quests source folder in StreamingAssets.
Declaration
public static string QuestSourceFolder { get; }
Property Value
Type | Description |
---|---|
String |
SiteLinkCount
Gets current count of all active SiteLinks.
Declaration
public int SiteLinkCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
SoundsTable
Gets the sounds data table.
Declaration
public Table SoundsTable { get; }
Property Value
Type | Description |
---|---|
Table |
SpellsTable
Gets the spells data table.
Declaration
public Table SpellsTable { get; }
Property Value
Type | Description |
---|---|
Table |
StaticMessagesTable
Gets the static message names data table.
Declaration
public Table StaticMessagesTable { get; }
Property Value
Type | Description |
---|---|
Table |
TablesSourceFolder
Gets Tables source folder in StreamingAssets. TODO: This folder isn't ultimately exclusive to quests. Find a more generic spot later, e.g. GameManager.
Declaration
public string TablesSourceFolder { get; }
Property Value
Type | Description |
---|---|
String |
Methods
| Improve this Doc View SourceActiveFactionPersons(Int32)
Gets any assigned Person resources of faction ID across all quests.
Declaration
public Person[] ActiveFactionPersons(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID | FactionID to search for. |
Returns
Type | Description |
---|---|
Person[] | Person array. |
ActiveQuestor(StaticNPC.NPCData)
Finds an active questor given a specific static NPC. NPCData passed must be populated with runtime data such as map id and building key.
Declaration
public Person ActiveQuestor(StaticNPC.NPCData npcData)
Parameters
Type | Name | Description |
---|---|---|
StaticNPC.NPCData | npcData |
Returns
Type | Description |
---|---|
Person |
ActiveQuestor(Int32)
Find an active questor for an individual NPC faction ID across all quests. Individual NPCs can only be assigned as a questor by one quest at a time.
Declaration
public Person ActiveQuestor(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID | FactionID of individual NPC to search for. |
Returns
Type | Description |
---|---|
Person | Person resource. |
AddFactionListener(Int32, IQuestAction)
Add a faction listener for the individual faction ID. Does nothing if faction ID already claimed.
Declaration
public void AddFactionListener(int factionID, IQuestAction owner)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID | |
IQuestAction | owner |
AddSiteLink(SiteLink)
Adds a site link to quest machine. There is no strong unique key to use for site links so they are stored in a flat list. Only a small number of site links will be ever active at one time in normal play.
Declaration
public void AddSiteLink(SiteLink siteLink)
Parameters
Type | Name | Description |
---|---|---|
SiteLink | siteLink | SiteLink to add. |
ClearQuests()
Declaration
public void ClearQuests()
ClearState()
Resets operating state - clears all quests, sitelinks, debuggers, etc. Quests will not be disposed or tombstoned they will just be dropped for garbage collector.
Declaration
public void ClearState()
CreateMessagePrompt(Message)
Creates a yes/no prompt from quest message. Caller must set events and call Show() when ready.
Declaration
public DaggerfallMessageBox CreateMessagePrompt(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message |
Returns
Type | Description |
---|---|
DaggerfallMessageBox |
CreateMessagePrompt(Quest, Int32)
Creates a yes/no prompt from quest message. Caller must set events and call Show() when ready.
Declaration
public DaggerfallMessageBox CreateMessagePrompt(Quest quest, int id)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | |
Int32 | id |
Returns
Type | Description |
---|---|
DaggerfallMessageBox |
CreateSiteLink(Quest, Symbol)
Creates a new SiteLink at Place.
Declaration
public static void CreateSiteLink(Quest parentQuest, Symbol placeSymbol)
Parameters
Type | Name | Description |
---|---|---|
Quest | parentQuest | |
Symbol | placeSymbol |
CullResourceTarget(QuestResource, Symbol)
Removes an existing quest resource allocation (if present). This is called when allocating a resource to ensure it is removed from any previous SiteLinks For example, Sx011 will move Barenziah's book from Orsinium to Scourg Barrow after a time limit expires. Allocation needs to be removed from Orsinium or item will be present in both locations. This needs to be done in a way that does not break resources allocated from other quests.
Declaration
public void CullResourceTarget(QuestResource resource, Symbol newPlace)
Parameters
Type | Name | Description |
---|---|---|
QuestResource | resource | The resource to cull. No action taken if resource null or not found. |
Symbol | newPlace |
FindQuestMachine(out QuestMachine)
Declaration
public static bool FindQuestMachine(out QuestMachine questMachineOut)
Parameters
Type | Name | Description |
---|---|---|
QuestMachine | questMachineOut |
Returns
Type | Description |
---|---|
Boolean |
FindQuests(String, Boolean)
Finds quests based on quest name.
Declaration
public ulong[] FindQuests(string questName, bool activeOnly = false)
Parameters
Type | Name | Description |
---|---|---|
String | questName | Quest name to search for. |
Boolean | activeOnly | Only find active quests. |
Returns
Type | Description |
---|---|
UInt64[] | ulong[] array of quest UIDs with matching quest name. |
GetActionTemplate(String)
Find registered action template based on source line.
Declaration
public IQuestAction GetActionTemplate(string source)
Parameters
Type | Name | Description |
---|---|---|
String | source | Action source line. |
Returns
Type | Description |
---|---|
IQuestAction | IQuestAction template. |
GetAllActiveQuests()
Returns an array of all active (not completed, not tombstoned) quest UIDs.
Declaration
public ulong[] GetAllActiveQuests()
Returns
Type | Description |
---|---|
UInt64[] | ulong[] array of quest UIDs. |
GetAllActiveQuestSites()
Get all Place site details for all active quests.
Declaration
public SiteDetails[] GetAllActiveQuestSites()
Returns
Type | Description |
---|---|
SiteDetails[] | SiteDetails[] array. |
GetAllQuestLogMessages()
Returns a list of all active log messages from all active quests
Declaration
public List<Message> GetAllQuestLogMessages()
Returns
Type | Description |
---|---|
List<Message> | List of log messages. |
GetAllQuests()
Returns an array of all quest UIDs, even if completed or tombstoned.
Declaration
public ulong[] GetAllQuests()
Returns
Type | Description |
---|---|
UInt64[] | ulong[] array of quest UIDs. |
GetCurrentLocationQuestMarker(out QuestMarker, out Vector3)
Gets active marker in player's current location.
Declaration
public bool GetCurrentLocationQuestMarker(out QuestMarker markerOut, out Vector3 buildingOriginOut)
Parameters
Type | Name | Description |
---|---|---|
QuestMarker | markerOut | Active QuestMarker out. |
Vector3 | buildingOriginOut | Building origin in scene, or Vector3.zero if not inside a building. |
Returns
Type | Description |
---|---|
Boolean | True if successful. |
GetQuest(UInt64)
Gets an active or tombstoned quest based on UID.
Declaration
public Quest GetQuest(ulong questUID)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | questUID | Quest UID to retrieve. |
Returns
Type | Description |
---|---|
Quest | Quest object. Returns null if UID not found. |
GetQuestSourceText(String)
Attempts to load quest source text from StreamingAssets/Quests.
Declaration
public string[] GetQuestSourceText(string questName)
Parameters
Type | Name | Description |
---|---|---|
String | questName | Quest filename. Extension .txt is optional. |
Returns
Type | Description |
---|---|
String[] | Array of lines in quest text, or empty array. |
GetSaveData()
Declaration
public QuestMachine.QuestMachineData_v1 GetSaveData()
Returns
Type | Description |
---|---|
QuestMachine.QuestMachineData_v1 |
GetSiteLinks(SiteTypes, Int32, Int32, Int32)
Selects all actives site links matching parameters. Very little information is needed to determine if player is in Town, Dungeon, or Building. This information is intended to be easily reached by scene builders at layout time.
Declaration
public SiteLink[] GetSiteLinks(SiteTypes siteType, int mapId, int buildingKey = 0, int magicNumberIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
SiteTypes | siteType | Type of sites to select. |
Int32 | mapId | MapID in world. |
Int32 | buildingKey | Building key for buidings. Not used if left at default 0. |
Int32 | magicNumberIndex | Magic number index for fixed sites. Not used is left at default 0. |
Returns
Type | Description |
---|---|
SiteLink[] | SiteLink[] array of found links. Check for null or empty on return. |
GetStoredExceptions()
Gets array of stored exceptions.
Declaration
public QuestMachine.StoredException[] GetStoredExceptions()
Returns
Type | Description |
---|---|
QuestMachine.StoredException[] |
GetTableSourceText(String)
Attempts to load table text from StreamingAssets/Tables. TODO: Tables are ultimately not exclusive to quests. Relocate this later.
Declaration
public string[] GetTableSourceText(string tableName)
Parameters
Type | Name | Description |
---|---|---|
String | tableName | Table filename. Extension .txt is optional. |
Returns
Type | Description |
---|---|
String[] | Array of lines in table text, or empty array. |
HasFactionListener(Int32)
Check if a faction listener is active for the individual faction ID.
Declaration
public bool HasFactionListener(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID |
Returns
Type | Description |
---|---|
Boolean |
HasSiteLink(Quest, Symbol)
Checks if a Place has a SiteLink available.
Declaration
public static bool HasSiteLink(Quest parentQuest, Symbol placeSymbol)
Parameters
Type | Name | Description |
---|---|---|
Quest | parentQuest | |
Symbol | placeSymbol |
Returns
Type | Description |
---|---|
Boolean |
IsIndividualNPC(Int32)
Checks if NPC is a special individual NPC. These NPCs can exist in world even if not currently part of any active quests.
Declaration
public bool IsIndividualNPC(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID | Faction ID of individual NPC. |
Returns
Type | Description |
---|---|
Boolean | True if this is an individual NPC. |
IsIndividualQuestNPCAtSiteLink(Int32)
Walks SiteLink > Quest > Place > QuestMarkers > Target to see if an individual NPC has been placed elsewhere. Used only to determine if an individual NPC should be disabled at home location by layout builders. Ignores non-individual NPCs.
Declaration
public bool IsIndividualQuestNPCAtSiteLink(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID | Faction ID of individual NPC. |
Returns
Type | Description |
---|---|
Boolean | True if individual has been placed elsewhere, otherwise false. |
IsLastNPCClickedAnActiveQuestor(IMacroContextProvider)
Checks if last NPC clicked is questor for any quests. This is used for quest turn-in and reward process.
Declaration
public bool IsLastNPCClickedAnActiveQuestor(IMacroContextProvider mcp = null)
Parameters
Type | Name | Description |
---|---|---|
IMacroContextProvider | mcp | External secondary context provider for quest macro expansion. (optional) |
Returns
Type | Description |
---|---|
Boolean | True if this NPC is a questor in any quest. |
IsNPCDataEqual(StaticNPC.NPCData, StaticNPC.NPCData)
Checks if two sets of StaticNPC data reference the same NPC. Notes:
- Still working through some issues here.
- Possible for Questor NPC to be moved.
- This will likely become more robust and conditional as quest system progresses.
Declaration
public bool IsNPCDataEqual(StaticNPC.NPCData person1, StaticNPC.NPCData person2)
Parameters
Type | Name | Description |
---|---|---|
StaticNPC.NPCData | person1 | |
StaticNPC.NPCData | person2 |
Returns
Type | Description |
---|---|
Boolean | True if person1 and person2 are considered the same. |
IsProtectedQuest(Quest)
Checks if a quest is protected from ending prematurely.
Declaration
public static bool IsProtectedQuest(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest |
Returns
Type | Description |
---|---|
Boolean | True if quest is protected. |
IsQuestComplete(UInt64)
Check if quest UID has been completed in quest machine.
Declaration
public bool IsQuestComplete(ulong questUID)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | questUID | Quest UID to check. |
Returns
Type | Description |
---|---|
Boolean | True if quest is complete. Also returns false if quest not found. |
IsQuestTombstoned(UInt64)
Check if quest UID has been tombstoned in quest machine.
Declaration
public bool IsQuestTombstoned(ulong questUID)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | questUID | Quest UID to check. |
Returns
Type | Description |
---|---|
Boolean | True if quest is tombstoned. Also returns false if quest not found. |
Log(Quest, String)
Declaration
public static void Log(Quest quest, string text)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | |
String | text |
Log(String)
Declaration
public static void Log(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text |
LogFormat(Quest, String, Object[])
Declaration
public static void LogFormat(Quest quest, string text, params object[] p)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | |
String | text | |
Object[] | p |
LogFormat(String, Object[])
Declaration
public static void LogFormat(string text, params object[] p)
Parameters
Type | Name | Description |
---|---|---|
String | text | |
Object[] | p |
ParseQuest(String, String[], Int32, Boolean)
Instantiate a new quest from source text array.
Declaration
public Quest ParseQuest(string questName, string[] questSource, int factionId = 0, bool partialParse = false)
Parameters
Type | Name | Description |
---|---|---|
String | questName | Name of quest filename. Extensions .txt is optional. |
String[] | questSource | Array of lines from quest source file. |
Int32 | factionId | Faction id of quest giver for guilds. |
Boolean | partialParse | If true the QRC and QBN sections will not be parsed. |
Returns
Type | Description |
---|---|
Quest | Quest. |
PurgeAllQuests(Boolean)
Immediately tombstones then removes all quests.
Declaration
public int PurgeAllQuests(bool keepStoryQuests = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | keepStoryQuests | Retain main story quests (start with S0000). |
Returns
Type | Description |
---|---|
Int32 | Number of quests removed. |
RaiseOnQuestEndedEvent(Quest)
Declaration
protected virtual void RaiseOnQuestEndedEvent(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest |
RaiseOnQuestErrorTerminationEvent(Quest)
Declaration
protected virtual void RaiseOnQuestErrorTerminationEvent(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest |
RaiseOnQuestStartedEvent(Quest)
Declaration
protected virtual void RaiseOnQuestStartedEvent(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest |
RaiseOnRegisterCustomerActionsEvent()
Declaration
protected virtual void RaiseOnRegisterCustomerActionsEvent()
RaiseOnTickEvent()
Declaration
protected virtual void RaiseOnTickEvent()
RegisterAction(IQuestAction)
Register a new action in the quest engine.
Declaration
public void RegisterAction(IQuestAction actionTemplate)
Parameters
Type | Name | Description |
---|---|---|
IQuestAction | actionTemplate | IQuestAction template. |
RemoveAllQuestSiteLinks(UInt64)
Removes all site links for a quest. Typically done when quest has completed.
Declaration
public void RemoveAllQuestSiteLinks(ulong questUID)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | questUID | UID of quest to remove site links to. |
RemoveFactionListener(Int32)
Remove a faction listener for the individual faction ID. Does nothing if faction ID not claimed.
Declaration
public void RemoveFactionListener(int factionID)
Parameters
Type | Name | Description |
---|---|---|
Int32 | factionID |
RemoveQuest(Quest)
Removes a quest completely from quest machine. Tombstones quest before removal.
Declaration
public bool RemoveQuest(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest |
Returns
Type | Description |
---|---|
Boolean | True if quest was removed. |
RemoveQuest(UInt64)
Removes a quest completely from quest machine. Tombstones quest before removal.
Declaration
public bool RemoveQuest(ulong questUID)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | questUID | Quest UID. |
Returns
Type | Description |
---|---|
Boolean | True if quest was removed. |
RestoreSaveData(QuestMachine.QuestMachineData_v1)
Declaration
public void RestoreSaveData(QuestMachine.QuestMachineData_v1 data)
Parameters
Type | Name | Description |
---|---|---|
QuestMachine.QuestMachineData_v1 | data |
ScheduleQuest(Quest)
Schedules quest to start on next tick.
Declaration
public void ScheduleQuest(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | Quest. |
SetLastNPCClicked(StaticNPC)
Sets the last StaticNPC clicked by player. Always called by PlayerActivate when player clicks on GameObject holding StaticNPC behaviour.
Declaration
public void SetLastNPCClicked(StaticNPC npc)
Parameters
Type | Name | Description |
---|---|---|
StaticNPC | npc |
SetStoredExceptions(QuestMachine.StoredException[])
Restores an array of stored exceptions.
Declaration
public void SetStoredExceptions(QuestMachine.StoredException[] exceptions)
Parameters
Type | Name | Description |
---|---|---|
QuestMachine.StoredException[] | exceptions |
SetupIndividualStaticNPC(GameObject, Int32)
Checks if NPC is a special individual NPC, then sets it up with components required for quests. If the NPC has an Individual faction, and the NPC is currently placed somewhere else in a quest, the GameObject will be deactivated
Declaration
public bool SetupIndividualStaticNPC(GameObject go, int factionID)
Parameters
Type | Name | Description |
---|---|---|
GameObject | go | GameObject representing the static NPC |
Int32 | factionID | Faction ID of the NPC |
Returns
Type | Description |
---|---|
Boolean |
StartQuest(Quest)
Start a parsed quest.
Declaration
public void StartQuest(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | Quest. |
StartQuest(String, Int32)
Parse and start a quest from quest name.
Declaration
public void StartQuest(string questName, int factionId = 0)
Parameters
Type | Name | Description |
---|---|---|
String | questName | Quest name. |
Int32 | factionId | Faction id. (optional) |
StoreQuestException(Quest, Exception)
Stores a quest exception in save file. Should only be used for major quest-ending errors to help diagnose difficult issues. Will only store a finite number of exceptions before overwriting oldest.
Declaration
public void StoreQuestException(Quest quest, Exception ex)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | Quest throwing the exception. |
Exception | ex | Exception being thrown. |
Tick()
Tick quest machine.
Declaration
public void Tick()
TombstoneQuest(Quest)
Tombstones a quest. It will remain in quest machine for "talk" links until removed. This calls Dispose() on quest, removes all related SiteLinks, then calls OnQuestEnded event.
Declaration
public void TombstoneQuest(Quest quest)
Parameters
Type | Name | Description |
---|---|---|
Quest | quest | Quest to Tombstone. |
UnmuteQuestNPCs()
Unmutes all quest NPCs. Supports console command workaround for "mute npc" bug present up to 0.7.36.
Declaration
public int UnmuteQuestNPCs()
Returns
Type | Description |
---|---|
Int32 |
Events
| Improve this Doc View SourceOnQuestEnded
Declaration
public static event QuestMachine.OnQuestEndedEventHandler OnQuestEnded
Event Type
Type | Description |
---|---|
QuestMachine.OnQuestEndedEventHandler |
OnQuestErrorTermination
Declaration
public static event QuestMachine.OnQuestErrorTerminationEventHandler OnQuestErrorTermination
Event Type
Type | Description |
---|---|
QuestMachine.OnQuestErrorTerminationEventHandler |
OnQuestStarted
Declaration
public static event QuestMachine.OnQuestStartedEventHandler OnQuestStarted
Event Type
Type | Description |
---|---|
QuestMachine.OnQuestStartedEventHandler |
OnRegisterCustomActions
Declaration
public static event QuestMachine.OnRegisterCustomActionsEventHandler OnRegisterCustomActions
Event Type
Type | Description |
---|---|
QuestMachine.OnRegisterCustomActionsEventHandler |
OnTick
Declaration
public static event QuestMachine.OnTickEventHandler OnTick
Event Type
Type | Description |
---|---|
QuestMachine.OnTickEventHandler |