xuchun18 2019-09-24 17:01 采纳率: 100%
浏览 844
已采纳

游戏LUA脚本.请教自动分行

图片说明

\
-------套装效果下的属性如何检测两组属性自动分行,------

function itemInfo.getItemSuitProp(itemFrom, itemPos)

local ret = ""
--获取当前装备为的套装属性
local ret_tbl = c.item.getItemPosSuitProp(itemPos, itemFrom)

if ret_tbl == nil then return ret end
local _caption = ret_tbl["caption"]
local _mode = ret_tbl["mode"]
local _suitOKCount = ret_tbl["suitOKCount"]
if _caption == nil or _mode == nil or _suitOKCount == nil then return ret end   

local prop_tbl = ret_tbl["prop"] or {} --属性表

local prop_hash_tbl = {}--属性哈希表
--数组转换哈希
for i=1, #prop_tbl do
    prop_hash_tbl[prop_tbl[i][1]] = prop_tbl[i][2]
end

-- 英文KEY = {中文名, 尾部所加字符[如果为nil则不加值]}
local prop_name_tbl = {
    ["MaxHP"] = {"HP上限增加+", "%  "},
    ["MaxMP"] = {"MP上限增加+", "%  "},
    ["DC"] = {"攻击", "-"},
    ["MC"] = {"魔法", "-"},
    ["SC"] = {"道术", "-"},
    ["TC"] = {"刺术", "-"},
    ["AC"] = {"防御", "-"},
    ["MAC"] = {"魔防", "-"},
    ["HitPoint"] = {"准确+", ""},
    ["SpeedPoint"] = {"敏捷+", ""},
    ["HealthRecover"] = {"体力恢复+", "%"},
    ["SpellRecover"] = {"魔法恢复+", "%"},
    ["RiskRate"] = {"幸运+", ""},
    ["Reserved"] = {"吸血(虹魔)+", ""},
    ["Reserved1"] = {"目标掉内力+", ""},
    ["HP"] = {"体力值+", ""},
    ["MP"] = {"魔法值+", ""},
    ["ExpRate"] = {"经验倍数+", ""},
    ["PowerRate"] = {"攻击倍数+", ""},
    ["MagicRate"] = {"魔法倍数+", ""},
    ["SCRate"] = {"道术倍数+", ""},
    ["TCRate"] = {"刺术倍数+", ""},
    ["ACRate"] = {"防御倍数+", ""},
    ["MACRate"] = {"魔御倍数+", ""},
    ["AntiMagic"] = {"魔法躲避+", ""},
    ["AntiPoison"] = {"毒物躲避+", ""},
    ["PoisonRecover"] = {"中毒恢复+", ""},
    ["IncDragonRate"] = {"合击伤害+", "%"},
    ["IncNHRate"] = {"内力回复增加+", "%"},
    ["UnBurstRate"] = {"防爆+", ""},
    ["VampirePoint"] = {"吸血(虎威)+", ""},
    ["IncDragon"] = {"合击威力+", ""},
    ["MasterAbility"] = {"主属性+", ""},
    ["MX"] = {"魔血值+", ""},
    ["HeartPower"] = {"神圣属性上限+", ""},
    ["HeartMaxPower"] = {"神圣属性下限+", ""},
    ["HeartAC"] = {"神圣防御+", ""},
    ["UnParalysisRate"] = {"麻痹抗性+", ""},
    ["ParalysisRate"] = {"麻痹强化+", ""},
    ["DrugsMxReply"] = {"药品魔血值回复+", "%"},
    ["DrugsHPReply"] = {"药品体力值回复+", "%"},
    ["DrugsMPReply"] = {"药品魔法值回复+", "%"},
    ["BreakUpRate"] = {"击破+", ""},
    ["HitSpeed"] = {"攻击速度+", ""},
    ["MagicDamage"] = {"法术伤害+", ""},
    ["DecDragonRate"] = {"合击伤害减免+", "%"},
    ["AddDamageRate"] = {"伤害附加+", "%"},
    ["Cutting"] = {"斩杀血量+", "%"},
    ["HeartPowerRate"] = {"神圣倍数+", "%"},
    ["CallTrollLevel"] = {"召唤巨魔技能LV", "\\冰眼巨魔能力冰眼神技"},
    ["Teleport"] = {"传送神技", "nil"},
    ["Paralysis"] = {"麻痹神技", "nil"},
    ["Revival"] = {"复活神技", "nil"},
    ["MagicShield"] = {"护身神技", "nil"},
    ["MagicShield1"] = {"聚魔护身神技", "nil"},
    ["MagicShield2"] = {"精英护身神技", "nil"},
    ["UnParalysis"] = {"防麻痹神技", "nil"},
    ["UnRevival"] = {"防复活神技", "nil"},
    ["UnMagicShield"] = {"防护身神技", "nil"},
    ["Paralysis1"] = {"战意麻痹神技", "nil"},
    ["Paralysis2"] = {"魔道麻痹神技", "nil"},
    ["Paralysis3"] = {"魔意麻痹神技", "nil"},
    ["Unfrozen"] = {"防冰冻神技", "nil"},
    ["AutoPoison"] = {"施毒神技", "nil"}
}
local function getPropName(tbl)
    local ret = ""
    local key = tbl[1] or "" --取得属性英文KEY
    local value = tbl[2] or 0 --取得属性值
    local _tbl = prop_name_tbl[key] --根据英文KEY查找中文名称

    if _tbl then
        local tmp = _tbl[1] --临时字符串储存
        local value1 = prop_hash_tbl["Max"..key] or 0 --联名属性值
        if _tbl[2] ~= "nil" then --nil=不加属性值
            tmp = tmp..value.._tbl[2]
            if _tbl[2] == "-" then --联名属性
                tmp = tmp..value1.."  "
            end
        end
        if (value > 0 and _tbl[2] ~= "-") or (value > 0 or value1 > 0 and _tbl[2] == "-") then 

                        ret = tmp   


        end
    end
    return ret
