/// <summary> /// Gets the UI content for a specific category. /// </summary> /// <param name="category">The content category (Dialogue, Journal, etc.).</param> /// <param name="speaker">The speaker whose content to get, or blank for the quest giver.</param> /// <returns>A list of content items based on the current state of the quest and all of its nodes.</returns> public List <QuestContent> GetContentList(QuestContentCategory category, QuestParticipantTextInfo speaker = null) { var contentList = new List <QuestContent>(); currentSpeaker = IsSpeakerQuestGiver(speaker) ? null : speaker; var stateInfo = GetStateInfo(GetState()); if (stateInfo != null) { contentList.AddRange(stateInfo.GetContentList(category)); } if (nodeList != null) { for (int i = 0; i < nodeList.Count; i++) { var node = nodeList[i]; var nodeContentList = (node != null) ? node.GetContentList(category) : null; if (nodeContentList != null) { contentList.AddRange(nodeContentList); } } } return(contentList); }
public virtual void ShowContents(QuestParticipantTextInfo speaker, List <QuestContent> contents) { Show(); mainPanel.gameObject.SetActive(true); SetContents(speaker, contents); SetControlButtons(true, false, false); }
protected virtual void SetContents(QuestParticipantTextInfo speaker, List <QuestContent> contents) { var displayName = (speaker != null) ? StringField.GetStringValue(speaker.displayName) : null; var image = (speaker != null) ? speaker.image : null; SetContents(displayName, image, contents); }
public virtual void ShowOfferQuest(QuestParticipantTextInfo speaker, Quest quest, QuestParameterDelegate acceptHandler, QuestParameterDelegate declineHandler) { selectedQuest = quest; this.acceptHandler = acceptHandler; this.declineHandler = declineHandler; ShowContents(speaker, quest.offerContentList); SetControlButtons(false, false, true); }
/// <summary> /// Assigns a quester (e.g., player) to the quest. /// </summary> /// <param name="questerTextInfo">Idenntifying information about the quester.</param> public void AssignQuester(QuestParticipantTextInfo questerTextInfo) { if (questerTextInfo == null || StringField.IsNullOrEmpty(questerTextInfo.id)) { return; } tagDictionary.SetTag(QuestMachineTags.QUESTERID, questerTextInfo.id); tagDictionary.SetTag(QuestMachineTags.QUESTER, questerTextInfo.displayName); }
/// <summary> /// Adds an instance of a quest to a quester's list. If the quest's maxTimes are reached, /// deletes the quest from the giver. Otherwise starts cooldown timer until it can be /// given again. /// </summary> /// <param name="quest">Quest to give to quester.</param> /// <param name="questerTextInfo">Quester's text info.</param> /// <param name="questerQuestListContainer">Quester's quest list container.</param> public virtual void GiveQuestToQuester(Quest quest, QuestParticipantTextInfo questerTextInfo, QuestListContainer questerQuestListContainer) { if (quest == null) { Debug.LogWarning("Quest Machine: " + name + ".GiveQuestToQuester - quest is null.", this); return; } if (questerTextInfo == null) { Debug.LogWarning("Quest Machine: " + name + ".GiveQuestToQuester - questerTextInfo is null.", this); return; } if (questerQuestListContainer == null) { Debug.LogWarning("Quest Machine: " + name + ".GiveQuestToQuester - questerQuestListContainer is null.", this); return; } // Make a copy of the quest for the quester: var questInstance = quest.Clone(); // Update the version on this QuestGiver: quest.timesAccepted++; if (quest.timesAccepted >= quest.maxTimes) { DeleteQuest(quest.id); } else { quest.StartCooldown(); } // Add the copy to the quester and activate it: questInstance.AssignQuestGiver(myQuestGiverTextInfo); questInstance.AssignQuester(questerTextInfo); questInstance.timesAccepted = 1; if (questerQuestListContainer.questList.Count > 0) { for (int i = questerQuestListContainer.questList.Count - 1; i >= 0; i--) { var inJournal = questerQuestListContainer.questList[i]; if (inJournal == null) { continue; } if (StringField.Equals(inJournal.id, quest.id) && inJournal.GetState() != QuestState.Active) { questInstance.timesAccepted++; questerQuestListContainer.DeleteQuest(inJournal); } } } questerQuestListContainer.deletedStaticQuests.Remove(StringField.GetStringValue(questInstance.id)); questerQuestListContainer.AddQuest(questInstance); questInstance.SetState(QuestState.Active); QuestMachineMessages.RefreshIndicators(questInstance); }
/// <summary> /// Starts dialogue with the player. The content of the dialogue will depend on the quest giver's /// offerable quests and the player's quests. /// </summary> /// <param name="player">Player conversing with this QuestGiver. If null, searches the scene for a GameObject tagged Player.</param> public virtual void StartDialogue(GameObject player) { if (questDialogueUI == null && Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". Quest Giver doesn't have access to a quest dialogue UI.", this); return; } // If player isn't specified, find it in the scene and find relevant quest journal: if (player == null) { player = FindPlayerGameObject(); } if (player == null && Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". No quester specified.", this); return; } playerQuestListContainer = player.GetComponent <QuestListContainer>(); if (playerQuestListContainer == null) { var playerID = player.GetComponent <QuestMachineID>(); if (playerID != null && playerID.questListContainer != null) { playerQuestListContainer = playerID.questListContainer; } else { var playerJournalObject = FindPlayerJournalGameObject(); playerQuestListContainer = (playerJournalObject != null) ? playerJournalObject.GetComponent <QuestListContainer>() : null; } } if (playerQuestListContainer == null && Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". Quester " + player.name + " doesn't have a Quest Journal and can't find one in scene.", this); return; } QuestMachineTags.fallbackTextTable = textTable; // Setup player info: this.player = player; playerTextInfo = new QuestParticipantTextInfo(QuestMachineMessages.GetID(player), QuestMachineMessages.GetDisplayName(player), null, null); // Greet before recording quests in case Greet message changes a quest state: QuestMachineMessages.Greet(player, this, id); // Record quests related to this player and me: RecordQuestsByState(); StartMostRelevantDialogue(); // Note: Sends Greeted immediately after opening dialogue UI, not when closing it: QuestMachineMessages.Greeted(player, this, id); }
public virtual void ShowActiveQuest(QuestParticipantTextInfo speaker, Quest quest, QuestParameterDelegate continueHandler, QuestParameterDelegate backHandler) { selectedQuest = quest; this.backHandler = backHandler; var contents = quest.GetContentList(QuestContentCategory.Dialogue, speaker); ShowContents(speaker, contents); SetControlButtons(true, backHandler != null, false); if (ContainsGroupButton(contents)) { SetControlButtonsInteractable(false); } }
/// <summary> /// Assigns a quest giver to the quest. /// </summary> /// <param name="questGiverTextInfo">Identifying information about the quest giver.</param> public void AssignQuestGiver(QuestParticipantTextInfo questGiverTextInfo) { if (questGiverTextInfo == null) { return; } questGiverID = questGiverTextInfo.id; if (!StringField.IsNullOrEmpty(questGiverTextInfo.id)) { speakers.Add(StringField.GetStringValue(questGiverTextInfo.id)); } QuestMachineTags.AddTagValuesToDictionary(tagDictionary, questGiverTextInfo.textTable); tagDictionary.SetTag(QuestMachineTags.QUESTGIVERID, questGiverTextInfo.id); tagDictionary.SetTag(QuestMachineTags.QUESTGIVER, questGiverTextInfo.displayName); }
/// <summary> /// Adds an instance of a quest to a quester's list. If the quest's maxTimes are reached, /// deletes the quest from the giver. Otherwise starts cooldown timer until it can be /// given again. /// </summary> /// <param name="quest">Quest to give to quester.</param> /// <param name="questerQuestListContainer">Quester's quest list container.</param> public virtual void GiveQuestToQuester(Quest quest, QuestListContainer questerQuestListContainer) { if (quest == null) { return; } if (questerQuestListContainer == null) { Debug.LogWarning("Quest Machine: " + name + ".GiveQuestToQuester - quester (QuestListContainer) is null.", this); return; } var questerTextInfo = new QuestParticipantTextInfo(QuestMachineMessages.GetID(questerQuestListContainer.gameObject), QuestMachineMessages.GetDisplayName(questerQuestListContainer.gameObject), null, null); GiveQuestToQuester(quest, questerTextInfo, questerQuestListContainer); }
public virtual void ShowQuestList(QuestParticipantTextInfo speaker, List <QuestContent> activeQuestsContents, List <Quest> activeQuests, List <QuestContent> offerableQuestsContents, List <Quest> offerableQuests, QuestParameterDelegate selectHandler) { ShowContents(speaker, null); SetControlButtons(true, false, false); if (activeQuests != null && activeQuests.Count > 0) { currentButtonList = null; AddQuestList(activeQuestsContents, activeQuests, selectHandler); } if (offerableQuests != null && offerableQuests.Count > 0) { currentButtonList = null; AddQuestList(offerableQuestsContents, offerableQuests, selectHandler); } }
public virtual void ShowCompletedQuest(QuestParticipantTextInfo speaker, List <Quest> quests) { if (quests == null || quests.Count == 0) { return; } var quest = quests[0]; var contents = quest.GetContentList(QuestContentCategory.Dialogue); ShowContents(speaker, contents); SetControlButtons(true, false, false); if (ContainsGroupButton(contents)) { SetControlButtonsInteractable(false); } }
/// <summary> /// Removes completed quests that have no dialogue to offer. /// </summary> protected virtual void RemoveCompletedQuestsWithNoDialogue() { if (completedQuests == null || completedQuests.Count == 0) { return; } var info = new QuestParticipantTextInfo(id, displayName, image, textTable); for (int i = completedQuests.Count - 1; i >= 0; i--) { if (!completedQuests[i].HasContent(QuestContentCategory.Dialogue, info)) { completedQuests.RemoveAt(i); } } }
/// <summary> /// Checks if there is any UI content for a specific category. /// </summary> /// <param name="category">The content category (Dialogue, Journal, etc.).</param> /// <param name="speaker">The speaker whose content to check, or blank for the quest giver.</param> /// <returns>True if GetContentList would return anything.</returns> public bool HasContent(QuestContentCategory category, QuestParticipantTextInfo speaker = null) { currentSpeaker = IsSpeakerQuestGiver(speaker) ? null : speaker; var stateInfo = GetStateInfo(GetState()); if (stateInfo.HasContent(category)) { return(true); } if (nodeList == null) { return(false); } for (int i = 0; i < nodeList.Count; i++) { var node = nodeList[i]; if (node != null && node.HasContent(category)) { return(true); } } return(false); }
public virtual void ShowOfferConditionsUnmet(QuestParticipantTextInfo speaker, List <QuestContent> contents, List <Quest> quests) { ShowContents(speaker, contents); //--- Don't show the unofferable quests: // ShowQuestList(speaker, null, null, quests, null, null); }
public bool IsSpeakerQuestGiver(QuestParticipantTextInfo speaker) { return((speaker == null) || StringField.Equals(speaker.id, questGiverID)); }