This set of changes revolves around finalizing the BattleManager class in order to begin implementing a battle system. This includes adding new attributes(battleState, heroPos) and editing/creating functions. As a result of these changes, there are also some other related classes that were adjusted to match the changes made to BattleManager. Finally, all the neccesary test files have been updated.
Attributes added:
battleState: This is a tuple of size 2. The first index is a boolean that shows whether or not a battle is happening and the second index contains a string that describes the state of the battle. If the string is empty that means that the battle (assuming there is one) is ongoing, if not then it states whether the player won or lost.
heroPos: This is the position of the hero object for targeting purposes. For now it's empty but when implementing the battle system into the actual game it will contain the x, y coordinates for the hero's location.
Functions adjusted:
do_one_turn(): Formerly named, do_battle(), This function now takes in a move and a target for said move. These two inputted values are decided by the player when it is their turn. Target is a tuple containing x, y coordinates for the target and move is the name of the chosen attack. The function also now returns a list of strings related to what happened in that one round of battle and the turnObject is not automatically popped from the list at the start of the round of battle. This is to account for player input, a player can not use a move until both the inputted move and target variables have proper values. Once a move has been properly used, the first index in the list is then popped, allowing for the next Entity's turn. Another change is that at the end of that round of combat, dead enemies are cleared from the list of enemies as well as the turn order list and all Entity objects get their stats fixed, ex) a player cannot have more health than the cap etc.
use_move(): The function now reports on what happened when the user used the move and returns a string array with details about what happened.
apply_effects(): The function now reports on what happened regarding the effects that were passed to it. It returns a string array with details about what happened.
reset_turn_order(): This function was simplified due to a change in the Entity class that simplified the finding of the turn order list.
clear_dead_enemies(): This function was causing a problem due to how the old enemies list used to be. The old enemies list only contained the Entities and not their positions like it does now.
fix_entity_stats(): This function goes through all active entity objects in the battle and adjusts the stats by using the correct_stats() function from the Entity class.
get_entity_from_pos: This function takes in a x, y coordinate tuple and matches that position with an Entity. It checks if that coordinate belongs to the Hero object before looking for the matching coordinate in the Enemy objects.
determine_battle_state(): This function changes the value of battleState depending on certain conditions. The player is deemed to have won the fight if the enemies list is empty and the hero isn't dead and the hero is deemed to have lost the fight if the hero is dead and the enemies list isn't empty, otherwise the battle continues.
Other Class Changes:
Entity: the correct_stats() function had some comments added as well as code for correcting the Mp stat. The class also received a __lt__ operator. This allows the entity objects to be compared via agility stat.
Move: The move class now has a new attribute called name.
UIHandler: UI handler now checks if the chosen move for the player is usable (whether the user meets the restrictions, has enough Mp etc) before making changes.
Other Changes:
changes to the init files of packages and some changes to the JSON files and changes to the test files of these classes. Also fixed a small bug in the UIManager class.
Next Steps
Write code for handling the stance system
Write code for handling the item system
Write code to handle status effects in the game
PR checklist
[x] All Pytests pass
[x] All changes are documented somewhere in the commit
[x] Rpg2.py is tested and works even with the changes
Pygame-RPG 15.3 Finalizing BattleManager
This set of changes revolves around finalizing the
BattleManager
class in order to begin implementing a battle system. This includes adding new attributes(battleState
,heroPos
) and editing/creating functions. As a result of these changes, there are also some other related classes that were adjusted to match the changes made toBattleManager
. Finally, all the neccesary test files have been updated.Attributes added:
battleState
: This is a tuple of size 2. The first index is a boolean that shows whether or not a battle is happening and the second index contains a string that describes the state of the battle. If the string is empty that means that the battle (assuming there is one) is ongoing, if not then it states whether the player won or lost.heroPos
: This is the position of the hero object for targeting purposes. For now it's empty but when implementing the battle system into the actual game it will contain the x, y coordinates for the hero's location.Functions adjusted:
do_one_turn()
: Formerly named,do_battle()
, This function now takes in a move and a target for said move. These two inputted values are decided by the player when it is their turn. Target is a tuple containing x, y coordinates for the target and move is the name of the chosen attack. The function also now returns a list of strings related to what happened in that one round of battle and the turnObject is not automatically popped from the list at the start of the round of battle. This is to account for player input, a player can not use a move until both the inputted move and target variables have proper values. Once a move has been properly used, the first index in the list is then popped, allowing for the next Entity's turn. Another change is that at the end of that round of combat, dead enemies are cleared from the list of enemies as well as the turn order list and all Entity objects get their stats fixed, ex) a player cannot have more health than the cap etc.use_move()
: The function now reports on what happened when the user used the move and returns a string array with details about what happened.apply_effects()
: The function now reports on what happened regarding the effects that were passed to it. It returns a string array with details about what happened.reset_turn_order()
: This function was simplified due to a change in theEntity
class that simplified the finding of the turn order list.clear_dead_enemies()
: This function was causing a problem due to how the old enemies list used to be. The old enemies list only contained the Entities and not their positions like it does now.fix_entity_stats()
: This function goes through all active entity objects in the battle and adjusts the stats by using thecorrect_stats()
function from theEntity
class.get_entity_from_pos
: This function takes in a x, y coordinate tuple and matches that position with an Entity. It checks if that coordinate belongs to theHero
object before looking for the matching coordinate in theEnemy
objects.determine_battle_state()
: This function changes the value ofbattleState
depending on certain conditions. The player is deemed to have won the fight if the enemies list is empty and the hero isn't dead and the hero is deemed to have lost the fight if the hero is dead and the enemies list isn't empty, otherwise the battle continues.Other Class Changes:
Entity
: thecorrect_stats()
function had some comments added as well as code for correcting the Mp stat. The class also received a__lt__
operator. This allows the entity objects to be compared via agility stat.Move
: The move class now has a newattribute
called name.UIHandler
: UI handler now checks if the chosen move for the player is usable (whether the user meets the restrictions, has enough Mp etc) before making changes.Other Changes: changes to the init files of packages and some changes to the JSON files and changes to the test files of these classes. Also fixed a small bug in the UIManager class.
Next Steps
PR checklist