Skip to content

Commit

Permalink
feat(#267): Fixed handle defeat
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jun 13, 2024
1 parent 7fbf376 commit 1c505f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 120 deletions.
3 changes: 1 addition & 2 deletions pokete_classes/fight/attack_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def __call__(self, attacker: Poke, defender: Poke, attack: Attack,
self.fightmap.show_effectivity(eff, n_hp, random_factor, attacker,
attack)
if defender == attacker:
time.sleep(SPEED_OF_TIME * 1)
self.fightmap.outp.outp(f'{attacker.ext_name} hurt itself!')
self.fightmap.show_hurt_it_self()
if random_factor != 0:
attack.give_effect(defender)
for obj in [defender, attacker] if defender != attacker else [
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/fight/fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __call__(self, providers: list[Provider]):
self.fightmap.show_used_all_attacks(player)
if winner is not None:
if any(p.hp > 0 for p in loser.pokes[:6]):
if not loser.handle_defeat(self, winner):
if not loser.handle_defeat(self.fightmap, winner):
break
else:
break
Expand Down
121 changes: 4 additions & 117 deletions pokete_classes/fight/fightmap/fightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,123 +267,6 @@ def add_providers(self, providers: list[Provider]):
self.show()
time.sleep(SPEED_OF_TIME * 0.5)

def fight(self, providers):
"""Fight between two Pokes
ARGS:
providers
RETURNS:
Provider that won the fight"""
"""
audio.switch("xDeviruchi - Decisive Battle (Loop).mp3")
self.providers = providers
logging.info(
"[Fight] Started between %s",
"and ".join(
f"{prov.curr.name} ({type(prov)}) lvl. {prov.curr.lvl()}"
for prov in self.providers
)
)
self.resize_view()
for prov in self.providers:
prov.index_conf()
if settings("animations").val: # Intro animation
animations.fight_intro(self.height, self.width)
self.add_1(*self.providers)
for prov in self.providers:
prov.greet(self)
time.sleep(SPEED_OF_TIME * 1)
self.add_2(self.providers[0])
self.fast_change(
[self.providers[0].curr.ico, self.deadico2, self.deadico1,
self.providers[0].curr.ico], self.providers[0].curr.ico)
self.outp.outp(f"You used {self.providers[0].curr.name}")
self.show()
time.sleep(SPEED_OF_TIME * 0.5)
index = self.providers.index(
max(self.providers, key=lambda i: i.curr.initiative)
)
for prov in self.providers:
i = prov.curr
for j in i.effects:
j.readd()
while True:
player = self.providers[index % 2]
enem = self.providers[(index + 1) % 2]
attack = player.get_attack(self, enem)
time.sleep(SPEED_OF_TIME * 0.3)
if attack == "won":
return player
if attack != "":
player.curr.attack(attack, enem.curr, self, self.providers)
self.show()
time.sleep(SPEED_OF_TIME * 0.5)
winner = None
loser = None
for i, prov in enumerate(self.providers):
if prov.curr.hp <= 0:
loser = prov
winner = self.providers[(i + 1) % 2]
if winner is not None:
self.outp.outp(f"{loser.curr.ext_name} is dead!")
elif all(i.ap == 0 for i in player.curr.attack_obs):
winner = self.providers[(index + 1) % 2]
loser = player
time.sleep(SPEED_OF_TIME * 2)
self.outp.outp(
f"{player.curr.ext_name} has used all its' attacks!")
time.sleep(SPEED_OF_TIME * 3)
if winner is not None:
if any(p.hp > 0 for p in loser.pokes[:6]):
if not loser.handle_defeat(self, winner):
break
else:
break
index += 1
audio.switch("xDeviruchi - Decisive Battle (End).mp3")
time.sleep(SPEED_OF_TIME * 1)
_xp = sum(
poke.lose_xp + max(0, poke.lvl() - winner.curr.lvl())
for poke in loser.pokes
) * loser.xp_multiplier
self.outp.outp(
f"{winner.curr.ext_name} won!" +
(f'\nXP + {_xp}' if winner.curr.player else '')
)
if winner.curr.player and isinstance(loser, Trainer):
achievements.achieve("first_duel")
if winner.curr.player and winner.curr.add_xp(_xp):
time.sleep(SPEED_OF_TIME * 1)
self.outp.outp(
f"{winner.curr.name} reached lvl {winner.curr.lvl()}!"
)
winner.curr.moves.shine()
time.sleep(SPEED_OF_TIME * 0.5)
winner.curr.set_vars()
winner.curr.learn_attack(self, self)
winner.curr.evolve(winner, self)
if winner.curr.player:
winner.curr.poke_stats.add_battle(True)
else:
loser.curr.poke_stats.add_battle(False)
self.show()
time.sleep(SPEED_OF_TIME * 1)
ico = loser.curr.ico
self.fast_change([ico, self.deadico1, self.deadico2], ico)
self.deadico2.remove()
self.show()
self.clean_up(*self.providers)
mvp.movemap.balls_label_rechar(winner.pokes)
logging.info(
"[Fight] Ended, %s(%s) won",
winner.curr.name, "player" if winner.curr.player else "enemy"
)
audio.switch(self.providers[0].map.song)
return winner
"""

def choose_poke(self, player, allow_exit=True):
"""Lets the player choose another Pokete from their deck
ARGS:
Expand Down Expand Up @@ -467,6 +350,10 @@ def show_weather(self, weather):
def set_providers(self, providers: list[Provider]):
self.providers = providers

def show_hurt_it_self(self, attacker):
time.sleep(SPEED_OF_TIME * 1)
self.outp.outp(f'{attacker.ext_name} hurt itself!')


if __name__ == "__main__":
print("\033[31;1mDo not execute this!\033[0m")

0 comments on commit 1c505f0

Please sign in to comment.