一、学习案例

(一)TPL模版.md中的案例

TPL_ITEM.DEMO = ItemTpl()
    :modelAlias("TreasureChest") -- 宝箱模型
    :name("物品例子")
    :bindAbility(TPL_ABILITY.DEMO)
    :icon("black")
    :worth({ gold = 10 })
    :onEvent(EVENT.Item.Get,
    function(getData)
        echo("获得物品", getData.triggerUnit:owner())
    end)
  • ItemTpl() 调用:

调用library/class/vast/itemTpl.lua中的构造函数。创建一个新的物品模板实例。
返回的对象支持链式调用

  • :modelAlias("TreasureChest")

设置模型别名,内部会转换为实际模型路径。对应itemTpl.lua中的model()方法。

  • :name("物品例子")

设置物品名称,继承自Tpl基类的方法。

  • :bindAbility(TPL_ABILITY.DEMO)

绑定技能模板。对应itemTpl.lua中的bindAbilityTpl()方法。TPL_ABILITY.DEMO是另一个技能模板。

  • :icon("black")

设置物品图标。继承自Tpl基类的方法。

  • :worth({ gold = 10 })

设置物品价值,继承自Tpl基类的方法。这里设置金币价值为10

:onEvent(EVENT.Item.Get, function(getData)
    echo("获得物品", getData.triggerUnit:owner())
end)

注册物品获取事件处理器。-- 对应itemTpl.lua中的onEvent()方法。当单位获得该物品时触发回调。
getData包含事件相关信息:triggerUnit: 触发事件的单位,owner(): 获取单位所属玩家。

(二)demo.lua中的案例

这个案例位于:projects\mylua\scripts\globals\tpl\item\demo.lua

TPL_ITEM.DEMO = ItemTpl()
--:model("???") -- 默认就是物品宝箱
    :name("勇气之剑")
    :description("就是一把剑")
    :bindAbilityTpl(TPL_ABILITY.DEMO)
    :icon("ReplaceableTextures\\CommandButtons\\BTNArcaniteMelee.blp")
    :worth({ gold = 10 })
    :onEvent(eventKind.itemGet,
    function(getData)
        echo(getData.triggerUnit:name() .. " 获得物品 " .. getData.triggerItem:name())
    end)

这个例子和TPL模版.md中的案例几乎一样,只是多了:

:description("就是一把剑") --物品描述
:icon("ReplaceableTextures\CommandButtons\BTNArcaniteMelee.blp") --使用了具体的图标路径,即War3内置的图标资源。
:bindAbilityTpl(TPL_ABILITY.DEMO) --对应itemTpl.lua中的方法名变更。功能相同,都是绑定技能模板。

二、学习输出

(一)War3原生物品图标数据表

物品ID物品名字物品图标
afac阿利亚之笛ReplaceableTextures\CommandButtons\BTNAlleriaFlute.blp
ajen古之忍耐姜歌ReplaceableTextures\CommandButtons\BTNJanggo.blp
amrc召唤护身符ReplaceableTextures\CommandButtons\BTNAmulet.blp
anfg远古雕像ReplaceableTextures\CommandButtons\BTNClayFigurine.blp
ankh重生十字章ReplaceableTextures\CommandButtons\BTNAnkh.blp
arsc神秘卷轴ReplaceableTextures\CommandButtons\BTNBansheeAdept.blp

(二)ItemTpl物品模板属性表

分类方法参数类型可选值/范围示例说明
等级经验expnumbernil≥0,不超过最大经验值exp(100)设置/获取物品当前经验值,自动限制范围
levelMaxnumbernil1 ≤ value ≤ game.expParams.item.maxLvlevelMax(5)设置/获取物品最大等级,不超过系统配置最大值
levelnumbernil1 ≤ value ≤ _levelMaxlevel(3)设置/获取物品当前等级,自动限制在1和_maxLevel之间
技能绑定bindAbilityTplAbilityTplnil有效的AbilityTpl对象bindAbilityTpl(TPL_ABILITY.DEMO)绑定技能模板,实例化物品时会转为具体技能
模型显示modelstringnil合法模型路径或别名model("war3mapModel\sword.mdl")设置/获取模型路径,支持别名系统
modelScalenumbernil>0的缩放系数modelScale(1.2)设置/获取模型缩放比例
animateScalenumbernil>0的动画速度系数animateScale(0.8)设置/获取动画播放速度
物品属性autoUsebooleanniltrue/falseautoUse(true)设置/获取是否捡取后自动使用
consumablebooleanniltrue/falseconsumable(true)设置/获取是否为消耗品(次数用完自动销毁)
pawnablebooleanniltrue/falsepawnable(false)设置/获取是否可出售
dropablebooleanniltrue/falsedropable(false)设置/获取是否可丢弃
chargesnumbernil≥0的整数charges(3)设置/获取使用次数(0表示无限)

以上2张表格资源回复可见下载地址:

此处内容已隐藏,回复后(需要填写邮箱)可见