Beispiel #1
0
		public override ReturnType Execute(GameObject self, GameObject targeted, GameObject selfTargetedBy, GameObject equipTarget, GameObject helper)
		{
			GameObject obj = DetermineTarget(self, targeted, selfTargetedBy, equipTarget, helper);
			if (obj == null)
			{
				Debug.LogError("DiaQ Dialogue Action Error: The subject did not exist.");
				return ReturnType.Done;
			}

			// get the DiaQ Conversation data
			DiaQConversation diaq = DiaQEngine.Instance.StartGraph(graphIdent);
			if (diaq != null)
			{
				// Build the Dialogue data
				GUIDialogueData data = new GUIDialogueData();

				// Grab some data from the character (NPC)
				CharacterBase c = obj.GetComponent<CharacterBase>();
				if (c != null)
				{
					data.screenName = c.Actor.screenName;
					data.description = c.Actor.description;
					data.portrait = c.Actor.portrait;
				}
				else
				{
					// it was not an NPC, see if it was an Object. The player can talk to rocks too :p
					RPGObject o = obj.GetComponent<RPGObject>();
					if (o != null)
					{
						data.screenName = o.screenName;
						data.description = o.description;
						data.portrait = o.icon;
					}
				}
				
				data.conversationText = diaq.conversationText;
				data.options = diaq.choices;
				data.buttonCallback = DiaQEngine.Instance.OnUniRPGDialogueCallback;

				// build rewards data
				DiaQEngine.Instance.UpdateUniRPGDialogueRewards(diaq, data);

				// Tell GUI to show dialogue
				UniRPGGlobal.GameGUIObject.SendMessage("ShowDialogue", data);
			}

			return ReturnType.Done;
		}
Beispiel #2
0
	public void HideDialogue()
	{
		ShowLeftPanel(DefaultGameGUIData_MenuOption.MenuOption.None, false, false);
		dialogueData = null;
	}
Beispiel #3
0
	public void ShowDialogue(GUIDialogueData data)
	{
		if (data == null)
		{
			Debug.LogError("Error: Could not show the Dialogue Panel. The Data parameter was null.");
			return;
		}

		dialogueData = data;
		ShowLeftPanel(DefaultGameGUIData_MenuOption.MenuOption.Dialogue, false, true);
	}
Beispiel #4
0
	// ================================================================================================================
	#region Dialogue & Quest (and journal/quest log)

	private void DrawDialogue()
	{
		if (!gui.plrMoveDialogue) if (dialogueData == null) return;
		UniRPGGlobal.GUIConsumedInput = true;
		GUILayout.BeginArea(r[2], string.IsNullOrEmpty(dialogueData.screenName) ? " " : dialogueData.screenName, GUI.skin.window);
		{
			if (GUI.Button(new Rect(r[2].width - gui.WindowCloseButton.fixedWidth - GUI.skin.window.padding.right,
									GUI.skin.window.padding.top + GUI.skin.window.contentOffset.y,
									gui.WindowCloseButton.fixedWidth, gui.WindowCloseButton.fixedHeight), GUIContent.none, gui.WindowCloseButton))
			{
				PlayButtonFX();
				if (dialogueData.buttonCallback != null) dialogueData.buttonCallback(-1, dialogueData);
				dialogueData = null;
				showDialogue = false;
				GUIUtility.ExitGUI();
				return;
			}

			float height = r[2].height - GUI.skin.window.padding.top - GUI.skin.window.padding.bottom;
			float h = height;
			if (dialogueData.showRewards) h = (height * 0.4f);
			else h = (height * 0.7f);
			height -= h;

			// *** SHOW THE CONVERSATION TEXT

			if (dialogueData.conversationText != null)
			{
				scroll[0] = GUILayout.BeginScrollView(scroll[0], GUILayout.Height(h));
				{
					GUILayout.Label(dialogueData.conversationText);
				}
				GUILayout.EndScrollView();
			}

			// *** SHOW THE REWARDS

			if (dialogueData.showRewards)
			{
				GUILayout.Box(GUIContent.none, gui.HorizontalLine);
				height -= gui.HorizontalLine.fixedHeight;
				h = (height * 0.5f);
				height -= h;

				string currency = null;
				if (dialogueData.currencyReward > 0f) currency = string.Format("{0}: +{1}", UniRPGGlobal.DB.currency, dialogueData.currencyReward);

				scroll[5] = GUILayout.BeginScrollView(scroll[5], GUILayout.Height(h));
				{
					GUILayout.Label("Rewards", gui.RewardsLabel);

					// attribute rewards
					if (dialogueData.attributeRewards != null)
					{
						for (int i = 0; i < dialogueData.attributeRewards.Count; i++)
						{
							if (dialogueData.attributeRewards[i].attrib == null) continue;
							GUILayout.Label(string.Format("{0}: +{1}", dialogueData.attributeRewards[i].attrib.screenName, dialogueData.attributeRewards[i].valueAdd));
						}
					}

					// currency reward
					if (dialogueData.currencyReward > 0f)
					{
						GUILayout.Label(currency);
					}

					// item rewards
					if (dialogueData.itemRewards != null)
					{
						for (int i = 0; i < dialogueData.itemRewards.Count; i++)
						{
							GUILayout.BeginHorizontal();
							RPGItem item = dialogueData.itemRewards[i].item;
							if (item != null) GUILayout.Box(item.icon[0] == null ? gui.txNoIcon : item.icon[0], gui.ListButton, GUILayout.Width(gui.ListButton.fixedHeight));
							else GUILayout.Box(GUIContent.none, gui.ListButton, GUILayout.Width(gui.ListButton.fixedHeight));
							GUILayout.Label(string.Format("{0}: {1}", item.screenName, dialogueData.itemRewards[i].count));
							GUILayout.EndHorizontal();
						}
					}
				}
				GUILayout.EndScrollView();
			}

			GUILayout.Box(GUIContent.none, gui.HorizontalLine);
			h = height - gui.HorizontalLine.fixedHeight;

			// *** SHOW THE OPTIONS

			if (dialogueData.options != null)
			{
				scroll[1] = GUILayout.BeginScrollView(scroll[1]);
				{
					for (int i = 0; i < dialogueData.options.Length; i++)
					{
						if (GUILayout.Button(dialogueData.options[i]))
						{
							PlayButtonFX();
							if (dialogueData.buttonCallback != null)
							{
								dialogueData.buttonCallback(i, dialogueData);

								// callback might have messed with dialogueData so rather drop out now
								GUIUtility.ExitGUI();
								return;
							}
						}
					}
				}
				GUILayout.EndScrollView();
			}

		}
		GUILayout.EndArea();
	}
