On version 0.2.1, if the first upgradable SKill or Equipment of a specific kind (id) is at Max level, and a second one is not at Max level, when the player gains an item of that specific kind, the second one is not upgraded and the notification section show a "[item_name] is already Max Level!" message.
The main cause of this behavior is some outdated code in the gain_item Function.
The legacy code from version 0.1.X only takes into account the first upgradable item of a specific kind in the inventory, since the dungeon was the only way for the player to obtain an instance of a specific item.
But since version 0.2.X, with the introduction of a "Home Inventory", the player can now move to/from the "Player Inventry" any item from previous explorations or purchases. Because of this, its possible for the player to have multiple instances of the same kind of upgradable item in the player's inventory before exploring the Dungeon, what needs to be taken into account for the "gain_item" Function in version 0.2.X.
A quick fix to allow upgrading any instance of the gained item in inventory is to reuse part of the logic for stackable items, upgrading a matching item on inventory instead of stacking it (if not Max level), and preventing the addition of a new item if there was at least one on the inventory (meaning that all instances of that item are already Max Level).
Additionally, to reuse the "upgradable_item" logic for Skills and Equipment, the different sections of the gain_item Function can be rearanged to new "private" Functions to do each separate logic to handle different item types. This makes easy to implement a way of setting a custom "starting level" for Skills and Equipment, and "starting uses" for Potions and Food.
[code]
File "game/init.rpy", lines 1448-1618, at gain_item in the "# INVENTORY MANAGEMENT #" python block:
init -1 python: # INVENTORY MANAGEMENT #
def gain_item(item_id, amount=None): # Added amount parameter, defaults defined by handlers
if item_id not in item_definitions:
renpy.log(f"Error: Tried to gain unknown item '{item_id}'")
return
item_data = item_definitions[item_id]
item_type = item_data.get("type", "unknown")
stack_limit = item_data.get("stack_limit") # Get stack limit if defined
# --- NEW: Handle Unique Items (check for duplicates) ---
if item_type == "unique":
if not _gain_unique_item(item_id):
return # Stop the function here to prevent adding the duplicate.
# --- NEW: Handle Artifacts ---
if item_type == "artifact":
_gain_artifact_item(item_id)
return # Artifacts are not added to persistent.player_inventory, so we notify and return.
# --- Handle Stackable Items (like Gold Coins) ---
if stack_limit is not None:
if amount is None: _gain_stackable_item(item_id)
else: _gain_stackable_item(item_id, amount)
# --- Handle Skills (logic: upgrade and reset cooldown if exists, else add new if space) ---
elif item_type == "skill":
if amount is None: _gain_upgradeable_item(item_id, _reset_cooldown=True)
else: _gain_upgradeable_item(item_id, amount, _reset_cooldown=True)
# --- Handle Equipment (logic: upgrade if exists and is upgradeable, else add new if space) ---
elif item_type == "equipment":
if amount is None: _gain_upgradeable_item(item_id, _allow_duplicates=True)
else: _gain_upgradeable_item(item_id, amount, _allow_duplicates=True)
# --- NEW: Handle Potions and Food Items (logic: limited uses) ---
elif item_type in ["potion", "food"]:
if amount is None: _gain_consumable_item(item_id)
else: _gain_consumable_item(item_id, amount)
# --- Handle Non-Stackable, Non-Upgradeable Items (Uniques) ---
# --- Handle Non-Stackable, Non-Upgradeable Items (Potions, Food, Uniques) ---
else:
_gain_other_item(item_id)
...