예제 #1
0
		void OnGUI()
		{
			scroll = GUILayout.BeginScrollView(scroll, false, true);
			{
				if (asset.quests.Count > 0)
				{
					foreach (DiaQuest q in asset.quests)
					{
						if (GUILayout.Toggle(selected == q, q.name, GUI.skin.button, GUILayout.Width(275))) selected = q;
					}
				}
				else
				{
					GUILayout.Label("No Quests found");
				}
			}
			GUILayout.EndScrollView();

			EditorGUILayout.BeginHorizontal();
			{
				GUILayout.FlexibleSpace();

				if (selected == null) GUI.enabled = false;
				if (GUILayout.Button("Accept", GUILayout.Width(60), GUILayout.Height(20))) accepted = true;
				GUI.enabled = true;

				if (GUILayout.Button("Cancel", GUILayout.Width(60), GUILayout.Height(20))) this.Close();
				GUILayout.FlexibleSpace();
			}
			EditorGUILayout.EndHorizontal();
			GUILayout.Space(10);
		}
예제 #2
0
    // =================================================================================
    // This is called from the Graph to give the player his rewards. The ideal would be
    // for you to create a specialised Reward Node that can be used. Have look at the
    // DiaQ docs to learn how new nodes can be created.
    public void GiveRewards(DiaQuest quest)
    {
        quest.rewarded = true;

        // access the reward keys to see what rewards to give the player
        // ideally you would create a Data Provider which can be selected
        // from in the quest editor. I use both methods in this sample to
        // demonstrate. First I will call RunRewardGivers() to try and run
        // through them. IN the sample quest I did set up one that works
        // in this manner - see DiaQSampleRewardGiver. There is also a
        // reward that works off of the keyString and that I handle here.

        quest.RunRewardGivers();

        for (int i = 0; i < quest.rewards.Count; i++)
        {
            if (quest.rewards[i].keyString == "Gold")
            {
                // this is the one I can manually handle. You can handle all
                // your rewards in this manner but it is bug prone as the
                // designer might enter the key incorrectly. The best would
                // be to try create a reward giver/ handler as demonstrated
                // in the DiaQSampleRewardGiver script. Also see the script
                // editor/DiaQSampleRewardGiverInfo as it is a supporting
                // script on the editor side of the sample reward giver

                Debug.Log("Player received: " + quest.rewards[i].value + " Gold");

            }

            // else ... check for other keys that can be handled
        }
    }
예제 #3
0
		private void GiveRewards(DiaQuest q)
		{
			// first set that quest was handed-in
			q.HandIn(true);

			// now hand out reward(s)
			foreach (DiaQuest.Reward r in q.rewards)
			{
				if (r.type == DiaQuest.Reward.Type.Currency)
				{
					UniRPGGlobal.Player.Actor.currency += r.value;
					if (UniRPGGlobal.Player.Actor.currency < 0) UniRPGGlobal.Player.Actor.currency = 0;
				}

				else if (r.type == DiaQuest.Reward.Type.Attribute)
				{
					if (!string.IsNullOrEmpty(r.ident))
					{
						RPGAttribute a = UniRPGGlobal.Player.Actor.ActorClass.GetAttribute(new GUID(r.ident));
						if (a != null)
						{
							a.Value += r.value;
						}
						else Debug.LogError("DiaQ Reward Action Error: The Player does not have the Attribute.");
					}
					else Debug.LogError("DiaQ Reward Action Error: No Attribute was specified.");
				}

				else if (r.type == DiaQuest.Reward.Type.Item)
				{
					if (r.value < 1)
					{
						Debug.LogError("DiaQ Reward Action Error: You must specify a number of (1) or higher for Item type rewards.");
					}
					else
					{
						if (!string.IsNullOrEmpty(r.ident))
						{
							RPGItem it = UniRPGGlobal.DB.GetItem(new GUID(r.ident));
							if (it != null)
							{
								UniRPGGlobal.Player.Actor.AddToBag(it, r.value);
							}
							else Debug.LogError("DiaQ Reward Action Error: The specified Item was not found in the Database.");
						}
						else Debug.LogError("DiaQ Reward Action Error: No Item was specified.");
					}
				}
			}
		}
예제 #4
0
		private void SetQuestRewardsData(DiaQuest diaq, GUIQuestData data)
		{
			data.showRewards = true;

			foreach (DiaQuest.Reward r in diaq.rewards)
			{
				if (r.type == DiaQuest.Reward.Type.Currency)
				{
					data.currencyReward += r.value;
				}

				else if (r.type == DiaQuest.Reward.Type.Attribute)
				{
					if (!string.IsNullOrEmpty(r.ident))
					{
						RPGAttribute a = UniRPGGlobal.DB.GetAttribute(new GUID(r.ident));
						if (a != null)
						{
							data.attributeRewards = data.attributeRewards ?? new List<GUIQuestData.AttribReward>(0);
							GUIQuestData.AttribReward ar = data.attributeRewards.FirstOrDefault(x => x.attrib == a);
							if (ar == null) data.attributeRewards.Add(new GUIQuestData.AttribReward() { attrib = a, valueAdd = r.value });
							else ar.valueAdd += r.value;
						}
					}
				}

				else if (r.type == DiaQuest.Reward.Type.Item)
				{
					if (!string.IsNullOrEmpty(r.ident))
					{
						if (r.value > 0)
						{
							RPGItem it = UniRPGGlobal.DB.GetItem(new GUID(r.ident));
							if (it != null)
							{
								data.itemRewards = data.itemRewards ?? new List<GUIQuestData.ItemReward>(0);
								GUIQuestData.ItemReward ir = data.itemRewards.FirstOrDefault(x => x.item == it);
								if (ir == null) data.itemRewards.Add(new GUIQuestData.ItemReward() { item = it, count = r.value });
								else ir.count += r.value;
							}
						}
					}
				}
			}
			
		}
