Elin Decompiled Documentation EA 23.344.1 Nightly
Loading...
Searching...
No Matches
QuestManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Newtonsoft.Json;
4using UnityEngine;
5
6public class QuestManager : EClass
7{
8 public const int MaxRandomQuest = 5;
9
10 [JsonProperty]
11 public List<Quest> list = new List<Quest>();
12
13 [JsonProperty]
14 public List<Quest> globalList = new List<Quest>();
15
16 [JsonProperty]
17 public HashSet<string> completedIDs = new HashSet<string>();
18
19 [JsonProperty]
20 public HashSet<string> completedTypes = new HashSet<string>();
21
22 [JsonProperty]
23 public int uid;
24
25 public QuestMain Main => Get<QuestMain>();
26
27 public new QuestHome Home => Get<QuestHome>();
28
29 public Quest Add(string id, string idGlobalChara = null)
30 {
31 Quest quest = Quest.Create(id);
32 if (idGlobalChara.IsEmpty())
33 {
34 idGlobalChara = quest.source.drama[0];
35 }
36 quest.SetClient(EClass.game.cards.globalCharas.Find(idGlobalChara), assignQuest: false);
37 EClass.game.quests.globalList.Add(quest);
38 return quest;
39 }
40
41 public Quest Start(string id, string idGlobalChara)
42 {
43 Quest q = Quest.Create(id).SetClient(EClass.game.cards.globalCharas.Find(idGlobalChara), assignQuest: false);
44 return Start(q);
45 }
46
47 public Quest Start(string id, Chara c = null, bool assignQuest = true)
48 {
49 return Start(Quest.Create(id).SetClient(c, assignQuest));
50 }
51
52 public Quest Start(Quest q)
53 {
54 list.Insert(0, q);
55 q.Start();
57 {
58 q.UpdateJournal();
60 {
62 }
63 }
64 return q;
65 }
66
67 public void Remove(Quest q)
68 {
69 if (!list.Remove(q))
70 {
71 Debug.Log("exception: Failed to remove quest:" + q?.ToString() + "/" + q.uid + "/" + q.source.id + "/" + q.deadline + "/" + q.Hours);
72 q = Get(q.uid);
73 Debug.Log(q);
74 if (q != null && q.IsRandomQuest)
75 {
76 list.Remove(q);
77 }
78 }
79 }
80
81 public void RemoveGlobal(Quest q)
82 {
83 globalList.Remove(q);
84 }
85
86 public void RemoveAll(Chara c)
87 {
88 foreach (Quest item in list.Where((Quest a) => a.chara == c).ToList())
89 {
90 Remove(item);
91 }
92 foreach (Quest item2 in globalList.Where((Quest a) => a.chara == c).ToList())
93 {
94 RemoveGlobal(item2);
95 }
96 }
97
98 public void Complete(Quest q)
99 {
100 q.Complete();
101 }
102
103 public bool OnShowDialog(Chara c)
104 {
105 foreach (Quest item in list)
106 {
107 if (!item.person.hasChara && item is QuestExploration && item.phase == 5 && c.id == "ashland")
108 {
109 EClass.ui.Say("Bug: Quest Ash not found");
110 item.person.uidChara = c.uid;
111 }
112 if (item.person.chara == c && (item.CanUpdateOnTalk(c) || (item.CanAutoAdvance && EClass.debug.autoAdvanceQuest)))
113 {
114 return item.UpdateOnTalk();
115 }
116 }
117 return false;
118 }
119
120 public void OnAdvanceHour()
121 {
122 list.ForeachReverse(delegate(Quest q)
123 {
124 if (q.IsExpired)
125 {
126 Msg.Say("questExpired", q.GetTitle());
127 q.Fail();
128 }
129 });
130 }
131
132 public bool IsCompleted(string id)
133 {
134 return completedIDs.Contains(id);
135 }
136
137 public bool IsCompleted<T>() where T : Quest
138 {
139 return completedTypes.Contains(typeof(T).ToString());
140 }
141
142 public bool IsAdded(string id)
143 {
144 if (IsStarted(id) || GetPhase(id) == 999)
145 {
146 return true;
147 }
148 foreach (Quest global in globalList)
149 {
150 if (global.id == id)
151 {
152 return true;
153 }
154 }
155 return false;
156 }
157
158 public bool IsAdded<T>() where T : Quest
159 {
160 if (IsStarted<T>() || GetPhase<T>() == 999)
161 {
162 return true;
163 }
164 foreach (Quest global in globalList)
165 {
166 if (global is T)
167 {
168 return true;
169 }
170 }
171 return false;
172 }
173
174 public bool IsStarted<T>() where T : Quest
175 {
176 return GetPhase<T>() != -1;
177 }
178
179 public bool IsStarted(string id)
180 {
181 return GetPhase(id) != -1;
182 }
183
184 public int GetPhase<T>() where T : Quest
185 {
186 if (completedTypes.Contains(typeof(T).ToString()))
187 {
188 return 999;
189 }
190 foreach (Quest item in list)
191 {
192 if (item is T)
193 {
194 return item.phase;
195 }
196 }
197 return -1;
198 }
199
200 public int GetPhase(string id)
201 {
202 if (IsCompleted(id))
203 {
204 return 999;
205 }
206 foreach (Quest item in list)
207 {
208 if (item.id == id)
209 {
210 return item.phase;
211 }
212 }
213 return -1;
214 }
215
216 public T Get<T>() where T : Quest
217 {
218 foreach (Quest item in list)
219 {
220 if (item is T)
221 {
222 return item as T;
223 }
224 }
225 return null;
226 }
227
228 public Quest Get(string id)
229 {
230 foreach (Quest item in list)
231 {
232 if (item.GetType().ToString() == id || item.id == id)
233 {
234 return item;
235 }
236 }
237 return null;
238 }
239
240 public Quest Get(int uid)
241 {
242 foreach (Quest item in list)
243 {
244 if (item.uid == uid)
245 {
246 return item;
247 }
248 }
249 return null;
250 }
251
252 public Quest GetGlobal(string id)
253 {
254 foreach (Quest global in globalList)
255 {
256 if (global.GetType().ToString() == id || global.id == id)
257 {
258 return global;
259 }
260 }
261 return null;
262 }
263
264 public int CountNew()
265 {
266 int num = 0;
267 foreach (Quest item in list)
268 {
269 if (item.isNew)
270 {
271 num++;
272 }
273 }
274 return num;
275 }
276
277 public int CountRandomQuest()
278 {
279 int num = 0;
280 foreach (Quest item in list)
281 {
282 if (item is QuestRandom)
283 {
284 num++;
285 }
286 }
287 return num;
288 }
289
290 public void UpdateJournal()
291 {
292 SE.WriteJournal();
293 Msg.Say("journalUpdate");
294 }
295
296 public bool IsDeliverTarget(Chara c)
297 {
298 foreach (Quest item in list)
299 {
300 if (item.IsDeliverTarget(c))
301 {
302 return true;
303 }
304 }
305 return false;
306 }
307
308 public void AddQuestAsh()
309 {
310 Chara c = EClass.game.cards.globalCharas.Find("ashland");
311 QuestCraft obj = Quest.Create("ash1") as QuestCraft;
312 obj.SetClient(c);
313 obj.req1.Add(new QuestCraft.Req("rock", 1));
314 obj.req1.Add(new QuestCraft.Req("branch", 1));
315 obj.req2.Add(new QuestCraft.Req("axe", 1));
316 }
317
318 public void AddQuestFiama()
319 {
320 Chara c = EClass.game.cards.globalCharas.Find("fiama");
321 QuestCraft obj = Quest.Create("fiama1") as QuestCraft;
322 obj.SetClient(c);
323 obj.req1.Add(new QuestCraft.Req("crim", 3));
324 obj.req2.Add(new QuestCraft.Req("hotcrim", 1));
325 }
326
327 public bool HasFarAwayEscort(bool execute = false)
328 {
329 bool has = false;
331 {
332 return false;
333 }
334 EClass._map.charas.ForeachReverse(delegate(Chara m)
335 {
336 if (m.IsEscorted() && EClass.pc.Dist(m) >= 5)
337 {
338 has = true;
339 if (execute)
340 {
341 m.Destroy();
342 }
343 }
344 });
345 if (has && execute)
346 {
347 OnEnterZone();
348 }
349 return has;
350 }
351
352 public void OnEnterZone()
353 {
354 list.ForeachReverse(delegate(Quest q)
355 {
356 q.OnEnterZone();
357 });
358 }
359}
Chara Find(string id)
Definition: CardManager.cs:20
GlobalCharaList globalCharas
Definition: CardManager.cs:46
int Dist(Card c)
Definition: Card.cs:8204
Definition: Chara.cs:10
bool IsEscorted()
Definition: Chara.cs:2627
bool autoAdvanceQuest
Definition: CoreDebug.cs:227
bool IsGameStarted
Definition: Core.cs:87
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static Core core
Definition: EClass.cs:7
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
static UI ui
Definition: EClass.cs:17
CardManager cards
Definition: Game.cs:156
QuestManager quests
Definition: Game.cs:183
List< Chara > charas
Definition: Map.cs:84
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
bool questTracker
Definition: Player.cs:1059
List< Req > req1
Definition: QuestCraft.cs:27
List< Req > req2
Definition: QuestCraft.cs:30
void OnAdvanceHour()
HashSet< string > completedIDs
Definition: QuestManager.cs:17
List< Quest > list
Definition: QuestManager.cs:11
bool IsAdded(string id)
int GetPhase< T >()
bool OnShowDialog(Chara c)
void AddQuestFiama()
bool IsStarted< T >()
Quest Get(int uid)
Quest Start(Quest q)
Definition: QuestManager.cs:52
Quest Start(string id, Chara c=null, bool assignQuest=true)
Definition: QuestManager.cs:47
Quest Add(string id, string idGlobalChara=null)
Definition: QuestManager.cs:29
bool IsStarted(string id)
void RemoveGlobal(Quest q)
Definition: QuestManager.cs:81
int GetPhase(string id)
int CountRandomQuest()
new QuestHome Home
Definition: QuestManager.cs:27
bool IsAdded< T >()
QuestMain Main
Definition: QuestManager.cs:25
void Complete(Quest q)
Definition: QuestManager.cs:98
void Remove(Quest q)
Definition: QuestManager.cs:67
void AddQuestAsh()
const int MaxRandomQuest
Definition: QuestManager.cs:8
bool IsCompleted(string id)
void UpdateJournal()
bool IsCompleted< T >()
Quest Start(string id, string idGlobalChara)
Definition: QuestManager.cs:41
void OnEnterZone()
List< Quest > globalList
Definition: QuestManager.cs:14
bool HasFarAwayEscort(bool execute=false)
HashSet< string > completedTypes
Definition: QuestManager.cs:20
Quest Get(string id)
bool IsDeliverTarget(Chara c)
Quest GetGlobal(string id)
void RemoveAll(Chara c)
Definition: QuestManager.cs:86
Definition: Quest.cs:7
virtual bool IsRandomQuest
Definition: Quest.cs:237
bool IsExpired
Definition: Quest.cs:112
int uid
Definition: Quest.cs:34
int Hours
Definition: Quest.cs:124
virtual void OnEnterZone()
Definition: Quest.cs:418
int deadline
Definition: Quest.cs:46
static Quest Create(string _id, string _idPerson=null, Chara c=null, bool assignQuest=true)
Definition: Quest.cs:241
void Start()
Definition: Quest.cs:405
Chara chara
Definition: Quest.cs:105
string id
Definition: Quest.cs:31
Quest SetClient(Chara c, bool assignQuest=true)
Definition: Quest.cs:380
void UpdateJournal()
Definition: Quest.cs:690
void Complete()
Definition: Quest.cs:473
virtual SourceQuest.Row source
Definition: Quest.cs:107
virtual bool HasLaw
Definition: Zone.cs:236
bool IsInstance
Definition: Zone.cs:496
virtual bool IsTown
Definition: Zone.cs:230
bool IsPCFaction
Definition: Zone.cs:480