2022-05-25 17:11:49 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class NPCDialogue : MonoBehaviour
|
|
|
|
{
|
2022-06-15 16:32:14 +02:00
|
|
|
public string name;
|
2022-05-25 17:11:49 +02:00
|
|
|
public Text nameText;
|
2022-06-14 15:54:28 +02:00
|
|
|
public Text nameText1;
|
2022-08-09 21:49:35 +02:00
|
|
|
public Text nameText2;
|
2022-05-25 17:11:49 +02:00
|
|
|
public Text dialogueText;
|
2022-07-24 20:01:29 +02:00
|
|
|
//first dialogue
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialogue;
|
2022-07-24 20:01:29 +02:00
|
|
|
//dialogue during quest
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialogueWQuest;
|
2022-07-24 20:01:29 +02:00
|
|
|
//dialotgue after quest
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialogueAQuest;
|
2022-07-24 20:01:29 +02:00
|
|
|
//first dialogue
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialoguePolish;
|
2022-07-24 20:01:29 +02:00
|
|
|
//dialogue during quest
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialogueWQuestPolish;
|
2022-07-24 20:01:29 +02:00
|
|
|
//dialotgue after quest
|
2022-12-04 18:42:34 +01:00
|
|
|
public DialogueNpcTest dialogueAQuestPolish;
|
2022-07-24 20:01:29 +02:00
|
|
|
|
|
|
|
private string language;
|
2022-05-25 17:11:49 +02:00
|
|
|
|
|
|
|
private Queue<string> sentences;
|
2022-06-14 15:54:28 +02:00
|
|
|
private Queue<string> sentencesWQuest;
|
|
|
|
private Queue<string> sentencesAQuest;
|
2022-05-25 17:11:49 +02:00
|
|
|
public GameObject Panel;
|
|
|
|
|
2022-06-20 20:50:48 +02:00
|
|
|
public string requiredItem;
|
2022-06-14 15:54:28 +02:00
|
|
|
public GameObject QuestPanel;
|
2022-06-20 20:50:48 +02:00
|
|
|
public GameObject FinishQuestPanel;
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
bool triggered = false;
|
|
|
|
|
2022-06-14 15:54:28 +02:00
|
|
|
public int isQuest;
|
2022-06-20 20:50:48 +02:00
|
|
|
// 0 - NPC no quest
|
|
|
|
// 1 - NPC with quest that hasnt been started
|
|
|
|
// 2 - NPC with ongoing quest
|
|
|
|
// 3 - NPC with quest that has been finished
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-06-20 22:31:48 +02:00
|
|
|
void Awake()
|
|
|
|
{
|
2022-12-06 01:58:32 +01:00
|
|
|
requiredItem = "Axe";
|
2022-06-20 22:31:48 +02:00
|
|
|
}
|
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
sentences = new Queue<string>();
|
2022-06-14 15:54:28 +02:00
|
|
|
sentencesWQuest = new Queue<string>();
|
|
|
|
sentencesAQuest = new Queue<string>();
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void TriggerDialogue()
|
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
language = PlayerPrefs.GetString("language");
|
2022-06-14 15:54:28 +02:00
|
|
|
if (isQuest == 2)
|
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuestPolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
|
|
|
else if (isQuest == 3)
|
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuestPolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialoguePolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if (Panel != null)
|
|
|
|
{
|
|
|
|
|
|
|
|
Panel.SetActive(false);
|
2022-08-09 21:49:35 +02:00
|
|
|
QuestPanel.SetActive(false);
|
|
|
|
FinishQuestPanel.SetActive(false);
|
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
triggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if (collision.tag == "Player")
|
|
|
|
{
|
|
|
|
triggered = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
if (triggered)
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.E))
|
|
|
|
{
|
|
|
|
if (Panel != null)
|
|
|
|
{
|
|
|
|
Panel.SetActive(true);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
if (isQuest == 2)
|
|
|
|
{
|
2022-11-24 03:48:23 +01:00
|
|
|
var questItem = InventoryUIManager.Instance.FindItemInWarehouseByName(requiredItem);
|
2022-06-20 22:31:48 +02:00
|
|
|
if(!questItem.Equals(new KeyValuePair<int, Item>()))
|
|
|
|
{
|
|
|
|
FinishQuestPanel.SetActive(true);
|
|
|
|
Panel.SetActive(false);
|
|
|
|
} else {
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuestPolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
2022-06-20 22:31:48 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
2022-06-20 20:50:48 +02:00
|
|
|
else if (isQuest == 3)
|
2022-06-14 15:54:28 +02:00
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuestPolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-24 20:01:29 +02:00
|
|
|
if (PlayerPrefs.HasKey("language"))
|
|
|
|
{
|
|
|
|
language = PlayerPrefs.GetString("language");
|
|
|
|
if (language == "English")
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
|
|
|
else if (language == "Polish")
|
|
|
|
{
|
|
|
|
StartDialogue(dialoguePolish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-04 18:42:34 +01:00
|
|
|
public void StartDialogue(DialogueNpcTest dialogue)
|
2022-05-25 17:11:49 +02:00
|
|
|
{
|
|
|
|
nameText.text = dialogue.name;
|
2022-06-14 15:54:28 +02:00
|
|
|
nameText1.text = dialogue.name;
|
2022-08-09 21:49:35 +02:00
|
|
|
nameText2.text = dialogue.name;
|
2022-05-25 17:11:49 +02:00
|
|
|
|
|
|
|
sentences.Clear();
|
|
|
|
|
|
|
|
foreach(string sentence in dialogue.sentences)
|
|
|
|
{
|
|
|
|
sentences.Enqueue(sentence);
|
|
|
|
}
|
|
|
|
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
DisplayNextSentence();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisplayNextSentence()
|
|
|
|
{
|
2022-06-14 15:54:28 +02:00
|
|
|
if (isQuest == 2)
|
2022-05-25 17:11:49 +02:00
|
|
|
{
|
2022-06-14 15:54:28 +02:00
|
|
|
if (sentences.Count == 0)
|
|
|
|
{
|
2022-11-24 03:48:23 +01:00
|
|
|
var questItem = InventoryUIManager.Instance.FindItemInWarehouseByName(requiredItem);
|
2022-06-20 20:50:48 +02:00
|
|
|
if(!questItem.Equals(new KeyValuePair<int, Item>()))
|
|
|
|
{
|
|
|
|
FinishQuestPanel.SetActive(true);
|
|
|
|
Panel.SetActive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-20 22:31:48 +02:00
|
|
|
EndDialogue();
|
|
|
|
return;
|
2022-06-20 20:50:48 +02:00
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
}
|
|
|
|
string sentence = sentences.Dequeue();
|
|
|
|
dialogueText.text = sentence;
|
|
|
|
}
|
|
|
|
else if (isQuest == 0)
|
|
|
|
{
|
|
|
|
if (sentences.Count == 0)
|
|
|
|
{
|
|
|
|
EndDialogue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string sentence = sentences.Dequeue();
|
|
|
|
dialogueText.text = sentence;
|
|
|
|
}
|
2022-06-20 20:50:48 +02:00
|
|
|
else if (isQuest == 3)
|
2022-06-14 15:54:28 +02:00
|
|
|
{
|
|
|
|
if (sentences.Count == 0)
|
|
|
|
{
|
|
|
|
EndDialogue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string sentence = sentences.Dequeue();
|
|
|
|
dialogueText.text = sentence;
|
|
|
|
}
|
|
|
|
else if (isQuest == 1)
|
|
|
|
{
|
|
|
|
if (sentences.Count == 0)
|
|
|
|
{
|
|
|
|
QuestPanel.SetActive(true);
|
|
|
|
Panel.SetActive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string sentence = sentences.Dequeue();
|
|
|
|
dialogueText.text = sentence;
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-14 15:54:28 +02:00
|
|
|
public void EndDialogue()
|
2022-05-25 17:11:49 +02:00
|
|
|
{
|
|
|
|
Panel.SetActive(false);
|
2022-06-14 15:54:28 +02:00
|
|
|
QuestPanel.SetActive(false);
|
2022-06-20 20:50:48 +02:00
|
|
|
FinishQuestPanel.SetActive(false);
|
2022-06-14 15:54:28 +02:00
|
|
|
|
|
|
|
}
|
2022-06-13 23:33:19 +02:00
|
|
|
|
2022-06-14 15:54:28 +02:00
|
|
|
public void QuestAccepted()
|
|
|
|
{
|
|
|
|
isQuest = 2;
|
|
|
|
QuestPanel.SetActive(false);
|
2022-06-13 23:33:19 +02:00
|
|
|
if(!gameObject.GetComponent<NPCQuest>().IsTaskAccepted())
|
|
|
|
{
|
2022-06-17 22:22:19 +02:00
|
|
|
// 1. Add task to palyer quests list
|
2022-06-13 23:33:19 +02:00
|
|
|
Task myTask = gameObject.GetComponent<NPCQuest>().AcceptTask();
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-10-22 18:04:21 +02:00
|
|
|
TaskUIManager.Instance.Add(myTask);
|
2022-06-17 22:22:19 +02:00
|
|
|
|
|
|
|
// 2. Drop Axe On Map
|
|
|
|
gameObject.GetComponent<NPCQuest>().DropItem();
|
2022-06-13 23:33:19 +02:00
|
|
|
} else {
|
|
|
|
Debug.Log("Ten task został juz rozpoczęty!");
|
|
|
|
}
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
2022-06-14 15:54:28 +02:00
|
|
|
|
2022-06-20 20:50:48 +02:00
|
|
|
public void FinishQuest()
|
|
|
|
{
|
2022-06-20 22:31:48 +02:00
|
|
|
// 1. Take item from palyer
|
2022-11-24 03:48:23 +01:00
|
|
|
var questItem = InventoryUIManager.Instance.FindItemInWarehouseByName(requiredItem);
|
2022-06-20 22:31:48 +02:00
|
|
|
|
2022-11-24 03:48:23 +01:00
|
|
|
InventoryUIManager.Instance.RemoveByPosition(questItem[0].Key);
|
2022-06-20 22:31:48 +02:00
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
// 3. remove quest from player list
|
|
|
|
var task = TaskUIManager.Instance.FindTaskByName(gameObject.GetComponent<NPCQuest>().quest.Title);
|
|
|
|
|
|
|
|
if (task.Count == 0)
|
|
|
|
Debug.LogError($"Task '{gameObject.GetComponent<NPCQuest>().quest.Title}' not found");
|
|
|
|
else
|
|
|
|
TaskUIManager.Instance.RemoveByName(gameObject.GetComponent<NPCQuest>().quest.Title);
|
|
|
|
|
2023-01-05 16:52:57 +01:00
|
|
|
// 4. Get reward
|
|
|
|
GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerActions>().GetReward(gameObject.GetComponent<NPCQuest>().reward);
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
// 3. Set as finished
|
2022-06-20 20:50:48 +02:00
|
|
|
isQuest = 3;
|
|
|
|
EndDialogue();
|
|
|
|
}
|
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|