|
|
-- EquipStrengthen.lua 高级装备强化系统
local M = {}
-- 强化配置:星级=【需要材料,成功率%,暴击率%,保底次数】
local STRENGTHEN_CFG = {
[1] = {item="强化石", num=1, rate=90, crit=10, protect=0},
[2] = {item="强化石", num=2, rate=80, crit=8, protect=0},
[3] = {item="强化石", num=3, rate=70, crit=6, protect=0},
[4] = {item="强化石", num=5, rate=60, crit=5, protect=3}, -- 4星开始保底
[5] = {item="强化石", num=8, rate=50, crit=3, protect=3},
[6] = {item="高级强化石", num=2, rate=40, crit=2, protect=4},
[7] = {item="高级强化石", num=5, rate=30, crit=1, protect=5},
}
-- 每星属性加成(攻魔道)
local STAR_ATTR = {1,2,3,5,8,12,18}
-- NPC强化主入口
function M.OnTalk(player)
local equip = player:GetCurrentEquip() -- 获取当前选中装备
if not equip then
player:SendMsg(0, "请先选中要强化的装备!")
return
end
local star = equip:GetStar() -- 装备当前星级
if star >= 7 then
player:SendMsg(0, "装备已强化至满级7星!")
return
end
M.DoStrengthen(player, equip, star)
end
-- 核心强化逻辑
function M.DoStrengthen(player, equip, star)
local cfg = STRENGTHEN_CFG[star+1]
-- 材料检查
if not player:CheckItem(cfg.item, cfg.num) then
player:SendMsg(0, string.format("缺少%s x%d", cfg.item, cfg.num))
return
end
-- 扣除材料
player elItem(cfg.item, cfg.num)
-- 保底计数(失败累计,满次数必成)
local protectCount = player:GetVarNumber("Strengthen_Protect_"..equip:GetUID())
local success = false
-- 概率判断
local rand = math.random(100)
if rand <= cfg.rate or protectCount >= cfg.protect then
success = true
end
if success then
-- 暴击强化(直接升2星)
local critRand = math.random(100)
local addStar = critRand <= cfg.crit and 2 or 1
local newStar = math.min(star + addStar, 7)
equip:SetStar(newStar)
equip:AddAttr(STAR_ATTR[newStar], STAR_ATTR[newStar], STAR_ATTR[newStar])
player:SetVarNumber("Strengthen_Protect_"..equip:GetUID(), 0) -- 重置保底
local msg = addStar==2 and "暴击!强化成功+2星!" or "强化成功+1星!"
player:SendMsg(1, string.format("%s 当前星级:%d", msg, newStar))
else
-- 失败:保底计数+1,不掉级
player:SetVarNumber("Strengthen_Protect_"..equip:GetUID(), protectCount + 1)
player:SendMsg(0, string.format("强化失败!保底进度:%d/%d", protectCount+1, cfg.protect))
end
end
return M
|
|