-
Notifications
You must be signed in to change notification settings - Fork 1
/
equipment.py
279 lines (205 loc) · 7.01 KB
/
equipment.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
from abc import ABC, abstractmethod
from typing import List, Union, Dict
from dataclasses import dataclass, field
from pathlib import Path
import json
script_path = Path(__file__).resolve()
data_path = script_path.parent / "data"
class AttackType:
pass
class StabAttackType(AttackType):
pass
class SlashAttackType(AttackType):
pass
class CrushAttackType(AttackType):
pass
class RangeAttackType(AttackType):
pass
class MagicAttackType(AttackType):
pass
class WeaponStyle:
pass
class AccurateMeleeStyle(WeaponStyle):
pass
class AggressiveStyle(WeaponStyle):
pass
class DefensiveStyle(WeaponStyle):
pass
class ControlledStyle(WeaponStyle):
pass
class AccurateRangeStyle(WeaponStyle):
pass
class RapidStyle(WeaponStyle):
pass
class LongrangeStyle(WeaponStyle):
pass
class ShortFuseStyle(WeaponStyle):
pass
class MediumFuseStyle(WeaponStyle):
pass
class LongFuseStyle(WeaponStyle):
pass
class AccurateMagicStyle(WeaponStyle):
pass
class DefensiveAutocastStyle(WeaponStyle):
pass
class AutocastStyle(WeaponStyle):
pass
class WeaponStance:
def __init__(self, attack_type: AttackType, weapon_style: WeaponStyle):
self.attack_type = attack_type
self.weapon_style = weapon_style
@dataclass
class StrengthBonuses:
melee_strength: int
range_strength: int
magic_strength: int
@dataclass
class AttackBonuses:
stab: int
slash: int
crush: int
magic: int
ranged: int
@dataclass
class DefenceBonuses:
stab: int
slash: int
crush: int
magic: int
ranged: int
@dataclass
class Gear(ABC):
name: str
id: int
slot: str
speed: int
category: str
prayer_bonus: int
strength_bonuses: StrengthBonuses
attack_bonuses: AttackBonuses
defence_bonuses: DefenceBonuses
@dataclass
class Weapon(Gear):
name: str
id: int
slot: str
speed: int
category: str
prayer_bonus: int
is_2h: bool
current_weapon_stance: WeaponStance = field(init=False)
available_weapon_stances: Dict[str, WeaponStance]
strength_bonuses: StrengthBonuses
attack_bonuses: AttackBonuses
defence_bonuses: DefenceBonuses
def __post_init__(self):
first_stance_key = next(iter(self.available_weapon_stances))
self.current_weapon_stance = self.available_weapon_stances[first_stance_key]
def select_stance(self, stance_name):
selected_stance = self.available_weapon_stances.get(stance_name)
if selected_stance:
self.current_weapon_stance = selected_stance
print(f"Selected stance is now: {self.current_weapon_stance}")
return
else:
print(f"{selected_stance} is not an option for this weapon")
return
@dataclass
class Armour(Gear):
name: str
id: int
slot: str
speed: int
category: str
prayer_bonus: int
strength_bonuses: StrengthBonuses
attack_bonuses: AttackBonuses
defence_bonuses: DefenceBonuses
class StanceOptionsFactory:
@staticmethod
def create_stance_options(weapon_category):
stance_options = {}
for combat_style, options in weapon_category.items():
match options["attack_type"]:
case "stab":
attack_type = StabAttackType()
case "slash":
attack_type = SlashAttackType()
case "crush":
attack_type = CrushAttackType()
case "ranged":
attack_type = RangeAttackType()
case "magic":
attack_type = MagicAttackType()
match options["weapon_style"]:
case "accurate":
if isinstance(attack_type, RangeAttackType):
weapon_style = AccurateRangeStyle()
elif isinstance(attack_type, MagicAttackType):
weapon_style = AccurateMagicStyle()
else:
weapon_style = AccurateMeleeStyle()
case "aggressive":
weapon_style = AggressiveStyle()
case "defensive":
weapon_style = DefensiveStyle()
case "controlled":
weapon_style = ControlledStyle()
case "rapid":
weapon_style = RapidStyle()
case "longrange":
weapon_style = LongrangeStyle()
case "short_fuse":
weapon_style = ShortFuseStyle()
case "medium_fuse":
weapon_style = MediumFuseStyle()
case "long_fuse":
weapon_style = LongFuseStyle()
case "defensive_autocast":
weapon_style = DefensiveAutocastStyle()
case "autocast":
weapon_style = AutocastStyle()
stance_option = WeaponStance(attack_type, weapon_style)
stance_options.update({combat_style: stance_option})
return stance_options
class WeaponFactory:
@staticmethod
def create_weapon(weapon_name, weapons_data, weapon_types):
if weapon_name in weapons_data:
weapon_data = weapons_data[weapon_name]
weapon_category = weapon_data.get("category")
if weapon_category in weapon_types:
available_weapon_stances = StanceOptionsFactory.create_stance_options(
weapon_types[weapon_category]
)
weapon_strength_bonuses = StrengthBonuses(**weapon_data["bonuses"])
weapon_attack_bonuses = AttackBonuses(**weapon_data["offensive"])
weapon_defence_bonuses = DefenceBonuses(**weapon_data["defensive"])
weapon = Weapon(
strength_bonuses=weapon_strength_bonuses,
attack_bonuses=weapon_attack_bonuses,
defence_bonuses=weapon_defence_bonuses,
available_weapon_stances=available_weapon_stances,
id=weapon_data["id"],
name=weapon_data["name"],
slot=weapon_data["slot"],
speed=weapon_data["speed"],
category=weapon_category,
prayer_bonus=weapon_data["prayer_bonus"],
is_2h=weapon_data["is_2h"],
)
return weapon
else:
raise ValueError(f"Weapon category {weapon_category} not found in data")
else:
raise ValueError(f"Weapon {weapon_name} not found in data")
if __name__ == "__main__":
weapon_stats = json.loads((data_path / "equipment_stats.json").read_text())
weapon_types = json.loads((data_path / "weapon_types.json").read_text())
ags = WeaponFactory.create_weapon("Armadyl godsword", weapon_stats, weapon_types)
print(vars(ags))
print(ags.current_weapon_stance.weapon_style)
ags.select_stance("slash")
print(ags.current_weapon_stance.weapon_style)
print(vars(ags))