PJ/Assets/scripts/dotfs_scripts/ENTITY_QuestNPC.cs

119 lines
No EOL
3.5 KiB
C#
Executable file

using UnityEngine;
using UnityEngine.Events;
using System.Collections.Generic;
public class ENTITY_QuestNPC : MonoBehaviour
{
[System.Serializable]
public class QuestStage
{
public string stageName;
[Header("Диалоги")]
public DATA_Dialogue dialogueWaiting;
public DATA_Dialogue dialogueReady;
[Header("События после реплик (Waiting)")]
public UnityEvent[] eventsWaiting;
[Header("События после реплик (Ready)")]
public UnityEvent[] eventsReady;
[Header("Требования")]
public string requiredItemID;
}
[Header("Настройки стадий")]
public List<QuestStage> stages = new List<QuestStage>();
public int currentStageIndex = 0;
[Header("Завершение")]
public DATA_Dialogue dialogueAllCompleted;
public UnityEvent[] eventsAllCompleted;
[Header("Ссылки (Заполнятся автоматически через Singleton)")]
public MANAGER_Dialogues dialogueManager;
public CORE_Inventory inventory;
void Start()
{
if (dialogueManager == null)
dialogueManager = MANAGER_Dialogues.Instance;
if (inventory == null)
inventory = CORE_Inventory.Instance;
if (inventory == null)
if (dialogueManager == null);
}
public void Interact()
{
if (dialogueManager == null)
{
return;
}
DATA_Dialogue dialogueToPlay = null;
UnityEvent[] eventsToPlay = null;
if (currentStageIndex < stages.Count)
{
QuestStage currentStage = stages[currentStageIndex];
if (!string.IsNullOrEmpty(currentStage.requiredItemID) && inventory != null)
{
bool hasItem = inventory.CheckItem(currentStage.requiredItemID);
if (hasItem)
{
dialogueToPlay = currentStage.dialogueReady;
eventsToPlay = currentStage.eventsReady;
}
else
{
dialogueToPlay = currentStage.dialogueWaiting;
eventsToPlay = currentStage.eventsWaiting;
}
}
else
{
dialogueToPlay = currentStage.dialogueWaiting;
eventsToPlay = currentStage.eventsWaiting;
}
}
else
{
dialogueToPlay = dialogueAllCompleted;
eventsToPlay = eventsAllCompleted;
}
if (dialogueToPlay != null)
{
dialogueManager.StartDialogue(dialogueToPlay, this.transform, eventsToPlay);
}
}
public void AdvanceQuest()
{
currentStageIndex++;
}
public void RemoveRequiredItem()
{
if (currentStageIndex < stages.Count && inventory != null)
{
string itemID = stages[currentStageIndex].requiredItemID;
if (!string.IsNullOrEmpty(itemID))
{
inventory.RemoveItem(itemID);
}
}
else if (inventory == null)
{
}
}
}