一、学习案例
(一)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物品模板属性表
分类 | 方法 | 参数类型 | 可选值/范围 | 示例 | 说明 | |
---|---|---|---|---|---|---|
等级经验 | exp | number | nil | ≥0,不超过最大经验值 | exp(100) | 设置/获取物品当前经验值,自动限制范围 |
levelMax | number | nil | 1 ≤ value ≤ game.expParams.item.maxLv | levelMax(5) | 设置/获取物品最大等级,不超过系统配置最大值 | |
level | number | nil | 1 ≤ value ≤ _levelMax | level(3) | 设置/获取物品当前等级,自动限制在1和_maxLevel之间 | |
技能绑定 | bindAbilityTpl | AbilityTpl | nil | 有效的AbilityTpl对象 | bindAbilityTpl(TPL_ABILITY.DEMO) | 绑定技能模板,实例化物品时会转为具体技能 |
模型显示 | model | string | nil | 合法模型路径或别名 | model("war3mapModel\sword.mdl") | 设置/获取模型路径,支持别名系统 |
modelScale | number | nil | >0的缩放系数 | modelScale(1.2) | 设置/获取模型缩放比例 | |
animateScale | number | nil | >0的动画速度系数 | animateScale(0.8) | 设置/获取动画播放速度 | |
物品属性 | autoUse | boolean | nil | true/false | autoUse(true) | 设置/获取是否捡取后自动使用 |
consumable | boolean | nil | true/false | consumable(true) | 设置/获取是否为消耗品(次数用完自动销毁) | |
pawnable | boolean | nil | true/false | pawnable(false) | 设置/获取是否可出售 | |
dropable | boolean | nil | true/false | dropable(false) | 设置/获取是否可丢弃 | |
charges | number | nil | ≥0的整数 | charges(3) | 设置/获取使用次数(0表示无限) |
以上2张表格资源回复可见下载地址:
此处内容已隐藏,回复后(需要填写邮箱)可见
NB