Beispiel #5
0
		public void UpdateUniRPGDialogueRewards(DiaQConversation diaq, GUIDialogueData data)
		{
			// first make sure the rewards are cleared in case this is a data being reused
			data.showRewards = false;
			data.currencyReward = 0;
			data.itemRewards = null;
			data.attributeRewards = null; 

			if (diaq.linkedQuest != null)
			{
				if (diaq.linkedQuest.rewards.Count > 0)
				{
					data.showRewards = true;

					foreach (DiaQuest.Reward r in diaq.linkedQuest.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<GUIDialogueData.AttribReward>(0);
									GUIDialogueData.AttribReward ar = data.attributeRewards.FirstOrDefault(x => x.attrib == a);
									if (ar == null) data.attributeRewards.Add(new GUIDialogueData.AttribReward() { attrib = a, valueAdd = r.value });
									else ar.valueAdd += r.value;
								}
						} } // else if (r.type == DiaQuest.Reward.Type.Attribute)

						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<GUIDialogueData.ItemReward>(0);
										GUIDialogueData.ItemReward ir = data.itemRewards.FirstOrDefault(x => x.item == it);
										if (ir == null) data.itemRewards.Add(new GUIDialogueData.ItemReward() { item = it, count = r.value });
										else ir.count += r.value;
									}
						} } } // else if (r.type == DiaQuest.Reward.Type.Item)
					}

				}
			}
		}
Beispiel #6
0
		// ============================================================================================================
		#region UniRPG specific

		/// <summary>
		/// This is the callback when a player made a choice in the open dialogue panel. -1 is when plaeyr closed the panel
		/// The GUIDialogueData that was used is send as a param so that it can be reused if needed.
		/// </summary>
		public void OnUniRPGDialogueCallback(int selectedChoice, GUIDialogueData data)
		{
			if (selectedChoice == -1)
			{	// dialogue was closed, deselect any targeted object
				UniRPGGlobal.Player.ClearTarget();
				return; // nothing to do
			}

			DiaQConversation diaq = SubmitChoice(selectedChoice);

			if (diaq == null)
			{	// null means there is no conversation to show, so close hide the dialogue panel now
				UniRPGGlobal.GameGUIObject.SendMessage("HideDialogue");
				
				// deselect any selected object now (most likely that an NPC was selected)
				UniRPGGlobal.Player.ClearTarget();
			}
			else
			{	// update the unirpg dialogue data and send it to be shown to the player
				data.conversationText = diaq.conversationText;
				data.options = diaq.choices;
				UpdateUniRPGDialogueRewards(diaq, data);
				UniRPGGlobal.GameGUIObject.SendMessage("ShowDialogue", data);
			}
			
		}