protected virtual bool PlayerHasSuccessfullyCompleted(StringField questID) { if (StringField.IsNullOrEmpty(questID) || playerQuestListContainer == null) { return(false); } var quest = playerQuestListContainer.FindQuest(questID); return((quest == null) ? false : (quest.GetState() == QuestState.Successful)); }
public string GetEditorName() { if (!StringField.IsNullOrEmpty(title)) { return(title.value); } if (!StringField.IsNullOrEmpty(id)) { return(id.value); } return("Unnamed Quest"); }
public string GetEditorName() { if (!StringField.IsNullOrEmpty(internalName)) { return(internalName.value); } if (!StringField.IsNullOrEmpty(id)) { return(id.value); } return("Node"); }
/// <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 text to show in UIs after a quest has been successfully completed. /// </summary> /// <param name="questBuilder">QuestBuilder.</param> /// <param name="mainTargetEntity">Main target entity that quest is about.</param> /// <param name="mainTargetDescriptor">Target descriptor (with count).</param> /// <param name="domainName">Target's domain.</param> /// <param name="goal">Goal step in quest.</param> protected virtual void AddSuccessfulText(QuestBuilder questBuilder, string mainTargetEntity, string mainTargetDescriptor, string domainName, PlanStep goal) { var successful = questBuilder.quest.GetStateInfo(QuestState.Successful); var hasSuccessfulDialogueText = !StringField.IsNullOrEmpty(goal.action.actionText.completedText.dialogueText); var hasSuccessfulJournalText = !StringField.IsNullOrEmpty(goal.action.actionText.completedText.journalText); if (hasSuccessfulDialogueText) { var dlgText = questBuilder.CreateBodyContent(ReplaceStepTags(goal.action.actionText.completedText.dialogueText.value, mainTargetEntity, mainTargetDescriptor, domainName, string.Empty, 0)); questBuilder.AddContents(successful.GetContentList(QuestContentCategory.Dialogue), dlgText); } if (hasSuccessfulJournalText) { var jrlText = questBuilder.CreateBodyContent(ReplaceStepTags(goal.action.actionText.completedText.journalText.value, mainTargetEntity, mainTargetDescriptor, domainName, string.Empty, 0)); questBuilder.AddContents(successful.GetContentList(QuestContentCategory.Journal), jrlText); } }
public override string GetEditorName() { if (StringField.IsNullOrEmpty(requiredQuestID) && StringField.IsNullOrEmpty(requiredQuestNodeID)) { return("Quest Node State: " + requiredState); } else if (StringField.IsNullOrEmpty(requiredQuestID)) { return("Quest Node State: '" + requiredQuestNodeID + "' State == " + requiredState); } else if (StringField.IsNullOrEmpty(requiredQuestNodeID)) { return("Quest Node State: Quest '" + requiredQuestID + "' Node (unspecified) == " + requiredState); } else { return("Quest Note State: Quest '" + requiredQuestID + "' Node '" + requiredQuestNodeID + "' == " + requiredState); } }
public override string GetEditorName() { if (StringField.IsNullOrEmpty(questID) && StringField.IsNullOrEmpty(questNodeID)) { return("Set Quest Node State: " + state); } else if (StringField.IsNullOrEmpty(questID)) { return("Set Quest Node State: '" + questNodeID + "' to " + state); } else if (StringField.IsNullOrEmpty(questNodeID)) { return("Set Quest Node State: Quest '" + questID + "' Node (unspecified) to " + state); } else { return("Set Quest Node State: Quest '" + questID + "' Node '" + questNodeID + "' to " + state); } }
private void OnDrawRuntimeElement(Rect rect, int index, bool isActive, bool isFocused) { if (!(0 <= index && index < questReorderableList.serializedProperty.arraySize)) { return; } var questProperty = questReorderableList.serializedProperty.GetArrayElementAtIndex(index); var quest = questProperty.objectReferenceValue as Quest; if (quest == null) { return; } var questName = !StringField.IsNullOrEmpty(quest.title) ? quest.title.value : string.Empty; EditorGUI.BeginDisabledGroup(true); EditorGUI.TextField(new Rect(rect.x, rect.y + 1, rect.width, EditorGUIUtility.singleLineHeight), questName); EditorGUI.EndDisabledGroup(); }
/// <summary> /// If UI info is unassigned, get it from the quest giver's QuestEntity if present. /// </summary> protected void BackfillInfoFromEntityType() { if (questEntity == null) { return; } if (StringField.IsNullOrEmpty(id)) { id = questEntity.id; } if (StringField.IsNullOrEmpty(displayName)) { displayName = questEntity.displayName; } if (image == null) { image = questEntity.image; } }
private bool IsContentValidForCurrentSpeaker(QuestContentCategory category) { // Non-dialogue content is always valid: if (category != QuestContentCategory.Dialogue) { return(true); } if (quest == null) { return(true); } // Are quest's current speaker and this node's speaker both the quest giver? if (quest.currentSpeaker == null) { return(StringField.IsNullOrEmpty(speaker) || StringField.Equals(speaker, quest.questGiverID)); } // Otherwise is quest's current speaker same as this node's speaker? return(StringField.Equals(speaker, quest.currentSpeaker.id)); }
public override void Execute() { if (StringField.IsNullOrEmpty(gameObjectName)) { return; } var gameObject = GameObjectUtility.GameObjectHardFind(StringField.GetStringValue(gameObjectName)); if (gameObject == null) { if (QuestMachine.debug) { Debug.LogWarning("Quest Machine: ActivateGameObjectQuestAction can't find a GameObject named '" + gameObjectName + "'."); } return; } if (QuestMachine.debug) { Debug.Log("Quest Machine: Setting GameObject '" + gameObjectName + "' " + (state ? "active." : "inactive.")); } gameObject.SetActive(state); }
public override string GetEditorName() { if (StringField.IsNullOrEmpty(gameObjectName)) { return("Control Animator"); } switch (action) { case AnimatorControlAction.Play: return("Animator on " + gameObjectName + ": Play state " + target); case AnimatorControlAction.SetTrigger: return("Animator on " + gameObjectName + ": Set " + target); case AnimatorControlAction.SetBool: return("Animator on " + gameObjectName + ": Set " + target + " to " + boolValue); case AnimatorControlAction.SetFloat: return("Animator on " + gameObjectName + ": Set " + target + " to " + floatValue); default: return("Animator on " + gameObjectName + ": Action not set yet"); } }
public override void Execute() { if (StringField.IsNullOrEmpty(gameObjectName) || StringField.IsNullOrEmpty(target)) { return; } var gameObject = GameObjectUtility.GameObjectHardFind(StringField.GetStringValue(gameObjectName)); if (gameObject == null) { if (QuestMachine.debug) { Debug.LogWarning("Quest Machine: AnimatorQuestAction can't find a GameObject named '" + gameObjectName + "'."); } return; } var animator = gameObject.GetComponentInChildren <Animator>(); if (animator == null) { if (QuestMachine.debug) { Debug.LogWarning("Quest Machine: AnimatorQuestAction: " + gameObjectName + " doesn't have an Animator."); } return; } switch (action) { case AnimatorControlAction.Play: if (QuestMachine.debug) { Debug.Log("Quest Machine: " + gameObjectName + ": Crossfading to state '" + target + "'.", gameObject); } animator.CrossFade(StringField.GetStringValue(target), floatValue); break; case AnimatorControlAction.SetTrigger: if (QuestMachine.debug) { Debug.Log("Quest Machine: " + gameObjectName + ": Setting trigger '" + target + "'.", gameObject); } animator.SetTrigger(StringField.GetStringValue(target)); break; case AnimatorControlAction.SetBool: if (QuestMachine.debug) { Debug.Log("Quest Machine: " + gameObjectName + ": Setting '" + target + "' to " + boolValue, gameObject); } animator.SetBool(StringField.GetStringValue(target), boolValue); break; case AnimatorControlAction.SetFloat: if (QuestMachine.debug) { Debug.Log("Quest Machine: " + gameObjectName + ": Setting '" + target + "' to " + floatValue, gameObject); } animator.SetFloat(StringField.GetStringValue(target), floatValue); break; } }
public override string GetEditorName() { return(!StringField.IsNullOrEmpty(caption) ? ("Button: " + ((count > 1) ? count + " " : string.Empty) + caption) : ((image != null) ? "Button: " + image.name : "Button")); }
/// <summary> /// Returns the GameObject with the specified ID, giving preference to quest list /// containers, then quest entities, and finally by GameObject name. /// </summary> /// <param name="id">ID to search for.</param> public static GameObject FindGameObjectWithID(StringField id) { return(StringField.IsNullOrEmpty(id) ? null : FindGameObjectWithID(id.value)); }
public override string GetEditorName() { return(StringField.IsNullOrEmpty(questID) ? ("Set Quest State: " + state) : ("Set Quest State: Quest '" + questID + "' to " + state)); }
public override string GetEditorName() { return(StringField.IsNullOrEmpty(message) ? "Message" : "Message: " + message.value + " " + StringField.GetStringValue(parameter) + " " + value.EditorNameValue()); }
public override string GetEditorName() { return(StringField.IsNullOrEmpty(m_requiredQuestID) ? ("Quest State: " + requiredState) : ("Quest State: " + requiredQuestID.value + " == " + requiredState)); }
/// <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); } }
protected virtual void RefreshNow() //[TODO] Optimize. { isDrawingSelectionPanel = true; selectionPanelContentManager.Clear(); // Set heading: if (entityImage != null) { entityImage.sprite = questJournal.image; } if (showDisplayNameInHeading && entityName != null && !StringField.IsNullOrEmpty(questJournal.displayName)) { entityName.text = questJournal.displayName.value; } // Get group names: var groupNames = new List <string>(); int numGroupless = 0; foreach (var quest in questJournal.questList) { if (quest.GetState() == QuestState.WaitingToStart) { continue; } var groupName = StringField.GetStringValue(quest.group); if (string.IsNullOrEmpty(groupName)) { numGroupless++; } if (string.IsNullOrEmpty(groupName) || groupNames.Contains(groupName)) { continue; } groupNames.Add(groupName); } // Add quests by group: foreach (var groupName in groupNames) { var groupFoldout = Instantiate <UnityUIFoldoutTemplate>(questGroupTemplate); selectionPanelContentManager.Add(groupFoldout, questSelectionContentContainer); groupFoldout.Assign(groupName, IsGroupExpanded(groupName)); if (alwaysExpandAllGroups) { groupFoldout.foldoutButton.interactable = false; } else { groupFoldout.foldoutButton.interactable = true; groupFoldout.foldoutButton.onClick.AddListener(() => { OnClickGroup(groupName, groupFoldout); }); } foreach (var quest in questJournal.questList) { if (quest.GetState() == QuestState.WaitingToStart) { continue; } if (string.Equals(quest.group.value, groupName)) { var questName = Instantiate <UnityUIQuestNameButtonTemplate>(GetQuestNameTemplateForState(quest.GetState())); questName.Assign(quest, OnToggleTracking); selectionPanelContentManager.Add(questName, groupFoldout.interiorPanel); var target = quest; SetupQuestNameUIEvents(questName.buttonTemplate.button, target); } } } // Add groupless quests: foreach (var quest in questJournal.questList) { if (quest.GetState() == QuestState.WaitingToStart) { continue; } var groupName = StringField.GetStringValue(quest.group); if (!string.IsNullOrEmpty(groupName)) { continue; } var questName = Instantiate <UnityUIQuestNameButtonTemplate>(GetQuestNameTemplateForState(quest.GetState())); questName.Assign(quest, OnToggleTracking); selectionPanelContentManager.Add(questName, questSelectionContentContainer); var target = quest; SetupQuestNameUIEvents(questName.buttonTemplate.button, target); } RepaintSelectedQuest(); RefreshNavigableSelectables(); }
public override string GetEditorName() { return(!StringField.IsNullOrEmpty(m_caption) ? ("Icon: " + ((m_count > 1) ? m_count + " " : string.Empty) + m_caption) : ((m_image != null) ? "Icon: " + m_image.name : "Icon")); }
/// <summary> /// Adds the plan's steps. /// </summary> /// <param name="questBuilder">QuestBuilder.</param> /// <param name="domainName">Main target's domain.</param> /// <param name="goal">Goal step.</param> /// <param name="plan">List of steps that end with goal step.</param> /// <returns>The last node added.</returns> protected virtual QuestNode AddSteps(QuestBuilder questBuilder, string domainName, PlanStep goal, Plan plan) { var previousNode = questBuilder.GetStartNode(); var counterNames = new HashSet <string>(); for (int i = 0; i < plan.steps.Count; i++) { var step = plan.steps[i]; // Create next condition node: var targetEntity = step.fact.entityType.name; var targetDescriptor = step.fact.entityType.GetDescriptor(step.requiredCounterValue); var id = (i + 1).ToString(); var internalName = step.action.displayName + " " + targetDescriptor; var conditionNode = questBuilder.AddConditionNode(previousNode, id, internalName, ConditionCountMode.All); previousNode = conditionNode; // Variables for node text tag replacement: var counterName = string.Empty; int requiredCounterValue = 0; var completion = step.action.completion; if (completion.mode == ActionCompletion.Mode.Counter) { // Setup counter condition: counterName = goal.fact.entityType.pluralDisplayName.value + completion.baseCounterName.value; if (!counterNames.Contains(counterName)) { var counter = questBuilder.AddCounter(counterName, completion.initialValue, completion.minValue, completion.maxValue, false, completion.updateMode); foreach (var messageEvent in completion.messageEventList) { var counterMessageEvent = new QuestCounterMessageEvent(messageEvent.targetID, messageEvent.message, new StringField(StringField.GetStringValue(messageEvent.parameter).Replace("{TARGETENTITY}", targetEntity)), messageEvent.operation, messageEvent.literalValue); counter.messageEventList.Add(counterMessageEvent); } } counterName = goal.fact.entityType.pluralDisplayName.value + completion.baseCounterName.value; requiredCounterValue = Mathf.Min(step.requiredCounterValue, step.fact.count); questBuilder.AddCounterCondition(conditionNode, counterName, CounterValueConditionMode.AtLeast, requiredCounterValue); // Consider: Add action to reset counter to zero in case future nodes repeat the same counter? } else { // Setup message condition: questBuilder.AddMessageCondition(conditionNode, QuestMessageParticipant.Any, completion.senderID, QuestMessageParticipant.Any, completion.targetID, completion.message, new StringField(StringField.GetStringValue(completion.parameter).Replace("{TARGETENTITY}", targetEntity))); } var activeState = conditionNode.stateInfoList[(int)QuestNodeState.Active]; AddStepNodeText(questBuilder, conditionNode, activeState, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue, step); // Actions when active: if (!StringField.IsNullOrEmpty(step.action.actionText.activeText.alertText)) { // Alert action: var alertAction = questBuilder.CreateAlertAction(ReplaceStepTags(step.action.actionText.activeText.alertText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue)); activeState.actionList.Add(alertAction); } // Send message action: if (!StringField.IsNullOrEmpty(step.action.sendMessageOnActive)) { var messageAction = questBuilder.CreateMessageAction(ReplaceStepTags(step.action.sendMessageOnActive.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue)); activeState.actionList.Add(messageAction); } // Actions when completed: if (!StringField.IsNullOrEmpty(step.action.sendMessageOnCompletion)) { var trueState = conditionNode.stateInfoList[(int)QuestNodeState.True]; var messageAction = questBuilder.CreateMessageAction(ReplaceStepTags(step.action.sendMessageOnCompletion.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue)); trueState.actionList.Add(messageAction); } } return(previousNode); }