end
local _color_tbl = {[true]=const.clyellow, [false]=const.clred}
ret = ret..hintHelper.text(_caption, const.clyellow, 1, nil, 10).."\\"
if _mode == 1 then --件数模式
    ret = ret.."\\    "..hintHelper.text("首饰3件", _color_tbl[in_array(_suitOKCount, {3,4})])
    ret = ret.."\\    "..hintHelper.text("首饰5件", _color_tbl[in_array(_suitOKCount, {5,6,7})])
    ret = ret.."\\    "..hintHelper.text("首饰8件", _color_tbl[in_array(_suitOKCount, {8,9})])
    ret = ret.."\\    "..hintHelper.text("首饰10件", _color_tbl[_suitOKCount >= 10])
else --装备模式
    local items_tlb = ret_tbl["items"] or {}
    if #items_tlb > 0 then
        ret = ret.."\\ \\"
        for i=1, #items_tlb do
            if (items_tlb[i][2] or 0) == 0 then
                ret = ret.."\\"..hintHelper.text((items_tlb[i][1] or "").."(缺)", const.clred)
            else
                ret = ret.."\\"..hintHelper.text((items_tlb[i][1] or ""), const.clyellow)
            end
        end
    end
end

ret = ret .. "\\ \\"..hintHelper.text("套装效果:", const.clyellow, 1)
if _suitOKCount > 0 then 
    ret = ret.."\\ \\"
    if _mode == 1 then --件数模式
        if in_array(_suitOKCount, {3,4}) then
            ret = ret.."LV1"
        elseif in_array(_suitOKCount, {5,6,7}) then
            ret = ret.."LV2"
        elseif in_array(_suitOKCount, {8,9}) then
            ret = ret.."LV3"
        elseif _suitOKCount == 10 then
            ret = ret.."LV4"
        end
    end


    --循环显示套装属性  
    local l_prop_tbl
    for i=1, #prop_tbl do
        l_prop_tbl = prop_tbl[i] or {}
        ret = ret..getPropName(l_prop_tbl)


    end

end

return ret

end

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 这段有什么bug 为什么总报错
      • ¥15 关于#php#根据url判断选择加载模板应该如何解决?会的速来捡钱!
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云
      • ¥50 unity使用easyar录屏更换视频保存路径
      • ¥15 CECGameSession::OutputLinkSevError(iRetCode=4) LINK超时
      • ¥20 出错 textread (第 124 行) [varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
      • ¥15 tensor flow目标检测环境配置问题
      • ¥15 数据库float型转换精度问题
      • ¥15 运行您代码时出现报错,如何解决?(标签-回归|关键词-无法识别)
      • ¥50 android service弹出dialog,showdialog就出错,如何解决?