其实这个NPC版的已经有了,我就改写成道具版的,并优化了显示,请直接看代码,注释都有
function petablility(itemindex, charaindex, toindex, haveitemindex) for i=0, 4 do --判断使用对象为自己的宠物 if toindex == char.getCharPet(charaindex, i) then --取宠物的能力值 LevelUpPoint = char.getInt(toindex, "能力值") --从能力值里取体力值 vital = char.getRightTo8(LevelUpPoint, 1) --从能力值里取腕力值 str = char.getRightTo8(LevelUpPoint, 2) --从能力值里取耐力值 tgh = char.getRightTo8(LevelUpPoint, 3) --从能力值里取速度 dex = char.getRightTo8(LevelUpPoint, 4) --成长区间1+ 对应RankRandTbl的行数 petrank = char.getInt(toindex, "成长区间") + 1 --范围判断1-5 if petrank < 1 or petrank > 6 then petrank = 1 end --初始化血攻防敏 hp = 0 atk = 0 def = 0 quick = 0 --模拟升级增加的能力值来计算成长率 for j=1, 140 do ability = {0, 0, 0, 0} for j=1, 10 do rnd = math.random(4) ability[rnd] = ability[rnd] + 1 end ivital = vital istr = str itgh = tgh idex = dex ivital = (ivital * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2]) + ability[1] * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2])) / 100 istr = (istr * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2]) + ability[2] * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2])) / 100 itgh = (itgh * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2]) + ability[3] * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2])) / 100 idex = (idex * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2]) + ability[4] * math.random(RankRandTbl[petrank][1], RankRandTbl[petrank][2])) / 100 ihp = (ivital * 4 + istr + itgh + idex) * 0.01 iatk = (istr * 0.01 + itgh * 0.001 + ivital * 0.001 + idex * 0.0005) idef = (itgh* 0.01 + istr * 0.001 + ivital * 0.001 + idex * 0.0005) iquick = idex * 0.01 hp = hp + ihp atk = atk + iatk def = def + idef quick = quick + iquick end --取血成长4位小数点 hp = string.format("%.4f", (hp/140)) --取攻成长4位小数点 atk = string.format("%.4f",(atk/140)) --取防成长4位小数点 def = string.format("%.4f",(def/140)) --取敏成长4点小数点 quick = string.format("%.4f",(quick/140)) --攻防敏相加的成长 grow = string.format("%.4f",(atk+def+quick)) token = " ※宠物成长镜※" .."\n" .. char.getChar(toindex, "名字") .. "("..char.getInt(toindex, "转数").."转".. char.getInt(toindex, "等级") .. "级):" .. "\n体力成长:" .. hp .. "\n腕力成功:" .. atk .. "\n耐力成功:" .. def .. "\n速度成长:" .. quick .. "\n三围成长:" .. grow .. "\n每次计算都会出现不同结果仅供参考。" lssproto.windows(charaindex, "对话框", "确定", -1, char.getWorkInt(toindex, "对象"), token) --删除物品 char.DelItem(charaindex, haveitemindex) return end end char.TalkToCli(charaindex, -1, "只能给宠物使用。", "红色") end function data() --从源码里提取的成长区间范围 RankRandTbl = {{ 450, 500 } ,{ 470, 520 } ,{ 490, 540 } ,{ 510, 560 } ,{ 530, 580 } ,{ 550, 600 } } end function main() data() item.addLUAListFunction( "ITEM_PETABLILITY", "petablility", "") end
效果图:
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。