90 lines
3.8 KiB
C#
90 lines
3.8 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class NpcInteraction {
|
|||
|
|
public DialogueID dialogueID;
|
|||
|
|
public bool showShop;
|
|||
|
|
|
|||
|
|
public NpcInteraction(DialogueID dialogueID,
|
|||
|
|
bool showAvailableQuests = false,
|
|||
|
|
bool showShop = false) {
|
|||
|
|
this.dialogueID = dialogueID;
|
|||
|
|
this.showShop = showShop;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public abstract class NpcBehavior {
|
|||
|
|
public NpcID npcID;
|
|||
|
|
public abstract NpcInteraction Interact();
|
|||
|
|
public abstract NpcInteraction QuestInteract(QuestID questID);
|
|||
|
|
public abstract NpcInteraction QuestInteractAll();
|
|||
|
|
public abstract NpcInteraction Cancel(); // Closing out from the Availble Quests window.
|
|||
|
|
|
|||
|
|
public Hashtable questAcceptDialogueMap; // Hashtable<QuestID, DialogueID>
|
|||
|
|
public Hashtable questCompleteDialogueMap; // Hashtable<QuestID, DialogueID>
|
|||
|
|
public DialogueID showQuestsDialogueID;
|
|||
|
|
public DialogueID cancelDialogueID;
|
|||
|
|
public DialogueID defaultDialogueID;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class NpcBehavior_Generic : NpcBehavior {
|
|||
|
|
public NpcBehavior_Generic(Hashtable questAcceptDialogueMap, Hashtable questCompleteDialogueMap, DialogueID showQuestsDialogueID, DialogueID cancelDialogueID, DialogueID defaultDialogueID) {
|
|||
|
|
this.questAcceptDialogueMap = questAcceptDialogueMap;
|
|||
|
|
this.questCompleteDialogueMap = questCompleteDialogueMap;
|
|||
|
|
this.showQuestsDialogueID = showQuestsDialogueID;
|
|||
|
|
this.cancelDialogueID = cancelDialogueID;
|
|||
|
|
this.defaultDialogueID = defaultDialogueID;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override NpcInteraction Interact() {
|
|||
|
|
return new NpcInteraction(defaultDialogueID);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override NpcInteraction QuestInteract(QuestID questID) {
|
|||
|
|
State.state.quests.RefreshAvailableQuests();
|
|||
|
|
|
|||
|
|
// If accepting the quest works, yield the quest acceptance dialogue for that quest.
|
|||
|
|
if (((NpcQuestProgress)State.state.npcState.npcQuestMap[npcID]).acceptingQuests.Contains(questID) &&
|
|||
|
|
((Npc)NpcInfo.npcs[npcID]).AcceptQuest(questID)) {
|
|||
|
|
return new NpcInteraction((DialogueID)questAcceptDialogueMap[questID]);
|
|||
|
|
}
|
|||
|
|
// If completing the quest works, yield the quest completion dialogue for that quest.
|
|||
|
|
if (((NpcQuestProgress)State.state.npcState.npcQuestMap[npcID]).inProgressQuests.Contains(questID) &&
|
|||
|
|
((Npc)NpcInfo.npcs[npcID]).CompleteQuest(questID)) {
|
|||
|
|
return new NpcInteraction((DialogueID)questCompleteDialogueMap[questID]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return new NpcInteraction(defaultDialogueID);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override NpcInteraction QuestInteractAll() {
|
|||
|
|
State.state.quests.RefreshAvailableQuests();
|
|||
|
|
|
|||
|
|
// Check completable quests
|
|||
|
|
HashSet<QuestID> inProgressQuests =
|
|||
|
|
((NpcQuestProgress)State.state.npcState.npcQuestMap[npcID]).inProgressQuests;
|
|||
|
|
foreach (QuestID questID in inProgressQuests) {
|
|||
|
|
// If completing the quest works, yield the quest completion dialogue for that quest.
|
|||
|
|
if (((Npc)NpcInfo.npcs[npcID]).CompleteQuest(questID)) {
|
|||
|
|
return new NpcInteraction((DialogueID)questCompleteDialogueMap[questID]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// If quests are available, show available quests
|
|||
|
|
HashSet<QuestID> acceptingQuests =
|
|||
|
|
((NpcQuestProgress)State.state.npcState.npcQuestMap[npcID]).acceptingQuests;
|
|||
|
|
foreach (QuestID questID in acceptingQuests) {
|
|||
|
|
// If accepting the quest works, yield the quest acceptance dialogue for that quest.
|
|||
|
|
if (((Npc)NpcInfo.npcs[npcID]).AcceptQuest(questID)) {
|
|||
|
|
return new NpcInteraction((DialogueID)questAcceptDialogueMap[questID]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return new NpcInteraction(defaultDialogueID);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override NpcInteraction Cancel() {
|
|||
|
|
return new NpcInteraction(cancelDialogueID);
|
|||
|
|
}
|
|||
|
|
}
|