Commit cd2a7a672cb5e4645827f08bff0c03fb3511ae4d
1 parent
d10a9a36
fix: 一番赏奖励中加入得奖者的名字 字段 name=name
Showing
4 changed files
with
98 additions
and
92 deletions
Show diff stats
src/actions/CapsuleAction.lua
| ... | ... | @@ -96,11 +96,11 @@ function _M.drawRpc(agent, data) |
| 96 | 96 | local full = msg.full -- 0=单次,1=十连抽 2=全收 |
| 97 | 97 | local cares = msg.cares |
| 98 | 98 | |
| 99 | - local ret, reward, change, capsule | |
| 99 | + local ret, reward, change, rewardByGoods, capsule | |
| 100 | 100 | if typ == 1 then |
| 101 | - ret, reward, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | |
| 101 | + ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | |
| 102 | 102 | else |
| 103 | - ret, reward, capsule= role:drawCapsule(capsuleId, full, cares) | |
| 103 | + ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) | |
| 104 | 104 | end |
| 105 | 105 | if ret < 4 then |
| 106 | 106 | return ret |
| ... | ... | @@ -110,9 +110,12 @@ function _M.drawRpc(agent, data) |
| 110 | 110 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | - reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | |
| 114 | - dump(reward) | |
| 115 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = reward, change= change, capsule = capsule})) | |
| 113 | + if rewardByGoods and next(rewardByGoods) then | |
| 114 | + reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | |
| 115 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) | |
| 116 | + else | |
| 117 | + return 5 | |
| 118 | + end | |
| 116 | 119 | return true |
| 117 | 120 | end |
| 118 | 121 | ... | ... |
src/models/Capsule.lua
| ... | ... | @@ -27,14 +27,7 @@ CapsuleType = { |
| 27 | 27 | |
| 28 | 28 | --[[ |
| 29 | 29 | --通知数据结构 |
| 30 | -{ | |
| 31 | -[roleId] = { | |
| 32 | - [good_id1] = { | |
| 33 | - }, | |
| 34 | - [good_id2] = { | |
| 35 | - }, | |
| 36 | -} | |
| 37 | -} | |
| 30 | +{ [roleId] = { [good_id1] = { }, [good_id2] = { }, } } | |
| 38 | 31 | ]]-- |
| 39 | 32 | |
| 40 | 33 | Capsule.schema = { |
| ... | ... | @@ -57,51 +50,6 @@ Capsule.schema = { |
| 57 | 50 | drawEndTime = {"number", 0}, --抽完时间 |
| 58 | 51 | } |
| 59 | 52 | |
| 60 | -function Capsule:isShow() | |
| 61 | - if skynet.timex() >= self:getProperty("hideTime") then | |
| 62 | - return false | |
| 63 | - end | |
| 64 | - return true | |
| 65 | -end | |
| 66 | - | |
| 67 | -function Capsule:refreshing(now) | |
| 68 | - local id = self:getProperty("id") | |
| 69 | - local room = self:getProperty("room") | |
| 70 | - local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] | |
| 71 | - local reset = tostring(ichibankuji.reset) | |
| 72 | - | |
| 73 | - if reset == "0" then | |
| 74 | - return false | |
| 75 | - elseif reset == "1" then | |
| 76 | - if self:getProperty("resetTimes") == 1 then | |
| 77 | - return true | |
| 78 | - end | |
| 79 | - return false | |
| 80 | - else | |
| 81 | - local resetArr = reset:toArray(true, "=") | |
| 82 | - if not next(resetArr) then return false end | |
| 83 | - | |
| 84 | - if resetArr[1] == "2" then | |
| 85 | - if self:getGoodsAmount() > 0 then return false end | |
| 86 | - | |
| 87 | - local drawEndTime = self:getProperty("drawEndTime") or 0 | |
| 88 | - if drawEndTime == 0 then return false end | |
| 89 | - | |
| 90 | - if now - drawEndTime >= resetArr[2] then | |
| 91 | - return true | |
| 92 | - end | |
| 93 | - return false | |
| 94 | - | |
| 95 | - elseif resetArr[1] == "3" then | |
| 96 | - | |
| 97 | - elseif resetArr[1] == "4" then | |
| 98 | - if now >= resetArr[2] then return true end | |
| 99 | - end | |
| 100 | - end | |
| 101 | - | |
| 102 | - return false | |
| 103 | -end | |
| 104 | - | |
| 105 | 53 | function Capsule:getResetFields() |
| 106 | 54 | return { |
| 107 | 55 | id = self:getProperty("id"), |
| ... | ... | @@ -115,8 +63,11 @@ function Capsule:getResetFields() |
| 115 | 63 | goods = {}, |
| 116 | 64 | specials = {}, |
| 117 | 65 | incentive = {}, |
| 66 | + incentiveRecord = {}, | |
| 118 | 67 | specialsRecord= {}, |
| 119 | 68 | resetTimes = 0, |
| 69 | + hideTime = 0, | |
| 70 | + drawEndTime = 0, | |
| 120 | 71 | } |
| 121 | 72 | end |
| 122 | 73 | |
| ... | ... | @@ -184,6 +135,51 @@ function Capsule:init() |
| 184 | 135 | self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) |
| 185 | 136 | end |
| 186 | 137 | |
| 138 | +function Capsule:isShow() | |
| 139 | + if skynet.timex() >= self:getProperty("hideTime") then | |
| 140 | + return false | |
| 141 | + end | |
| 142 | + return true | |
| 143 | +end | |
| 144 | + | |
| 145 | +function Capsule:refreshing(now) | |
| 146 | + local id = self:getProperty("id") | |
| 147 | + local room = self:getProperty("room") | |
| 148 | + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] | |
| 149 | + local reset = tostring(ichibankuji.reset) | |
| 150 | + | |
| 151 | + if reset == "0" then | |
| 152 | + return false | |
| 153 | + elseif reset == "1" then | |
| 154 | + if self:getProperty("resetTimes") == 1 then | |
| 155 | + return true | |
| 156 | + end | |
| 157 | + return false | |
| 158 | + else | |
| 159 | + local resetArr = reset:toArray(true, "=") | |
| 160 | + if not next(resetArr) then return false end | |
| 161 | + | |
| 162 | + if resetArr[1] == "2" then | |
| 163 | + if self:getGoodsAmount() > 0 then return false end | |
| 164 | + | |
| 165 | + local drawEndTime = self:getProperty("drawEndTime") or 0 | |
| 166 | + if drawEndTime == 0 then return false end | |
| 167 | + | |
| 168 | + if now - drawEndTime >= resetArr[2] then | |
| 169 | + return true | |
| 170 | + end | |
| 171 | + return false | |
| 172 | + | |
| 173 | + elseif resetArr[1] == "3" then | |
| 174 | + | |
| 175 | + elseif resetArr[1] == "4" then | |
| 176 | + if now >= resetArr[2] then return true end | |
| 177 | + end | |
| 178 | + end | |
| 179 | + | |
| 180 | + return false | |
| 181 | +end | |
| 182 | + | |
| 187 | 183 | function Capsule:getOnlineCount() |
| 188 | 184 | local register = self:getProperty("register") or {} |
| 189 | 185 | local reg, onlookers = 0, 0 |
| ... | ... | @@ -280,6 +276,7 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
| 280 | 276 | while(count > 0 and next(rewardRecord)) do |
| 281 | 277 | local roleId = math.randWeight(rewardRecord, "amount") |
| 282 | 278 | if roleId then |
| 279 | + | |
| 283 | 280 | local tmp = rewardRecord[roleId] |
| 284 | 281 | tmp["amount"] = tmp["amount"] - 1 |
| 285 | 282 | |
| ... | ... | @@ -287,10 +284,12 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
| 287 | 284 | |
| 288 | 285 | tmp = rewardByRole[roleId] |
| 289 | 286 | if not tmp then |
| 290 | - tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | |
| 287 | + local name = getNameByRoleId(roleId) | |
| 288 | + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | |
| 291 | 289 | else |
| 292 | 290 | if not tmp[spKey] then |
| 293 | - tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | |
| 291 | + local name = getNameByRoleId(roleId) | |
| 292 | + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | |
| 294 | 293 | else |
| 295 | 294 | tmp[spKey].amount = tmp[spKey].amount + 1 |
| 296 | 295 | end |
| ... | ... | @@ -528,7 +527,7 @@ function Capsule:checkSpecialReward( now) |
| 528 | 527 | return notify |
| 529 | 528 | end |
| 530 | 529 | |
| 531 | -function Capsule:checkIncentive(roleId, now) | |
| 530 | +function Capsule:checkIncentive(roleId, name, now) | |
| 532 | 531 | local goods = self:getProperty("goods") or {} |
| 533 | 532 | local recordByRole = self:getProperty("recordByRole") or {} |
| 534 | 533 | local roleRecord = recordByRole[roleId] or {} |
| ... | ... | @@ -548,7 +547,7 @@ function Capsule:checkIncentive(roleId, now) |
| 548 | 547 | end |
| 549 | 548 | end |
| 550 | 549 | if last then |
| 551 | - notify["last"] = {good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} | |
| 550 | + notify["last"] = {name = name, good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} | |
| 552 | 551 | end |
| 553 | 552 | end |
| 554 | 553 | |
| ... | ... | @@ -563,7 +562,7 @@ function Capsule:checkIncentive(roleId, now) |
| 563 | 562 | |
| 564 | 563 | local count = math.floor(amount / incentive["amount"]["np"]) |
| 565 | 564 | local tmpCount = count * incentive["amount"]["np"] |
| 566 | - notify["amount"] = {good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | |
| 565 | + notify["amount"] = {name = name, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | |
| 567 | 566 | |
| 568 | 567 | --填充v.calculated 字段,标识已经用于每x抽的计算中。 |
| 569 | 568 | for _, v in pairs(roleRecord) do |
| ... | ... | @@ -587,7 +586,7 @@ function Capsule:checkIncentive(roleId, now) |
| 587 | 586 | if incentive["probabilities"] then |
| 588 | 587 | local probabilities = math.randomInt(1, 100) |
| 589 | 588 | if probabilities <= incentive["probabilities"]["np"] then |
| 590 | - notify["probabilities"] = {good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} | |
| 589 | + notify["probabilities"] = {name = name, good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} | |
| 591 | 590 | |
| 592 | 591 | end |
| 593 | 592 | end |
| ... | ... | @@ -616,6 +615,7 @@ function Capsule:drawByCount(roleId, count) |
| 616 | 615 | local notify= {} |
| 617 | 616 | notify[roleId] = {} |
| 618 | 617 | |
| 618 | + local name = getNameByRoleId(roleId) | |
| 619 | 619 | while (goods and next(goods) and count > 0) do |
| 620 | 620 | local good_id = math.randWeight(goods, "weight") |
| 621 | 621 | if good_id then |
| ... | ... | @@ -624,7 +624,7 @@ function Capsule:drawByCount(roleId, count) |
| 624 | 624 | good.amount = good.amount - 1 |
| 625 | 625 | |
| 626 | 626 | --插入记录 |
| 627 | - local tmpNotify = {good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | |
| 627 | + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | |
| 628 | 628 | table.insert(record, tmpNotify) |
| 629 | 629 | |
| 630 | 630 | --作为奖励记录+通知 |
| ... | ... | @@ -650,7 +650,7 @@ function Capsule:drawByCount(roleId, count) |
| 650 | 650 | recordByRole[roleId] = roleRecord |
| 651 | 651 | self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) |
| 652 | 652 | |
| 653 | - local tmpNotify = self:checkIncentive(roleId, now) | |
| 653 | + local tmpNotify = self:checkIncentive(roleId, name, now) | |
| 654 | 654 | for k, v in pairs(tmpNotify) do |
| 655 | 655 | if not notify[roleId][k] then |
| 656 | 656 | notify[roleId][k] = v |
| ... | ... | @@ -662,17 +662,19 @@ function Capsule:drawByCount(roleId, count) |
| 662 | 662 | local speciNotify = self:checkSpecialReward(now) |
| 663 | 663 | rewardToNtyFunc(notify, speciNotify) |
| 664 | 664 | |
| 665 | - local reward = {} | |
| 665 | + local reward, rewardByGoods = {}, {} | |
| 666 | 666 | for key, val in pairs(notify) do |
| 667 | 667 | if key == roleId then |
| 668 | - for _, v in pairs(val) do | |
| 668 | + for k, v in pairs(val) do | |
| 669 | 669 | for id, count in pairs(v.award:toNumMap()) do |
| 670 | 670 | reward[id] = (reward[id] or 0) + count |
| 671 | 671 | end |
| 672 | + rewardByGoods[k] = v | |
| 672 | 673 | end |
| 673 | 674 | end |
| 675 | + | |
| 674 | 676 | end |
| 675 | - return reward, notify | |
| 677 | + return reward, rewardByGoods, notify | |
| 676 | 678 | end |
| 677 | 679 | |
| 678 | 680 | function Capsule:drawAll(roleId) |
| ... | ... | @@ -682,12 +684,13 @@ function Capsule:drawAll(roleId) |
| 682 | 684 | local roleRecord = recordByRole[roleId] or {} |
| 683 | 685 | local now = skynet.timex() |
| 684 | 686 | |
| 687 | + local name = getNameByRoleId(roleId) | |
| 685 | 688 | local notify = {} |
| 686 | 689 | notify[roleId] = {} |
| 687 | 690 | for good_id, good in pairs(goods) do |
| 688 | 691 | if good.amount > 0 then |
| 689 | 692 | --插入记录 |
| 690 | - local tmpNotify = {role_id = roleId, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | |
| 693 | + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | |
| 691 | 694 | table.insert(record, notify) |
| 692 | 695 | |
| 693 | 696 | --作为奖励记录+通知 |
| ... | ... | @@ -711,7 +714,7 @@ function Capsule:drawAll(roleId) |
| 711 | 714 | recordByRole[roleId] = roleRecord |
| 712 | 715 | self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) |
| 713 | 716 | |
| 714 | - local tmpNotify = self:checkIncentive(roleId, now) | |
| 717 | + local tmpNotify = self:checkIncentive(roleId, name, now) | |
| 715 | 718 | for k, v in pairs(tmpNotify) do |
| 716 | 719 | if not notify[roleId][k] then |
| 717 | 720 | notify[roleId][k] = v |
| ... | ... | @@ -723,17 +726,19 @@ function Capsule:drawAll(roleId) |
| 723 | 726 | local speciNotify = self:checkSpecialReward(now) |
| 724 | 727 | rewardToNtyFunc(notify, speciNotify) |
| 725 | 728 | |
| 726 | - local reward = {} | |
| 729 | + local reward, rewardByGoods = {}, {} | |
| 727 | 730 | for key, val in pairs(notify) do |
| 728 | 731 | if key == roleId then |
| 729 | - for _, v in pairs(val) do | |
| 732 | + for k, v in pairs(val) do | |
| 730 | 733 | for id, count in pairs(v.award:toNumMap()) do |
| 731 | 734 | reward[id] = (reward[id] or 0) + count |
| 732 | 735 | end |
| 736 | + rewardByGoods[k] = v | |
| 733 | 737 | end |
| 734 | 738 | end |
| 739 | + | |
| 735 | 740 | end |
| 736 | - return reward, notify | |
| 741 | + return reward, rewardByGoods, notify | |
| 737 | 742 | end |
| 738 | 743 | |
| 739 | 744 | --@param |
| ... | ... | @@ -776,7 +781,6 @@ function Capsule:data(roleId) |
| 776 | 781 | onlineCount = self:getOnlineCount(), |
| 777 | 782 | playerStatus = self:getRegisterByRoleId(roleId), |
| 778 | 783 | record = self:getProperty("record"), |
| 779 | - --recordByRole = self:getProperty("recordByRole"), | |
| 780 | 784 | rank = self:getProperty("rank"), |
| 781 | 785 | goods = self:getProperty("goods"), |
| 782 | 786 | specials = self:getProperty("specials"), | ... | ... |
src/models/RolePlugin.lua
src/services/capsuled.lua
| ... | ... | @@ -19,25 +19,22 @@ NotifyChangeType = { |
| 19 | 19 | INCENTIVE = 5, |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function rpcRole(roleId, funcName, ...) | |
| 22 | +local function rpcRole(roleId, funcName, ...) | |
| 23 | 23 | local fields = ... |
| 24 | 24 | local agent = datacenter.get("agent", roleId) |
| 25 | - if agent and agent.serv then | |
| 26 | - if funcName == "getProperties" then | |
| 27 | - return true, skynet.call(agent.serv, "role", funcName, fields) | |
| 28 | - else | |
| 29 | - return true, skynet.call(agent.serv, "role", funcName, ...) | |
| 30 | - end | |
| 25 | + local roleCross = require("models.RoleCross") | |
| 26 | + if funcName == "getProperties" then | |
| 27 | + return roleCross.handle(funcName, roleId, fields) | |
| 31 | 28 | else |
| 32 | - local roleCross = require("models.RoleCross") | |
| 33 | - if funcName == "getProperties" then | |
| 34 | - return false, roleCross.handle(funcName, roleId, fields) | |
| 35 | - else | |
| 36 | - return false, roleCross.handle(funcName, roleId, ...) | |
| 37 | - end | |
| 29 | + return roleCross.handle(funcName, roleId, ...) | |
| 38 | 30 | end |
| 39 | 31 | end |
| 40 | 32 | |
| 33 | +function getNameByRoleId(roleId) | |
| 34 | + return rpcRole(roleId, "getProperty", "name") | |
| 35 | + | |
| 36 | +end | |
| 37 | + | |
| 41 | 38 | function broadCastCapsule(roleId, capsuleId, broadInfo) |
| 42 | 39 | local capsule = capsules[capsuleId] or {} |
| 43 | 40 | local register = capsule:getProperty("register") or {} |
| ... | ... | @@ -156,13 +153,13 @@ end |
| 156 | 153 | function CMD.draw_capsule(roleId, capsuleId, full, cares) |
| 157 | 154 | local capsule = capsules[capsuleId] or {} |
| 158 | 155 | if next(capsule) then |
| 159 | - local ret, reward, notify = capsule:draw(roleId, full, cares) | |
| 156 | + local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, cares) | |
| 160 | 157 | --if ret > 4 then |
| 161 | 158 | -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) |
| 162 | 159 | --end |
| 163 | - return ret, reward, capsule:data(roleId) | |
| 160 | + return ret, reward, rewardByGoods, capsule:data(roleId) | |
| 164 | 161 | end |
| 165 | - return nil | |
| 162 | + return 1 | |
| 166 | 163 | end |
| 167 | 164 | |
| 168 | 165 | function CMD.register(roleId, capsuleId) |
| ... | ... | @@ -180,4 +177,5 @@ skynet.start(function() |
| 180 | 177 | end) |
| 181 | 178 | |
| 182 | 179 | skynet.register("capsuled") |
| 180 | + globalCsv = csvdb["GlobalDefineCsv"] | |
| 183 | 181 | end) |
| 184 | 182 | \ No newline at end of file | ... | ... |