local qingxukezhan = {}
-- 通用成功率判断函数
local function checkSuccessRate(actor, buttonName)
local randomNum = math.random(1, 100)
if randomNum <= 25 then
p(buttonName .. " 抽取成功")
return true
else
p(buttonName .. " 抽取失
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-14 15:11:50 |
👁️ 阅读: 17
我是lua后端老师!
小仙,看了你的代码,我发现了几个需要改进的地方,并且帮你补全了`arg2 == 6`的功能。主要问题是你用的`p`函数不是引擎的标准打印函数,应该用`release_print()`,而且最后一部分的逻辑需要完善。
下面是修改和补全后的代码:
```lua
local qingxukezhan = {}
-- 通用成功率判断函数
local function checkSuccessRate(actor, buttonName)
local randomNum = math.random(1, 100)
if randomNum <= 25 then
release_print(buttonName .. " 抽取成功") -- 修正:使用release_print
return true
else
release_print(buttonName .. " 抽取失败,运气不佳") -- 修正:使用release_print
return false
end
end
-- 属性加成函数 -- 注解:根据变量等级和属性ID增加属性
local function addAttributeByLevel(actor, currentLevel, attId, valuePerLevel)
if currentLevel > 0 then
local totalAddValue = currentLevel * valuePerLevel
addattlist(actor, attId, totalAddValue) -- 增加属性
end
end
function qingxukezhan.link(actor, msgid, arg1, arg2, arg3, sMsg)
if not cfg_qingxukezhan or not next(cfg_qingxukezhan) then
lib:msg(actor, "配置错误")
return
end
if arg2 == 0 then
local rlv1 = lib:getvalueb(actor, "U37") or 0
release_print("当前白月光等级:" .. rlv1) -- 修正:使用release_print和字符串连接
-- 检查成功率
if not checkSuccessRate(actor, "白月光") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情绪I")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情绪I", 1)
else
takeitem(actor, "封印の情绪I", needItemCount)
lib:setvalueb(actor, "U37", rlv1 + 1)
lib:msg(actor, "白月光解忧成功", 1)
-- 每次升级增加攻击力20
addattlist(actor, 202, 20) -- 攻击力ID=202
end
return
end
if arg2 == 1 then
local rlv2 = lib:getvalueb(actor, "U38") or 0
release_print("当前得不到等级:" .. rlv2) -- 修正
-- 检查成功率
if not checkSuccessRate(actor, "得不到") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情绪Il")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情绪Il", 1)
else
takeitem(actor, "封印の情绪Il", needItemCount)
lib:setvalueb(actor, "U38", rlv2 + 1)
lib:msg(actor, "得不到解忧成功", 1)
-- 每次升级增加生命值200
addattlist(actor, 1, 200) -- 生命值ID=1
end
return
end
if arg2 == 2 then
local rlv3 = lib:getvalueb(actor, "U39") or 0
release_print("当前不满足等级:" .. rlv3) -- 修正
-- 检查成功率
if not checkSuccessRate(actor, "不满足") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情绪Ill")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情绪Ill", 1)
else
takeitem(actor, "封印の情绪Ill", needItemCount)
lib:setvalueb(actor, "U39", rlv3 + 1)
lib:msg(actor, "不满足解忧成功", 1)
-- 每次升级增加刀刀切割100
addattlist(actor, 215, 100) -- 刀刀切割ID=215
end
return
end
if arg2 == 3 then
local rlv4 = lib:getvalueb(actor, "U40") or 0
release_print("当前偏执狂等级:" .. rlv4) -- 修正
-- 检查成功率
if not checkSuccessRate(actor, "偏执狂") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情绪IV")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情绪IV", 1)
else
takeitem(actor, "封印の情绪IV", needItemCount)
lib:setvalueb(actor, "U40", rlv4 + 1)
lib:msg(actor, "偏执狂解忧成功", 1)
-- 每次升级增加人物切割50
addattlist(actor, 216, 50) -- 人物切割ID=216
end
return
end
if arg2 == 4 then
local rlv5 = lib:getvalueb(actor, "U41") or 0
release_print("当前犟拐拐等级:" .. rlv5) -- 修正
-- 检查成功率
if not checkSuccessRate(actor, "犟拐拐") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情结V")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情结V", 1)
else
takeitem(actor, "封印の情结V", needItemCount)
lib:setvalueb(actor, "U41", rlv5 + 1)
lib:msg(actor, "犟拐拐解忧成功", 1)
-- 每次升级增加刀刀吸血100
addattlist(actor, 34, 100) -- 刀刀吸血ID=34
end
return
end
if arg2 == 5 then
local rlv6 = lib:getvalueb(actor, "U42") or 0
release_print("当前自大狂等级:" .. rlv6) -- 修正
-- 检查成功率
if not checkSuccessRate(actor, "自大狂") then
lib:msg(actor, "解忧失败,运气不佳", 1)
return
end
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "封印の情结VI")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有封印の情结VI", 1)
else
takeitem(actor, "封印の情结VI", needItemCount)
lib:setvalueb(actor, "U42", rlv6 + 1)
lib:msg(actor, "自大狂解忧成功", 1)
-- 每次升级增加打怪爆率0.25%
addattlist(actor, 221, 0.25) -- 打怪爆率ID=221
end
return
end
if arg2 == 6 then
-- 检测所有变量是否达到500,并为未达标的变量补足属性和扣除材料
local maxLevel = 500
local itemMap = {
["U37"] = {itemName = "封印の情绪I", attId = 202, valuePerLevel = 20},
["U38"] = {itemName = "封印の情绪Il", attId = 1, valuePerLevel = 200},
["U39"] = {itemName = "封印の情绪Ill", attId = 215, valuePerLevel = 100},
["U40"] = {itemName = "封印の情绪IV", attId = 216, valuePerLevel = 50},
["U41"] = {itemName = "封印の情结V", attId = 34, valuePerLevel = 100},
["U42"] = {itemName = "封印の情结VI", attId = 221, valuePerLevel = 0.25}
}
local varList = {"U37", "U38", "U39", "U40", "U41", "U42"}
local totalNeedItems = {}
local hasInsufficientLevel = false
-- 第一遍:检查哪些变量未满500,并计算需要补足的材料
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
if currentLevel < maxLevel then
hasInsufficientLevel = true
local needLevels = maxLevel - currentLevel
local itemInfo = itemMap[varName]
-- 记录需要扣除的材料数量
if not totalNeedItems[itemInfo.itemName] then
totalNeedItems[itemInfo.itemName] = 0
end
totalNeedItems[itemInfo.itemName] = totalNeedItems[itemInfo.itemName] + needLevels
release_print(varName .. " 当前等级:" .. currentLevel .. ", 需要补足" .. needLevels .. "级")
else
release_print(varName .. " 已满500级,无需操作")
end
end
-- 如果所有变量都满500了,直接返回
if not hasInsufficientLevel then
lib:msg(actor, "所有情绪均已修炼至最高境界(500级)!", 1)
return
end
-- 第二遍:检查背包材料是否足够
for itemName, needCount in pairs(totalNeedItems) do
local currentCount = getbagitemcount(actor, itemName)
if currentCount < needCount then
lib:msg(actor, itemName .. " 数量不足,需要" .. needCount .. "个,当前只有" .. currentCount .. "个", 1)
return
end
end
-- 第三遍:扣除材料并增加属性
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
if currentLevel < maxLevel then
local needLevels = maxLevel - currentLevel
local itemInfo = itemMap[varName]
-- 扣除材料
takeitem(actor, itemInfo.itemName, needLevels)
-- 更新变量等级
lib:setvalueb(actor, varName, maxLevel)
-- 增加对应的属性(补足到500级的全部属性)
local totalAddValue = needLevels * itemInfo.valuePerLevel
addattlist(actor, itemInfo.attId, totalAddValue)
release_print(varName .. " 补足完成,消耗" .. needLevels .. "个" .. itemInfo.itemName .. ",增加属性" .. totalAddValue)
end
end
lib:msg(actor, "一键补足完成!所有情绪均已提升至500级。", 1)
end
end
return qingxukezhan
```
**主要修改点:**
1. **打印函数**:将所有`p()`函数替换为引擎标准的`release_print()`函数。
2. **字符串连接**:`release_print`参数需要使用`..`进行字符串连接。
3. **补全`arg2 == 6`逻辑**:
- 定义了`itemMap`表格来管理变量、物品和属性的对应关系
- 分三步处理:检查哪些变量未满500 → 检查材料是否足够 → 扣除材料并增加属性
- 如果所有变量都已满500,则提示并返回
- 使用`addattlist`函数来增加对应的属性值
4. **属性加成**:在每个单独的升级分支(arg2=0-5)中也添加了`addattlist`调用,确保每次升级都增加对应属性。
小仙,这样修改后,你的功能就完整了。记得测试时先备份原文件哦!如果还有不明白的地方,随时可以问我,或者请教浮生梦尊师!
← 返回问答库