Keith1039 / Pygame-RPG

A repository of me trying to make an RPG with a custom game engine with Pygame added in as support.
0 stars 0 forks source link

Pygame-RPG 14 Creation of BattleManager class #45

Closed Keith1039 closed 9 months ago

Keith1039 commented 9 months ago

Pygame-RPG 14 Creation of BattleManager class

This commit is the compilation of all of the changes that were done for the sake of the BattleManager class and the Move class. This PR includes changes that directly impact the classes and some miscellaneous changes. The BattleManager class was created for the purpose of managing the fight encounters between Entity objects. The Move class was created to take the structured move data from JSON and turn it into a real object.

To begin with, this PR introduces the Move class. This class takes in an Entity object and the dictionary it needs for it's attributes. It only has one notable function, the parse_damage_calculation() function. This function uses the damage formula present in the dictionary to calculate the damage this Move object can do. If there is no damage formula in the dictionary information, the damage is 0.

To begin with, this PR introduces the BattleManager class. This class has the following attributes. moveDict, hero, enemies, turnOrder and lootPool.

The BattleManager class has the following relevant functions. do_battle(), use_move(), parse_effects(), apply_effects(), apply_effect_buff(), parse_restriction(), reset_turn_order() and clear_dead_enemies().

clear_dead_enemies(): This function iterates through the enemies and turnOrder list and adds the Entity objects that aren't dead to a new list. This effectively removes dead Entity objects from the two lists.

reset_turn_order(): This function adds all of the Entity objects in the battle to a list and sorts them based on their Agl stats. This list then becomes the new turnOrder.

parse_restriction(): This function takes in an Entity object and a dictionary containing information about the move they want to use. It then uses the restriction string (if there is any) to determine whether the Entity object meets the requirement to use the move by returning a boolean value.

parse_effects(): this function take in a Move object. It then uses the effect attribute of the object to determine the type of effect that it has. It parses the string (if it's present) and returns a list of tuples containing the effects and their targets in an easier to understand way. If there is no effect, an empty list is returned.

apply_effect_buff(): This function takes in a target Entity and a dictionary that describes a buff. To ensure that there is no permanent stat loss or gain, the target's buffs are removed first before the buffs are updated and re-applied. To do this, a False boolean value is passed to the Entity object's remove_bonuses() and apply_bonuses() function. This flag tells the functions to not remove buffs that have reached the end of their turn count in the case of remove_bonuses() and to not lower the turn count of existing buffs when apply_bonuses() is used.

apply_effects(): This function takes in an effectList, the object whose turn it is and the object this object is targetting. This function iterates through the effectList and parses the curated effects. It first determines who the target of the effect should be by using the value at index 0 of the tupple, it then looks at the class of the value in index 1 of the tupple. If the class is a string then it deals with it in a "try-except" block. If the class is a dictionary then it calls the apply_effect_buff() function for the target.

use_move(): This function takes in the turnObject, a Move object and a list of targets that the move is to be used on. It gets the effectList from the parse_effects() function and then iterates through the list of targets. If the Move object's type attribute is "Attack" then the target takes damage equal to the Move object's damage attribute. Depending on which class the object is part of, the function called for this is different. The effects of the move are then applied.

do_battle(): this function pops the object at the 0 index of the turnOrder list. If the object is of the Knight class, the player will then have to choose what to do. If not, the enemy randomly determines what move in their movelist will do. There is a failsafe for this where if the enemy fails to land on a usable move 20 times over, the enemy will just attack.

Other Changes:

PR checklist