我是lua后端老师!小仙,你需要在`jxtp_tp`函数中添加系统变量来记录失败次数,实现“失败N次后第N+1次必成”的保底机制。我来帮你修改这个函数。
根据你的需求,你需要使用系统变量`U76`来记录连续失败的次数。这里的关键逻辑是:
1. 每次失败时,`U76`增加1
2. 每次成功时,`U76`重置为0
3. 当`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') or 0
local next_cfg = jxtp_cfg[next_lv]
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_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
-- 检查保底机制
local is_guaranteed = false
if fail_count >= 3 and fail_count < 4 then -- 前3次失败,第4次必成
is_guaranteed = true
elseif fail_count >= 4 and fail_count < 5 then -- 前4次失败,第5次必成
is_guaranteed = true
elseif fail_count >= 5 and fail_count < 6 then -- 前5次失败,第6次必成
is_guaranteed = true
elseif fail_count >= 6 and fail_count < 7 then -- 前6次失败,第7次必成
is_guaranteed = true
elseif fail_count >= 8 and fail_count < 9 then -- 前8次失败,第9次必成
is_guaranteed = true
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
-- 判断是否成功
local success = false
if is_guaranteed then
success = true
else
success = getRandomIsHit(40, 100) -- 原来的40%概率
end
if success 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
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)
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_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`变量**:这个变量用来记录连续失败的次数,每次失败加1,成功时重置为0
2. **保底判断逻辑**:
- `fail_count >= 3 and fail_count < 4`:前3次失败,第4次必成
- `fail_count >= 4 and fail_count < 5`:前4次失败,第5次必成
- `fail_count >= 5 and fail_count < 6`:前5次失败,第6次必成
- `fail_count >= 6 and fail_count < 7`:前6次失败,第7次必成
- `fail_count >= 8 and fail_count < 9`:前8次失败,第9次必成
3. **成功处理**:当触发保底或随机成功时,会执行升级操作,并将`U76`重置为0
4. **失败处理**:随机失败时,将`U76`的值加1,为下一次尝试积累保底计数
这样修改后,玩家在突破失败时会有保底机制,达到指定的失败次数后下一次必定成功。小仙可以根据实际需求调整保底的次数条件。如果还有不明白的地方,随时问我哦!