Pygame-RPG 17 Item Management System Implementation
This PR serves to create the item management code for items. This is done by adding 2 classes which are used to handle item based tasks. The two classes are the Equipment class which provides bonuses to the player character when equipped and the ItemManager class who manages all items.
The Equipment class is a class with the following attributes. name, statsApplied, attribure, Hpcap, Mpcap, Str, Mag, Agl, Defense and movelist. All of these attributes are stored as JSON.
name: The name of the piece of equipment in question.
statsApplied: A boolean flag that tracks whether this object has applied it's bonuses to the player character.
attribute: The attribute of the equipment. This is mostly going to be used for weapons to determine whether a given attack should do more or less damage depending on the enemy's weakness and resistance.
Hpcap, Mpcap, Str, Mag, Agl, Defense: are all the stats that get directly influenced from equipping a piece of equipment. These values can be positive or negative.
movelist: is an array of moves that are added to the player's move list once it is equipped.
The Equipment class has two functions. apply_stat_bonuses() and remove_stat_bonuses().
apply_stat_bonuses(): This function takes in a Knight object and sets the statsApplied flag to true
while applying the equipment's stat bonuses to the player character along with adding to the player character's move list.
remove_stat_bonuses(): This function takes in a Knight object and removes the stat bonuses applied to
the Knight along with the moves that the piece of equipment added. This only runs if the equipment was previously equipped, indicated by the statsApplied flag. If the code successfully runs, statsApplied is set to False after the stat bonuses are removed.
The ItemManager class is a general manager class that is used to facilitate Item based events in the game. The class has the following attributes, itemJson, itemEffectJson, equipmentJson, itemFustionJson, and knight.
itemJson: is a dictionary containing all of the general item information in the game.
itemEffectJson: This is a dictionary containing all item effects.
equipmentJson: This is a dictionary containing all of the information about equipment.
itemFusionJson: This is a dictionary that contains the potential fusions of materials that produce items.
knight: A reference to the Knight object
This class also has a variety of functions for the sake of its role, these include, determine_limited(), get_all_purchasable(), get_all_sellable(), get_effect(), get_parsable_item_info(), get_usable_items(), fuse_items().
determine_limited(): This function takes in an item's name and returns a boolean that indicates if the player can buy the item. The logic for this is as follows, any item that is not limited or is limited but is not present in the player's inventory is purchasable.
get_all_purchasable(): this function iterates through the itemJson dictionary and adds items to a new dictionary only if the two following conditions are met. The first condition is that the item is purchasable and the second condition is that the item complies with the criteria in the determine_limited() function. If the item meets both criteria, it is mapped to it's purchase price and added to the new dictionary. Once When the loop ends, the new dictionary is returned.
get_all_sellable(): This function iterates through the player's inventory for non key items and adds it to a new dictionary where the item name is mapped to the sell price. The new dictionary is returned.
get_effect(): This function takes in an item and returns an effect string if the item has an effect or returns empty string if the item does not have an effect.
get_parsable_item_info(): This function takes in an item name and returns a the JSON information regarding them without the trivial details meant for the back end.
get_usable_items(): This function returns a list of items in the Knight object's inventory that is usable in a combat context along with their amount.
fuse_items(): This function takes in 2 materials and first determines whether they can be fused. If they can be fused, fusion occurs resulting in the loss of the materials and the addition of the fused item in the Knight object's inventory. The knight's inventory then has its inventory corrected and a flag is returned communicating if the fusion was successful or not.
Other Notable Changes:
As a result of these changes, other classes were changed as well.
BattleManager: The BattleManager class' parse_effects() function now directly takes in the Move object's effect attribute instead of taking the object itself. This was done to make the function integrate well with the item effects. The function was also upgraded for it to now be able to process % inputs in regards to stat changes.
Entity: All Entity classes such as Knight and Enemy now have the mag attribute.
Knight: The Knight class now has an equipment dictionary with multiple keys for Equipment objects. Some slight changes were made to the inventory_to_list() function so that the "x amount" part only happens when the amount of the item is greater than 1. The correct_inventory() and equip() functions were added.
correct_inventory(): This function iterates through the player's inventory and adds all items with an amount of 0 to a list. Afterwards it deletes all of the members of the list from the player's inventory.
equip(): This function takes in an equipment object and has a flag called remove associated with it. if remove is not set to true, the function will attempt to equip the item. If there is another item present in the slot, it's stat bonuses are removed and the new item is equipped and the equipment dictionary is updated.
If the remove flag is set to true, the equipped item's bonuses are removed and the dictionary entry for the slot is set to None.
UIHandler: The class now takes in a pointer to the ItemManager object and uses it to display items in a battle related context.
As with all other major changes, the test classes for all the above have been created/modified to encompass the changes made. The JSON data necessary for the items to work have also all been added and the save files have been updated to reflect the changes made to Knight.
Some new helper scrips have been added as well to both the script bash file and the Scripts.py file.
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 17 Item Management System Implementation
This PR serves to create the item management code for items. This is done by adding 2 classes which are used to handle item based tasks. The two classes are the Equipment class which provides bonuses to the player character when equipped and the ItemManager class who manages all items.
The Equipment class is a class with the following attributes.
name
,statsApplied
,attribure
,Hpcap
,Mpcap
,Str
,Mag
,Agl
,Defense
andmovelist
. All of these attributes are stored as JSON.name
: The name of the piece of equipment in question.statsApplied
: A boolean flag that tracks whether this object has applied it's bonuses to the player character.attribute
: The attribute of the equipment. This is mostly going to be used for weapons to determine whether a given attack should do more or less damage depending on the enemy's weakness and resistance.Hpcap
,Mpcap
,Str
,Mag
,Agl
,Defense
: are all the stats that get directly influenced from equipping a piece of equipment. These values can be positive or negative.movelist
: is an array of moves that are added to the player's move list once it is equipped.The Equipment class has two functions.
apply_stat_bonuses()
andremove_stat_bonuses()
.apply_stat_bonuses()
: This function takes in a Knight object and sets thestatsApplied
flag to true while applying the equipment's stat bonuses to the player character along with adding to the player character's move list.remove_stat_bonuses()
: This function takes in a Knight object and removes the stat bonuses applied to the Knight along with the moves that the piece of equipment added. This only runs if the equipment was previously equipped, indicated by thestatsApplied
flag. If the code successfully runs,statsApplied
is set to False after the stat bonuses are removed.The ItemManager class is a general manager class that is used to facilitate Item based events in the game. The class has the following attributes,
itemJson
,itemEffectJson
,equipmentJson
,itemFustionJson
, andknight
.itemJson
: is a dictionary containing all of the general item information in the game.itemEffectJson
: This is a dictionary containing all item effects.equipmentJson
: This is a dictionary containing all of the information about equipment.itemFusionJson
: This is a dictionary that contains the potential fusions of materials that produce items.knight
: A reference to the Knight objectThis class also has a variety of functions for the sake of its role, these include,
determine_limited()
,get_all_purchasable()
,get_all_sellable()
,get_effect()
,get_parsable_item_info()
,get_usable_items()
,fuse_items()
.determine_limited()
: This function takes in an item's name and returns a boolean that indicates if the player can buy the item. The logic for this is as follows, any item that is not limited or is limited but is not present in the player's inventory is purchasable.get_all_purchasable()
: this function iterates through theitemJson
dictionary and adds items to a new dictionary only if the two following conditions are met. The first condition is that the item is purchasable and the second condition is that the item complies with the criteria in thedetermine_limited()
function. If the item meets both criteria, it is mapped to it's purchase price and added to the new dictionary. Once When the loop ends, the new dictionary is returned.get_all_sellable()
: This function iterates through the player's inventory for non key items and adds it to a new dictionary where the item name is mapped to the sell price. The new dictionary is returned.get_effect()
: This function takes in an item and returns an effect string if the item has an effect or returns empty string if the item does not have an effect.get_parsable_item_info()
: This function takes in an item name and returns a the JSON information regarding them without the trivial details meant for the back end.get_usable_items()
: This function returns a list of items in the Knight object's inventory that is usable in a combat context along with their amount.fuse_items()
: This function takes in 2 materials and first determines whether they can be fused. If they can be fused, fusion occurs resulting in the loss of the materials and the addition of the fused item in the Knight object's inventory. The knight's inventory then has its inventory corrected and a flag is returned communicating if the fusion was successful or not.Other Notable Changes: As a result of these changes, other classes were changed as well.
BattleManager
: The BattleManager class'parse_effects()
function now directly takes in the Move object's effect attribute instead of taking the object itself. This was done to make the function integrate well with the item effects. The function was also upgraded for it to now be able to process % inputs in regards to stat changes.Entity
: All Entity classes such asKnight
andEnemy
now have themag
attribute.Knight
: The Knight class now has an equipment dictionary with multiple keys for Equipment objects. Some slight changes were made to theinventory_to_list()
function so that the "x amount" part only happens when the amount of the item is greater than 1. Thecorrect_inventory()
andequip()
functions were added.correct_inventory()
: This function iterates through the player's inventory and adds all items with an amount of 0 to a list. Afterwards it deletes all of the members of the list from the player's inventory.equip()
: This function takes in an equipment object and has a flag calledremove
associated with it. ifremove
is not set to true, the function will attempt to equip the item. If there is another item present in the slot, it's stat bonuses are removed and the new item is equipped and the equipment dictionary is updated. If theremove
flag is set to true, the equipped item's bonuses are removed and the dictionary entry for the slot is set to None.UIHandler
: The class now takes in a pointer to the ItemManager object and uses it to display items in a battle related context.As with all other major changes, the test classes for all the above have been created/modified to encompass the changes made. The JSON data necessary for the items to work have also all been added and the save files have been updated to reflect the changes made to Knight.
Some new helper scrips have been added as well to both the
script
bash file and theScripts.py
file.PR checklist