-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattle_system.py
138 lines (120 loc) · 5.86 KB
/
battle_system.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
import math
class TurnBattleSystem:
def __init__(self, player, ai):
self.player = player
self.ai = ai
self.player_mon = self.player.in_battle
self.enemy_mon = self.ai.in_battle
self.turn_count = 1 # turn counter
# first turn is of the player
self.player.token = True
self.ai.token = False
def switch_turn(self):
if self.player.token == True:
self.player.token = False
self.ai.token = True
print("----- END PLAYER TURN -----\n")
print("\n----- START AI TURN -----")
elif self.ai.token == True:
self.ai.token = False
self.player.token = True
print("----- END AI TURN -----\n")
print("\n----- START PLAYER TURN -----")
self.turn_count += 1
print('Turn n: {turn}'.format(turn = self.turn_count))
def get_turn(self):
if self.player.token == True:
# player turn
return 'PL'
else:
# AI turn
return 'AI'
def get_player(self):
return self.player
def get_ai(self):
return self.ai
def handle_turns(self):
self.player_mon = self.player.in_battle # prevents non updating target
ai_win_msg = 'AI Trainer won the battle...\nThe battle lasted {n_turns} turns.'.format(n_turns = self.turn_count)
ai_lose_msg = 'AI Trainer lost the battle!\nThe battle lasted {n_turns} turns.'.format(n_turns = self.turn_count)
if self.player.game_over_lose() or self.ai.game_over_lose():
if self.player.game_over_lose():
self.player_mon.msg = ai_win_msg
self.enemy_mon.msg = ai_win_msg
else:
self.player_mon.msg = ai_lose_msg
self.enemy_mon.msg = ai_lose_msg
else:
if self.player.is_turn():
pass
else:
self.ai.get_choice(self.player_mon)
self.handle_status_by_turn()
self.handle_leech_seed()
self.switch_turn()
# damages every turn
def handle_burn_poison(self):
# prevents non updating in battle pokemons
self.player_mon = self.player.in_battle
self.enemy_mon = self.ai.in_battle
if self.player_mon.status == 'BRN' or self.player_mon.status == 'PSN':
player_mon_max_hp = self.player_mon.max_hp
self.player_mon.hit(math.floor((1/16)*player_mon_max_hp), None, status = True)
if self.player_mon.status == 'BRN':
self.player_mon.msg += '\n{pkmn} is hurt by its burn!'.format(pkmn = self.player_mon.name)
else:
self.player_mon.msg += '\n{pkmn} is hurt by poison!'.format(pkmn = self.player_mon.name)
if self.enemy_mon.status == 'BRN' or self.enemy_mon.status == 'PSN':
enemy_mon_max_hp = self.enemy_mon.max_hp
self.enemy_mon.hit(math.floor((1/16)*enemy_mon_max_hp), None, status = True)
if self.player_mon.status == 'BRN':
self.enemy_mon.msg += '\n{pkmn} is hurt by its burn!'.format(pkmn = self.enemy_mon.name)
else:
self.enemy_mon.msg += '\n{pkmn} is hurt by poison!'.format(pkmn = self.enemy_mon.name)
# like PSN, but it encreases the damage every turn
def handle_toxicity(self):
# prevents non updating in battle pokemons
self.player_mon = self.player.in_battle
self.enemy_mon = self.ai.in_battle
if self.player_mon.status == 'TOX':
self.player_mon.toxic_turns += 1
player_mon_max_hp = self.player_mon.max_hp
damage = math.floor(1/16 * player_mon_max_hp) * self.player_mon.toxic_turns
if damage >= 15 * math.floor(1/16 * player_mon_max_hp):
damage = math.floor(1/16 * player_mon_max_hp)
self.player_mon.hit(damage, None, status = True)
self.player_mon.msg += '\n{pkmn} is hurt by toxine!'.format(pkmn = self.player_mon.name)
if self.enemy_mon.status == 'TOX':
self.enemy_mon.toxic_turns += 1
enemy_mon_max_hp = self.enemy_mon.max_hp
damage = math.floor(1/16 * enemy_mon_max_hp) * self.enemy_mon.toxic_turns
if damage >= 15 * math.floor(1/16 * enemy_mon_max_hp):
damage = math.floor(1/16 * enemy_mon_max_hp)
self.enemy_mon.hit(damage, None, status = True)
self.enemy_mon.msg += '\n{pkmn} is hurt by toxine!'.format(pkmn = self.enemy_mon.name)
# damage mon and heals enemy_mon every turn if mon is seeded (and viceversa)
def handle_leech_seed(self):
# prevents non updating in battle pokemons
self.player_mon = self.player.in_battle
self.enemy_mon = self.ai.in_battle
if self.player_mon.seeded:
player_mon_max_hp = self.player_mon.max_hp
damage = math.floor((1/16)*player_mon_max_hp)
self.player_mon.hit(damage, None, status = True)
if (self.enemy_mon.hp + damage) > self.enemy_mon.max_hp:
self.enemy_mon.hp = self.enemy_mon.max_hp
else:
self.enemy_mon.hp += damage
self.player_mon.msg += '\nLeech Seed saps {pkmn}!'.format(pkmn = self.player_mon.name)
if self.enemy_mon.seeded:
enemy_mon_max_hp = self.enemy_mon.max_hp
damage = math.floor(math.floor((1/16)*enemy_mon_max_hp))
self.enemy_mon.hit(damage, None, status = True)
if (self.player_mon.hp + damage) > self.player_mon.max_hp:
self.player_mon.hp = self.player_mon.max_hp
else:
self.player_mon.hp += damage
self.enemy_mon.msg += '\nLeech Seeds saps {pkmn}!'.format(pkmn = self.enemy_mon.name)
def handle_status_by_turn(self):
self.handle_burn_poison()
self.handle_toxicity()