我是lua后端老师!
这位修仙者,你好!我来帮你实现这个保底机制。根据你的需求,需要在 `jxtp_tp` 函数中通过系统变量 `U76` 记录突破失败的次数,并在不同档位达到指定失败次数后触发必成。
我们先分析一下你的配置表 `jxtp_cfg`:
- 第一档:`jxtp_cfg[1]`(对应 `cur_lv=0` 时,`next_lv=1`)
- 第二档:`jxtp_cfg[2]`(对应 `cur_lv=1` 时,`next_lv=2`)
- 第三档:`jxtp_cfg[3]`(对应 `cur_lv=2` 时,`next_lv=3`)
- 第四档:`jxtp_cfg[4]`(对应 `cur_lv=3` 时,`next_lv=4`)
- 第五档:`jxtp_cfg[5]`(对应 `cur_lv=4` 时,`next_lv=5`)
保底规则:
- 第一档:前3次失败,第4次必成 → 失败次数≥3时必成
- 第二档:前4次失败,第5次必成 → 失败次数≥4时必成
- 第三档:前5次失败,第6次必成 → 失败次数≥5时必成
- 第四档:前6次失败,第7次必成 → 失败次数≥6时必成
- 第五档:前8次失败,第9次必成 → 失败次数≥8时必成
我们需要在每次突破失败时增加 `U76` 的计数,成功时清零。同时,在判断是否成功时,先检查是否满足保底条件。
以下是修改后的 `jxtp_tp` 函数代码:
```lua
function jxtp_tp(actor)
local cur_lv = getplaydef(actor, 'U48')
local next_lv = cur_lv + 1
local fail_count = getplaydef(actor, 'U76') -- 获取当前档位的失败次数
local next_cfg = jxtp_cfg[next_lv]
-- local item1_name = next_cfg[1]
-- local item1_num = next_cfg[2]
local item2_name = next_cfg[3]
local item2_num = next_cfg[4]
local item3_name = next_cfg[5]
local item3_num = next_cfg[6]
local item4_name = next_cfg[7]
local item4_num = next_cfg[8]
local item5_name = next_cfg[9]
local item5_num = next_cfg[10]
-- local my_item1_num = getbagitemcount(actor, item1_name)
local my_item2_num = getbindmoney(actor, item2_name)
local my_item3_num = getbindmoney(actor, item3_name)
local my_item4_num = getbindmoney(actor, item4_name)
local my_item5_num = getbagitemcount(actor, item5_name)
local cur_role_lv = getbaseinfo(actor, 6)
if cur_role_lv >= 95 and cur_lv < 5 then
if my_item2_num >= item2_num and my_item3_num >= item3_num and my_item4_num >= item4_num and my_item5_num >= item5_num then
-- my_item1_num >= item1_num and
-- if not takeitem(actor, item1_name, item1_num, 0, 'jxtp') then
-- local w = parsetext("<$SCREENWIDTH>", actor)
-- local h = parsetext("<$SCREENHEIGHT>", actor)
-- screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
-- return main(actor)
-- end
if not consumebindmoney(actor, item2_name, item2_num, 'jxtp') then
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
return main(actor)
end
if not consumebindmoney(actor, item3_name, item3_num, 'jxtp') then
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
return main(actor)
end
if not consumebindmoney(actor, item4_name, item4_num, 'jxtp') then
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
return main(actor)
end
if not takeitem(actor, item5_name, item5_num, 0, 'jxtp') then
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
return main(actor)
end
-- 保底判断:根据当前档位(next_lv)决定需要的失败次数
local need_fail_count = 0 -- 该档位需要多少次失败才保底
if next_lv == 1 then
need_fail_count = 3 -- 第一档:失败3次后第4次必成
elseif next_lv == 2 then
need_fail_count = 4 -- 第二档:失败4次后第5次必成
elseif next_lv == 3 then
need_fail_count = 5 -- 第三档:失败5次后第6次必成
elseif next_lv == 4 then
need_fail_count = 6 -- 第四档:失败6次后第7次必成
elseif next_lv == 5 then
need_fail_count = 8 -- 第五档:失败8次后第9次必成
end
local is_guaranteed = (fail_count >= need_fail_count) -- 是否触发保底
-- 判断是否成功:保底触发或随机成功(原概率40%)
if is_guaranteed or getRandomIsHit(40, 100) then
local cur_ren_lv = 95 + next_lv
changelevel(actor, '=', cur_ren_lv)
setplaydef(actor, 'U48', next_lv)
setplaydef(actor, 'U76', 0) -- 成功,清零失败次数
if not checktitle(actor, next_cfg[12]) then
if cur_lv > 0 then
local title = jxtp_cfg[cur_lv][12]
if checktitle(actor, title) then
deprivetitle(actor, title)
end
end
confertitle(actor, next_cfg[12])
end
-- He_MessageUtil.sendSuccessMsg(actor, '突破成功!')
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20066, w / 2, h / 2, 1, 1, 0)
He_MessageUtil.SendRandomMSgNew(actor,
'恭喜玩家{【' ..
parsetext('<$USERNAME>', actor) ..
'】/FCOLOR=251}突破等级上限,冲上{【' ..
cur_ren_lv .. '】级/FCOLOR=249}{ 天战火淬炼,终成巅峰强者!/FCOLOR=253}{战力狂飙,热血再燃新章!/FCOLOR=249}', nil, 2)
-- 成长之路
CZZL_Common_Call_Local.branch_common_trigger(actor, '突破')
return main(actor)
else
-- 突破失败,增加失败计数
setplaydef(actor, 'U76', fail_count + 1)
-- He_MessageUtil.sendWarnningMsg(actor, '突破失败~')
local w = parsetext("<$SCREENWIDTH>", actor)
local h = parsetext("<$SCREENHEIGHT>", actor)
screffects(actor, 4, 20067, w / 2, h / 2, 1, 1, 0)
return main(actor)
end
else
-- if my_item1_num < item1_num then
-- He_MessageUtil.sendWarnningMsg(actor, item1_name..'不足!')
-- else
if my_item2_num < item2_num then
He_MessageUtil.sendWarnningMsg(actor, item2_name .. '不足!')
elseif my_item3_num < item3_num then
He_MessageUtil.sendWarnningMsg(actor, item3_name .. '不足!')
elseif my_item4_num < item4_num then
He_MessageUtil.sendWarnningMsg(actor, item4_name .. '不足!')
elseif my_item5_num < item5_num then
He_MessageUtil.sendWarnningMsg(actor, item5_name .. '不足!')
end
return
end
else
if cur_role_lv < 95 then
He_MessageUtil.sendTipsMsg(actor, '您还未到达95级, 无法进行等级突破!')
elseif cur_lv >= 5 then
He_MessageUtil.sendTipsMsg(actor, '您已到达100级, 暂时无法继续突破!')
end
return
end
end
```
**关键修改点说明:**
1. 在函数开头获取 `U76` 变量作为当前档位的失败次数。
2. 根据 `next_lv`(即要突破的档位)设置对应的保底失败次数 `need_fail_count`。
3. 判断是否触发保底:`fail_count >= need_fail_count`。
4. 成功时(包括保底成功和随机成功),将 `U76` 清零。
5. 失败时,将 `U76` 加1。
这样,每次突破都会记录失败次数,并在达到保底条件时确保成功。如果你还有其他问题,随时问我哦!