-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcore.py
82 lines (79 loc) · 2.23 KB
/
core.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
import races, classes, moves, util
import random
class Entity(object):
def set_stats(self):
#self.stats = dict(hp=0, mp=0, attack=0, defense=0, wisdom=0, speed=0)
self.hp = self.stats['hp']
self.mp = self.stats['mp']
def attack(self, other, move):
print('{} used {}'.format(self, move))
move.use(self, other)
def deal_damage(self, other, n):
n = int(n)
other.take_damage(n)
if other.dead:
other.die()
self.killed(other)
return True
return False
@property
def dead(self):
return self.hp <= 0
def take_damage(self, n):
if n != 0:
self.hp -= n
print('{} took {} damage!'.format(self, n))
def heal(self, n):
self.hp = min(self.hp + n, self.stats['hp'])
print('{} healed {} HP!'.format(self, n))
def every_round(self):
self.hp = min(self.hp + 1, self.stats['hp'])
self.mp = min(self.mp + round(self.stats['wisdom']/10), self.stats['mp'])
def choose_move(self):
return random.choice(self.moves)
def __str__(self):
return type(self).__name__
def die(self):
print('{} died'.format(self))
def killed(self, other):
pass
class Player(Entity):
def __init__(self, race, class_, name):
super().__init__()
race.__init__(self)
class_.__init__(self)
self.stats = {}
self.level = 1
self.xp = 0;
self.update_stats()
self.set_stats() # here for a good reason
self.type = race.name + ' ' + class_.__name__
self.name = name
def update_stats(self):
lv_up = False
if self.xp >= self.level ** 2:
lv_up = True
self.xp -= self.level ** 2
self.level += 1
print('New level: {level}'.format(level=self.level))
for i in self.bases:
self.stats[i] = round(self.bases[i] + (self.bases[i]/4) * self.multipliers[i] * self.level)
if lv_up:
self.set_stats()
def every_round(self):
super().every_round()
print('HP: {} / {} MP: {} / {}'.format(self.hp, self.stats['hp'], self.mp, self.stats['mp']))
def choose_move(self):
return util.prompt('What move do you want to use? ', {k: v for k, v in moves.moves.items() if v in self.moves})
def die(self):
Entity.die(self)
self.level -= 1
self.xp = 0
print('You died. Respawning. One level lost.')
self.update_stats()
self.set_stats()
def killed(self, other):
self.xp += other.xp
self.update_stats()
def __str__(self):
return self.name