Add card salvage system and player storefront / trading features
Server: - CardSalvageValues: rarity-base + (SpCost+StCost)*CostMultiplier formula, foil 2x - CollectionSalvageCardHandler: collection.salvage_card — validates ownership, tradeable, not listed, deck copy check, then atomically deletes card + credits OP - BazaarGetPlayerShopHandler: bazaar.get_player_shop — paginated active listings for any seller with their display name (public read endpoint) - BazaarGetSuggestedPriceHandler: bazaar.get_suggested_price — recent sale avg if ≥3 sales, otherwise 4× salvage floor - Added GetPlayerShopRequest/Response + GetSuggestedPriceRequest/Response DTOs - Added SalvageCardRequest/Response DTOs - Registered all 3 new handlers in their respective ServiceRegistration files Client: - card_detail_popup: List for Sale form (with live price suggestion) + Salvage button with OP preview; both gated on IsTradeable - salvage_confirm_popup: confirmation modal that calls collection.salvage_card, emits confirmed(player_card_id, op_awarded) on success - bazaar_screen: My Shop tab (own active listings + cancel), player storefront search by account ID, sort options for own listings Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -6,11 +6,22 @@ extends Control
|
||||
##
|
||||
## Added to the viewport root at runtime by collection_screen.gd so it renders
|
||||
## above the VBoxContainer layout regardless of scene structure.
|
||||
##
|
||||
## Economy actions:
|
||||
## "List for Sale" — opens an inline listing form backed by bazaar.list_card.
|
||||
## "Salvage" — opens salvage_confirm_popup to destroy the card for OP.
|
||||
|
||||
const _CardWidget = preload("res://scenes/collection/components/card_widget.gd")
|
||||
const _StatRow = preload("res://scenes/collection/components/StatRow.tscn")
|
||||
const _AbilityRow = preload("res://scenes/collection/components/AbilityRow.tscn")
|
||||
|
||||
## Emitted after a successful salvage so the parent collection screen can
|
||||
## remove the card from its list without a full reload.
|
||||
signal card_salvaged(player_card_id: String)
|
||||
|
||||
## Emitted after a successful listing so the parent can update UI state.
|
||||
signal card_listed(player_card_id: String)
|
||||
|
||||
const RARITY_COLOR := {
|
||||
"Common": Color(0.67, 0.67, 0.67),
|
||||
"Uncommon": Color(0.27, 0.85, 0.27),
|
||||
@@ -19,6 +30,14 @@ const RARITY_COLOR := {
|
||||
"Legendary": Color(1.00, 0.67, 0.13),
|
||||
}
|
||||
|
||||
# Rarity → OP per combined SP+ST point (mirrors CardSalvageValues server-side).
|
||||
const SALVAGE_BASE := {
|
||||
"Common": 5, "Uncommon": 12, "Rare": 40, "Epic": 120, "Legendary": 300
|
||||
}
|
||||
const SALVAGE_COST_MULT := {
|
||||
"Common": 1, "Uncommon": 2, "Rare": 5, "Epic": 12, "Legendary": 25
|
||||
}
|
||||
|
||||
# ── Node refs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@onready var overlay : ColorRect = %Overlay
|
||||
@@ -33,33 +52,67 @@ const RARITY_COLOR := {
|
||||
@onready var abilities_sep : HSeparator = %AbilitiesSep
|
||||
@onready var abilities_title: Label = %AbilitiesTitle
|
||||
@onready var abilities_list : VBoxContainer = %AbilitiesList
|
||||
@onready var action_row : HBoxContainer = %ActionRow
|
||||
@onready var list_btn : Button = %ListBtn
|
||||
@onready var salvage_btn : Button = %SalvageBtn
|
||||
@onready var list_form : VBoxContainer = %ListForm
|
||||
@onready var list_price_input : LineEdit = %ListPriceInput
|
||||
@onready var list_type_option : OptionButton = %ListTypeOption
|
||||
@onready var list_submit_btn : Button = %ListSubmitBtn
|
||||
@onready var list_cancel_btn : Button = %ListCancelBtn
|
||||
@onready var list_hint_label : Label = %ListHintLabel
|
||||
@onready var salvage_popup : Control = %SalvageConfirmPopup
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var _player_card_id : String = ""
|
||||
var _card_name : String = ""
|
||||
var _rarity : String = ""
|
||||
var _is_foil : bool = false
|
||||
var _sp_cost : int = 0
|
||||
var _st_cost : int = 0
|
||||
var _submitting : bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
overlay.gui_input.connect(_on_overlay_input)
|
||||
close_btn.pressed.connect(hide)
|
||||
list_btn.pressed.connect(_on_list_pressed)
|
||||
salvage_btn.pressed.connect(_on_salvage_pressed)
|
||||
list_submit_btn.pressed.connect(_on_list_submit)
|
||||
list_cancel_btn.pressed.connect(_hide_list_form)
|
||||
list_type_option.add_item("Fixed Price")
|
||||
list_type_option.add_item("Auction")
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## show_card(dto, def)
|
||||
## dto: PlayerCardDto dict (playerCardId, isFoil, isTradeable, ...)
|
||||
## def: CardDefinition dict merged in by the collection screen (name, rarity, spCost, stCost, ...)
|
||||
func show_card(dto: Dictionary, def: Dictionary) -> void:
|
||||
var affinity := str(dto.get("affinity", ""))
|
||||
var rarity := str(dto.get("rarity", ""))
|
||||
var card_type := str(dto.get("cardType", ""))
|
||||
var is_foil := bool(dto.get("isFoil", false))
|
||||
_player_card_id = str(dto.get("playerCardId", ""))
|
||||
var affinity := str(dto.get("affinity", def.get("affinity", "")))
|
||||
_rarity = str(dto.get("rarity", def.get("rarity", "")))
|
||||
var card_type := str(dto.get("cardType", def.get("cardType", "")))
|
||||
_is_foil = bool(dto.get("isFoil", false))
|
||||
_sp_cost = int(def.get("spCost", 0))
|
||||
_st_cost = int(def.get("stCost", 0))
|
||||
_card_name = str(def.get("name", dto.get("name", "Unknown")))
|
||||
var is_tradeable := bool(dto.get("isTradeable", true))
|
||||
|
||||
# Header
|
||||
name_label.text = str(dto.get("name", "Unknown"))
|
||||
name_label.text = _card_name
|
||||
affinity_icon.texture = _CardWidget.affinity_icon(affinity)
|
||||
affinity_icon.modulate = _CardWidget.AFFINITY_BORDER.get(affinity, Color.WHITE)
|
||||
foil_badge.visible = is_foil
|
||||
foil_badge.visible = _is_foil
|
||||
|
||||
# Tags
|
||||
type_label.text = card_type
|
||||
affinity_label.text = affinity
|
||||
affinity_label.modulate = _CardWidget.AFFINITY_BORDER.get(affinity, Color.WHITE)
|
||||
rarity_label.text = rarity
|
||||
rarity_label.modulate = RARITY_COLOR.get(rarity, Color(0.67, 0.67, 0.67))
|
||||
rarity_label.text = _rarity
|
||||
rarity_label.modulate = RARITY_COLOR.get(_rarity, Color(0.67, 0.67, 0.67))
|
||||
|
||||
# Stats grid
|
||||
_populate_stats(def)
|
||||
@@ -67,8 +120,119 @@ func show_card(dto: Dictionary, def: Dictionary) -> void:
|
||||
# Abilities
|
||||
_populate_abilities(def)
|
||||
|
||||
# Economy buttons — only tradeable cards can be listed or salvaged.
|
||||
action_row.visible = is_tradeable
|
||||
list_btn.visible = is_tradeable
|
||||
salvage_btn.visible = is_tradeable
|
||||
if is_tradeable:
|
||||
var op := _calc_salvage_op()
|
||||
salvage_btn.text = "Salvage (%d OP)" % op
|
||||
|
||||
_hide_list_form()
|
||||
show()
|
||||
|
||||
# ── Economy helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
func _calc_salvage_op() -> int:
|
||||
var base_val : int = SALVAGE_BASE.get(_rarity, 5)
|
||||
var mult : int = SALVAGE_COST_MULT.get(_rarity, 1)
|
||||
var value : int = base_val + (_sp_cost + _st_cost) * mult
|
||||
return value * 2 if _is_foil else value
|
||||
|
||||
|
||||
func _on_list_pressed() -> void:
|
||||
list_form.visible = true
|
||||
list_btn.visible = false
|
||||
# Fetch suggested price in the background; populate when it arrives.
|
||||
list_price_input.placeholder_text = "Loading suggestion..."
|
||||
list_hint_label.text = ""
|
||||
Network.request(
|
||||
"bazaar.get_suggested_price",
|
||||
{ "cardDefinitionId": str(def.get("cardDefinitionId", "")), "isFoil": _is_foil },
|
||||
_on_price_suggestion_ok,
|
||||
_on_price_suggestion_err
|
||||
)
|
||||
|
||||
|
||||
func _on_price_suggestion_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var suggested := float(d.get("suggestedPrice", 0))
|
||||
list_price_input.text = str(int(suggested))
|
||||
list_price_input.placeholder_text = ""
|
||||
var sale_count : int = int(d.get("saleCount", 0))
|
||||
if sale_count >= 3:
|
||||
list_hint_label.text = "Based on %d recent sales" % sale_count
|
||||
else:
|
||||
list_hint_label.text = "Suggested floor (no sale history)"
|
||||
|
||||
|
||||
func _on_price_suggestion_err(_code: String, _msg: String) -> void:
|
||||
var floor_op := _calc_salvage_op() * 4
|
||||
list_price_input.text = str(floor_op)
|
||||
list_price_input.placeholder_text = ""
|
||||
list_hint_label.text = "Using salvage-based floor"
|
||||
|
||||
|
||||
func _hide_list_form() -> void:
|
||||
list_form.visible = false
|
||||
list_btn.visible = true
|
||||
_submitting = false
|
||||
|
||||
|
||||
func _on_list_submit() -> void:
|
||||
if _submitting or _player_card_id.is_empty():
|
||||
return
|
||||
var price_str := list_price_input.text.strip_edges()
|
||||
if not price_str.is_valid_int() and not price_str.is_valid_float():
|
||||
list_hint_label.text = "Enter a valid price."
|
||||
return
|
||||
var price := float(price_str)
|
||||
if price <= 0:
|
||||
list_hint_label.text = "Price must be greater than 0."
|
||||
return
|
||||
|
||||
_submitting = true
|
||||
list_submit_btn.disabled = true
|
||||
list_hint_label.text = "Listing..."
|
||||
|
||||
var listing_type : String = "Fixed" if list_type_option.selected == 0 else "Auction"
|
||||
Network.request(
|
||||
"bazaar.list_card",
|
||||
{
|
||||
"playerCardId": _player_card_id,
|
||||
"price": price,
|
||||
"listingType": listing_type,
|
||||
"isMasked": false,
|
||||
},
|
||||
_on_list_ok,
|
||||
_on_list_err
|
||||
)
|
||||
|
||||
|
||||
func _on_list_ok(_t: String, _p: Variant) -> void:
|
||||
list_hint_label.text = "Listed successfully!"
|
||||
card_listed.emit(_player_card_id)
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
hide()
|
||||
|
||||
|
||||
func _on_list_err(code: String, _msg: String) -> void:
|
||||
_submitting = false
|
||||
list_submit_btn.disabled = false
|
||||
list_hint_label.text = "Error: %s" % code
|
||||
|
||||
|
||||
func _on_salvage_pressed() -> void:
|
||||
if _player_card_id.is_empty():
|
||||
return
|
||||
salvage_popup.show_confirm(_player_card_id, _card_name, _rarity, _is_foil, _calc_salvage_op())
|
||||
salvage_popup.confirmed.connect(_on_salvage_confirmed, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _on_salvage_confirmed(player_card_id: String, op_awarded: int) -> void:
|
||||
card_salvaged.emit(player_card_id)
|
||||
hide()
|
||||
|
||||
|
||||
# ── Private ───────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
extends Control
|
||||
## Salvage confirmation popup.
|
||||
##
|
||||
## Call show_confirm(...) to populate and display.
|
||||
## Emits confirmed(player_card_id, op_awarded) on success.
|
||||
## Emits cancelled() if the player backs out.
|
||||
##
|
||||
## The popup sends collection.salvage_card to the server and only emits
|
||||
## confirmed after a successful response, so the caller never needs to
|
||||
## handle partial state.
|
||||
|
||||
signal confirmed(player_card_id: String, op_awarded: int)
|
||||
signal cancelled
|
||||
|
||||
# ── Node refs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@onready var overlay : ColorRect = %Overlay
|
||||
@onready var card_name_lbl: Label = %CardNameLbl
|
||||
@onready var rarity_lbl : Label = %RarityLbl
|
||||
@onready var foil_lbl : Label = %FoilLbl
|
||||
@onready var reward_lbl : Label = %RewardLbl
|
||||
@onready var confirm_btn : Button = %ConfirmBtn
|
||||
@onready var cancel_btn : Button = %CancelBtn
|
||||
@onready var status_lbl : Label = %StatusLbl
|
||||
|
||||
const RARITY_COLOR := {
|
||||
"Common": Color(0.67, 0.67, 0.67),
|
||||
"Uncommon": Color(0.27, 0.85, 0.27),
|
||||
"Rare": Color(0.27, 0.53, 1.00),
|
||||
"Epic": Color(0.67, 0.27, 1.00),
|
||||
"Legendary": Color(1.00, 0.67, 0.13),
|
||||
}
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var _player_card_id : String = ""
|
||||
var _op_preview : int = 0
|
||||
var _busy : bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
confirm_btn.pressed.connect(_on_confirm)
|
||||
cancel_btn.pressed.connect(_on_cancel)
|
||||
overlay.gui_input.connect(_on_overlay_input)
|
||||
hide()
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
func show_confirm(
|
||||
player_card_id : String,
|
||||
card_name : String,
|
||||
rarity : String,
|
||||
is_foil : bool,
|
||||
op_preview : int) -> void:
|
||||
_player_card_id = player_card_id
|
||||
_op_preview = op_preview
|
||||
_busy = false
|
||||
confirm_btn.disabled = false
|
||||
status_lbl.text = "This cannot be undone."
|
||||
|
||||
card_name_lbl.text = card_name
|
||||
rarity_lbl.text = rarity
|
||||
rarity_lbl.modulate = RARITY_COLOR.get(rarity, Color.WHITE)
|
||||
foil_lbl.visible = is_foil
|
||||
reward_lbl.text = "You will receive ◆ %d OP" % op_preview
|
||||
|
||||
show()
|
||||
|
||||
# ── Handlers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_confirm() -> void:
|
||||
if _busy or _player_card_id.is_empty():
|
||||
return
|
||||
_busy = true
|
||||
confirm_btn.disabled = true
|
||||
status_lbl.text = "Salvaging..."
|
||||
|
||||
Network.request(
|
||||
"collection.salvage_card",
|
||||
{ "playerCardId": _player_card_id },
|
||||
_on_ok,
|
||||
_on_err
|
||||
)
|
||||
|
||||
|
||||
func _on_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var op_awarded : int = int(d.get("originPointsAwarded", _op_preview))
|
||||
status_lbl.text = "Done! ◆ %d OP awarded." % op_awarded
|
||||
await get_tree().create_timer(0.8).timeout
|
||||
confirmed.emit(_player_card_id, op_awarded)
|
||||
hide()
|
||||
|
||||
|
||||
func _on_err(code: String, _msg: String) -> void:
|
||||
_busy = false
|
||||
confirm_btn.disabled = false
|
||||
status_lbl.text = "Error: %s" % code
|
||||
|
||||
|
||||
func _on_cancel() -> void:
|
||||
if _busy:
|
||||
return
|
||||
cancelled.emit()
|
||||
hide()
|
||||
|
||||
|
||||
func _on_overlay_input(event: InputEvent) -> void:
|
||||
if _busy:
|
||||
return
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
_on_cancel()
|
||||
elif event is InputEventScreenTouch and event.pressed:
|
||||
_on_cancel()
|
||||
Reference in New Issue
Block a user