forked from Matthew2000/OLD_Elementals-The-Shadow-Wars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuestClass.py
241 lines (203 loc) · 8.5 KB
/
QuestClass.py
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import json
import os
from enum import Enum
import Items
from BaseClasses import NpcClass
from Globals import *
class QuestType(Enum):
Collect = 1
Assassinate = 2
Kill = 3
Craft = 4
Talk = 5
class Quest:
all = []
names = []
def __init__(self, name: str, quest_type: QuestType, giver: str, coin_reward: int, exp_reward: float,
object_reward: Items.Item, description: str, repeatable: bool):
self.name = name
self.type = quest_type
self.giver = giver
self.coin_reward = coin_reward
self.exp_reward = exp_reward
self.object_reward = object_reward
self.description = description
self.completed = False
self.repeatable = repeatable
@classmethod
def dictionary(cls, quest: dict):
name = quest["name"]
quest_type = quest["type"]
giver = quest["giver"]
coin_reward = quest["coin_reward"]
exp_reward = quest["exp_reward"]
object_reward = quest["object_reward"]
description = quest["description"]
repeatable = quest["repeatable"]
new_quest = Quest(name, quest_type, giver, coin_reward, exp_reward, object_reward, description, repeatable)
return new_quest
def update_quest(self, player, npc):
pass
def reset(self):
pass
class CollectQuest(Quest):
def __init__(self, name: str, giver: str,
coin_reward: int, exp_reward: float, object_reward: Items.Item,
description: str, item_to_collect: Items.Item, amount: int, repeatable: bool):
super().__init__(name, QuestType.Collect, giver, coin_reward, exp_reward, object_reward, description,
repeatable)
self.item_to_collect = item_to_collect
self.amount = amount
if self.name not in Quest.names:
Quest.names.append(self.name)
Quest.all.append(self)
@classmethod
def dictionary(cls, quest: dict):
temp = super().dictionary(quest)
item_to_collect = quest["item_to_collect"]
amount = quest["amount"]
new_quest = CollectQuest(temp.name, temp.giver, temp.coin_reward, temp.exp_reward,
temp.object_reward, temp.description, item_to_collect, amount, temp.repeatable)
return new_quest
def update_quest(self, player):
if self.item_to_collect in player.inventory[0]:
index = player.inventory[0].index(self.item_to_collect)
if player.inventory[1][index] == self.amount:
self.completed = True
def reset(self):
self.completed = False
class AssassinateQuest(Quest):
def __init__(self, name: str, giver: str,
coin_reward: int, exp_reward: float, object_reward: Items.Item,
description: str, target: NpcClass, repeatable: bool):
super().__init__(name, QuestType.Assassinate, giver, coin_reward, exp_reward, object_reward, description,
repeatable)
self.target = target
if self.name not in Quest.names:
Quest.names.append(self.name)
Quest.all.append(self)
@classmethod
def dictionary(cls, quest: dict):
temp = super().dictionary(quest)
target = quest["target"]
new_quest = AssassinateQuest(temp.name, temp.giver, temp.coin_reward, temp.exp_reward,
temp.object_reward, temp.description, target, temp.repeatable)
return new_quest
def update_quest(self, npc):
if npc.name == self.target:
if npc.is_dead():
self.completed = True
def reset(self):
self.completed = False
class KillQuest(Quest):
def __init__(self, name: str, giver: str,
coin_reward: int, exp_reward: float, object_reward: Items.Item,
description: str, target: NpcClass, amount: int, repeatable: bool):
super().__init__(name, QuestType.Kill, giver, coin_reward, exp_reward, object_reward, description, repeatable)
self.target = target
self.amount = amount
self.amount_killed = 0
if self.name not in Quest.names:
Quest.names.append(self.name)
Quest.all.append(self)
@classmethod
def dictionary(cls, quest: dict):
temp = super().dictionary(quest)
target = quest["target"]
amount = quest["amount"]
new_quest = KillQuest(temp.name, temp.giver, temp.coin_reward, temp.exp_reward,
temp.object_reward, temp.description, target, amount, temp.repeatable)
return new_quest
def update_quest(self, npc):
if npc.name == self.target:
self.amount_killed += 1
if self.amount_killed >= self.amount:
if not self.completed:
DebugLog.write("\n####################\n" + self.name + " completed\n####################\n\n")
self.completed = True
def reset(self):
self.completed = False
self.amount_killed = 0
class CraftQuest(Quest):
def __init__(self, name: str, giver: str,
coin_reward: int, exp_reward: float, object_reward: Items.Item,
description: str, item: Items.Item, amount: int, repeatable: bool):
super().__init__(name, QuestType.Craft, giver, coin_reward, exp_reward, object_reward, description, repeatable)
self.item = item
self.amount = amount
if self.name not in Quest.names:
Quest.names.append(self.name)
Quest.all.append(self)
@classmethod
def dictionary(cls, quest: dict):
temp = super().dictionary(quest)
item = quest["item"]
amount = quest["amount"]
new_quest = CraftQuest(temp.name, temp.giver, temp.coin_reward, temp.exp_reward,
temp.object_reward, temp.description, item, amount, temp.repeatable)
return new_quest
def update_quest(self, player):
if self.item in player.inventory[0]:
index = player.inventory[0].index(self.item)
if player.inventory[1][index] == self.amount:
self.completed = True
def reset(self):
self.completed = False
class TalkQuest(Quest):
def __init__(self, name: str, giver: str,
coin_reward: int, exp_reward: float, object_reward: Items.Item,
description: str, person: NpcClass, topic: str, repeatable: bool):
super().__init__(name, QuestType.Talk, giver, coin_reward, exp_reward, object_reward, description, repeatable)
self.person = person
self.topic = topic
if self.name not in Quest.names:
Quest.names.append(self.name)
Quest.all.append(self)
@classmethod
def dictionary(cls, quest: dict):
temp = super().dictionary(quest)
person = quest["person"]
topic = quest["topic"]
new_quest = TalkQuest(temp.name, temp.giver, temp.coin_reward, temp.exp_reward,
temp.object_reward, temp.description, person, topic, temp.repeatable)
return new_quest
def update_quest(self, npc, topic):
if npc.name == self.person:
if topic == self.topic:
self.completed = True
def reset(self):
self.completed = False
def load_all_quests():
DebugLog.write("Quests:\n")
for file in os.listdir("./Quests"):
if file.endswith(".json"):
filename = "Quests/" + file
DebugLog.write(" " + filename + "\n")
with open(filename, 'r') as f:
quest_data = json.load(f)
f.close()
if quest_data["type"] == 1:
CollectQuest.dictionary(quest_data)
continue
if quest_data["type"] == 2:
AssassinateQuest.dictionary(quest_data)
continue
if quest_data["type"] == 3:
KillQuest.dictionary(quest_data)
continue
if quest_data["type"] == 4:
CraftQuest.dictionary(quest_data)
continue
if quest_data["type"] == 5:
TalkQuest.dictionary(quest_data)
continue
DebugLog.write("\n")
def load_quests(npc_quests):
quests = []
for quest in Quest.all:
if quest.name in npc_quests:
if quest not in quests:
DebugLog.write("Quest added: " + quest.name + "\n")
quests.append(quest)
DebugLog.write("quests loaded\n\n")
return quests