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-05-25 17:11:49 +02:00
|
|
|
public Text dialogueText;
|
|
|
|
public Dialogue dialogue;
|
2022-06-14 15:54:28 +02:00
|
|
|
public Dialogue dialogueWQuest;
|
|
|
|
public Dialogue dialogueAQuest;
|
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-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
|
|
|
|
2022-06-15 19:54:44 +02:00
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void TriggerDialogue()
|
|
|
|
{
|
2022-06-14 15:54:28 +02:00
|
|
|
if (isQuest == 2)
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
|
|
|
else if (isQuest == 3)
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if (Panel != null)
|
|
|
|
{
|
|
|
|
|
|
|
|
Panel.SetActive(false);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
StartDialogue(dialogueWQuest);
|
|
|
|
}
|
2022-06-20 20:50:48 +02:00
|
|
|
else if (isQuest == 3)
|
2022-06-14 15:54:28 +02:00
|
|
|
{
|
|
|
|
StartDialogue(dialogueAQuest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartDialogue(dialogue);
|
|
|
|
}
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void StartDialogue(Dialogue dialogue)
|
|
|
|
{
|
|
|
|
nameText.text = dialogue.name;
|
2022-06-14 15:54:28 +02:00
|
|
|
nameText1.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-06-20 20:50:48 +02:00
|
|
|
var questItem = InventoryManager.Instance.FindItemInWarehouse(requiredItem);
|
|
|
|
if(!questItem.Equals(new KeyValuePair<int, Item>()))
|
|
|
|
{
|
|
|
|
FinishQuestPanel.SetActive(true);
|
|
|
|
Panel.SetActive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-14 15:54:28 +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-06-13 23:33:19 +02:00
|
|
|
TaskManager.Instance.AddTask(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()
|
|
|
|
{
|
|
|
|
isQuest = 3;
|
|
|
|
EndDialogue();
|
|
|
|
}
|
|
|
|
|
2022-05-25 17:11:49 +02:00
|
|
|
}
|
|
|
|
|