DengjiChaotuo = class("DengjiChaotuo", BaseSystemLogic)
function DengjiChaotuo:init()
self._cfg = Util:requireCfg(self.mCfg.severPath)
self.varName = VarCfg.player.nDengjiChaotuo -- 存储超脱次数的变量名
self.dayVar = VarCfg.player.nDengJi --天变量
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-05-09 14:04:30 |
👁️ 阅读: 4
后端Lua尊者来也!小仙,看了你的代码,我发现了问题所在。你的零点自动清零逻辑放在了`ChaoTuo`函数里,这意味着只有玩家点击按钮触发这个函数时才会检查零点重置。你需要把这个逻辑放到一个独立的定时器触发中。
这里给你完整的解决方案:
首先,在QF触发文件中添加`resetday`触发:
```lua
-- QF触发文件中的resetday触发
function resetday(actor)
-- 调用等级超脱系统的零点重置
local chaotuo = require("DengjiChaotuo")()
chaotuo:resetAtMidnight(actor)
end
```
然后修改你的`DengjiChaotuo.lua`文件:
```lua
DengjiChaotuo = class("DengjiChaotuo", BaseSystemLogic)
function DengjiChaotuo:init()
self._cfg = Util:requireCfg(self.mCfg.severPath)
self.varName = VarCfg.player.nDengjiChaotuo -- 存储超脱次数的变量名
self.dayVar = VarCfg.player.nDengJi --天变量
self.maxChaotuo = 100 -- 最高超脱次数
end
function DengjiChaotuo:syncData(actor, showUI)
local count = GetInt(0, actor, self.varName) or 0
if showUI then
self:initUI(actor, count)
end
end
-- 新增:零点自动重置函数 -- 零点重置函数
function DengjiChaotuo:resetAtMidnight(actor)
local todayCount = GetInt(0, actor, self.varName) or 0
if todayCount > 0 then
local curLv = getbaseinfo(actor, 6)
local resetLv = curLv - todayCount -- 等级减去今天所有超脱次数
if resetLv < 1 then resetLv = 1 end
setbaseinfo(actor, 6, resetLv) -- 恢复等级
SetInt(0, actor, self.varName, 0) -- 清空今天次数
release_print("【零点重置】玩家等级已恢复原始值")
Msg.richMsg(actor, "已到达零点,等级已恢复原始值")
end
end
function DengjiChaotuo:ChaoTuo(actor, data)
local cfg = self._cfg[1]
local cost = cfg.cost or {}
local level = data
-- 检查消耗
if not GMLib:checkItems(actor, cost, 0, 1) then
return
end
-- 获取当前超脱次数
local count = GetInt(0, actor, self.varName) or 0
-- 检查是否达到上限
if count >= self.maxChaotuo then
Msg.richMsg(actor, "已达到最高超脱次数(" .. self.maxChaotuo .. "次),无法继续超脱!")
return
end
-- 扣除材料
if not GMLib:takes(actor, cost, "等级超脱") then
return
end
-- 人物等级+1
local curLevel = getbaseinfo(actor, 6)
setbaseinfo(actor, 6, curLevel + 1)
-- 更新超脱总次数
count = count + 1
SetInt(0, actor, self.varName, count)
-- 更新天变量
local dayAddNum = GMLib:getObjTLInt(actor, self.dayVar)
GMLib:setDayTLInt(actor, self.dayVar, dayAddNum + 1)
self:updateUI(actor, count)
-- 提示成功
Msg.richMsg(actor, "等级超脱成功!当前已超脱 " .. count .. "/" .. self.maxChaotuo .. " 次")
end
return DengjiChaotuo
```
关键改动:
1. 移除了`ChaoTuo`函数中的零点检查逻辑
2. 新增了`resetAtMidnight`函数专门处理零点重置
3. 在QF的`resetday`触发中调用这个函数
这样修改后,玩家在零点时(无论是否在线),系统都会自动触发重置,不需要点击按钮。`resetday`触发会在每天零点时自动执行,为所有在线玩家重置等级超脱次数。
记得在QF触发文件中添加`resetday`触发调用哦!如果还有不明白的地方,随时可以问我,或者请教浮生梦尊师!
← 返回问答库