Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when your pokete runs out of all its AP #200

Closed
2 tasks done
magnus-ISU opened this issue Jun 19, 2022 · 2 comments
Closed
2 tasks done

Crash when your pokete runs out of all its AP #200

magnus-ISU opened this issue Jun 19, 2022 · 2 comments

Comments

@magnus-ISU
Copy link
Contributor

Checklist
I have:

  • Searched the Issues page for my problem/feature request
  • Updated all related software and Pokete it self

Describe the bug
Crash during a fight, I think before I lost.

To Reproduce
Steps to reproduce the behavior:
Haven't tried yet, but suspect it is due to running out of AP on all my (1) pokete that wasn't knocked out
You can see in the code near fightmap.py:361:

            for i, prov in enumerate(providers):
                if prov.curr.hp <= 0:
                    loser = prov
                    winner = providers[(i + 1) % 2]
            if all(i.ap == 0 for i in player.curr.attack_obs):
                winner = providers[(index + 1) % 2]
                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 (
                    loser.curr.player

That if the for loop comes up with no loser and the if does come up with a winner, then winner is not None but loser is None and the crash will happen

Expected behavior
no crash

Screenshots

Traceback (most recent call last):
  File "/home/mag/Documents/code/gamedev/random/pokete/./pokete.py", line 1547, in <module>
    main()
  File "/home/mag/Documents/code/gamedev/random/pokete/./pokete.py", line 1198, in main
    game.game(figure.map)
  File "/home/mag/Documents/code/gamedev/random/pokete/./pokete.py", line 1024, in _game
    figure.set(figure.x + get_X_strength(action), figure.y + get_Y_strength(action))
  File "/usr/lib/python3.10/site-packages/scrap_engine.py", line 283, in set
    obj.action(self)
  File "/home/mag/Documents/code/gamedev/random/pokete/pokete_classes/npcs.py", line 31, in action
    self.npc.action()
  File "/home/mag/Documents/code/gamedev/random/pokete/pokete_classes/npcs.py", line 251, in action
    winner = fm.fightmap.fight(
  File "/home/mag/Documents/code/gamedev/random/pokete/pokete_classes/fightmap.py", line 361, in fight
    loser.curr.player
AttributeError: 'NoneType' object has no attribute 'curr'
@magnus-ISU
Copy link
Contributor Author

magnus-ISU commented Jun 19, 2022

There are edge cases here which can result in you getting softlocked I think, if this is fixed.

A solution should take the following three things into account:

  1. You should be able to win with your last action point
  2. Combat currently begins with asking the player for an action before checking if anyone won
  3. The player could be unable to act if they have no poketes with action points

All this logic should be abstracted into
a has_lost() for trainers/providers, which handles the player choosing a new pokete (and trainers doing the same, maybe could handle wild poketes running away if any want to do that, idk)
a can_act() for poketes, called by has_lost()
a is_alive() for poketes, called in several areas of the code that now check hp directly but maybe should be using can_act()

(is alive would be useful, for example, for making a pokete that can use a super charged attack with his dying breath maybe, getting 1 turn of immortality when he drops to 0 hp. That would also require a take_damage function which I don't know if exists, and maybe other stuff, but putting the systems in place now would make the process easy when you do decide to implement it).

@magnus-ISU
Copy link
Contributor Author

magnus-ISU commented Jun 19, 2022

Also I triggered it again somehow but didn't run out of action points, I don't understand why. I'm gonna run in debug mode and see if I can see anything weird

EDIT: maybe. I wasn't actually paying attention super well, and I just added 1 line which seems to have made it work and it did happen when I ran out of AP (minus fixing the softlock). So I might have a fix for this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant