寻找一种更干净、更高效的方式
2017-1-5 10:30:53
收藏:0
阅读:106
评论:1
function GetDamage(spell, unit)
if spell == _Q and (isReady(_Q) or qActive) and not HasItem(3025) and not HasItem(3100) and not HasItem(3057) and not HasItem(3078) then
return myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks))
elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3057) or sheenActive) then
return myHero:CalcDamage(unit, myHero.damage) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks))
elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3025) or fActive) then
return myHero:CalcDamage(unit, myHero.damage) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks))
elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3100) or lActive) then
return myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks))
elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3078) or tActive) then
return myHero:CalcDamage(unit, (myHero.damage * 2)) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks))
elseif spell == _E and isReady(_E) then
return myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6)))
else
return 0
end
end
这是我用来返回对特定敌人造成伤害的代码,虽然它能按预期工作,但它看起来过于冗长而且难看,而且我希望它能稍微有些不同的工作方式,我不确定如何编写它。
我希望它能做到的是,如果我输入了例如GetDamage(all)或类似的东西,我希望它返回我可以造成的总伤害,只要isReady(spell)为true,即如果技能q和e准备就绪,它将只返回q和e的总伤害,或者如果所有技能都准备就绪,它将返回所有技能的总伤害,此外,如果我只需要知道r的伤害,我仍然只需要输入GetDamage(_R)。
有没有一种更干净的方法使用一个表或者一种更有效的方式来得到我所需要的结果?因为当前使用GetDamage(spell) + GetDamage(spell2) + GetDamage(spell3)等方式看起来像一个非常糟糕的编码。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

介绍新技能“ALL”
function GetDamage(spell, unit) local result = 0 if (spell == "ALL" or spell == _Q) and (isReady(_Q) or qActive) then local bonus = 0 if (HasItem(3057) or sheenActive) then bonus = myHero:CalcDamage(unit, myHero.damage) elseif (HasItem(3025) or fActive) then bonus = myHero:CalcDamage(unit, myHero.damage) elseif (HasItem(3100) or lActive) then bonus = myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) elseif (HasItem(3078) or tActive) then bonus = myHero:CalcDamage(unit, (myHero.damage * 2)) end result = result + bonus + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) end if (spell == "ALL" or spell == _E) and isReady(_E) then result = result + myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6))) end return result end使用示例:
dmg = GetDamage("ALL", unit) dmg = GetDamage(_Q, unit) dmg = GetDamage(_E, unit)编辑:
还有一种实现方式是使用以技能为键、以函数为值的表:
spell_dmg_func = { [_Q] = function(unit) if (isReady(_Q) or qActive) then local bonus = 0 if (HasItem(3057) or sheenActive) then bonus = myHero:CalcDamage(unit, myHero.damage) elseif (HasItem(3025) or fActive) then bonus = myHero:CalcDamage(unit, myHero.damage) elseif (HasItem(3100) or lActive) then bonus = myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) elseif (HasItem(3078) or tActive) then bonus = myHero:CalcDamage(unit, (myHero.damage * 2)) end return bonus + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) end end, [_E] = function(unit) if isReady(_E) then return myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6))) end end, } function GetDamage(spell, unit) if spells == "ALL" then local sum = 0 for spell, func in pairs(spell_dmg_func) do sum = sum + (func(unit) or 0) end return sum else return spell_dmg_func[spell](unit) or 0 end end