这三个函数用于在 GameServer 与网站之间完整转移一件物品(例如网站上的物品市场、WebAPI.lua 文件)。物品通过一个记录 (record) 字符串转移,其格式与数据库中保存的物品数据相同:完整保留 serial、option、socket、Harmony、380 以及扩展字段,因此不会丢失任何内容,也不会产生新的 serial。记录字符串的内容是系统内部数据:只需原样保存和原样传回,不要自行修改。
Item.TakeRecord 函数在成功时会立即从 GameServer 删除该物品。调用方必须先保存返回的记录(例如写入数据库)再做其他事情,否则物品将会丢失。这些函数中使用的 box 值:1 = 背包(从第 12 格开始,即装备格之后,直到可用背包部分的末尾;源码注释写的是 12 到 203),2 = 仓库。
Item.GetRecord
读取某个格子中物品的记录(只读,不删除)。
Item.GetRecord(aIndex, box, slot) -> string | nil
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
box | integer | 1 = 背包,2 = 仓库 |
slot | integer | 格子序号 |
返回值:记录字符串;如果格子为空或参数错误则为 nil。
local rec = Item.GetRecord(aIndex, 1, 20)
if rec then Log.Add(rec) end
Item.TakeRecord
从角色身上取出物品:返回记录并从 GameServer 删除该物品。
Item.TakeRecord(aIndex, box, slot [, serial]) -> record, itemCode | nil, reason
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引(必须正在游戏中) |
box | integer | 1 = 背包(不能取走已穿戴的物品,不能取走个人商店中的物品),2 = 仓库(仓库被密码锁定时拒绝) |
slot | integer | 格子序号 |
serial | integer(可选) | 如果传入,则该格子中的物品必须正是这个 serial(用于玩家在网站上选择后物品刚好被移动位置的情况) |
返回值:
- 成功:2 个值
record(记录字符串)和itemCode(物品代码)。物品已从 GameServer 删除。 - 失败:
nil以及一个英文的原因字符串。
| 原因 (reason) | 含义 |
|---|---|
character is not in game | 角色不在游戏中 |
busy | 角色正在打开窗口、交易或传送 |
bad box | box 不是 1 或 2 |
bad slot | 格子超出该 box 允许的范围 |
warehouse locked | 仓库已锁定 |
empty slot | 格子中没有物品 |
item moved | 传入的 serial 与该格子中的物品不匹配 |
item not allowed | 物品被禁止:有期限、被锁定 / 不允许交易、是 Pentagram 或 Errtel |
每次成功取出都会记入物品日志。
local rec, code = Item.TakeRecord(aIndex, 1, 20, serial)
if rec == nil then
Log.AddC(3, "无法取出物品:" .. tostring(code)) -- 失败时,第 2 个值是原因
else
-- 在此处立即把 rec 保存到数据库
end
Item.GremoryAddRecord
根据一条记录,在角色的 Gremory 箱中重新创建完全相同的物品(保留 serial)。
Item.GremoryAddRecord(aIndex, record [, storage]) -> true | false, reason
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引(必须正在游戏中) |
record | string | 恰好 1 件物品的记录字符串(来自 Item.GetRecord / Item.TakeRecord) |
storage | integer | 1 = 角色箱,2 = 账号箱,其他值或省略 = Personal Store 标签页(默认 3) |
返回值:已添加则为 true;失败则为 false 并附带原因字符串:
| 原因 (reason) | 含义 |
|---|---|
character is not in game | 角色不在游戏中 |
bad record | 记录字符串无效(必须恰好包含 1 件物品) |
unknown item | 记录中的物品代码不在 ItemList 中 |
item already in game | 该 serial 已存在于角色身上(背包、仓库或 Gremory):拒绝以防止复制物品 |
gremory case is full | Gremory 箱已满 |
在箱中的保存期限按 GremoryCase.xml 的配置(键 StorageExpire);记录中物品的使用期限保持不变。
local ok, why = Item.GremoryAddRecord(aIndex, rec, 1)
if not ok then Log.AddC(3, "GremoryAddRecord: " .. tostring(why)) end