예제 #5
0
		public void InitEditor()
		{
			currGraph = null;
			currNode = null;
			currQuest = null;
			LoadAsset(true);
		}
예제 #6
0
		// ============================================================================================================
		#region inspector

		private void DrawInspector()
		{
			// toolbar
			GUILayout.BeginHorizontal();
			{
				if (inspectorArea != 0 && inspectorArea != 2) GUI.enabled = false;
				if (GUILayout.Button("+", EditorStyles.toolbarButton, GUILayout.Width(25)))
				{
					if (inspectorArea == 0)
					{	// new dialogue graph
						currGraph = new DiaQGraph();
						currGraph.name = "Dialogue";
						currGraph.CreateNode(DiaQNode.Type.Start, new Vector2(100f, 70f));
						asset.graphs.Add(currGraph);
						EditorUtility.SetDirty(asset);
					}
					else
					{	// new quest
						currQuest = new DiaQuest();
						currQuest.name = "Quest";
						asset.quests.Add(currQuest);
						EditorUtility.SetDirty(asset);
					}
				}
				GUI.enabled = true;

				if (DiaQEdGUI.ToggleButton(inspectorArea == 0, "Graphs", EditorStyles.toolbarButton))
				{
					currQuest = null;
					inspectorArea = 0;
					inspectorScroll[0] = Vector2.zero;
				}

				if (DiaQEdGUI.ToggleButton(inspectorArea == 2, "Quests", EditorStyles.toolbarButton))
				{
					currGraph = null;
					currNode = null;
					inspectorArea = 2;
					inspectorScroll[0] = Vector2.zero;
				}

				if (DiaQEdGUI.ToggleButton(inspectorArea == 1, "Settings", EditorStyles.toolbarButton))
				{
					currGraph = null;
					currNode = null;
					currQuest = null;
					inspectorArea = 1;
					inspectorScroll[0] = Vector2.zero;
				}

				if (GUILayout.Button(new GUIContent(DiaQEdGUI.Icon_Help), EditorStyles.toolbarButton, GUILayout.Width(25)))
				{
					DiaQVersion.ShowAbout();
				}
			}
			GUILayout.EndHorizontal();
			DiaQEdGUI.DrawHorizontalLine(2f, DiaQEdGUI.Col_Back, 0f, 2f);

			if (inspectorArea == 0)
			{
				// list of graphs
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width), GUILayout.Height(splitterPos[1] - 18));
				{
					foreach (DiaQGraph g in asset.graphs)
					{
						if (g == null) continue;
						if (DiaQEdGUI.ToggleButton(g == currGraph, g.name, EditorStyles.miniButton))
						{
							currNode = null;
							currGraph = g;
							UpdateGraphCachedStrings();
							GUI.FocusControl("");
						}
					}
				}
				GUILayout.EndScrollView();

				// splitter
				if (splitterPos[1] == 0f) splitterPos[1] = this.position.height * 0.5f;
				splitterRect[1] = new Rect(0f, splitterPos[1], this.position.width, 5f);
				GUI.Box(splitterRect[1], GUIContent.none, DiaQEdGUI.SplitterStyle);
				GUILayout.Space(1);

				// properties of selected node/ graph
				inspectorScroll[1] = GUILayout.BeginScrollView(inspectorScroll[1], false, true, GUILayout.Width(inspectorRect.width));
				{
					if (currNode != null) DrawNodeProperties();
					else if (currGraph != null) DrawGraphProperties();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}

			else if (inspectorArea == 1)
			{	// show settings/ tools
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width));
				{
					DrawInspectorTools();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}

			else if (inspectorArea == 2)
			{	// show list of quests
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width));
				{
					DrawQuestList();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}
		}
예제 #7
0
		private bool DeleteQuest(DiaQuest q)
		{
			if (q == null) return false;

			if (EditorUtility.DisplayDialog("Delete the Quest?", "This action can't be undone.", "Yes", "Cancel"))
			{
				asset.quests.Remove(q);
				if (q == currQuest) currQuest = null;
				EditorUtility.SetDirty(asset);
				return true;
			}
			return false;
		}
예제 #8
0
		/// <summary>
		/// Remove the quest from list of accepted quests. Completed quests can be dropped if allowDropCompleted = true, else not
		/// </summary>
		public void DropQuest(DiaQuest quest, bool allowDropCompleted)
		{
			if (quest == null) return;
			if (allowDropCompleted == false && quest.IsCompleted) return;
			acceptedQuests.Remove(quest);
		}
예제 #9
0
		/// <summary>
		/// Remove the quest from list of accepted quests. Completed quests can't be dropped
		/// </summary>
		public void DropQuest(DiaQuest quest)
		{
			DropQuest(quest, false);
		}
예제 #10
0
		// ============================================================================================================
		#region quest

		/// <summary>
		/// Give the payer the quest. Quest will be set as not completed.
		/// Nothing is done if the quest is already in he list of accepted quests.
		/// </summary>
		public void AcceptQuest(DiaQuest quest)
		{
			if (quest == null) return;
			quest.Accept(); // .Accept will add the quest to acceptedQuests if needed
		}
예제 #11
0
    // =================================================================================
    protected void Start()
    {
        // find the quest and cache a reference to it so I do not have to look it up
        // each time I want to work with it. Will simply search by its name but there
        // are methods too.
        quest = DiaQEngine.Instance.questManager.GetQuestByName("Sample Quest");

        // will also cache the graph. A graph is the conversation flow of the
        // quest giver's dialogue
        conversation = DiaQEngine.Instance.graphManager.GetGraphByName("Sample Graph");
    }