From 6304b5ad4baa92bc2a87f0cfd418432ca457437d Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 29 Jul 2021 18:30:56 +0800 Subject: [PATCH] feat: 一番赏 增加重置扭蛋机指令 --- src/actions/GmAction.lua | 13 ++++++++++++- src/models/RolePlugin.lua | 24 ++++++++++++++++++++++++ src/services/capsuled.lua | 24 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 794a303..8ff3f98 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -9,7 +9,7 @@ function _M.clientRequest(agent, data) SendPacket(actionCodes.Gm_receiveResponse, bin) return true end - local ret = action(role, msg) + local ret = action(role, msg, agent.capsule_serv) bin = MsgPack.pack({ cmd = ret }) SendPacket(actionCodes.Gm_receiveResponse, bin) return true @@ -1075,4 +1075,15 @@ function _M.clear_sea(role, pms) return "成功" end +table.insert(helpDes, {"重置扭蛋机", "reset_capsule", "typ"}) +function _M.reset_capsule(role, pms, capsule_serv) + local typ = tonumber(pms.pm1) + if typ == 1 then + skynet.call(capsule_serv, "lua", "reset") + else + role:resetCapsule() + end + return "成功" +end + return _M \ No newline at end of file diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 095092c..8795878 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -3196,6 +3196,30 @@ function RolePlugin.bind(Role) local capsule = self.capsules[capsuleId] or {} return capsule:data() end + + function Role:resetCapsule() + local roleId = self:getProperty("id") + local res = redisproxy:smembers(CAPSULE_ID_ROLE:format(roleId)) or {} + for _, key in pairs(res) do + redisproxy:del(CAPSULE_ROLE:format(roleId, tonumber(key))) + redisproxy:srem(CAPSULE_ID_ROLE, key) + end + + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do + for _, val in pairs(data) do + if val.typ == 0 then + local key = val.id..val.room + if not self.capsules[key] then + local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId, tonumber(key)), id= val.id, room = val.room, typ = 0, name=val.name}) + capsule:init() + capsule:create() + self.capsules[key] = capsule + redisproxy.sadd(CAPSULE_ID_ROLE:format(roleId), key) + end + end + end + end + end end return RolePlugin \ No newline at end of file diff --git a/src/services/capsuled.lua b/src/services/capsuled.lua index b509ceb..4926a2d 100644 --- a/src/services/capsuled.lua +++ b/src/services/capsuled.lua @@ -100,6 +100,30 @@ local function check_capsules() skynet.timeout(60, check_capsules) end +function CMD.reset() + local now = skynet.timex() + local res = redisproxy:smembers(CAPSULE_INFO) or {} + for _, key in pairs(res) do + redisproxy:del(CAPSULE_PUBLIC:format(key)) + redisproxy:srem(CAPSULE_INFO, key) + end + + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do + for _, val in ipairs(data) do + if val.type == 1 then + local key = val.id..val.room + if not capsules[key] then + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name}) + capsule:init() + capsule:create() + capsules[key] = capsule + redisproxy:sadd(CAPSULE_INFO, key) + end + end + end + end +end + function CMD.start() local now = skynet.timex() local res = redisproxy:smembers(CAPSULE_INFO) or {} -- libgit2 0.21.2