游戏创意与功能

你的下一项功能

物品

为所选项目管理独立装备、属性、目录规则与玩家背包。

SDK:develop 分支需要玩家会话
Godot
物品功能示意图
可见的结果

保存后目录包含starter_sword。完成核对后的示例购买后,当前背包包含其唯一instanceId。

视频稍后提供

此步骤尚无视频。指南和MCP请求已可使用。

物品

准备同一个项目

  1. 在仪表盘中选择与游戏配置相同的项目。

    物品 →
  2. 在控制台表单中创建或复用这些测试条目。这些是示例值,并非项目当前数据。

    键
    starter_sword
    名称
    Quickstart Sword
    类型
    equipment
    稀有度
    common
    启用
    true
    基础属性
    {"damage":5}
    属性规则
    []

    物品拥有独立身份和属性。可计数资源属于玩家数值,纯外观装饰属于玩家档案。

    按玩家值指南准备coins。保存启用的starter-sword报价:花费10 coins,物品奖励为1 starter_sword。

    玩家数值 →
  3. 运行示例前先保存、重新加载并核对条目。保留其他定义。

实现此功能

你可以预览指南。运行需要有效的项目密钥。 准备项目

已安装 SDK、导入项目配置,且玩家已登录。

此 SDK 示例使用 develop。请检查已安装的 SDK 是否具备所需 API。

先通过快速入门连接目标玩家,再通过明确的按钮或场景操作调用read_catalog_page(), read_inventory()。仅打开文件不会发送请求。

GDScript
res://scripts/items.gd
horizOn 调用
1extends Node
2​
3# Connect and restore the existing player first. Each function is an explicit action.
4func read_inventory() -> void:
5 var user = Horizon.auth.getCurrentUser()
6 if user == null:
7 return
8 var result = await Horizon.items.getInventory(user.userId)
9 if not result.success:
10 push_warning(result.errorCode)
11 return
12 for item in result.data.instances:
13 print(item.instanceId, ": ", item.itemKey)
14 # Keep result.data.revision for a separately reviewed mutation.
15​
16func read_catalog_page() -> void:
17 var user = Horizon.auth.getCurrentUser()
18 if user == null:
19 return
20 var result = await Horizon.items.getCatalog(user.userId, "", 1)
21 if not result.success:
22 push_warning(result.errorCode)
23 return
24 print("Catalog revision: ", result.data.revision)
25 # Explicit Next retains revision and nextAfterKey; no automatic page loop.
26# Durable mutations: addons/horizon_sdk/examples/features/items_example.gd.
27# Preserve original instance/body/revision and the original PV purchase operationId.
28# Initial success may include item references; retained replay may return empty applied/items.
29# Read the current inventory separately; never reconstruct earlier item references.
30# A failed refresh never authorizes another purchase or a local item grant.
打开完整SDK示例 ↗

使用已保存的物品

导入官方示例及辅助文件。核对报价后,用现有玩家按下方顺序执行。等待每一步完成,只确认购买一次。响应不确定时保留原始请求。

items_example.gd: load_catalog_page() → review_offer("starter-sword") → purchase_reviewed_offer() → refresh_inventory()

测试你的新功能。

保存后目录包含starter_sword。完成核对后的示例购买后,当前背包包含其唯一instanceId。

在仪表盘中选择与游戏配置相同的项目。

接口
  • GET/items
  • GET/items/catalog
  • POST/items/adjust
  • POST/items/equip
  • POST/items/discard
API 参考中的全部接口
排行榜功能示意图
下一步建议

为每一局添加最高分。

每局结束后保存分数并展示领先者。继续使用现有连接和玩家会话。