feat: 2.3.2
This commit is contained in:
@@ -25,6 +25,7 @@ var fragments: Dictionary = {} # frag_common, frag_uncommon, frag_rare
|
||||
var inventory: Array = []
|
||||
var loadout: Dictionary = {"head": "", "costume": "", "glove": "", "accessory": ""}
|
||||
var shop_catalog: Dictionary = {}
|
||||
var featured_banners: Array = []
|
||||
var is_profile_loaded: bool = false
|
||||
|
||||
# Nakama storage collection names
|
||||
@@ -311,14 +312,13 @@ func update_loadout(category: String, item_id: String) -> bool:
|
||||
loadout[category] = item_id
|
||||
return await _save_profile_data()
|
||||
|
||||
func purchase_item(item_id: String, price_gold: int, price_star: int, category: String) -> bool:
|
||||
if not NakamaManager.session: return false
|
||||
func purchase_item(item_id: String) -> String:
|
||||
if not NakamaManager.session: return "Not authenticated"
|
||||
|
||||
var payload = JSON.stringify({
|
||||
"item_id": item_id,
|
||||
"price_gold": price_gold,
|
||||
"price_star": price_star,
|
||||
"category": category
|
||||
"quantity": 1,
|
||||
"idempotency_key": str(randi()) + "_" + str(Time.get_ticks_usec())
|
||||
})
|
||||
|
||||
var result = await NakamaManager.client.rpc_async(
|
||||
@@ -328,17 +328,20 @@ func purchase_item(item_id: String, price_gold: int, price_star: int, category:
|
||||
)
|
||||
|
||||
if result.is_exception():
|
||||
push_error("[UserProfileManager] Purchase failed: ", result.get_exception().message)
|
||||
return false
|
||||
var msg = result.get_exception().message
|
||||
push_error("[UserProfileManager] Purchase failed: ", msg)
|
||||
return msg
|
||||
|
||||
# Update local cache
|
||||
if price_gold > 0: wallet["gold"] -= price_gold
|
||||
if price_star > 0: wallet["star"] -= price_star
|
||||
if not inventory.has(item_id):
|
||||
inventory.append(item_id)
|
||||
|
||||
emit_signal("profile_updated")
|
||||
return true
|
||||
var response = JSON.parse_string(result.payload)
|
||||
if typeof(response) == TYPE_DICTIONARY and response.has("success") and response.success == true:
|
||||
await _reload_wallet()
|
||||
if not inventory.has(item_id):
|
||||
inventory.append(item_id)
|
||||
|
||||
emit_signal("profile_updated")
|
||||
return ""
|
||||
|
||||
return "Unknown error"
|
||||
|
||||
func fetch_shop_catalog() -> void:
|
||||
if not NakamaManager.session: return
|
||||
@@ -356,6 +359,8 @@ func fetch_shop_catalog() -> void:
|
||||
var payload: Dictionary = JSON.parse_string(result.payload)
|
||||
if payload and payload.has("catalog"):
|
||||
shop_catalog = payload.catalog
|
||||
if payload.has("featured_banners"):
|
||||
featured_banners = payload.get("featured_banners", [])
|
||||
emit_signal("profile_updated")
|
||||
|
||||
## Admin-only: grants a large amount of gold via a server-authoritative RPC.
|
||||
@@ -377,7 +382,9 @@ func buy_currency(package_id: String) -> bool:
|
||||
if not NakamaManager.session: return false
|
||||
|
||||
var payload = JSON.stringify({
|
||||
"package_id": package_id
|
||||
"package_id": package_id,
|
||||
"idempotency_key": str(randi()) + "_" + str(Time.get_ticks_usec()),
|
||||
"receipt": "mock_receipt_for_now"
|
||||
})
|
||||
|
||||
var result = await NakamaManager.client.rpc_async(
|
||||
@@ -387,9 +394,17 @@ func buy_currency(package_id: String) -> bool:
|
||||
)
|
||||
|
||||
if result.is_exception():
|
||||
push_error("[UserProfileManager] Failed to buy currency: ", result.get_exception().message)
|
||||
var msg = result.get_exception().message
|
||||
if "NotEnoughFunds" in msg:
|
||||
push_error("[UserProfileManager] Failed to buy currency: Not enough funds.")
|
||||
else:
|
||||
push_error("[UserProfileManager] Failed to buy currency: ", msg)
|
||||
return false
|
||||
|
||||
var response = JSON.parse_string(result.payload)
|
||||
if typeof(response) == TYPE_DICTIONARY and response.has("status") and response.status == "pending":
|
||||
print("[UserProfileManager] Currency purchase pending verification.")
|
||||
|
||||
await _reload_wallet()
|
||||
return true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user