function fentian.upmain()
if not fentian.parent or not fentian.parent._ui then
return
end
local ui = fentian.parent._ui
local cfg = fentian.parent.cfg
if not cfg then
return
end
local var = tonum
你的代码逻辑基本正确,但需要根据你描述的“区间显示”规则进行调整。目前你的代码是查找比当前等级大的最小等级,而你需要的是根据当前等级所在区间,显示对应区间的最高等级配置。
以下是修改后的代码,主要调整了查找 `next_level` 的逻辑:
```lua
function fentian.upmain()
if not fentian.parent or not fentian.parent._ui then
return
end
local ui = fentian.parent._ui
local cfg = fentian.parent.cfg
if not cfg then
return
end
local var = tonumber(lib:getstr("U13") or 0)
SL:Print("获取当前焚天等级 var =", var)
local max_level = 0
for level, _ in pairs(cfg) do
if level > max_level then
max_level = level
end
end
if var >= max_level then
lib:msg("焚天已满级!")
if not GUI:Win_IsNull(ui["Button_1"]) then
GUI:setTouchEnabled(ui["Button_1"], false)
end
return
end
-- 根据区间规则找到下一个要显示的等级
local next_level = nil
-- 定义区间端点
local breakpoints = {7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77}
for i, bp in ipairs(breakpoints) do
if var < bp then
next_level = bp
break
end
end
-- 如果当前等级已经超过所有区间端点,则取最大等级
if not next_level then
next_level = max_level
end
local next_cfg = cfg[next_level]
if not next_cfg then
return
end
-- 显示下一级属性
if not GUI:Win_IsNull(ui.Text_1) then
GUI:Text_setString(ui.Text_1, "攻击速度+" .. (next_cfg.cur_attr_5 or 0))
end
if not GUI:Win_IsNull(ui.Text_3) then
GUI:Text_setString(ui.Text_3, "生命值+" .. (next_cfg.cur_attr_8 or 0))
end
if not GUI:Win_IsNull(ui.Text_4) then
GUI:Text_setString(ui.Text_4, "攻击力+" .. (next_cfg.cur_attr_4 or 0))
end
if not GUI:Win_IsNull(ui.Text_5) then
GUI:Text_setString(ui.Text_5, "攻魔道+" .. (next_cfg.cur_attr_9 or 0))
end
if not GUI:Win_IsNull(ui.Text_6) then
GUI:Text_setString(ui.Text_6, "生命加成+" .. (next_cfg.cur_attr_3 or 0))
end
if not GUI:Win_IsNull(ui.Text_7) then
GUI:Text_setString(ui.Text_7, "防御加成+" .. (next_cfg.cur_attr_2 or 0))
end
if not GUI:Win_IsNull(ui.Text_8) then
GUI:Text_setString(ui.Text_8, "打怪伤害+" .. (next_cfg.cur_attr_1 or 0))
end
if not GUI:Win_IsNull(ui.Text_9) then
GUI:Text_setString(ui.Text_9, "打怪伤害+" .. (next_cfg.cur_attr_10 or 0))
end
if not GUI:Win_IsNull(ui.Text_10) then
GUI:Text_setString(ui.Text_10, "防御值+" .. (next_cfg.cur_attr_6 or 0))
end
end
```
**主要修改点:**
1. **查找逻辑变更**:将原来的 `for level, _ in pairs(cfg)` 循环查找改为基于 `breakpoints` 数组的区间判断。
2. **区间规则实现**:
- 1-7级 → 显示7级配置
- 8-14级 → 显示14级配置
- 15-21级 → 显示21级配置
- 以此类推
3. **`breakpoints` 数组**:包含了所有配置表中的关键等级点(7,14,21,...)。
**运行示例:**
- 当前等级 `var = 5` → 显示7级配置
- 当前等级 `var = 10` → 显示14级配置
- 当前等级 `var = 25` → 显示28级配置
这样修改后,代码就符合你描述的“区间显示”需求了。