Add finite prebattle shop stock

This commit is contained in:
2026-06-18 09:29:16 +09:00
parent 01c7851b1d
commit 07861391c7
10 changed files with 155 additions and 30 deletions

View File

@@ -2662,9 +2662,12 @@ func _rebuild_shop_buy_list() -> void:
var item := state.get_item_def(normalized_id)
var price := int(item.get("price", 0))
var owned := int(inventory.get(normalized_id, 0))
var stock_limit := state.get_shop_stock_limit(normalized_id)
var purchased := campaign_state.get_shop_purchase_count(active_scenario_id, normalized_id)
var remaining := stock_limit - purchased if stock_limit >= 0 else -1
var buy_button := Button.new()
buy_button.text = _format_shop_item_button_text(normalized_id, item, price, owned)
buy_button.disabled = campaign_state.gold < price
buy_button.text = _format_shop_item_button_text(normalized_id, item, price, owned, stock_limit, remaining)
buy_button.disabled = campaign_state.gold < price or (stock_limit >= 0 and remaining <= 0)
buy_button.pressed.connect(_on_shop_item_pressed.bind(normalized_id))
shop_list.add_child(buy_button)
@@ -2695,15 +2698,21 @@ func _clear_shop_list() -> void:
child.queue_free()
func _format_shop_item_button_text(item_id: String, item: Dictionary, price: int, owned: int) -> String:
func _format_shop_item_button_text(item_id: String, item: Dictionary, price: int, owned: int, stock_limit: int = -1, remaining: int = -1) -> String:
var unavailable := ""
if campaign_state.gold < price:
if stock_limit >= 0 and remaining <= 0:
unavailable = " - sold out"
elif campaign_state.gold < price:
unavailable = " - need %dG" % (price - campaign_state.gold)
return "%s %dG %s Owned x%d%s" % [
var stock_text := ""
if stock_limit >= 0:
stock_text = " Stock %d/%d" % [max(0, remaining), stock_limit]
return "%s %dG %s Owned x%d%s%s" % [
_item_display_name(item_id),
price,
_format_shop_item_effect_text(item),
owned,
stock_text,
unavailable
]
@@ -2743,7 +2752,14 @@ func _on_shop_item_pressed(item_id: String) -> void:
var item_name := _item_display_name(item_id)
if item.is_empty() or price <= 0:
return
if campaign_state.try_buy_item(item_id, price):
var stock_limit := state.get_shop_stock_limit(item_id)
var purchased := campaign_state.get_shop_purchase_count(active_scenario_id, item_id)
if stock_limit >= 0 and purchased >= stock_limit:
_play_ui_cancel()
_on_log_added("%s is sold out." % item_name)
_rebuild_shop_menu()
return
if campaign_state.try_buy_item(item_id, price, active_scenario_id, stock_limit):
state.set_inventory_snapshot(campaign_state.get_inventory_snapshot())
_on_log_added("Bought %s for %d gold." % [item_name, price])
else: