def _gain_unique_item(item_id):
# --- NEW: Handle Unique Items (check for duplicates) ---
if item_id in persistent.unique_items_acquired:
# Player already has this unique item. Give a consolation prize instead.
renpy.notify(f"Duplicate Unique Item! Converted to 100 Gold Coins.")
gain_item("gold_coins", 100)
return False # Dont add the duplicate item.
else:
# This is a new unique item. Add it to the master list.
persistent.unique_items_acquired.add(item_id)
return True # Add the first unique item.
def _gain_artifact_item(item_id):
# --- NEW: Handle Artifacts Separately ---
if not hasattr(persistent, 'artifacts_collected'):
persistent.artifacts_collected = set()
persistent.artifacts_collected.add(item_id)
# Artifacts are not added to persistent.player_inventory, so we notify and return.
renpy.notify(f"Artifact Acquired: {item_definitions[item_id].get('name', item_id)}!")
def _gain_stackable_item(item_id, amount=1):
# --- Handle Stackable Items (like Gold Coins) ---
current_max_capacity = inventory_capacity + getattr(persistent, 'inventory_capacity_bonus', 0) + getattr(store, 'temporary_inventory_bonus', 0) # Include temporary bonus
item_data = item_definitions[item_id]
item_name = item_data.get("name", item_id)
stack_limit = item_data.get("stack_limit") # Stack limit for the item
amount_to_add = max(amount, 1) # Start with the full amount requested (min 1)
# 1. Try to add to existing, non-full stacks
for item_dict in persistent.player_inventory:
if not item_dict.get("id") == item_id:
continue # Skip other items
current_quantity = item_dict.get("quantity", 0)
can_add_to_stack = stack_limit - current_quantity
if not can_add_to_stack > 0:
continue # Item is already max quantity
add_now = min(amount_to_add, can_add_to_stack)
item_dict["quantity"] = current_quantity + add_now
amount_to_add -= add_now
message_text = f"Added {add_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")
if amount_to_add <= 0: break # Added everything
# 2. If amount still remains, try adding new stacks
while amount_to_add > 0:
if len(persistent.player_inventory) < current_max_capacity:
add_this_stack = min(amount_to_add, stack_limit)
persistent.player_inventory.append({"id": item_id, "quantity": add_this_stack})
amount_to_add -= add_this_stack
message_text = f"Added new stack of {add_this_stack} {item_name}."
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
else:
message_text = "Inventory Full!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
break # Stop trying to add new stacks
def _gain_upgradeable_item(item_id, level=1, _reset_cooldown=False, _allow_duplicates=False):
# --- Handle Upgradeable Items (Equipment/Skill logic: upgrade if exists, else add new if space) ---
global current_skill_cooldowns
current_max_capacity = inventory_capacity + getattr(persistent, 'inventory_capacity_bonus', 0) + getattr(store, 'temporary_inventory_bonus', 0) # Include temporary bonus
item_data = item_definitions[item_id]
item_name = item_data.get("name", item_id)
max_level = item_data.get("max_level", 1) # Max level for the item
#is_upgradeable = item_data.get("upgradeable", False) # LEGACY
is_upgradeable = max_level > 1
if is_upgradeable or not _allow_duplicates: # Only skip non-upgradeable duplicable items (Equipment)
found_existing = False # Found existing item
for found_existing_index, existing_item_dict in enumerate(persistent.player_inventory):
if not existing_item_dict.get("id") == item_id:
continue # Skip other items
# Item already exists
found_existing = True
current_level = existing_item_dict.get("level", 1)
# max_level is already defined from item_data
if not current_level < max_level:
continue # Item is already max level
new_level = max(level, 1)
new_level = min(current_level + new_level, max_level)
existing_item_dict["level"] = new_level
message_text = f"Upgraded {item_name} to Level {new_level}!"
store._turn_notification_counter += 1
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")
if not _reset_cooldown:
continue # No cooldown reset
if item_id in current_skill_cooldowns: # Reset cooldown on upgrade
del current_skill_cooldowns[item_id]
if store.in_dungeon: renpy.restart_interaction()
return # Stop the function here to prevent the "already Max Level!" notification.
if found_existing: # All items are already max level
message_text = f"{item_name} is already Max Level!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"): renpy.show_screen("chat_notify_display")
return # Stop the function here to prevent adding the item.
if len(persistent.player_inventory) < current_max_capacity: # Item doesn't exist or its non-upgradeable and duplicable, add new if space
new_level = max(level, 1)
new_level = min(new_level, max_level)
persistent.player_inventory.append({"id": item_id, "level": new_level}) # Always add new items at level 1 (default if not given)
if is_upgradeable: # Only show starting level for upgradeable items
message_text = f"Obtained: {item_name} (Level {new_level})!"
else:
message_text = f"Obtained: {item_name}!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
else: # No space for new item
message_text = "Inventory Full!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
def _gain_consumable_item(item_id, uses=0):
# --- NEW: Handle Consumable Items (Potions/Food logic: limited uses) ---
current_max_capacity = inventory_capacity + getattr(persistent, 'inventory_capacity_bonus', 0) + getattr(store, 'temporary_inventory_bonus', 0) # Include temporary bonus
item_data = item_definitions[item_id]
item_name = item_data.get("name", item_id)
max_uses = item_data.get("uses", 1) # Max amount of uses for the item
if len(persistent.player_inventory) < current_max_capacity: # Add new if space
new_item_dict = {"id": item_id, "level": 1} # Base item dict
remaining_uses = max_uses
if not uses == 0:
starting_uses = min(uses, max_uses - 1) if uses > 0 else max(max_uses + uses, 0) # Uses done from 0 to max-1, or, Uses remaining from max-abs(uses) to 0
if not starting_uses == 0: # Only set if not default 0
new_item_dict["uses"] = starting_uses # Initialize with an amount of uses done
remaining_uses -= starting_uses
persistent.player_inventory.append(new_item_dict)
if not max_uses == 1:
message_text = f"Obtained: {item_name} ({remaining_uses} Uses)!" if remaining_uses > 1 else f"Obtained: {item_name} ({remaining_uses} Use)!"
else:
message_text = f"Obtained: {item_name}!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
else: # No space for new item
message_text = "Inventory Full!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
def _gain_other_item(item_id):
# --- Handle Non-Stackable, Non-Upgradeable Items ---
current_max_capacity = inventory_capacity + getattr(persistent, 'inventory_capacity_bonus', 0) + getattr(store, 'temporary_inventory_bonus', 0) # Include temporary bonus
item_data = item_definitions[item_id]
item_name = item_data.get("name", item_id)
if len(persistent.player_inventory) < current_max_capacity: # Add new if space
# MODIFICATION START: Data-driven stack initialization
new_item_dict = {"id": item_id, "level": 1} # Base item dict
if item_data.get("has_stacks", False):
new_item_dict["stacks"] = 0 # Initialize with 0 stacks if defined
persistent.player_inventory.append(new_item_dict)
# MODIFICATION END
message_text = f"Obtained: {item_name}!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
else: # No space for new item
message_text = "Inventory Full!"
store._turn_notification_counter += 1
add_chat_notification(message_text, store._turn_notification_counter)
if not renpy.get_screen("chat_notify_display"):
renpy.show_screen("chat_notify_display")
def use_item(item_id, index_in_list):
[/code]
;)