On version 0.2.1, all actions centered on spending "Gold Coins" from player's inventory may fail to detect payability from the total gold amount and only will take into account the first "gold_coins" stack item in inventory. This is not allways a problem, if the player has a "gold_coins" stack item equal or above the required amount, he can use the inventory menu (right-click) to move the higher stack to be first one.
But in cases where the required amount is only reached using 2 gold stacks (each gold stacks been bellow the required amount), the player will not be able to perform that action. The most extreme case of this behavior if getting a debt to Cubi of 110 or more (11 services), making impossible for the player to pay the debt.
A Solution to avoid these scenarios is:
- Use a function to calculate the total collective gold quantity from all the player's inventory,
- Use another function to substract a given amount from multiple "gold_coins" items (or any other item quantity), and
- Adapt the gold-spending-centered mechanics to use these functions.
The following list show all the places affected by the minor bug, and the quick fixes I applied (all code line numbers based on original v0.2.1 unaltered files):
1) Refactor the (unused) get_current_gold_amount Function to return the total quantity of gold from all "gold_coins" items in the inventory.
[code]
File "game/init.rpy", lines 1926-1937, inside get_current_gold_amount:
def get_current_gold_amount():
gold_qty = 0
# Ensure persistent.player_inventory is a list before iterating
if not isinstance(store.persistent.player_inventory, list):
renpy.log("Warning: persistent.player_inventory is not a list in get_current_gold_amount.")
return 0 # Or handle as an error
for item_dict in store.persistent.player_inventory:
if item_dict.get("id") == "gold_coins":
gold_qty += item_dict.get("quantity", 0) # <-- Collective gold quantity
#break # <-- Continue with all the items
return gold_qty
[/code]
2) Add a "lose_item" Function to remove the stackable (and maybe non-stackable) items, like "gold_coins". This function does the opposite of the gain_item Function (File "game/init.rpy", lines 1449-1616) for stackable items on the "# INVENTORY MANAGEMENT #" python block (lines 1448-1945).
# (!) This fix doesnt handle "cursed" equipment that cannot be discarted, or any other special item (that is handled by the discard_item Function, invoked by player).
[code]
File "game/init.rpy", lines 1939-1948, appended after yuki_has_item:
def yuki_has_item(item_id_to_check):
...
return False
def lose_item(item_id, amount=1): # Removed amount parameter, defaults to 1
if item_id not in item_definitions:
renpy.log(f"Error: Tried to lose unknown item '{item_id}'")
return 0
if amount <= 0:
return 0
item_data = item_definitions[item_id]
item_name = item_data.get("name", item_id)
amount_to_remove = amount # Start with the full amount requested
# --- Handle Stackable and Non-Stackable Items (like Gold Coins) ---
i = 0
while i <= len(persistent.player_inventory) and amount_to_remove > 0:
index_in_list = i
item_dict = persistent.player_inventory[index_in_list]
if item_dict.get("id") == item_id:
current_quantity = item_dict.get("quantity", 0)
can_remove_from_stack = current_quantity
if can_remove_from_stack > 0:
remove_now = min(amount_to_remove, can_remove_from_stack)
item_dict["quantity"] = current_quantity - remove_now
amount_to_remove -= remove_now
if item_dict["quantity"] <= 0:
# Continue next iteration using the same index after removing current item
store.persistent.player_inventory.pop(index_in_list)
message_text = f"Subtracted {remove_now} {item_name}."
else:
# Continue next iteration using the next index
i += 1
message_text = f"Subtracted {remove_now} {item_name} (Total: {item_dict['quantity']})."
store._turn_notification_counter += 1 # Increment counter regardless of context
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"): # Ensure chat display is shown
renpy.show_screen("chat_notify_display")
continue
i += 1 # Continue next iteration using the next index
return amount - amount_to_remove # The effectively removed item quantity
init -1 python: # QTE FUNCTIONS #
[/code]
;)