restructure script folder

This commit is contained in:
2026-03-07 14:42:14 -06:00
parent 94fa81168d
commit 1e08b70e2c
33 changed files with 40 additions and 17 deletions
@@ -0,0 +1,65 @@
using UnityEngine;
public class Quest : MonoBehaviour
{
public bool hasStarted = false;
public bool hasCompleted = false;
public string[] askText; // ask the player to complete the task
public string[] duringText; // what to say to the player when the task is complete
public string[] completionText; // what to say to the player upon completion
public int questID = 0; // connects the quest to the registry, which gives us conditions
public void Start()
{
// check if we've completed the quest
hasCompleted = QuestRegistry.Instance.CompletedQuests.Contains(questID);
hasStarted = QuestRegistry.Instance.ActiveQuests.Contains(questID);
// this shouldn't be possible, but if the save is changed manually it could happen
if (hasStarted && hasCompleted)
{
hasStarted = false;
// make sure only one reference exists
QuestRegistry.Instance.CompletedQuests.RemoveAll(id => id == questID);
QuestRegistry.Instance.CompletedQuests.Add(questID);
QuestRegistry.Instance.ActiveQuests.RemoveAll(id => id == questID);
SaveSystem.Save();
}
}
public void StartQuest()
{
hasStarted = true;
QuestRegistry.Instance.ActiveQuests.Add(questID);
SaveSystem.Save();
}
public bool CheckComplete()
{
QuestBool[] conditionList = QuestRegistry.Instance.QuestBoolMap[questID];
if (conditionList != null)
{
foreach (QuestBool condition in conditionList)
{
// try each condition until we hit a false
if (!condition.getValue())
return false;
}
// otherwise return true and mark quest complete
QuestRegistry.Instance.ActiveQuests.Remove(questID);
QuestRegistry.Instance.CompletedQuests.Add(questID);
SaveSystem.Save();
hasCompleted = true;
return true;
}
return false;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2db38219bed101e44b995a3611e4cedd
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class QuestRegistry : MonoBehaviour
{
// This will keep a register of all quest data and status
public static QuestRegistry Instance { get; private set; }
public Dictionary<int, QuestBool[]> QuestBoolMap;
public List<int> CompletedQuests;
public List<int> ActiveQuests;
private void Awake()
{
// If there is an instance, and it's not me, delete myself.
if (Instance != null && Instance != this)
{
Destroy(this);
}
else
{
Instance = this;
Instance.QuestBoolMap = PopulateQuestData();
PopulateQuestData();
DontDestroyOnLoad(gameObject);
}
}
private Dictionary<int, QuestBool[]> PopulateQuestData()
{
Dictionary<int, QuestBool[]> questBoolMap = new Dictionary<int, QuestBool[]>();
// Quest Bool Structure: QID<QuestID>_<Bool Number>_<descriptiveName>
// Example: QID11_4_landBurgerGreaseCleared
#region 1 - Sam's Plea
QuestBool[] QID1_List = new QuestBool[2];
// QID1_1_hasEnoughStarshards
QID1_List[0] = new QuestBool(() =>
{
return GameManager.Instance.Inventory.GetItemQuantity(ItemIdEnum.STAR_SHARD) > 2;
});
// QID1_2_hasHelpedSam
QID1_List[1] = new QuestBool(() =>
{
return GameManager.Instance.Storybools.hasHelpedSam;
});
questBoolMap.Add(1, QID1_List);
#endregion
return questBoolMap;
}
// Save completed quests to disk
public void SaveQuestData(ref QuestSaveData data)
{
data.ActiveQuests = Instance.ActiveQuests;
data.CompletedQuests = Instance.CompletedQuests;
}
public void LoadQuestData(QuestSaveData data)
{
if (data.ActiveQuests != null)
{
Instance.ActiveQuests = data.ActiveQuests;
}
else
{
Instance.ActiveQuests = new List<int>();
}
if (data.CompletedQuests != null)
{
Instance.CompletedQuests = data.CompletedQuests;
}
else
{
Instance.CompletedQuests = new List<int>();
}
}
}
public class QuestBool
{
// This let's us define complex behavior for quests. We can also store
// raw booleans for this if we have story beats we want to keep track of.
public Func<bool> getValue;
public QuestBool(Func<bool> getValue)
{
this.getValue = getValue;
}
}
[System.Serializable]
public struct QuestSaveData
{
public List<int> CompletedQuests;
public List<int> ActiveQuests;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf9658f7202522245b3ac80235b98b50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -2
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
using UnityEngine;
[System.Serializable]
public class Storybools
{
// not sure how we'll organize this yet, but right now lets do it by quest
#region QID1
public bool hasHelpedSam = false;
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 70e96df6062507943b1f7ae7df89dee5