forked from alexfrostdesu/RoyalBattleofRogalique
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py
715 lines (593 loc) · 18.9 KB
/
classes.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
from events import DialogMessage, StatusMessage
from item import *
import random
import math
class Character:
_maxhp = 100
_mp = 0
_attack = 10
_exp = 0
_lvl = 1
_gold = 0
_armour = 0
_character = True
_hp_item_bonus = 0
_mp_item_bonus = 0
_attack_item_bonus = 0
_armour_item_bonus = 0
def __init__(self):
self._cls = 'Character'
self._inventory = {'Armour': None, 'Weapon': None, 'Helm': None, 'Boots': None, 'Ring': None}
self._skills = []
self._passives = {}
self._hp = self._maxhp = self.get_maxhp()
# Class getters and setters #
def get_class(self):
"""
Returns character's class
"""
return self._cls
def set_class(self, cls):
"""
Takes new value for character's class and sets it
"""
self._cls = cls
def get_character(self):
"""
Check if it is a character
"""
return self._character
# HP getters and setters #
def get_current_hp(self):
"""
Returns character's hp
"""
return self._hp
def get_maxhp(self):
"""
Returns character's maxhp
"""
return self._maxhp + self.get_hp_modifier()
def set_hp(self, hp):
"""
Takes new value for character's hp and sets it
"""
if 0 < hp <= self.get_maxhp():
self._hp = hp
elif hp < 0:
self._hp = 1
else:
self._hp = self.get_maxhp()
def get_hp_modifier(self):
"""
Returns character's hp modifier
"""
return self._hp_item_bonus
def set_hp_item_bonus(self, hp_bonus):
"""
Sets character's hp modifier
"""
self._hp_item_bonus = hp_bonus
# if charater have max hp and unequips item with bonus hp,
# current hp is recalclated
if self.get_current_hp() > self.get_maxhp():
self.set_hp(self.get_maxhp())
# MP getters and setters #
def get_mp(self):
"""
Returns character's mp
"""
return self._mp + self._mp_item_bonus
def set_mp(self, mp):
"""
Takes new value for character's mp and sets it
"""
self._mp = mp
# Gold getters and setters #
def get_gold(self):
"""
Returns character's mp
"""
return self._gold
def set_gold(self, gold):
"""
Takes new value for character's mp and sets it
"""
self._gold = gold
# Attack getters and setters #
def get_attack_stat(self):
"""
Returns character's attack stat
"""
return self._attack + self._attack_item_bonus
def get_attack(self):
"""
Returns character's attack (+-10%)
"""
return random.uniform((self._attack + self._attack_item_bonus) * 0.9, (self._attack + self._attack_item_bonus) * 1.1)
def set_attack(self, attack):
"""
Takes new value for character's attack and sets it
"""
self._attack = attack
def get_attack_modifier(self):
"""
Returns character's attack modifier
Default modifier is 1 and used for player classes
"""
return 1
# Defence getters and setters #
def get_armour(self):
"""
Returns character's armour
"""
return self._armour + self._armour_item_bonus
def set_armour(self, armour):
"""
Takes new value for character's armour and sets it
"""
self._armour = armour
def get_defence_modifier(self):
"""
Returns character's defence modifier
"""
return 1 / math.sqrt(self.get_armour()/30 + 1)
# EXP getters and setters #
def get_exp(self):
"""
Returns character's exp
"""
return self._exp
def _set_exp(self, exp):
"""
Takes new value for character's exp and sets it
Not really intended to use
Not until I fix problems with lvlup
"""
self._exp = exp
def get_exp_to_next_lvl(self):
"""
Returns character's exp to the next lvl
"""
return 100 * math.sqrt(self._lvl * 2)
# LVL getters and setters #
def get_lvl(self):
"""
Returns character's lvl
"""
return self._lvl
def set_lvl(self, lvl):
"""
Sets character's lvl
"""
self._lvl = lvl
# Adding EXP and lvlup #
def add_exp(self, exp):
"""
Adds an amount of exp to character
"""
self._exp += exp
if self._exp >= self.get_exp_to_next_lvl():
self._lvl += 1
lvlup = DialogMessage('lvlup_CA', self, self.get_lvl()).get_message()
self.lvlup()
lvlup += StatusMessage(self).stats_message()
return lvlup
def lvlup(self):
"""
Gives character a lvlup bonus
"""
self._maxhp += 10
self._hp = self.get_maxhp()
self._mp += 1
self._attack += 1
self._exp = 0
# Items and inventory #
def add_item(self, item):
"""
Adds an item to character inventory
"""
if item is None:
pass
else:
self._inventory[item.get_type()] = item
self.recalculate_item_bonus()
def get_inventory(self):
"""
Returns character's inventory
"""
return self._inventory
def recalculate_item_bonus(self):
"""
Recalculates all item bonuses
"""
hp_percent = self.get_current_hp()/self.get_maxhp()
self._hp_item_bonus = 0
self._mp_item_bonus = 0
self._attack_item_bonus = 0
self._armour_item_bonus = 0
for i in range(0, len(self._inventory)):
slot = list(self._inventory)[i]
item = self._inventory[slot]
if item is not None:
self.set_hp_item_bonus(self.get_hp_modifier() + item.get_bonus_hp())
self._mp_item_bonus += item.get_bonus_mp()
self._attack_item_bonus += item.get_bonus_attack()
self._armour_item_bonus += item.get_bonus_defence()
self.set_hp(self.get_maxhp() * hp_percent)
# Skills #
def get_skills(self):
"""
Returns character's skills
"""
return self._skills
def add_skill(self, skill):
"""
Adds skill to character
"""
self._skills.append(skill)
def is_skill_available(self):
"""
Returns if any of skills are available
"""
for skill in self.get_skills():
if skill.get_current_cd() == 0:
return True
return False
def first_available_skill(self):
"""
Cycles through character's skills and returns first spell that is ready to be used
Skills are in order of first added
"""
for skill in self.get_skills():
if skill.get_current_cd() == 0:
return skill
def use_attack_skill(self, skill, other):
damage = skill.get_damage()
return DialogMessage('used_skill_C', self).get_message() + "\n" + other.take_damage_pure(damage, self)
def get_passives(self):
"""
Returns character's passives (only names and descriptions)
"""
return self._passives
# is_alive check #
def is_alive(self):
"""
Returns True if character is alive and False if not
"""
return self._hp > 0
# Attacking and taking damage #
def take_damage_from(self, damage, other):
"""
Takes damage from other character
Prints message about that attack
"""
self._hp -= damage * self.get_defence_modifier()
return DialogMessage('attack_CAT', other, damage * self.get_defence_modifier(), self).get_message() + "\n"
def take_damage_pure(self, damage, other):
"""
Takes pure damage from skills
"""
self._hp -= damage
return DialogMessage('attack_pure_CAT', other, damage, self).get_message() + "\n"
def attack(self, other):
"""
Reduces other character's hp by self's attack
"""
attack = self.get_attack() * self.get_attack_modifier()
return other.take_damage_from(attack, self)
# Getting character's stats #
def get_stats(self):
"""
Returns character's stats in a dictionary
"""
stats = dict(CLS=self.get_class(),
HP=self.get_current_hp(),
MAX_HP=self.get_maxhp(),
MP=self.get_mp(),
ATT=round(self.get_attack_stat(), 2),
ATT_BONUS=round(self._attack_item_bonus, 2),
DEF=round(1 - self.get_defence_modifier(), 2),
LVL=self.get_lvl(),
EXP=round(self.get_exp(), 2),
EXPLVL=round(self.get_exp_to_next_lvl(), 2),
GOLD=self.get_gold(),
INV=self.get_inventory(),
SKILLS=self.get_skills(),
PASSIVES=self.get_passives())
return stats
# testing used stuff #
def _print_stats(self):
"""
Prints character's stats
"""
print(self.get_stats())
def _get_all_items(self):
"""
Prints character's inventory
"""
itemlist = "Slot | Equipped Item\n" \
"=========================\n"
have_items = False
for item in self.get_inventory():
if self.get_inventory()[item] is not None:
itemlist += f"{item} | {self.get_inventory()[item].get_full_name()}\n"
have_items = True
# while have_items:
# print("Show item stats? (N/Slot)")
# slot = input()
# if slot in list(self._inventory):
# item = self._inventory[slot]
# item._print_stats()
# else:
# break
if not have_items:
itemlist += "Your inventory is empty."
return itemlist
class Mage(Character):
_maxhp = 90
_mp = 10
_attack = 8
def __init__(self):
super().__init__()
self._cls = 'Mage'
self._es = self.get_es()
self.add_skill(Fireball(self))
self._passives['Energy Shield'] = "This passive allows Mage to absorb some of incoming damage.\n" \
"ES scales with MP and lvl"
# ES getter and setter #
def get_es(self):
"""
Returns character's es
"""
return self._mp * math.sqrt(self.get_lvl() * 2)
def _set_es(self, es):
"""
Takes new value for character's es and sets it
Not really intended to use
"""
self._es = es
# Class specific methods modifications #
def lvlup(self):
"""
Gives character a lvlup bonus
"""
super().lvlup()
self._es = self.get_es()
def take_damage_from(self, damage, other):
"""
Takes other character's attack and reduces self es or/and hp by it
Prints message about that attack
"""
if self._es > 0 and damage < self._es:
self._es -= damage
return DialogMessage('attack_es_CAT', other, damage, self).get_message() + "\n"
elif 0 < self._es <= damage:
if self._es == damage:
self._es = 0
return DialogMessage('broke_es_C', self).get_message() + "\n"
else:
leftoverdmg = damage - self._es
self._hp -= leftoverdmg * self.get_attack_modifier()
self._es = 0
return DialogMessage('broke_es_dmg_hp_CAT', other, leftoverdmg * self.get_attack_modifier(), self).get_message() + "\n"
else:
return super().take_damage_from(damage, other)
def get_stats(self):
"""
Prints character's stats
"""
stats = super().get_stats()
stats['ES'] = self._es
return stats
class Warrior(Character):
hp_mult = 1.1
def __init__(self):
super().__init__()
self._cls = 'Warrior'
self._hp = self.get_maxhp()
self._passives['Warrior Blood'] = "This passive adds Warrior additional defence for every missing HP.\n"
self._passives['Great Health'] = "This passive adds additional defence for Warrior.\n"
# HP modifier, but with passive #
def get_hp_modifier(self):
"""
Returns character's attack modifier
"""
return self._hp_item_bonus
def get_maxhp(self):
"""
Returns character's maxhp
"""
return (self._maxhp + self.get_hp_modifier()) * self.hp_mult
# Armour passive getter #
def get_passive_defence_bonus(self):
"""
Returns warrior's passive defence bonus
"""
hp_percent = math.fabs(self.get_current_hp()/self.get_maxhp())
return math.exp(math.sqrt(hp_percent))/math.e
# Class specific methods modifications #
def get_defence_modifier(self):
"""
Returns character's defence modifier
"""
return (1 / (math.sqrt(self.get_armour()/30 + 1))) * self.get_passive_defence_bonus()
def get_stats(self):
"""
Returns character's stats in a dictionary
"""
stats = super().get_stats()
stats['DEF_BONUS'] = self.get_passive_defence_bonus()
stats['HP_BONUS'] = self.hp_mult
return stats
class Rogue(Character):
_crit_chance = 0.15
_evade_chance = 0.15
_attack = 12
_maxhp = 90
def __init__(self):
super().__init__()
self._cls = 'Rogue'
self._evade_chance = self._evade_chance + 0.001 * self.get_mp()
self._passives['Evasion'] = "This passive allows Rogue to evade some of incoming damage.\n" \
"EV scales with MP"
self._passives['Critical Strike'] = "This passive allows Rogue to double the damage some of his attacks.\n" \
"Crit chance scales with MP"
# Evasion getters and setters #
def get_evasion(self):
"""
Returns character's evade chance
"""
return self._evade_chance + 0.001 * self.get_mp()
def set_evasion(self, ev):
"""
Sets character's evade chance
"""
self._evade_chance = ev
def get_dodge(self):
"""
Returns evasion proc True or False
"""
return random.random() < self.get_evasion()
# Crit getters and setters #
def get_crit_chance(self):
"""
Returns character's evade chance
"""
return self._crit_chance + 0.001 * self.get_mp()
def set_crit_chance(self, chance):
"""
Takes new value for character's evade chance and sets it
"""
self._crit_chance = chance
def get_crit(self):
"""
Returns crit proc True or False
"""
return random.random() < self.get_crit_chance()
# Class specific methods modifications #
def take_damage_from(self, damage, other):
"""
Takes damage from other character
Prints message about that attack
"""
if self.get_dodge():
return DialogMessage('evaded_CA', self, damage).get_message() + "\n"
else:
return super().take_damage_from(damage, other)
def attack(self, other):
"""
Reduces other character's hp by self's attack
"""
if self.get_crit():
attack = self.get_attack() * self.get_attack_modifier() * 2
return DialogMessage('crit', self, attack).get_message() + "\n" + other.take_damage_from(attack, self)
else:
attack = self.get_attack() * self.get_attack_modifier()
return other.take_damage_from(attack, self)
def add_item(self, item):
"""
Adds an item to character inventory
"""
if item is None:
pass
else:
if item.get_type() == 'Weapon':
item.set_name('Dagger')
super().add_item(item)
def get_stats(self):
"""
Returns character's stats in a dictionary
"""
stats = super().get_stats()
stats['EV_CHANCE'] = self.get_evasion()
stats['CRIT_CHANCE'] = self.get_crit_chance()
return stats
class Monster(Character):
def __init__(self, lvl_mult=1):
super().__init__()
self._cls = 'Monster'
self._lvl_mult = lvl_mult * 2 / math.sqrt(lvl_mult * 3)
self._maxhp = (random.randint(16, 40) * self._lvl_mult)
self._hp = self.get_maxhp()
self._mp = (random.randint(1, 1) * self._lvl_mult)
self._attack = (random.randint(5, 10) * self._lvl_mult)
self._armour = 5 * random.uniform(1, 2)
class GreaterMonster(Monster):
def __init__(self, lvl_mult=1):
lvl_mult *= 1.5
super().__init__(lvl_mult)
self._cls = 'Greater Monster'
self.add_item(RareItem(int(lvl_mult/2)))
self.add_item(RareItem(int(lvl_mult/2)))
self.add_item(RareItem(int(lvl_mult/2)))
self.add_item(RareItem(int(lvl_mult/2)))
self._hp = self.get_maxhp()
self._mp = self.get_mp()
if random.random() > 0.5:
self.add_skill(VoidStrike(self))
class Skill:
def __init__(self, character):
self._owner = character
self._cooldown = 0
self._current_cd = 0
def get_owner(self):
"""
Returns skill's owner
"""
return self._owner
def get_name(self):
"""
Returns skill's name
"""
return self.__class__.__name__
def get_cooldown_timer(self):
"""
Returns spells's cd timer
"""
return self._cooldown
def set_cooldown_timer(self, cd):
"""
Sets spells's cd timer
"""
self._cooldown = cd
def get_current_cd(self):
"""
Returns spell's current cd
"""
return self._current_cd
def set_current_cd(self, cd):
"""
Set new amount for current cd
More then max cd = max cd
Less then 0 = 0
"""
if cd < 0:
self._current_cd = 0
elif cd <= self._cooldown:
self._current_cd = cd
else:
self._current_cd = self._cooldown
def is_available(self):
"""
Returns if spell is ready to use
"""
return self._current_cd == 0
class Fireball(Skill):
def __init__(self, character):
super().__init__(character)
self._cooldown = 4
def get_damage(self):
"""
Returns spell's damage
"""
return self._owner.get_mp() * 1.5
class VoidStrike(Skill):
def __init__(self, character):
super().__init__(character)
self._cooldown = 3
def get_damage(self):
"""
Returns spell's damage
"""
return self._owner.get_attack()