QuestChartDemo.cs
7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using VIDE_Data;
using UnityEngine.UI;
public class QuestChartDemo : MonoBehaviour
{
public static VIDE_Assign assigned;
public GameObject questChartContainer;
public GameObject ovGameObject;
public GameObject peGameObject;
//Tasks
static int totalInteractions = 12;
static int cylinderGuyTotal = 9;
static List<string> interactedWith = new List<string>();
static List<int> cylinderGuyInteractions = new List<int>();
void Awake()
{
//Will load saved progress in PlayerPrefs
LoadProgress();
}
void OnEnable()
{
assigned = GetComponent<VIDE_Assign>();
}
void Update()
{
//This is checking if the QuestChart UI Manager is
if (gameObject != null)
if (questChartContainer.activeSelf)
{
if (Input.GetKeyDown(KeyCode.X))
{
PlayerPrefs.DeleteAll();
if (System.IO.Directory.Exists(Application.dataPath + "/VIDE/saves"))
{
System.IO.Directory.Delete(Application.dataPath + "/VIDE/saves", true);
#if UNITY_EDITOR
UnityEditor.AssetDatabase.Refresh();
#endif
}
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
}
}
}
// Will Use the SetVisible method to switch the visibility of a comment
// When a comment is not visible, its content will not be included in the nodeData arrays
// The method will also add info to an ExtraVariables key to mark the completion of a quest
public static void SetQuest(int quest, bool visible)
{
VD.SetVisible(assigned.assignedDialogue, 0, quest, visible);
Dictionary<string, object> newEV = VD.GetExtraVariables(assigned.assignedDialogue, 1);
newEV["complete"] += "[" + quest.ToString() + "]";
VD.SetExtraVariables(assigned.assignedDialogue, 1, newEV);
}
//Will start and end the assigned dialogue
public void Interact()
{
if (!questChartContainer.activeSelf)
{
questChartContainer.SetActive(true);
VD.NodeData nd = VD.BeginDialogue(assigned);
LoadChart(nd);
}
else
{
for (int i = 0; i < peGameObject.transform.parent.childCount; i++)
if (i != 0) Destroy(peGameObject.transform.parent.GetChild(i).gameObject);
for (int i = 0; i < ovGameObject.transform.parent.childCount; i++)
if (i != 0) Destroy(ovGameObject.transform.parent.GetChild(i).gameObject);
questChartContainer.SetActive(false);
VD.EndDialogue();
}
}
// Uses both NodeData and local variables to populate the Quest UI
public void LoadChart(VD.NodeData data)
{
//Pending quests
for (int i = 0; i < data.comments.Length; i++)
{
GameObject pe = (GameObject)Instantiate(peGameObject);
pe.transform.SetParent(peGameObject.transform.parent, true);
pe.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -15 - (15 * i));
pe.GetComponent<Text>().text = "~" + data.comments[i] + "~";
if (data.comments[i].Contains("Talk to")) pe.GetComponent<Text>().text += " (" + interactedWith.Count.ToString() + "/" + totalInteractions.ToString() + ")";
if (data.comments[i].Contains("CylinderGuy")) pe.GetComponent<Text>().text += " (" + cylinderGuyInteractions.Count.ToString() + "/" + cylinderGuyTotal.ToString() + ")";
pe.SetActive(true);
}
//Overview quests
VD.NodeData overviewData = VD.GetNodeData(assigned.assignedDialogue, 1, true);
for (int i = 0; i < overviewData.comments.Length; i++)
{
string completeKey = (string)overviewData.extraVars["complete"];
GameObject ov = (GameObject)Instantiate(ovGameObject);
if (completeKey.Contains("[" + i.ToString() + "]"))
{
ov.GetComponent<Text>().text = overviewData.comments[i] + " [✓]";
ov.GetComponent<Text>().color = new Color(1, 1, 1, 0.4f);
}
else
{
ov.GetComponent<Text>().text = overviewData.comments[i];
}
ov.transform.SetParent(ovGameObject.transform.parent, true);
ov.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -15 - (15 * i));
ov.SetActive(true);
}
}
//Set CylinderGuy quest
public static void CylinderGuyAddInteraction(int index)
{
if (!cylinderGuyInteractions.Contains(index))
cylinderGuyInteractions.Add(index);
}
//Check some of the Quests completion
public static void CheckTaskCompletion(VD.NodeData data)
{
if (VD.assigned == null) return;
if (!interactedWith.Contains(VD.assigned.gameObject.name))
interactedWith.Add(VD.assigned.gameObject.name);
//Check
// 0 Talk to Everyone
// 1 Listen to CylinderGuy
// 2 Get all items from Crazy Cap
// 3 Threaten Charlie
if (interactedWith.Count == totalInteractions) SetQuest(0, false);
if (cylinderGuyInteractions.Count == cylinderGuyTotal) SetQuest(1, false);
}
//Set Charlie quest
public void SetCharlieQuestComplete()
{
SetQuest(3, false);
}
public static void SaveProgress()
{
var player = GameObject.Find("Player").GetComponent<VIDEDemoPlayer>();
List<string> items = player.demo_ItemInventory;
PlayerPrefs.SetInt("interactedWith", interactedWith.Count);
PlayerPrefs.SetInt("cylinderGuyInteractions", cylinderGuyInteractions.Count);
PlayerPrefs.SetInt("example_ItemInventory", items.Count);
for (int i = 0; i < interactedWith.Count; i++)
{
PlayerPrefs.SetString("interWith" + i.ToString(), interactedWith[i]);
}
for (int i = 0; i < cylinderGuyInteractions.Count; i++)
{
PlayerPrefs.SetInt("cylGuyInt" + i.ToString(), cylinderGuyInteractions[i]);
}
for (int i = 0; i < items.Count; i++)
{
PlayerPrefs.SetString("item" + i.ToString(), items[i]);
}
}
public static void LoadProgress()
{
var player = GameObject.Find("Player").GetComponent<VIDEDemoPlayer>();
if (!PlayerPrefs.HasKey("interactedWith")) return;
List<string> items = new List<string>(); ;
interactedWith = new List<string>();
cylinderGuyInteractions = new List<int>();
for (int i = 0; i < PlayerPrefs.GetInt("interactedWith"); i++)
{
interactedWith.Add(PlayerPrefs.GetString("interWith" + i.ToString()));
}
for (int i = 0; i < PlayerPrefs.GetInt("cylinderGuyInteractions"); i++)
{
cylinderGuyInteractions.Add(PlayerPrefs.GetInt("cylGuyInt" + i.ToString()));
}
for (int i = 0; i < PlayerPrefs.GetInt("example_ItemInventory"); i++)
{
items.Add(PlayerPrefs.GetString("item" + i.ToString()));
}
player.demo_ItemInventory = items;
}
}