-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpq_enemies.py
144 lines (132 loc) · 5.92 KB
/
pq_enemies.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
"""
Enemy and Quest(enemy) class declarations
for Percival's Quest RPG
"""
#
# pq_enemies.py
# part of Percival's Quest RPG
import random, json
from pq_equipment import pq_treasuregen
from pq_namegen import dragon_namegen, simple_namegen, monster_gen, artygen
pq_dragonskill = {'Bronze':'Evade', 'Gold':'Smite', 'Blue':'Backstab',
'Silver':'Cure', 'Brass':'Charm', 'Green':'Entangle', 'Red':'Rage',
'Force':'Missile', 'Mercury':'Doublestrike', 'Crystal':'Dominate',
'Black':'Poison', 'White':'Flee', 'Bone':'Fear', 'Stone':'Petrify'}
class PQ_Enemy(object):
"""Enemy class declaration"""
def __init__(self):
"""Initialize the random monster."""
self.name = ''
self.level = [0, 0]
self.hitpoints = [0, 0]
self.skillpoints = [0, 0]
self.stats = [0, 0, 0, 0, 0, 0]
self.treasure = {'weapon':'', 'armor':'', 'ring':'', 'gp':0}
self.skill = ''
self.temp = {'stats':{}, 'statturns':{}, 'condition':{}}
self.combat = {'atk':[0, self.stats[0]], 'dfn':[0, self.stats[1]]}
self.skillcounter = 1
self.flee = True
def gen(self, lev):
"""Generate the monster based on dungeon level."""
if lev < 2:
lvl = random.choice([lev]*4 + [lev+1])
else:
lvl = random.choice([lev-1] + [lev]*3 + [lev+1])
if lvl >= 10: #if we're at level 10, face Dragons!
self.dragongen(lvl)
else:
with open('data/pq_bestiary.json') as f:
pq_monsters = json.load(f)
self.level = [lvl, lvl]
self.name = random.choice(pq_monsters[str(lvl)].keys())
this_monster = pq_monsters[str(lvl)][self.name]
for i in range(0, 6):
stat_roll = random.choice([random.randint(1, 6) \
for j in range(0, 6)])
self.stats[i] = stat_roll + this_monster['stat'][i]
self.skill = this_monster['skill']
for i in range(0, lvl):
hpi = random.choice([random.randint(max([1, \
self.stats[3] / 2]), self.stats[3]) for j in range(0, 6)])
self.hitpoints = [x + hpi for x in self.hitpoints]
spi = random.choice([random.randint(1, self.stats[5]) \
for j in range(0, 6)]) + 2 * (lvl - 1)
self.skillpoints = [spi, spi]
self.treasure = pq_treasuregen(lvl)
self.combat['atk'] = [0, self.stats[0]]
self.combat['dfn'] = [0, self.stats[1]]
self.flee = this_monster.get("flee",True)
def dragongen(self, lvl):
"""Generate a random dragon based on dungeon level, for level 10+ """
self.level = [lvl, lvl]
color = random.choice([random.choice(pq_dragonskill.keys()) \
for i in range(0, 6)])
self.name = dragon_namegen(2, 6) + ' the ' + color + ' Dragon'
for i in range(0, 6):
statroll = random.choice([random.randint(1, 6) \
for j in range(0, 6)])
self.stats[i] = statroll + lvl - 5
self.skill = pq_dragonskill[color]
for i in range(0, lvl):
hpi = random.choice([random.randint(max([1, self.stats[3] / 2]), \
self.stats[3]) for j in range(0, 6)])
self.hitpoints = [x + hpi for x in self.hitpoints]
spi = random.choice([random.randint(1, self.stats[5]) \
for j in range(0, 6)]) + 2 * (lvl - 1)
self.skillpoints = [spi, spi]
self.treasure = pq_treasuregen(lvl)
self.combat['atk'] = [lvl / 3, self.stats[0]]
self.combat['dfn'] = [lvl / 3, self.stats[1]]
self.flee = False
def ouch(self, damage):
"""Deal damage to self. WHY WOULD YOU DO THIS IT'S INHUMANE"""
self.hitpoints[0] -= damage
def huh(self, damage):
"""Deal damage to self's skill points. WHUT"""
self.skillpoints[0] -= damage
def reset_skillcounter(self):
"""Reset the counter... for the skills..."""
self.skillcounter = 1
def cure(self, damage):
"""Cure damage to self. Much nicer."""
self.hitpoints[0] = self.hitpoints[1] if self.hitpoints[0] + damage \
> self.hitpoints[1] else self.hitpoints[0] + damage
def temp_bonus(self, stat, bonus, turns):
"""Apply a temporary bonus or penalty to self."""
for i in stat:
if self.temp['stats'].get(i, False):
sign = -1 if bonus < 0 else 1
bonus = sign * max([abs(self.temp['stats'][i]), abs(bonus)])
self.temp['stats'][i] = bonus
self.temp['statturns'][i] = turns
class PQ_Quest(PQ_Enemy):
"""Quest Monster version of the enemy class declaration."""
def __init__(self):
"""Initialize Quest monster and item."""
PQ_Enemy.__init__(self)
self.description = ''
self.artifact = []
def gen(self, lvl):
"""Generate a Quest monster and Macguffin I mean artifact."""
self.level = [lvl, lvl]
self.name = simple_namegen(2, 5).capitalize()
self.description = monster_gen()
for i in range(0, 6):
statroll = random.choice([random.randint(1, 6) \
for j in range(0, 6)])
self.stats[i] = statroll + lvl
artifact = artygen().split(':')
self.treasure['quest'] = artifact[0].strip()
self.artifact = [a.strip() for a in artifact]
self.skill = 'Cure'
for i in range(0, lvl):
hpi = random.choice([random.randint(max([1, self.stats[3] / 2]), \
self.stats[3]) for j in range(0, 6)])
self.hitpoints = [x + hpi for x in self.hitpoints]
spi = random.choice([random.randint(1, self.stats[5]) \
for j in range(0, 6)]) + 2 * (lvl - 1)
self.skillpoints = [spi, spi]
self.combat['atk'] = [lvl / 2, self.stats[0]]
self.combat['dfn'] = [lvl / 2, self.stats[1]]
self.flee = False