public QuestNode AddNode(QuestNode parent, StringField id, StringField internalName, QuestNodeType nodeType, bool isOptional = false) { if (parent == null) { if (Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: QuestBuilder.AddNode must be provided a valid parent node."); } return(null); } if (parent.childIndexList == null) { return(null); } parent.childIndexList.Add(quest.nodeList.Count); var node = new QuestNode(id, internalName, nodeType, isOptional); node.canvasRect = new Rect(parent.canvasRect.x, parent.canvasRect.y + 20 + QuestNode.DefaultNodeHeight, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight); quest.nodeList.Add(node); QuestStateInfo.ValidateStateInfoListCount(node.stateInfoList); QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.Active].categorizedContentList); QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.Inactive].categorizedContentList); QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.True].categorizedContentList); return(node); }
public void DestroySubassets() { if (conditionSet != null) { conditionSet.DestroySubassets(); } QuestStateInfo.DestroyListSubassets(stateInfoList); }
private QuestContentProxy[] GetNewArrayForCategory(QuestStateInfo stateInfo, QuestContentCategory category) { var index = (int)category; return((0 <= index && index < stateInfo.categorizedContentList.Count) ? QuestContentProxy.NewArray(stateInfo.categorizedContentList[index].contentList) : new QuestContentProxy[0]); }
/// <summary> /// Gets the UI content for a specific category. /// </summary> /// <param name="category">The content category (Dialogue, Journal, etc.).</param> /// <returns>A list of UI content items based on the current state of the quest and all of its nodes.</returns> public List <QuestContent> GetContentList(QuestContentCategory category) { if (!IsContentValidForCurrentSpeaker(category)) { return(null); } var stateInfo = QuestStateInfo.GetStateInfo(stateInfoList, m_state); return((stateInfo != null) ? stateInfo.GetContentList(category) : null); }
private void ValidateListSizes() { var numStates = Enum.GetNames(typeof(QuestState)).Length; QuestStateInfo.ValidateStateInfoListCount(quest.stateInfoList, numStates); for (int i = 0; i < numStates; i++) { QuestStateInfo.ValidateCategorizedContentListCount(quest.stateInfoList[i].categorizedContentList); } }
public void CloneSubassetsInto(QuestNode copy) { // Assumes lists are identical except subassets haven't been copied. if (copy == null) { return; } conditionSet.CloneSubassetsInto(copy.conditionSet); QuestStateInfo.CloneSubassets(stateInfoList, copy.stateInfoList); tagDictionary.CopyInto(copy.tagDictionary); }
private void MoveTextToTextTable(QuestStateInfo stateInfo, TextTable textTable) { if (stateInfo == null || stateInfo.categorizedContentList == null) { return; } for (int i = 0; i < stateInfo.categorizedContentList.Count; i++) { MoveTextToTextTable(stateInfo.categorizedContentList[i].contentList, textTable); } }
public static void AddQuestTagsToTextTable(QuestStateInfo stateInfo, TextTable textTable) { if (stateInfo == null || stateInfo.categorizedContentList == null) { return; } for (int i = 0; i < stateInfo.categorizedContentList.Count; i++) { AddQuestTagsToTextTable(stateInfo.categorizedContentList[i].contentList, textTable); } }
public void CopyFrom(QuestStateInfo stateInfo) { if (stateInfo == null) { Debug.LogWarning("Quest Machine: QuestStateInfoProxy.CopyFrom source is null."); return; } acn = QuestActionProxy.NewArray(stateInfo.actionList); dlg = GetNewArrayForCategory(stateInfo, QuestContentCategory.Dialogue); jrl = GetNewArrayForCategory(stateInfo, QuestContentCategory.Journal); hud = GetNewArrayForCategory(stateInfo, QuestContentCategory.HUD); }
public void SetRuntimeNodeReferences() { var stateCount = Enum.GetNames(typeof(QuestNodeState)).Length; for (int i = 0; i < stateCount; i++) { var stateInfo = QuestStateInfo.GetStateInfo(stateInfoList, (QuestNodeState)i); if (stateInfo != null) { stateInfo.SetRuntimeReferences(quest, this); } } }
public void CopyTo(QuestStateInfo stateInfo) { if (stateInfo == null) { Debug.LogWarning("Quest Machine: QuestStateInfoProxy.CopyTo destination is null."); return; } stateInfo.actionList = QuestActionProxy.CreateList(acn); stateInfo.categorizedContentList = new List <QuestContentSet>(); for (int i = 0; i < QuestStateInfo.NumContentCategories; i++) { var contentSet = QuestContentProxy.CreateContentSet(GetContentListProxy((QuestContentCategory)i)); stateInfo.categorizedContentList.Add(contentSet); } }
/// <summary> /// Checks if there is any UI content for a specific category. /// </summary> /// <param name="category">The content category (Dialogue, Journal, etc.).</param> /// <returns>True if GetContentList would return anything.</returns> public bool HasContent(QuestContentCategory category) { if (!IsContentValidForCurrentSpeaker(category)) { return(false); } var stateInfo = QuestStateInfo.GetStateInfo(stateInfoList, m_state); if (stateInfo == null) { return(false); } var contentList = stateInfo.GetContentList(category); return(contentList != null && contentList.Count > 0); }
public static List <QuestStateInfo> CreateList(QuestStateInfoProxy[] stateInfoListProxy) { var list = new List <QuestStateInfo>(); if (stateInfoListProxy == null) { Debug.LogWarning("Quest Machine: QuestStateInfoProxy.CreateList source is null."); return(list); } for (int i = 0; i < stateInfoListProxy.Length; i++) { var counter = new QuestStateInfo(); stateInfoListProxy[i].CopyTo(counter); list.Add(counter); } return(list); }
/// <summary> /// Returns a new instance of the quest, including new instances of all subassets /// such as QuestAction, QuestCondition, and QuestContent subassets. /// </summary> public Quest Clone() { var clone = Instantiate(this); SetRuntimeReferences(); // Fix original's references since Instantiate calls OnEnable > SetRuntimeReferences while clone's fields still point to original. clone.isInstance = true; clone.originalAsset = originalAsset; autostartConditionSet.CloneSubassetsInto(clone.autostartConditionSet); offerConditionSet.CloneSubassetsInto(clone.offerConditionSet); clone.offerConditionsUnmetContentList = QuestSubasset.CloneList(offerConditionsUnmetContentList); clone.offerContentList = QuestSubasset.CloneList(offerContentList); QuestStateInfo.CloneSubassets(stateInfoList, clone.stateInfoList); QuestNode.CloneSubassets(nodeList, clone.nodeList); tagDictionary.CopyInto(clone.tagDictionary); clone.SetRuntimeReferences(); return(clone); }
private static void RegisterMediaInStateInfo(QuestStateInfo stateInfo) { if (stateInfo == null || stateInfo.categorizedContentList == null) { return; } for (int i = 0; i < stateInfo.categorizedContentList.Count; i++) { if (stateInfo.categorizedContentList[i] != null) { RegisterMediaInContentList(stateInfo.categorizedContentList[i].contentList); } if (stateInfo.actionList != null) { RegisterMediaInActionList(stateInfo.actionList); } } }
private void OnDestroy() { if (isInstance && Application.isPlaying) { QuestMachine.UnregisterQuestInstance(this); SetState(QuestState.Disabled); if (autostartConditionSet != null) { autostartConditionSet.DestroySubassets(); } if (offerConditionSet != null) { offerConditionSet.DestroySubassets(); } QuestSubasset.DestroyList(offerConditionsUnmetContentList); QuestSubasset.DestroyList(offerContentList); QuestStateInfo.DestroyListSubassets(stateInfoList); QuestNode.DestroyListSubassets(nodeList); } }
/// <summary> /// Adds UI content to the return node. /// </summary> protected virtual void AddReturnNodeText(QuestBuilder questBuilder, QuestNode returnNode, QuestGiver questGiver, string mainTargetEntity, string mainTargetDescriptor, string domainName, PlanStep goal, string hudText) { var stateInfo = returnNode.stateInfoList[(int)QuestNodeState.Active]; QuestStateInfo.ValidateCategorizedContentListCount(stateInfo.categorizedContentList); var successText = ReplaceStepTags(StringField.GetStringValue(goal.action.actionText.successText), mainTargetEntity, mainTargetDescriptor, domainName, string.Empty, 0); var bodyText = questBuilder.CreateBodyContent(successText); var dialogueList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.Dialogue]; dialogueList.contentList.Add(bodyText); var jrlText = "{Return to} " + questGiver.displayName; var jrlBodyText = questBuilder.CreateBodyContent(jrlText); var journalList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.Journal]; journalList.contentList.Add(jrlBodyText); var hudBodyText = questBuilder.CreateBodyContent(hudText); var hudList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.HUD]; hudList.contentList.Add(hudBodyText); }
public void CloneSubassetsInto(QuestStateInfo copy) { // Assumes lists are identical except subassets haven't been copied. if (copy == null || copy.categorizedContentList == null) { if (Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: QuestStateInfo.CloneSubassetsInto() failed because the destination copy or its content list is null."); } } else if (m_actionList == null || m_categorizedContentList == null) { if (Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: QuestStateInfo.CloneSubassetsInto() failed because the original state info's action list or content list is null."); } } else if (copy.categorizedContentList.Count != m_categorizedContentList.Count) { if (Debug.isDebugBuild) { Debug.LogWarning("Quest Machine: QuestStateInfo.CloneSubassetsInto() failed because the destination copy's content list is a different size than the original's."); } } else { copy.actionList = QuestSubasset.CloneList(m_actionList); for (int i = 0; i < m_categorizedContentList.Count; i++) { if (copy.categorizedContentList[i] == null) { copy.categorizedContentList[i] = new QuestContentSet(); } copy.categorizedContentList[i].contentList = QuestSubasset.CloneList(m_categorizedContentList[i].contentList); } } }
/// <summary> /// Adds a final "return to quest giver" step. /// </summary> /// <returns>The return node.</returns> protected virtual QuestNode AddReturnNode(QuestBuilder questBuilder, QuestNode previousNode, QuestEntity entity, string mainTargetEntity, string mainTargetDescriptor, string domainName, PlanStep goal, int rewardsContentIndex = 9999) // Default to 9999 to not break any customer code using old signature. { var questGiver = entity.GetComponent <QuestGiver>(); var giverID = (questGiver != null) ? questGiver.id : ((entity != null) ? entity.displayName : null); var returnNode = questBuilder.AddDiscussQuestNode(previousNode, QuestMessageParticipant.QuestGiver, giverID); returnNode.id = new StringField("Return"); previousNode = returnNode; QuestStateInfo.ValidateStateInfoListCount(returnNode.stateInfoList); var hudText = "{Return to} " + questGiver.displayName; // Text when active: AddReturnNodeText(questBuilder, returnNode, questGiver, mainTargetEntity, mainTargetDescriptor, domainName, goal, hudText); // Add rewards content: var dialogueList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.Dialogue]; var offerContentList = questBuilder.quest.offerContentList; for (int i = rewardsContentIndex; i < offerContentList.Count; i++) { var original = offerContentList[i]; var copy = QuestContent.Instantiate(original) as QuestContent; original.CloneSubassetsInto(copy); dialogueList.contentList.Add(copy); } var actionList = returnNode.GetStateInfo(QuestNodeState.Active).actionList; // Alert when active: AddReturnNodeAlert(questBuilder, returnNode, actionList, hudText); // Indicators: AddReturnNodeIndicators(questBuilder, returnNode, actionList, entity); return(previousNode); }
/// <summary> /// Sets sub-objects' runtime references to this quest. /// </summary> public void SetRuntimeReferences() { // Set references in start info: if (Application.isPlaying) { m_timeCooldownLastChecked = GameTime.time; } if (autostartConditionSet != null) { autostartConditionSet.SetRuntimeReferences(this, null); } if (offerConditionSet != null) { offerConditionSet.SetRuntimeReferences(this, null); } QuestContent.SetRuntimeReferences(offerConditionsUnmetContentList, this, null); QuestContent.SetRuntimeReferences(offerContentList, this, null); // Set references in counters: if (counterList != null) { for (int i = 0; i < counterList.Count; i++) { counterList[i].SetRuntimeReferences(this); } } // Set references in state info: if (stateInfoList != null) { for (int i = 0; i < stateInfoList.Count; i++) { var stateInfo = QuestStateInfo.GetStateInfo(stateInfoList, (QuestState)i); if (stateInfo != null) { stateInfo.SetRuntimeReferences(this, null); } } } // Set references in nodes: if (nodeList != null) { for (int i = 0; i < nodeList.Count; i++) { if (nodeList[i] != null) { nodeList[i].InitializeRuntimeReferences(this); } } for (int i = 0; i < nodeList.Count; i++) { if (nodeList[i] != null) { nodeList[i].ConnectRuntimeNodeReferences(); } } for (int i = 0; i < nodeList.Count; i++) { if (nodeList[i] != null) { nodeList[i].SetRuntimeNodeReferences(); } } } // Record list of any nodes' speakers who aren't the quest giver: RecordSpeakersUsedInQuestAndAnyNodes(); // Add tags to dictionary: QuestMachineTags.AddTagsToDictionary(tagDictionary, title); QuestMachineTags.AddTagsToDictionary(tagDictionary, group); if (!StringField.IsNullOrEmpty(questGiverID)) { tagDictionary.SetTag(QuestMachineTags.QUESTGIVERID, questGiverID); } }
/// <summary> /// Adds the text for a step. /// </summary> protected virtual void AddStepNodeText(QuestBuilder questBuilder, QuestNode conditionNode, QuestStateInfo activeState, string targetEntity, string targetDescriptor, string domainName, string counterName, int requiredCounterValue, PlanStep step) { // Text for condition node's Active state: var taskText = ReplaceStepTags(step.action.actionText.activeText.dialogueText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue); var bodyText = questBuilder.CreateBodyContent(taskText); var dialogueList = activeState.categorizedContentList[(int)QuestContentCategory.Dialogue]; dialogueList.contentList.Add(bodyText); var jrlText = ReplaceStepTags(step.action.actionText.activeText.journalText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue); var jrlbodyText = questBuilder.CreateBodyContent(jrlText); var journalList = activeState.categorizedContentList[(int)QuestContentCategory.Journal]; journalList.contentList.Add(jrlbodyText); var hudText = ReplaceStepTags(step.action.actionText.activeText.hudText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue); var hudbodyText = questBuilder.CreateBodyContent(hudText); var hudList = activeState.categorizedContentList[(int)QuestContentCategory.HUD]; hudList.contentList.Add(hudbodyText); }
/// <summary> /// Returns the state info associated with a quest node state. /// </summary> public QuestStateInfo GetStateInfo(QuestNodeState state) { return((stateInfoList != null) ? QuestStateInfo.GetStateInfo(stateInfoList, state) : null); }
public QuestStateInfoProxy(QuestStateInfo stateInfo) { CopyFrom(stateInfo); }