From cd2a7a672cb5e4645827f08bff0c03fb3511ae4d Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Tue, 27 Jul 2021 19:25:04 +0800 Subject: [PATCH] fix: 一番赏奖励中加入得奖者的名字 字段 name=name --- src/actions/CapsuleAction.lua | 15 +++++++++------ src/models/Capsule.lua | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- src/models/RolePlugin.lua | 1 + src/services/capsuled.lua | 30 ++++++++++++++---------------- 4 files changed, 98 insertions(+), 92 deletions(-) diff --git a/src/actions/CapsuleAction.lua b/src/actions/CapsuleAction.lua index 90c1848..6620a97 100644 --- a/src/actions/CapsuleAction.lua +++ b/src/actions/CapsuleAction.lua @@ -96,11 +96,11 @@ function _M.drawRpc(agent, data) local full = msg.full -- 0=单次,1=十连抽 2=全收 local cares = msg.cares - local ret, reward, change, capsule + local ret, reward, change, rewardByGoods, capsule if typ == 1 then - ret, reward, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) + ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) else - ret, reward, capsule= role:drawCapsule(capsuleId, full, cares) + ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) end if ret < 4 then return ret @@ -110,9 +110,12 @@ function _M.drawRpc(agent, data) SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) end - reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) - dump(reward) - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = reward, change= change, capsule = capsule})) + if rewardByGoods and next(rewardByGoods) then + reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) + else + return 5 + end return true end diff --git a/src/models/Capsule.lua b/src/models/Capsule.lua index 7c5c1d6..fab0a3e 100644 --- a/src/models/Capsule.lua +++ b/src/models/Capsule.lua @@ -27,14 +27,7 @@ CapsuleType = { --[[ --通知数据结构 -{ -[roleId] = { - [good_id1] = { - }, - [good_id2] = { - }, -} -} +{ [roleId] = { [good_id1] = { }, [good_id2] = { }, } } ]]-- Capsule.schema = { @@ -57,51 +50,6 @@ Capsule.schema = { drawEndTime = {"number", 0}, --抽完时间 } -function Capsule:isShow() - if skynet.timex() >= self:getProperty("hideTime") then - return false - end - return true -end - -function Capsule:refreshing(now) - local id = self:getProperty("id") - local room = self:getProperty("room") - local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] - local reset = tostring(ichibankuji.reset) - - if reset == "0" then - return false - elseif reset == "1" then - if self:getProperty("resetTimes") == 1 then - return true - end - return false - else - local resetArr = reset:toArray(true, "=") - if not next(resetArr) then return false end - - if resetArr[1] == "2" then - if self:getGoodsAmount() > 0 then return false end - - local drawEndTime = self:getProperty("drawEndTime") or 0 - if drawEndTime == 0 then return false end - - if now - drawEndTime >= resetArr[2] then - return true - end - return false - - elseif resetArr[1] == "3" then - - elseif resetArr[1] == "4" then - if now >= resetArr[2] then return true end - end - end - - return false -end - function Capsule:getResetFields() return { id = self:getProperty("id"), @@ -115,8 +63,11 @@ function Capsule:getResetFields() goods = {}, specials = {}, incentive = {}, + incentiveRecord = {}, specialsRecord= {}, resetTimes = 0, + hideTime = 0, + drawEndTime = 0, } end @@ -184,6 +135,51 @@ function Capsule:init() self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) end +function Capsule:isShow() + if skynet.timex() >= self:getProperty("hideTime") then + return false + end + return true +end + +function Capsule:refreshing(now) + local id = self:getProperty("id") + local room = self:getProperty("room") + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] + local reset = tostring(ichibankuji.reset) + + if reset == "0" then + return false + elseif reset == "1" then + if self:getProperty("resetTimes") == 1 then + return true + end + return false + else + local resetArr = reset:toArray(true, "=") + if not next(resetArr) then return false end + + if resetArr[1] == "2" then + if self:getGoodsAmount() > 0 then return false end + + local drawEndTime = self:getProperty("drawEndTime") or 0 + if drawEndTime == 0 then return false end + + if now - drawEndTime >= resetArr[2] then + return true + end + return false + + elseif resetArr[1] == "3" then + + elseif resetArr[1] == "4" then + if now >= resetArr[2] then return true end + end + end + + return false +end + function Capsule:getOnlineCount() local register = self:getProperty("register") or {} local reg, onlookers = 0, 0 @@ -280,6 +276,7 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) while(count > 0 and next(rewardRecord)) do local roleId = math.randWeight(rewardRecord, "amount") if roleId then + local tmp = rewardRecord[roleId] tmp["amount"] = tmp["amount"] - 1 @@ -287,10 +284,12 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) tmp = rewardByRole[roleId] if not tmp then - tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} + local name = getNameByRoleId(roleId) + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} else if not tmp[spKey] then - tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} + local name = getNameByRoleId(roleId) + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} else tmp[spKey].amount = tmp[spKey].amount + 1 end @@ -528,7 +527,7 @@ function Capsule:checkSpecialReward( now) return notify end -function Capsule:checkIncentive(roleId, now) +function Capsule:checkIncentive(roleId, name, now) local goods = self:getProperty("goods") or {} local recordByRole = self:getProperty("recordByRole") or {} local roleRecord = recordByRole[roleId] or {} @@ -548,7 +547,7 @@ function Capsule:checkIncentive(roleId, now) end end if last then - notify["last"] = {good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} + notify["last"] = {name = name, good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} end end @@ -563,7 +562,7 @@ function Capsule:checkIncentive(roleId, now) local count = math.floor(amount / incentive["amount"]["np"]) local tmpCount = count * incentive["amount"]["np"] - notify["amount"] = {good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} + notify["amount"] = {name = name, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} --填充v.calculated 字段,标识已经用于每x抽的计算中。 for _, v in pairs(roleRecord) do @@ -587,7 +586,7 @@ function Capsule:checkIncentive(roleId, now) if incentive["probabilities"] then local probabilities = math.randomInt(1, 100) if probabilities <= incentive["probabilities"]["np"] then - notify["probabilities"] = {good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} + notify["probabilities"] = {name = name, good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} end end @@ -616,6 +615,7 @@ function Capsule:drawByCount(roleId, count) local notify= {} notify[roleId] = {} + local name = getNameByRoleId(roleId) while (goods and next(goods) and count > 0) do local good_id = math.randWeight(goods, "weight") if good_id then @@ -624,7 +624,7 @@ function Capsule:drawByCount(roleId, count) good.amount = good.amount - 1 --插入记录 - local tmpNotify = {good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} table.insert(record, tmpNotify) --作为奖励记录+通知 @@ -650,7 +650,7 @@ function Capsule:drawByCount(roleId, count) recordByRole[roleId] = roleRecord self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) - local tmpNotify = self:checkIncentive(roleId, now) + local tmpNotify = self:checkIncentive(roleId, name, now) for k, v in pairs(tmpNotify) do if not notify[roleId][k] then notify[roleId][k] = v @@ -662,17 +662,19 @@ function Capsule:drawByCount(roleId, count) local speciNotify = self:checkSpecialReward(now) rewardToNtyFunc(notify, speciNotify) - local reward = {} + local reward, rewardByGoods = {}, {} for key, val in pairs(notify) do if key == roleId then - for _, v in pairs(val) do + for k, v in pairs(val) do for id, count in pairs(v.award:toNumMap()) do reward[id] = (reward[id] or 0) + count end + rewardByGoods[k] = v end end + end - return reward, notify + return reward, rewardByGoods, notify end function Capsule:drawAll(roleId) @@ -682,12 +684,13 @@ function Capsule:drawAll(roleId) local roleRecord = recordByRole[roleId] or {} local now = skynet.timex() + local name = getNameByRoleId(roleId) local notify = {} notify[roleId] = {} for good_id, good in pairs(goods) do if good.amount > 0 then --插入记录 - local tmpNotify = {role_id = roleId, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} table.insert(record, notify) --作为奖励记录+通知 @@ -711,7 +714,7 @@ function Capsule:drawAll(roleId) recordByRole[roleId] = roleRecord self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) - local tmpNotify = self:checkIncentive(roleId, now) + local tmpNotify = self:checkIncentive(roleId, name, now) for k, v in pairs(tmpNotify) do if not notify[roleId][k] then notify[roleId][k] = v @@ -723,17 +726,19 @@ function Capsule:drawAll(roleId) local speciNotify = self:checkSpecialReward(now) rewardToNtyFunc(notify, speciNotify) - local reward = {} + local reward, rewardByGoods = {}, {} for key, val in pairs(notify) do if key == roleId then - for _, v in pairs(val) do + for k, v in pairs(val) do for id, count in pairs(v.award:toNumMap()) do reward[id] = (reward[id] or 0) + count end + rewardByGoods[k] = v end end + end - return reward, notify + return reward, rewardByGoods, notify end --@param @@ -776,7 +781,6 @@ function Capsule:data(roleId) onlineCount = self:getOnlineCount(), playerStatus = self:getRegisterByRoleId(roleId), record = self:getProperty("record"), - --recordByRole = self:getProperty("recordByRole"), rank = self:getProperty("rank"), goods = self:getProperty("goods"), specials = self:getProperty("specials"), diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 143edf6..30a0c43 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -3170,6 +3170,7 @@ function RolePlugin.bind(Role) local roleId = self:getProperty("id") return capsule:draw(roleId, full, cares) end + return 1 end function Role:joinCapsule(capsuleId) diff --git a/src/services/capsuled.lua b/src/services/capsuled.lua index e1395fc..31bb2ad 100644 --- a/src/services/capsuled.lua +++ b/src/services/capsuled.lua @@ -19,25 +19,22 @@ NotifyChangeType = { INCENTIVE = 5, } -function rpcRole(roleId, funcName, ...) +local function rpcRole(roleId, funcName, ...) local fields = ... local agent = datacenter.get("agent", roleId) - if agent and agent.serv then - if funcName == "getProperties" then - return true, skynet.call(agent.serv, "role", funcName, fields) - else - return true, skynet.call(agent.serv, "role", funcName, ...) - end + local roleCross = require("models.RoleCross") + if funcName == "getProperties" then + return roleCross.handle(funcName, roleId, fields) else - local roleCross = require("models.RoleCross") - if funcName == "getProperties" then - return false, roleCross.handle(funcName, roleId, fields) - else - return false, roleCross.handle(funcName, roleId, ...) - end + return roleCross.handle(funcName, roleId, ...) end end +function getNameByRoleId(roleId) + return rpcRole(roleId, "getProperty", "name") + +end + function broadCastCapsule(roleId, capsuleId, broadInfo) local capsule = capsules[capsuleId] or {} local register = capsule:getProperty("register") or {} @@ -156,13 +153,13 @@ end function CMD.draw_capsule(roleId, capsuleId, full, cares) local capsule = capsules[capsuleId] or {} if next(capsule) then - local ret, reward, notify = capsule:draw(roleId, full, cares) + local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, cares) --if ret > 4 then -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) --end - return ret, reward, capsule:data(roleId) + return ret, reward, rewardByGoods, capsule:data(roleId) end - return nil + return 1 end function CMD.register(roleId, capsuleId) @@ -180,4 +177,5 @@ skynet.start(function() end) skynet.register("capsuled") + globalCsv = csvdb["GlobalDefineCsv"] end) \ No newline at end of file -- libgit2 0.21.2