restructure script folder
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Talkable : Interactable
|
||||
{
|
||||
// this is a character or object that will talk upon interaction
|
||||
public Dialogue defaultDialogue;
|
||||
public GameObject talkIndicator;
|
||||
|
||||
public Quest[] quests;
|
||||
Dialogue currentDialogue;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
talkIndicator.SetActive(false);
|
||||
}
|
||||
|
||||
void DetermineDialogue()
|
||||
{
|
||||
// based on if we have any open quests and where we're at in the quest,
|
||||
// determine what dialogue to show
|
||||
Quest currentQuest = null;
|
||||
|
||||
// Grab the first ACTIVE quest
|
||||
// If none active, grab the first AVAILABLE quest
|
||||
// If none available, revert to default dialogue
|
||||
if (quests.Length > 0)
|
||||
{
|
||||
// check for ACTIVE quests
|
||||
foreach (Quest q in quests)
|
||||
{
|
||||
if (q.hasStarted && !q.hasCompleted)
|
||||
{
|
||||
currentQuest = q;
|
||||
}
|
||||
}
|
||||
// check for AVAILABLE quests
|
||||
if (currentQuest == null)
|
||||
{
|
||||
foreach (Quest q in quests)
|
||||
{
|
||||
if (!q.hasStarted && !q.hasCompleted)
|
||||
{
|
||||
currentQuest = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// revert to default if no suitable quest found
|
||||
if (currentQuest == null)
|
||||
{
|
||||
currentDialogue = defaultDialogue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentQuest.hasStarted)
|
||||
currentQuest.CheckComplete(); // don't check for completion before asking player for help
|
||||
|
||||
currentDialogue = new Dialogue();
|
||||
currentDialogue.charName = defaultDialogue.charName;
|
||||
|
||||
// set up dialogue based on quest
|
||||
if (currentQuest.hasStarted && !currentQuest.hasCompleted)
|
||||
{
|
||||
currentDialogue.sentences = currentQuest.duringText;
|
||||
}
|
||||
else if (!currentQuest.hasStarted && !currentQuest.hasCompleted)
|
||||
{
|
||||
currentDialogue.sentences = currentQuest.askText;
|
||||
currentQuest.StartQuest();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentDialogue.sentences = currentQuest.completionText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
if (currentDialogue == null || !currentDialogue.isActive)
|
||||
{
|
||||
DetermineDialogue();
|
||||
GameManager.Instance.DialogueManager.StartDialogue(currentDialogue);
|
||||
}
|
||||
else
|
||||
GameManager.Instance.DialogueManager.DisplayNextSentence();
|
||||
|
||||
talkIndicator.SetActive(false);
|
||||
}
|
||||
|
||||
public override void MoveInsideRange()
|
||||
{
|
||||
talkIndicator.SetActive(true);
|
||||
}
|
||||
|
||||
public override void MoveOutsideRange()
|
||||
{
|
||||
GameManager.Instance.DialogueManager.EndDialogue();
|
||||
talkIndicator.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user