local baixiaosheng = {}
-- 定义称号列表
local titleList = {
"暗金魔气",
"血木魔气",
"黑水魔气",
"啖火魔气",
"戾土魔气"
}
-- 终极称号
local wuxingTitle = "五行の暗魔体"
-- 检查是否集齐五个称号
function baixiaosheng.checkAllTitles(actor)
for _, title in ipairs(titleList
我是lua后端老师!
小仙,我来帮你添加保底触发功能。根据你的需求,20次随机抽取后必定给一个未拥有的称号,使用U35变量来记录次数。下面是完整的代码:
```lua
local baixiaosheng = {}
-- 定义称号列表
local titleList = {
"暗金魔气",
"血木魔气",
"黑水魔气",
"啖火魔气",
"戾土魔气"
}
-- 终极称号
local wuxingTitle = "五行の暗魔体"
-- 检查是否集齐五个称号
function baixiaosheng.checkAllTitles(actor)
for _, title in ipairs(titleList) do
local hasTitle = checktitle(actor, title) -- 返回布尔值
if not hasTitle then
return false, title
end
end
return true, nil
end
-- 获取玩家尚未拥有的称号列表
function baixiaosheng.getMissingTitles(actor)
local missing = {}
for _, title in ipairs(titleList) do
local hasTitle = checktitle(actor, title) -- 检查称号
if not hasTitle then
table.insert(missing, title)
end
end
return missing
end
-- 获取保底次数
function baixiaosheng.getBaoDiCount(actor)
local count = getplayvar(actor, "U35") or 0
return tonumber(count)
end
-- 设置保底次数
function baixiaosheng.setBaoDiCount(actor, count)
setplayvar(actor, "U35", tostring(count))
end
-- 保底触发:20次后必定给一个未拥有的称号
function baixiaosheng.baodiReward(actor)
local currentCount = baixiaosheng.getBaoDiCount(actor)
local newCount = currentCount + 1
-- 更新次数
baixiaosheng.setBaoDiCount(actor, newCount)
-- 检查是否达到保底
if newCount >= 20 then
-- 获取未拥有的称号
local missingTitles = baixiaosheng.getMissingTitles(actor)
if #missingTitles > 0 then
-- 随机选择一个未拥有的称号
local randomIndex = math.random(1, #missingTitles)
local getTitle = missingTitles[randomIndex]
-- 给予玩家称号
confertitle(actor, getTitle)
lib:msg(actor, "保底触发!恭喜你获得称号:" .. getTitle, 1)
-- 重置保底计数器
baixiaosheng.setBaoDiCount(actor, 0)
-- 检查是否集齐
local nowHasAll, _ = baixiaosheng.checkAllTitles(actor)
if nowHasAll then
lib:msg(actor, "你已集齐所有魔气称号,可以兑换【" .. wuxingTitle .. "】了!", 1)
end
return true, getTitle
end
end
return false, nil
end
-- 主处理函数
function baixiaosheng.link(actor, msgid, arg1, arg2, arg3, sMsg)
-- 检查配置(假设cfg_baixiaosheng是全局配置表)
if not cfg_baixiaosheng or not next(cfg_baixiaosheng) then
lib:msg(actor, "配置错误", 1) -- 使用lib:msg发送消息,参数3为消息颜色/类型
return
end
-- 提交化魔志 (arg2 == 2)
if arg2 == 2 then
local needItemCount = 1
local currentItemCount = getbagitemcount(actor, "化魔志")
if currentItemCount < needItemCount then
lib:msg(actor, "你还没有化魔志", 1)
else
takeitem(actor, "化魔志", needItemCount) -- 扣除物品
lib:msg(actor, "提交成功", 1)
end
return
end
-- 使用化魔志抽奖 (arg2 == 3)
if arg2 == 3 then
local needItemCount = 3
local currentItemCount = getbagitemcount(actor, "地煞归魔石")
if currentItemCount < needItemCount then
lib:msg(actor, "地煞归魔石数量不足,需要"..needItemCount.."个", 1)
return
end
-- 检查是否已集齐所有基础称号
local hasAll, _ = baixiaosheng.checkAllTitles(actor)
if hasAll then
lib:msg(actor, "你已经集齐所有魔气称号,请先兑换终极称号!", 1)
return
end
-- 扣除化魔志
takeitem(actor, "化魔志", needItemCount)
-- 先检查保底触发
local isBaodi, baodiTitle = baixiaosheng.baodiReward(actor)
if isBaodi then
return
end
-- 25%成功率判断
local randomNum = math.random(1, 100)
if randomNum > 25 then
lib:msg(actor, "抽取失败,运气不佳", 1)
return
end
-- 成功:随机抽取一个玩家尚未拥有的称号
local missingTitles = baixiaosheng.getMissingTitles(actor)
if #missingTitles == 0 then
lib:msg(actor, "未知错误:未检测到缺失称号", 1)
return
end
local randomIndex = math.random(1, #missingTitles)
local getTitle = missingTitles[randomIndex]
-- 给予玩家称号
confertitle(actor, getTitle) -- 给予物品
lib:msg(actor, "恭喜你!获得称号:" .. getTitle, 1)
-- 再次检查是否集齐
local nowHasAll, _ = baixiaosheng.checkAllTitles(actor)
if nowHasAll then
lib:msg(actor, "你已集齐所有魔气称号,可以兑换【" .. wuxingTitle .. "】了!", 1)
end
return
end
-- 使用元宝 (arg2 == 4)
if arg2 == 4 then
local needYuanBao = 660000
local currentYuanBao = querymoney(actor, 2)
if currentYuanBao < needYuanBao then
lib:msg(actor, "你的元宝不足,需要"..needYuanBao.."元宝", 1)
return
end
-- 检查是否已集齐所有基础称号
local hasAll, _ = baixiaosheng.checkAllTitles(actor)
if hasAll then
lib:msg(actor, "你已经集齐所有魔气称号,请先兑换终极称号!", 1)
return
end
-- 扣除元宝
changemoney(actor, 2, "-", needYuanBao, "百晓生抽取", true)
-- 先检查保底触发
local isBaodi, baodiTitle = baixiaosheng.baodiReward(actor)
if isBaodi then
return
end
-- 25%成功率判断
local randomNum = math.random(1, 100)
if randomNum > 25 then
lib:msg(actor, "抽取失败,运气不佳", 1)
return
end
-- 成功:随机抽取一个玩家尚未拥有的称号
local missingTitles = baixiaosheng.getMissingTitles(actor)
if #missingTitles == 0 then
lib:msg(actor, "未知错误:未检测到缺失称号", 1)
return
end
local randomIndex = math.random(1, #missingTitles)
local getTitle = missingTitles[randomIndex]
-- 给予玩家称号
confertitle(actor, getTitle)
lib:msg(actor, "恭喜你!获得称号:" .. getTitle, 1)
-- 再次检查是否集齐
local nowHasAll, _ = baixiaosheng.checkAllTitles(actor)
if nowHasAll then
lib:msg(actor, "你已集齐所有魔气称号,可以兑换【" .. wuxingTitle .. "】了!", 1)
end
return
end
-- 兑换终极称号 (arg2 == 5)
if arg2 == 5 then
-- 检查是否集齐五个称号
local hasAll, missingTitle = baixiaosheng.checkAllTitles(actor)
if hasAll then
-- 收回五个称号
for _, title in ipairs(titleList) do
takeitem(actor, title, 1)
end
-- 给予五行の暗魔体称号
confertitle(actor, wuxingTitle)
lib:msg(actor, "恭喜你!获得终极称号:" .. wuxingTitle, 1)
else
local missingTitles = baixiaosheng.getMissingTitles(actor)
lib:msg(actor, "兑换失败,你还缺少以下称号:" .. table.concat(missingTitles, "、"), 1)
end
return
end
-- 如果arg2未匹配任何已知操作
lib:msg(actor, "未知的操作选项", 1)
end
return baixiaosheng
```
主要改动:
1. **新增了保底计数功能**:
- `getBaoDiCount()` - 获取U35变量值
- `setBaoDiCount()` - 设置U35变量值
- `baodiReward()` - 处理保底逻辑
2. **保底机制**:
- 每次抽奖(无论成功与否)都会累加U35变量
- 当U35达到20时触发保底
- 保底会从玩家未拥有的称号中随机给一个
- 触发保底后重置U35为0
3. **集成到抽奖流程**:
- 在两种抽奖方式(化魔志和元宝)中,都先检查保底
- 如果触发保底,直接给予称号并返回,不执行后续的25%成功率判断
这样就能实现20次抽奖必定给一个未拥有称号的保底机制了!小仙,如果还有不明白的地方,随时问我哦!