/// <summary> /// Gets reference to all QuestResource objects referenced by message macros /// </summary> /// <param name="message">Message to extract resources from.</param> /// <returns>QuestResource array or null.</returns> public QuestResource[] GetMessageResources(Message message) { // Must have a message if (message == null) { return(null); } // Get raw message and enumerate resource tokens List <QuestResource> resources = new List <QuestResource>(); TextFile.Token[] tokens = message.GetTextTokens(-1, false); for (int token = 0; token < tokens.Length; token++) { string[] words = GetWords(tokens[token].text); for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); QuestResource resource = message.ParentQuest.GetResource(macro.symbol); if (resource != null) { resources.Add(resource); } } } return(resources.ToArray()); }
/// <summary> /// Change amount of resource with specified type /// </summary> public void Update(QuestResourceType type, int value) { QuestResource questResource = GetResourceByType(type); if (questResource != null) { questResource.Update(value); } }
public void loadQuestResources() { Debug.Log("퀘스트 정보 로드 성공"); textAsset = Resources.Load <TextAsset>("Quest/QuestDatas"); questResource = JsonUtility.FromJson <QuestResource>(textAsset.ToString()); questDB = questResource.quests; //putQuest(questResource.quests); }
public override void Update(Task caller) { base.Update(caller); // Attempt to get Item resource Item item = ParentQuest.GetItem(itemSymbol); if (item == null) { SetComplete(); throw new Exception(string.Format("Could not find Item resource symbol {0}", itemSymbol)); } // Attempt to get target resource QuestResource target = ParentQuest.GetResource(targetSymbol); if (target == null) { SetComplete(); throw new Exception(string.Format("Could not find target resource symbol {0}", targetSymbol)); } // Target must exist in the world if (!target.QuestResourceBehaviour) { return; } // Must have an Entity to receive item DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>(); if (!entityBehaviour) { SetComplete(); throw new Exception(string.Format("GiveItem target {0} is not an Entity with DaggerfallEntityBehaviour", targetSymbol)); } // Assign item for player to find // * Some quests assign item to Foe at create time, others on injured event // * It's possible for target enemy to be one-shot or to be killed by other means (such as "killall") // * This assignment will direct quest loot item either to live enemy or corpse loot container if (entityBehaviour.CorpseLootContainer) { // If enemy is already dead then place item in corpse loot container entityBehaviour.CorpseLootContainer.Items.AddItem(item.DaggerfallUnityItem); } else { // Otherwise add quest Item to Entity item collection // It will be transferred to corpse marker loot container when dropped entityBehaviour.Entity.Items.AddItem(item.DaggerfallUnityItem); } SetComplete(); }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest)); } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> /// <param name="resolveDialogLinks">will reveal dialog linked resources in talk window (this must be false for all calls to this function except if caller is talk manager when expanding answers).</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens, bool revealDialogLinks = false) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest)); } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } // reveal dialog linked resources in talk window if (revealDialogLinks) { System.Type t = resource.GetType(); if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Place))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Location); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Person))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Person); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Item))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, result, TalkManager.QuestInfoResourceType.Thing); } } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
public override void Update(Task caller) { base.Update(caller); // Attempt to get Item resource Item item = ParentQuest.GetItem(itemSymbol); if (item == null) { SetComplete(); throw new Exception(string.Format("Could not find Item resource symbol {0}", itemSymbol)); } // Attempt to get target resource QuestResource target = ParentQuest.GetResource(targetSymbol); if (target == null) { SetComplete(); throw new Exception(string.Format("Could not find target resource symbol {0}", targetSymbol)); } // Add item to Foe resource or generic entity // In practice GiveItem will always be to a Foe resource - NPCs are handled by "get item" // Keeping generic GiveItem behaviour as entity catch-all and reference if (target is Foe) { // Add to Foe item queue (target as Foe).QueueItem(item.DaggerfallUnityItem); // Dequeue items on entity immediately if target already exists in the world // Will also handle placing items to dead enemy loot container if (target.QuestResourceBehaviour) { DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>(); if (entityBehaviour) { target.QuestResourceBehaviour.AddItemQueue(target as Foe, entityBehaviour); } } } else { // Target must exist in the world if (!target.QuestResourceBehaviour) { return; } // Must have an Entity to receive item DaggerfallEntityBehaviour entityBehaviour = target.QuestResourceBehaviour.GetComponent <DaggerfallEntityBehaviour>(); if (!entityBehaviour) { SetComplete(); throw new Exception(string.Format("GiveItem target {0} is not an Entity with DaggerfallEntityBehaviour", targetSymbol)); } // Assign item for player to find // * Some quests assign item to Foe at create time, others on injured event // * It's possible for target enemy to be one-shot or to be killed by other means (such as "killall") // * This assignment will direct quest loot item either to live enemy or corpse loot container if (entityBehaviour.CorpseLootContainer) { // If enemy is already dead then place item in corpse loot container entityBehaviour.CorpseLootContainer.Items.AddItem(item.DaggerfallUnityItem); } else { // Otherwise add quest Item to Entity item collection // It will be transferred to corpse marker loot container when dropped entityBehaviour.Entity.Items.AddItem(item.DaggerfallUnityItem); } } // Remove item from player inventory if they are holding it if (GameManager.Instance.PlayerEntity.Items.Contains(item.DaggerfallUnityItem)) { GameManager.Instance.PlayerEntity.Items.RemoveItem(item.DaggerfallUnityItem); } SetComplete(); }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { // TODO: Get a quest context macro like %qdt // Quick support for common tokens // Will rework this later if (macro.token == "%pcn") { // Full name words[word] = words[word].Replace(macro.token, GameManager.Instance.PlayerEntity.Name); } else if (macro.token == "%pcf") { // First name string[] parts = GameManager.Instance.PlayerEntity.Name.Split(' '); if (parts != null && parts.Length >= 1) { words[word] = words[word].Replace(macro.token, parts[0]); } } else if (macro.token == "%qdt") { // Quest date time words[word] = words[word].Replace(macro.token, parentQuest.QuestStartTime.DateString()); } else if (macro.token == "%ra") { // Race words[word] = words[word].Replace(macro.token, GameManager.Instance.PlayerEntity.RaceTemplate.Name); } } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { // TODO: Get a quest context macro like %qdt // Quick support for common tokens // Will rework this later if (macro.token == "%pcn") { // Full name words[word] = words[word].Replace(macro.token, GameManager.Instance.PlayerEntity.Name); } else if (macro.token == "%pcf") { // First name string[] parts = GameManager.Instance.PlayerEntity.Name.Split(' '); if (parts != null && parts.Length >= 1) { words[word] = words[word].Replace(macro.token, parts[0]); } } else if (macro.token == "%qdt") { // Quest date time words[word] = words[word].Replace(macro.token, parentQuest.QuestStartTime.DateString()); } else if (macro.token == "%ra") { // Race words[word] = words[word].Replace(macro.token, GameManager.Instance.PlayerEntity.RaceTemplate.Name); } else if (macro.token == "%pct") { // Just use "Apprentice" for all %pct guild titles for now // Guilds are not implemented yet words[word] = words[word].Replace(macro.token, "Apprentice"); } else if (macro.token == "%oth") { // Generate an oath // TODO: Need a way of passing NPC race to oath generator words[word] = words[word].Replace(macro.token, GetOath()); } else if (macro.token == "%reg") { // Get current region words[word] = words[word].Replace(macro.token, GetRegionName()); } else if (macro.token == "%god") { // Get god of last NPC words[word] = words[word].Replace(macro.token, GetGod(parentQuest)); } else if (macro.token == "%g" || macro.token == "%g1") { // He/She words[word] = words[word].Replace(macro.token, GetPronoun1(parentQuest)); } else if (macro.token == "%g2") { // Him/Her words[word] = words[word].Replace(macro.token, GetPronoun2(parentQuest)); } else if (macro.token == "%g2self") { // Himself/Herself words[word] = words[word].Replace(macro.token, GetPronoun2self(parentQuest)); } else if (macro.token == "%g3") { // His/Hers words[word] = words[word].Replace(macro.token, GetPronoun3(parentQuest)); } } else { // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Expands any macros found inside quest message tokens. /// </summary> /// <param name="parentQuest">Parent quest of message.</param> /// <param name="tokens">Array of message tokens to expand macros inside of.</param> /// <param name="resolveDialogLinks">will reveal dialog linked resources in talk window (this must be false for all calls to this function except if caller is talk manager when expanding answers or for quest popups).</param> public void ExpandQuestMessage(Quest parentQuest, ref TextFile.Token[] tokens, bool revealDialogLinks = false) { // Iterate message tokens for (int token = 0; token < tokens.Length; token++) { // Split token text into individual words string[] words = GetWords(tokens[token].text); // Iterate words to find macros for (int word = 0; word < words.Length; word++) { Macro macro = GetMacro(words[word]); if (macro.type == MacroTypes.ContextMacro) { words[word] = words[word].Replace(macro.token, MacroHelper.GetValue(macro.token, parentQuest, parentQuest.ExternalMCP)); } else { // fix for bug when parent quest is no longer available (http://forums.dfworkshop.net/viewtopic.php?f=24&t=1002) in case // quest injected entries and rumors stay in list due to other bugs // so parentQuest is no longer available if (parentQuest == null) { return; } // Ask resource to expand macro if possible QuestResource resource = parentQuest.GetResource(macro.symbol); if (resource != null) { string result; if (resource.ExpandMacro(macro.type, out result)) { words[word] = words[word].Replace(macro.token, result); } // reveal dialog linked resources in talk window if (revealDialogLinks && macro.type == MacroTypes.NameMacro1) // only resolve if their true name was expanded (given) which is MacroTypes.NameMacro1 { System.Type t = resource.GetType(); if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Place))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Location); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Person))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Person); } else if (t.Equals(typeof(DaggerfallWorkshop.Game.Questing.Item))) { GameManager.Instance.TalkManager.AddDialogForQuestInfoResource(parentQuest.UID, macro.symbol, TalkManager.QuestInfoResourceType.Thing); } } } } // TODO: Need to store previous macro resource for pronomial context expansions } // Reassemble words and expanded macros back into final token text string final = string.Empty; for (int i = 0; i < words.Length; i++) { final += words[i]; if (i != words.Length - 1) { final += " "; } } // Store result back into token tokens[token].text = final; } }
/// <summary> /// Finds SiteLinks matching this interior and walks Place markers to inject quest resources. /// Some of this handling will be split and relocated for other builders. /// Just working through the steps in buildings interiors for now. /// This will be moved to a different setup class later. /// </summary> public static void AddQuestResourceObjects(SiteTypes siteType, Transform parent, int buildingKey = 0) { // Collect any SiteLinks associdated with this site SiteLink[] siteLinks = QuestMachine.Instance.GetSiteLinks(siteType, GameManager.Instance.PlayerGPS.CurrentMapID, buildingKey); if (siteLinks == null || siteLinks.Length == 0) { return; } // Walk through all found SiteLinks foreach (SiteLink link in siteLinks) { // Get the Quest object referenced by this link Quest quest = QuestMachine.Instance.GetActiveQuest(link.questUID); if (quest == null) { throw new Exception(string.Format("Could not find active quest for UID {0}", link.questUID)); } // Get the Place resource referenced by this link Place place = quest.GetPlace(link.placeSymbol); if (place == null) { throw new Exception(string.Format("Could not find Place symbol {0} in quest UID {1}", link.placeSymbol, link.questUID)); } // Get selected spawn QuestMarker for this Place QuestMarker spawnMarker = place.SiteDetails.questSpawnMarkers[place.SiteDetails.selectedQuestSpawnMarker]; if (spawnMarker.targetResources != null) { foreach (Symbol target in spawnMarker.targetResources) { // Get target resource QuestResource resource = quest.GetResource(target); if (resource == null) { continue; } // Inject to scene based on resource type if (resource is Person) { AddQuestNPC(siteType, quest, spawnMarker, (Person)resource, parent); } else if (resource is Foe) { AddQuestFoe(siteType, quest, spawnMarker, (Foe)resource, parent); } } } // Get selected item QuestMarker for this Place QuestMarker itemMarker = place.SiteDetails.questItemMarkers[place.SiteDetails.selectedQuestItemMarker]; if (itemMarker.targetResources != null) { foreach (Symbol target in itemMarker.targetResources) { // Get target resource QuestResource resource = quest.GetResource(target); if (resource == null) { continue; } // Inject into scene if (resource is Item) { AddQuestItem(siteType, quest, itemMarker, (Item)resource, parent); } } } } }