外观
GN_Item 物品接口
GetEquipDurability
用途: 读取人物或英雄装备的当前耐久。
pascal
function This_Player.GetEquipDurability(
Slot: Integer; IsHero: Boolean): Integer;| 参数 | 说明 |
|---|---|
Slot | 装备位置 0..15 |
IsHero | False 人物,True 当前已加载的英雄 |
返回内部耐久值,1000 对应显示耐久 1。空槽、位置无效、英雄未加载或耐久耗尽时返回 0。
pascal
if This_Player.GetEquipDurability(1, False) > 0 then
DebugOut('武器仍有耐久');GN_Item_Give
用途: 创建物品,写入已注册的命名属性后放入背包。
pascal
function GN_Item_Give(Player: TPlayer; const ItemName: string;
ForceBind: Boolean; const AttrsJson: string): Integer;| 参数 | 说明 |
|---|---|
Player | 当前有效的玩家对象 |
ItemName | 物品模板名称 |
ForceBind | True 额外永久绑定;False 保留模板规则 |
AttrsJson | 命名属性 JSON;无属性可传 {} |
JSON 示例:{"yanshen":{"element.1":100}}。
| 返回值 | 说明 |
|---|---|
| 1 | 成功 |
| -1 | 玩家或参数无效 |
| -2 | 物品不存在 |
| -3 | 背包已满或入包失败 |
| -4 | JSON、属性或编码无效 |
| -5 | 属性容量超限 |
pascal
GN_Item_Give(This_Player, '木剑', False, '{}');GN_Item_GiveWithRare
用途: 同时写入命名属性和六槽极品值后发放物品。
pascal
function GN_Item_GiveWithRare(Player: TPlayer; const ItemName: string;
ForceBind: Boolean; const AttrsJson: string;
Rare1, Rare2, Rare3, Rare4, Rare5, Rare6: Int64): Integer;返回值与 GN_Item_Give 相同。Int32 模式下每个极品值为 0..255;Int64 模式下为非负 Int64,越界返回 -1。
GN_ItemRare_Get / GN_ItemRare_Set
用途: 按位置读取或设置物品的六槽极品值。
pascal
function GN_ItemRare_Get(Player: TPlayer;
LocationType, ItemId, RareSlot: Integer;
DefaultValue: Int64): Int64;
function GN_ItemRare_Set(Player: TPlayer;
LocationType, ItemId, RareSlot: Integer;
Value: Int64): Boolean;LocationType | ItemId 的含义 |
|---|---|
| 0 | 人物装备位置 0..15 |
| 1 | 当前背包列表下标,从 0 开始 |
| 2 | 物品 MakeIndex,先查装备再查背包 |
RareSlot 为 1..6,Value=0 清除该槽。读取失败返回 DefaultValue,设置失败返回 False。背包下标会变化,不应跨操作长期保存。
GN_ItemAttr 对象接口
用途: 通过物品对象读写已注册的命名数值属性。
pascal
function GN_ItemAttr_Get(Item: TBaseItem;
const Namespace, Key: string; DefaultValue: Int64): Int64;
function GN_ItemAttr_Set(Item: TBaseItem;
const Namespace, Key: string; Value: Int64): Integer;
function GN_ItemAttr_Remove(Item: TBaseItem;
const Namespace, Key: string): Boolean;
function GN_ItemAttr_Exists(Item: TBaseItem;
const Namespace, Key: string): Boolean;Set 中 Value=0 表示删除。
| Set 返回值 | 说明 |
|---|---|
| 1 | 新增 |
| 2 | 更新或删除 |
| 0 | 没有变化 |
| -1 | 物品无效 |
| -2 | 属性未注册 |
| -3 | 超过 32 项 |
| -4 | 超过 128 字节编码容量 |
| -5 | 属性数据损坏或格式不支持 |
当前公开登记的命名属性为 yanshen / element.1 至 element.17。保存属性只负责存储,不会自动产生战斗效果。
GN_ItemAttr 装备接口
用途: 按人物装备位置读写命名数值属性。
pascal
function GN_ItemAttr_GetEquipped(Player: TPlayer; Slot: Integer;
IsHero: Boolean; const Namespace, Key: string;
DefaultValue: Int64): Int64;
function GN_ItemAttr_SetEquipped(Player: TPlayer; Slot: Integer;
IsHero: Boolean; const Namespace, Key: string;
Value: Int64): Integer;
function GN_ItemAttr_RemoveEquipped(Player: TPlayer; Slot: Integer;
IsHero: Boolean; const Namespace, Key: string): Boolean;
function GN_ItemAttr_ExistsEquipped(Player: TPlayer; Slot: Integer;
IsHero: Boolean; const Namespace, Key: string): Boolean;返回规则与对象接口相同。当前只支持 IsHero=False;传入 True 会报告该能力不可用。
pascal
GN_ItemAttr_ExistsEquipped(
This_Player, 1, False, 'yanshen', 'element.1');