Repository navigation
Expand file tree
/
Copy pathcombat.py
More file actions
245 lines (230 loc) · 10.9 KB
/
Copy pathcombat.py
File metadata and controls
245 lines (230 loc) · 10.9 KB
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
#Combat Function start
def combat(pc,*npc):
npc_count = len(npc)
choice = None
atk_trgt = None
trgt_count = npc_count
while trgt_count > 0 and pc.hp > 0:
print(f'\nCurrent HP: {pc.hp}/{pc.hpmax}')
print(f'\nCurrent Stamina: {pc.stam}/{pc.stam_max}')
if trgt_count == 1:
for x in range(0, npc_count):
if npc[x].hp == 0:
pass
else:
print(f'You are faced by one {npc[x].name}.')
elif trgt_count < npc_count:
print(f'You have slain {npc_count - trgt_count} enemies, {trgt_count} enemies remain.')
else:
print(f'You are faced by {trgt_count} enemies.')
print('''
1 - Attack
2 - Defend
3 - Use Ability
4 - Use Item
''')
choice = input('What will you do?: ')
if choice == '1':
pc.atk()
if trgt_count == 1:
for x in range(0,npc_count):
if npc[x].hp == 0:
pass
else:
print(f'You make an attack against the {npc[x].name}, with your {pc.wpn_equip}.')
if pc.hit >= npc[x].ac or pc.crit:
if pc.crit:
print(f'Critical hit! Your attack hits the {npc[x].name}! Dealing {pc.dmg} damage.')
else:
print(f'Your attack hits the {npc[x].name}! ({pc.hit} vs {npc[x].ac}) Dealing {pc.dmg} damage.')
if npc[x].hp - pc.dmg <= 0:
npc[x].hp = 0
trgt_count -= 1
print(f'Your blow deals lethal damage, the {npc[x].name}s blood splatters across the floor and its body drops limp and lifeless to the floor.')
else:
npc[x].hp -= pc.dmg
elif pc.hit < npc[x].ac:
print(f'Your attack misses! ({pc.hit} vs {npc[x].ac}) The {npc[x].name} laughs at your attempt.')
else:
atk_trgt = None
print('''
Current Available Targets:
''')
for x in range(0,npc_count):
if npc[x].hp > 0:
print(f'''
{x+1} - {npc[x].name} {x+1}
''')
print('''
0 - Back
''')
while atk_trgt == None:
atk_trgt = input('Which enemy would you like to attack?: ')
try:
atk_trgt = int(atk_trgt)
except:
print('Invalid choice.')
atk_trgt = None
continue
if atk_trgt == 0:
choice = None
break
elif 1 > atk_trgt or atk_trgt > npc_count:
print('Invalid choice.')
atk_trgt = None
continue
else:
atk_trgt -= 1
if npc[atk_trgt].hp == 0:
print('Invalid choice.')
atk_trgt = None
continue
print(f'You make an attack against the {npc[atk_trgt].name}({atk_trgt+1}), with your {pc.wpn_equip}.')
if pc.hit >= npc[atk_trgt].ac or pc.crit:
if pc.crit:
print(f'Critical hit! Your attack hits the {npc[atk_trgt].name}! Dealing {pc.dmg} damage.')
else:
print(f'Your attack hits the {npc[atk_trgt].name}! ({pc.hit} vs {npc[atk_trgt].ac}) Dealing {pc.dmg} damage.')
if npc[atk_trgt].hp - pc.dmg <= 0:
npc[atk_trgt].hp = 0
trgt_count -= 1
print(f'Your blow deals lethal damage, the {npc[atk_trgt].name}s blood splatters across the floor and its body drops limp and lifeless to the floor.')
else:
npc[atk_trgt].hp -= pc.dmg
elif pc.hit < npc[atk_trgt].ac:
print(f'Your attack misses! ({pc.hit} vs {npc[atk_trgt].ac}) The {npc[atk_trgt].name} laughs at your attempt.')
elif choice == '2':
choice = None
while choice == None:
choice = input('Are you sure you want to defend? (1-Y/2-N): ')
choice = choice.upper()
if choice == '':
print('Invalid input.')
choice = None
continue
elif choice[0] == 'N' or choice == '2':
choice = None
break
elif choice[0] == 'Y' or choice == '1':
pc.ac += 2
print(f'You raise your weapon into a defensive stance(AC raised by 2 ({pc.ac}!).')
break
else:
print('Invalid input.')
choice = None
continue
elif choice == '3':
if pc.stam <= 0:
print('You have no stamina left.')
choice = None
continue
else:
choice = pc.cability()
if choice == '':
pc.atk()
if trgt_count == 1:
for x in range(0,npc_count):
if npc[x].hp == 0:
pass
else:
print(f'You make an attack against the {npc[x].name}, with your {pc.wpn_equip}.')
if pc.hit >= npc[x].ac or pc.crit:
if pc.crit:
print(f'Critical hit! Your attack hits the {npc[x].name}! Dealing {pc.dmg} damage.')
else:
print(f'Your attack hits the {npc[x].name}! ({pc.hit} vs {npc[x].ac}) Dealing {pc.dmg} damage.')
if npc[x].hp - pc.dmg <= 0:
npc[x].hp = 0
trgt_count -= 1
print(f'Your blow deals lethal damage, the {npc[x].name}s blood splatters across the floor and its body drops limp and lifeless to the floor.')
else:
npc[x].hp -= pc.dmg
elif pc.hit < npc[x].ac:
print(f'Your attack misses! ({pc.hit} vs {npc[x].ac}) The {npc[x].name} laughs at your attempt.')
else:
atk_trgt = None
print('''
Current Available Targets:
''')
for x in range(0,npc_count):
if npc[x].hp > 0:
print(f'''
{x+1} - {npc[x].name} {x+1}
''')
print('''
0 - Back
''')
while atk_trgt == None:
atk_trgt = input('Which enemy would you like to attack?: ')
try:
atk_trgt = int(atk_trgt)
except:
print('Invalid choice.')
atk_trgt = None
continue
if atk_trgt == 0:
choice = None
break
elif 1 > atk_trgt or atk_trgt > npc_count:
print('Invalid choice.')
atk_trgt = None
continue
else:
atk_trgt -= 1
if npc[atk_trgt].hp == 0:
print('Invalid choice.')
atk_trgt = None
continue
print(f'You make an attack against the {npc[atk_trgt].name}({atk_trgt+1}), with your {pc.wpn_equip}.')
if pc.hit >= npc[atk_trgt].ac or pc.crit:
if pc.crit:
print(f'Critical hit! Your attack hits the {npc[atk_trgt].name}! Dealing {pc.dmg} damage.')
else:
print(f'Your attack hits the {npc[atk_trgt].name}! ({pc.hit} vs {npc[atk_trgt].ac}) Dealing {pc.dmg} damage.')
if npc[atk_trgt].hp - pc.dmg <= 0:
npc[atk_trgt].hp = 0
trgt_count -= 1
print(f'Your blow deals lethal damage, the {npc[atk_trgt].name}s blood splatters across the floor and its body drops limp and lifeless to the floor.')
else:
npc[atk_trgt].hp -= pc.dmg
elif pc.hit < npc[atk_trgt].ac:
print(f'Your attack misses! ({pc.hit} vs {npc[atk_trgt].ac}) The {npc[atk_trgt].name} laughs at your attempt.')
elif choice == '4':
if len(pc.invtry) == 0:
print('You have no items.')
choice = None
continue
else:
choice = pc.useitem()
else:
print('invalid input')
continue
if choice == None:
continue
else:
pass
for x in range(0,npc_count):
if npc[x].hp <= 0:
pass
else:
npc[x].atk()
print(f'\nThe {npc[x].name}({x+1}), swings at you with their {npc[x].wpn_equip}.')
if npc[x].hit >= pc.ac or npc[x].crit:
if npc[x].crit:
print(f'The {npc[x].name} hits a critical hit! Dealing {npc[x].dmg} damage.')
else:
print(f"The {npc[x].name}'s attack hits! ({npc[x].hit} vs {pc.ac}) Dealing {npc[x].dmg} damage.")
if pc.hp - npc[x].dmg <= 0:
print(f"The {npc[x].name}'s blow deals lethal damage! They chuckle as you fall to the ground dead.")
pc.hp = 0
break
else:
pc.hp -= npc[x].dmg
elif npc[x].hit < pc.ac:
print(f"The {npc[x].name}'s attack misses!({npc[x].hit} vs {pc.ac}) They yell in frustration.")
if pc.hp == 0:
pass
elif pc.ac != (10+pc.agi_bonus):
pc.ac = 10+pc.agi_bonus
print(f'You leave your defensive stance (AC returned to normal ({pc.ac})).')
#Combat function end