看了你的代码,我发现你已经在使用 `U30` 变量来存储奖励领取状态了,这是正确的做法。不过你的后端代码中还没有添加对 `U30` 变量的处理逻辑。
根据你的前端代码,`U30` 变量应该存储以逗号分隔的已领取奖励等级(如 "5,10,15,20")。需要修改后端代码来支持这个功能:
```lua
-- 魔神原力系统后端处理
local moshenyuanli = {}
local var_cfg = {
[1] = "U25",
[2] = "U26",
[3] = "U27",
[4] = "U28",
[5] = "U29",
}
function moshenyuanli.link(actor, msgid, arg1, arg2, arg3, sMsg)
if not cfg_moshenyuanli or not next(cfg_moshenyuanli) then
return
end
--提升
if arg1 == 1 then
local type_cfgs = gbl_moshenyuanli[arg2]
if not type_cfgs then
lib:msg(actor, "配置不存在")
return
end
local var_name = var_cfg[arg2]
local cur_level = lib:getvalueb(actor, var_name) or 0
local next_level = cur_level + 1
if cur_level >= #type_cfgs then
lib:msg(actor, "已提升到最高级")
return
end
--获取下级配置
local cfg = type_cfgs[next_level]
if not cfg then
return
end
if not lib:checkitem(actor, cfg, "魔神元力" .. cfg.name .. "扣除") then
return
end
lib:setvalueb(actor, var_name, next_level)
return
end
-- 领取奖励
if arg1 == 2 then
-- 获取所有技能等级
local allLevels = true
local minLevel = 100
for i = 1, 5 do
local level = lib:getvalueb(actor, var_cfg[i]) or 0
if level < arg2 then
allLevels = false
break
end
if level < minLevel then
minLevel = level
end
end
if not allLevels then
lib:msg(actor, "所有技能需要达到指定等级才能领取奖励")
return
end
-- 检查是否已领取
local receivedStr = lib:getvalue(actor, "U30") or ""
local alreadyReceived = false
if receivedStr ~= "" then
for level in string.gmatch(receivedStr, "[^,]+") do
if tonumber(level) == arg2 then
alreadyReceived = true
break
end
end
end
if alreadyReceived then
lib:msg(actor, "该奖励已领取")
return
end
-- 添加奖励到U30变量
local rewards = {}
if receivedStr ~= "" then
for level in string.gmatch(receivedStr, "[^,]+") do
table.insert(rewards, level)
end
end
table.insert(rewards, tostring(arg2))
table.sort(rewards, function(a, b) return tonumber(a) < tonumber(b) end)
local newStr = table.concat(rewards, ",")
lib:setvalue(actor, "U30", newStr)
-- 根据等级发放称号
if arg2 == 5 then
confertitle(actor, "称号:魔神的祝福")
lib:msg(actor, "你已获得称号:魔神的祝福")
elseif arg2 == 10 then
confertitle(actor, "称号:魔神的低语")
lib:msg(actor, "你已获得称号:魔神的低语")
elseif arg2 == 15 then
confertitle(actor, "称号:魔神的传承")
lib:msg(actor, "你已获得称号:魔神的传承")
elseif arg2 == 20 then
confertitle(actor, "称号:魔神降世录")
lib:msg(actor, "你已获得称号:魔神降世录")
end
end
end
return moshenyuanli
```
**主要改动:**
1. **添加了 `U30` 变量处理**:现在后端会读取和更新 `U30` 变量来记录奖励领取状态
2. **优化了奖励领取逻辑**:
- 使用 `arg1 == 2` 来区分提升和领取操作
- 使用 `arg2` 参数传递要领取的奖励等级(5、10、15、20)
- 检查所有技能是否达到指定等级
- 检查该奖励是否已领取
3. **简化了条件判断**:去掉了原来的多个if-else判断,改为根据参数动态判断
4. **正确更新 `U30` 变量**:将已领取的奖励等级以逗号分隔存储在 `U30` 中
这样修改后,你的前端和后端就能正确配合使用 `U30` 变量来管理奖励领取状态了。记得在前端发送领取请求时,参数要正确设置(`arg1=2`,`arg2=奖励等级`)。