Commit 0eb317fbb1fbead847c33488e037cafb582f1af2
1 parent
cd2a7a67
fix: 一番赏奖励抽奖的bug与功能完善
1. 增加获取扭蛋机信息的协议 2. 特殊赏奖励发放 3. 增加抽扭蛋机消耗 --暂时屏蔽 4. 激励奖暂时屏蔽
Showing
7 changed files
with
197 additions
and
87 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -279,10 +279,11 @@ actionCodes = { |
279 | 279 | Capsule_joinRpc = 851, --扭蛋机详情 |
280 | 280 | Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中 |
281 | 281 | Capsule_drawRpc = 854, --抽扭蛋机 |
282 | - Capsule_switchRoomRpc = 855, --切换扭蛋机房间 | |
282 | + --Capsule_switchRoomRpc = 855, --切换扭蛋机房间 | |
283 | 283 | Capsule_notifyChange = 856, -- 通知信息变动 |
284 | 284 | Capsule_payReward = 857, -- 特殊赏 奖励通知 |
285 | 285 | Capsule_exitRpc = 858, -- 退出 |
286 | + Capsule_getDataRpc = 859, --获取扭蛋机信息 | |
286 | 287 | } |
287 | 288 | |
288 | 289 | rpcResponseBegin = 10000 | ... | ... |
src/actions/CapsuleAction.lua
... | ... | @@ -93,40 +93,83 @@ function _M.drawRpc(agent, data) |
93 | 93 | local roleId = role:getProperty("id") |
94 | 94 | local capsuleId = msg.capsule_id |
95 | 95 | local typ = msg.typ --0=独享,1= 公开 |
96 | - local full = msg.full -- 0=单次,1=十连抽 2=全收 | |
96 | + local full = msg.full or 0-- 0=单次,1=十连抽 2=全收 | |
97 | 97 | local cares = msg.cares |
98 | 98 | |
99 | - local ret, reward, change, rewardByGoods, capsule | |
99 | + local ret, token, reward, change, rewardByGoods, capsule | |
100 | + | |
101 | + --检查库存 | |
102 | + if typ == 1 then | |
103 | + ret, token = skynet.call(agent.capsule_serv, "lua", "goods_stock", capsuleId) | |
104 | + else | |
105 | + ret, token = role:goodStock(capsuleId) | |
106 | + end | |
107 | + if ret == 0 then skynet.error("零库存 " .. capsuleId) return 1 end | |
108 | + | |
109 | + --检查余额 | |
110 | + if not next(token) then skynet.error("代币未配置 " .. capsuleId) return 1 end | |
111 | + local cost, drawsNum = {}, 0 | |
112 | + if full == 0 then | |
113 | + drawsNum = 1 | |
114 | + elseif full == 1 then | |
115 | + if ret < 10 then | |
116 | + drawsNum = ret | |
117 | + else | |
118 | + drawsNum = 10 | |
119 | + end | |
120 | + elseif full == 2 then | |
121 | + drawsNum = ret | |
122 | + end | |
123 | + cost[token[1]] = drawsNum * token[2] | |
124 | + | |
125 | + --if not role:checkItemEnough(cost) then return 2 end | |
126 | + --role:costItems(cost, {log = {desc = "CapsuleCoinCost", int1 = token[1], int2 = cost[token[1]]}}) | |
127 | + | |
128 | + --开始抽奖 | |
100 | 129 | if typ == 1 then |
101 | 130 | ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) |
102 | 131 | else |
103 | 132 | ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) |
104 | 133 | end |
105 | - if ret < 4 then | |
134 | + if ret < 5 then | |
106 | 135 | return ret |
107 | 136 | end |
108 | 137 | |
109 | - if ret == 4 then | |
110 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) | |
138 | + dump(reward) | |
139 | + dump(rewardByGoods) | |
140 | + | |
141 | + if ret == 5 then | |
142 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule})) | |
143 | + return true | |
111 | 144 | end |
112 | 145 | |
146 | + -- rewardByGoods是抽到的扭蛋信息,reward是抽扭蛋后获得的所有奖励信息。 | |
113 | 147 | if rewardByGoods and next(rewardByGoods) then |
114 | 148 | reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) |
115 | 149 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) |
116 | 150 | else |
117 | - return 5 | |
151 | + return ret | |
118 | 152 | end |
119 | 153 | return true |
120 | 154 | end |
121 | 155 | |
122 | -function _M.switchRoomRpc(agent, data) | |
156 | +function _M.getData(agent, data) | |
123 | 157 | local role = agent.role |
124 | 158 | local msg = MsgPack.unpack(data) |
125 | - local roleId = role:getProperty("id") | |
159 | + local capsuleId = msg.capsule_id | |
160 | + local typ = msg.typ --0=独享,1= 公开 | |
126 | 161 | |
127 | - local ret = skynet.call(agent.capsule_serv, "lua", "switch_room", roleId) | |
128 | - SendPacket(actionCodes.Capsule_switchRoomRpc, MsgPack.pack(ret)) | |
162 | + local capsule | |
163 | + if typ == 1 then | |
164 | + capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", capsuleId) | |
165 | + else | |
166 | + capsule = role:getCapsuleData(capsuleId) | |
167 | + end | |
168 | + if not capsule then return 1 end | |
169 | + | |
170 | + SendPacket(actionCodes.Capsule_getDataRpc, MsgPack.pack({capsule = capsule})) | |
129 | 171 | return true |
172 | + | |
130 | 173 | end |
131 | 174 | |
132 | 175 | return _M |
133 | 176 | \ No newline at end of file | ... | ... |
src/models/Capsule.lua
... | ... | @@ -36,6 +36,7 @@ Capsule.schema = { |
36 | 36 | name = {"string"}, |
37 | 37 | typ = {"number", 1}, -- 1=共享,2=独享 |
38 | 38 | coin = {"number", 0}, --货币代号 |
39 | + token = {"table", {}}, --抽一次,货币=消耗 | |
39 | 40 | register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 |
40 | 41 | record = {"table", {}}, --抽取记录 列表 |
41 | 42 | recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record} |
... | ... | @@ -56,6 +57,7 @@ function Capsule:getResetFields() |
56 | 57 | room = self:getProperty("room"), |
57 | 58 | typ = self:getProperty("typ"), |
58 | 59 | coin = 0, |
60 | + token = {}, | |
59 | 61 | register = {}, |
60 | 62 | record = {}, |
61 | 63 | recordByRole = {}, |
... | ... | @@ -132,7 +134,7 @@ function Capsule:init() |
132 | 134 | end |
133 | 135 | --货币类型 |
134 | 136 | local coin = ichibankuji["token"]:toArray(true, "=") |
135 | - self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) | |
137 | + self:setProperties({coin = coin[1] or 0, token = coin, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) | |
136 | 138 | end |
137 | 139 | |
138 | 140 | function Capsule:isShow() |
... | ... | @@ -233,11 +235,11 @@ function Capsule:confirmed(cares) |
233 | 235 | for k, v in pairs(cares) do |
234 | 236 | if v.typ == 1 then |
235 | 237 | if goods[k] and goods[k].amount ~= v.count then |
236 | - change[k] = goods[k].amount | |
238 | + change[k] = {typ=1, count = goods[k].amount} | |
237 | 239 | end |
238 | 240 | else |
239 | 241 | if specials[k] and specials[k].amount ~= v.count then |
240 | - change[k] = specials[k].amount | |
242 | + change[k] = {typ=1, count = specials[k].amount} | |
241 | 243 | end |
242 | 244 | end |
243 | 245 | end |
... | ... | @@ -282,8 +284,8 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
282 | 284 | |
283 | 285 | if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end |
284 | 286 | |
285 | - tmp = rewardByRole[roleId] | |
286 | - if not tmp then | |
287 | + tmp = rewardByRole[roleId] or {} | |
288 | + if not next(tmp) then | |
287 | 289 | local name = getNameByRoleId(roleId) |
288 | 290 | tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} |
289 | 291 | else |
... | ... | @@ -372,7 +374,7 @@ function Capsule:getCore(record) |
372 | 374 | if not roleRecord[v.roleId]then |
373 | 375 | roleRecord[v.roleId] = {amount = v.amount } |
374 | 376 | else |
375 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} | |
377 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount} | |
376 | 378 | end |
377 | 379 | end |
378 | 380 | |
... | ... | @@ -416,7 +418,7 @@ function Capsule:getLast(record) |
416 | 418 | if not roleRecord[v.roleId]then |
417 | 419 | roleRecord[v.roleId] = {amount = v.amount } |
418 | 420 | else |
419 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} | |
421 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount} | |
420 | 422 | end |
421 | 423 | end |
422 | 424 | |
... | ... | @@ -443,7 +445,7 @@ function Capsule:getJoker(record) |
443 | 445 | if not roleRecord[v.roleId]then |
444 | 446 | roleRecord[v.roleId] = {amount = v.amount } |
445 | 447 | else |
446 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | |
448 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount} | |
447 | 449 | end |
448 | 450 | end |
449 | 451 | |
... | ... | @@ -470,7 +472,7 @@ function Capsule:getKing(record) |
470 | 472 | if not roleRecord[v.roleId]then |
471 | 473 | roleRecord[v.roleId] = {amount = v.amount } |
472 | 474 | else |
473 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | |
475 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount} | |
474 | 476 | end |
475 | 477 | end |
476 | 478 | |
... | ... | @@ -522,8 +524,7 @@ function Capsule:checkSpecialReward( now) |
522 | 524 | local kingReward = self:getKing(record) |
523 | 525 | rewardToNtyFunc(notify, kingReward) |
524 | 526 | |
525 | - --广播出去TODO | |
526 | - --rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) | |
527 | + | |
527 | 528 | return notify |
528 | 529 | end |
529 | 530 | |
... | ... | @@ -562,7 +563,7 @@ function Capsule:checkIncentive(roleId, name, now) |
562 | 563 | |
563 | 564 | local count = math.floor(amount / incentive["amount"]["np"]) |
564 | 565 | local tmpCount = count * incentive["amount"]["np"] |
565 | - notify["amount"] = {name = name, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | |
566 | + notify["amount"] = {name = name, roleId= roleId, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | |
566 | 567 | |
567 | 568 | --填充v.calculated 字段,标识已经用于每x抽的计算中。 |
568 | 569 | for _, v in pairs(roleRecord) do |
... | ... | @@ -594,7 +595,8 @@ function Capsule:checkIncentive(roleId, name, now) |
594 | 595 | incentiveRecord[roleId] = incentiveByRole |
595 | 596 | self:setProperty("incentiveRecord", incentiveRecord) |
596 | 597 | |
597 | - return notify | |
598 | + --TODO 先屏蔽 | |
599 | + return {} | |
598 | 600 | end |
599 | 601 | |
600 | 602 | function Capsule:drawByCount(roleId, count) |
... | ... | @@ -618,32 +620,32 @@ function Capsule:drawByCount(roleId, count) |
618 | 620 | local name = getNameByRoleId(roleId) |
619 | 621 | while (goods and next(goods) and count > 0) do |
620 | 622 | local good_id = math.randWeight(goods, "weight") |
621 | - if good_id then | |
622 | - local good = goods[good_id] or {} | |
623 | - if good and good.amount > 0 then | |
624 | - good.amount = good.amount - 1 | |
625 | - | |
626 | - --插入记录 | |
627 | - local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | |
628 | - table.insert(record, tmpNotify) | |
629 | - | |
630 | - --作为奖励记录+通知 | |
631 | - if not notify[roleId][good_id] then | |
632 | - notify[roleId][good_id] = tmpNotify | |
633 | - else | |
634 | - notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 | |
635 | - end | |
623 | + if not good_id then break end | |
636 | 624 | |
637 | - --记录角色的抽奖记录 计算激励奖需要用到 | |
638 | - if not roleRecord[good_id] then | |
639 | - roleRecord[good_id] = tmpNotify | |
640 | - else | |
641 | - roleRecord[good_id].amount = roleRecord[good_id].amount + 1 | |
642 | - end | |
625 | + local good = goods[good_id] or {} | |
626 | + if good and good.amount > 0 then | |
627 | + good.amount = good.amount - 1 | |
628 | + | |
629 | + --插入记录 | |
630 | + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | |
631 | + table.insert(record, tmpNotify) | |
632 | + | |
633 | + --作为奖励记录+通知 | |
634 | + if not notify[roleId][good_id] then | |
635 | + notify[roleId][good_id] = tmpNotify | |
636 | + else | |
637 | + notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 | |
638 | + end | |
643 | 639 | |
644 | - good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight | |
645 | - count = count - 1 | |
640 | + --记录角色的抽奖记录 计算激励奖需要用到 | |
641 | + if not roleRecord[good_id] then | |
642 | + roleRecord[good_id] = tmpNotify | |
643 | + else | |
644 | + roleRecord[good_id].amount = roleRecord[good_id].amount + 1 | |
646 | 645 | end |
646 | + | |
647 | + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight | |
648 | + count = count - 1 | |
647 | 649 | end |
648 | 650 | |
649 | 651 | end |
... | ... | @@ -690,8 +692,8 @@ function Capsule:drawAll(roleId) |
690 | 692 | for good_id, good in pairs(goods) do |
691 | 693 | if good.amount > 0 then |
692 | 694 | --插入记录 |
693 | - local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | |
694 | - table.insert(record, notify) | |
695 | + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | |
696 | + table.insert(record, tmpNotify) | |
695 | 697 | |
696 | 698 | --作为奖励记录+通知 |
697 | 699 | if not notify[roleId][good_id] then |
... | ... | @@ -702,7 +704,7 @@ function Capsule:drawAll(roleId) |
702 | 704 | |
703 | 705 | --记录角色的抽奖记录 |
704 | 706 | if not roleRecord[good_id] then |
705 | - roleRecord[good_id] = notify | |
707 | + roleRecord[good_id] = tmpNotify | |
706 | 708 | else |
707 | 709 | roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount |
708 | 710 | end |
... | ... | @@ -749,24 +751,23 @@ end |
749 | 751 | ]]-- |
750 | 752 | |
751 | 753 | function Capsule:draw(roleId, full, cares) |
752 | - if self:getGoodsAmount() == 0 then return 2 end | |
753 | 754 | if self:getProperty("typ") == 1 then |
754 | 755 | --是否报名 |
755 | - if self:isRegister(roleId) == false then return 3 end | |
756 | + if self:isRegister(roleId) == false then return 4 end | |
756 | 757 | |
757 | 758 | --关注的奖品的数量发生了变化 |
758 | 759 | if cares then |
759 | 760 | local change = self:confirmed(cares) |
760 | - if next(change) then return 4, change end | |
761 | + if next(change) then return 5, change end | |
761 | 762 | end |
762 | 763 | end |
763 | 764 | |
764 | 765 | if full == 0 then |
765 | - return 5, self:drawByCount(roleId, 1) | |
766 | + return 6, self:drawByCount(roleId, 1) | |
766 | 767 | elseif full == 1 then |
767 | - return 5, self:drawByCount(roleId, 10) | |
768 | + return 6, self:drawByCount(roleId, 10) | |
768 | 769 | elseif full == 2 then |
769 | - return 5, self:drawAll(roleId) | |
770 | + return 6, self:drawAll(roleId) | |
770 | 771 | end |
771 | 772 | end |
772 | 773 | ... | ... |
src/models/RoleCross.lua
... | ... | @@ -210,10 +210,22 @@ RoleCross.bind = function (Role) |
210 | 210 | return "成功" |
211 | 211 | end |
212 | 212 | |
213 | - function Role:paySpecialReward(typ, reward) | |
214 | - local tmpReward, _= self:award(reward, {log = {desc = "specialsReward", int1=self:getKey(), int2 = typ}}) | |
215 | - SendPacket(actionCodes.Capsule_payReward, MsgPack.pack({reward=tmpReward})) | |
216 | - return "reward" | |
213 | + function Role:paySpecialReward(roleId, notify) | |
214 | + if notify and next(notify) then | |
215 | + local reward = {} | |
216 | + for key, val in pairs(notify) do | |
217 | + if key == roleId then | |
218 | + for k, v in pairs(val) do | |
219 | + for id, count in pairs(v.award:toNumMap()) do | |
220 | + reward[id] = (reward[id] or 0) + count | |
221 | + end | |
222 | + end | |
223 | + end | |
224 | + | |
225 | + end | |
226 | + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) | |
227 | + role:award(reward, {log = {desc = "CapsuleReward", int1=roleId}}) | |
228 | + end | |
217 | 229 | end |
218 | 230 | |
219 | 231 | end |
... | ... | @@ -376,9 +388,22 @@ function CMD.redPTag(roleId, tag, pms) |
376 | 388 | end |
377 | 389 | end |
378 | 390 | |
379 | -function CMD.paySpecialReward(roleId, typ, reward) | |
380 | - local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) | |
381 | - role:award(reward, {log = {desc = "specialsReward", int1=self:getKey(), int2 = typ}}) | |
391 | +function CMD.paySpecialReward(roleId, notify) | |
392 | + if notify and next(notify) then | |
393 | + local reward = {} | |
394 | + for key, val in pairs(notify) do | |
395 | + if key == roleId then | |
396 | + for k, v in pairs(val) do | |
397 | + for id, count in pairs(v.award:toNumMap()) do | |
398 | + reward[id] = (reward[id] or 0) + count | |
399 | + end | |
400 | + end | |
401 | + end | |
402 | + end | |
403 | + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) | |
404 | + role:award(reward, {log = {desc = "CapsuleReward", int1=roleId}}) | |
405 | + end | |
406 | + | |
382 | 407 | end |
383 | 408 | |
384 | 409 | RoleCross.handle = function(cmd, roleId, ...) | ... | ... |
src/models/RoleLog.lua
src/models/RolePlugin.lua
... | ... | @@ -3170,7 +3170,7 @@ function RolePlugin.bind(Role) |
3170 | 3170 | local roleId = self:getProperty("id") |
3171 | 3171 | return capsule:draw(roleId, full, cares) |
3172 | 3172 | end |
3173 | - return 1 | |
3173 | + return 3 | |
3174 | 3174 | end |
3175 | 3175 | |
3176 | 3176 | function Role:joinCapsule(capsuleId) |
... | ... | @@ -3186,6 +3186,16 @@ function RolePlugin.bind(Role) |
3186 | 3186 | end |
3187 | 3187 | end |
3188 | 3188 | end |
3189 | + | |
3190 | + function Role:goodStock(capsuleId) | |
3191 | + local capsule = self.capsules[capsuleId] or {} | |
3192 | + return capsule:getGoodsAmount(), capsule:getProperty("token") | |
3193 | + end | |
3194 | + | |
3195 | + function Role:getCapsuleData(capsuleId) | |
3196 | + local capsule = self.capsules[capsuleId] or {} | |
3197 | + return capsule:data() | |
3198 | + end | |
3189 | 3199 | end |
3190 | 3200 | |
3191 | 3201 | return RolePlugin |
3192 | 3202 | \ No newline at end of file | ... | ... |
src/services/capsuled.lua
... | ... | @@ -16,22 +16,37 @@ NotifyChangeType = { |
16 | 16 | EXIT = 2, |
17 | 17 | DRAW = 3, |
18 | 18 | SPECIAL = 4, |
19 | - INCENTIVE = 5, | |
19 | +} | |
20 | + | |
21 | +skynet.register_protocol { | |
22 | + name = "role", | |
23 | + id = 101, | |
24 | + pack = skynet.pack, | |
25 | + unpack = skynet.unpack, | |
20 | 26 | } |
21 | 27 | |
22 | 28 | local function rpcRole(roleId, funcName, ...) |
23 | 29 | local fields = ... |
24 | 30 | local agent = datacenter.get("agent", roleId) |
25 | - local roleCross = require("models.RoleCross") | |
26 | - if funcName == "getProperties" then | |
27 | - return roleCross.handle(funcName, roleId, fields) | |
31 | + if agent and agent.serv then | |
32 | + if funcName == "getProperties" then | |
33 | + return true, skynet.call(agent.serv, "role", funcName, fields) | |
34 | + else | |
35 | + return true, skynet.call(agent.serv, "role", funcName, ...) | |
36 | + end | |
28 | 37 | else |
29 | - return roleCross.handle(funcName, roleId, ...) | |
38 | + local roleCross = require("models.RoleCross") | |
39 | + if funcName == "getProperties" then | |
40 | + return false, roleCross.handle(funcName, roleId, fields) | |
41 | + else | |
42 | + return false, roleCross.handle(funcName, roleId, ...) | |
43 | + end | |
30 | 44 | end |
31 | 45 | end |
32 | 46 | |
33 | 47 | function getNameByRoleId(roleId) |
34 | - return rpcRole(roleId, "getProperty", "name") | |
48 | + local status, name = rpcRole(roleId, "getProperty", "name") | |
49 | + return name | |
35 | 50 | |
36 | 51 | end |
37 | 52 | |
... | ... | @@ -47,16 +62,23 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) |
47 | 62 | end |
48 | 63 | end |
49 | 64 | |
50 | -local function getCapsuleId(id, room) | |
51 | - return string.format("%d%d", id, room) | |
65 | +function broadCastSpecial(roleId, capsuleId, broadInfo) | |
66 | + local capsule = capsules[capsuleId] or {} | |
67 | + local register = capsule:getProperty("register") or {} | |
68 | + if next(capsule) then | |
69 | + for id, _ in pairs(register) do | |
70 | + if id ~= roleId then | |
71 | + rpcRole(id, "paySpecialReward", id, broadInfo) | |
72 | + end | |
73 | + end | |
74 | + end | |
52 | 75 | end |
53 | 76 | |
54 | - | |
55 | 77 | local function add(roleId, capsuleId) |
56 | 78 | local capsule = capsules[capsuleId] or {} |
57 | 79 | if next(capsule) then |
58 | 80 | capsule:join(roleId) |
59 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.JOIN, roleId = roleId}) | |
81 | + broadCastCapsule(roleId, capsuleId, {notifyType= NotifyChangeType.JOIN, roleId = roleId}) | |
60 | 82 | return capsule:data(roleId) |
61 | 83 | end |
62 | 84 | print("id 不存在: ".. capsuleId) |
... | ... | @@ -138,36 +160,44 @@ function CMD.exit(roleId, capsuleId) |
138 | 160 | local capsule = capsules[capsuleId] or {} |
139 | 161 | if next(capsule) then |
140 | 162 | capsule:exit(roleId) |
141 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | |
163 | + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) | |
142 | 164 | end |
143 | 165 | else |
144 | 166 | for _, capsule in pairs(capsules) do |
145 | 167 | if next(capsule) then |
146 | 168 | capsule:exit(roleId) |
147 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | |
169 | + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) | |
148 | 170 | end |
149 | 171 | end |
150 | 172 | end |
151 | 173 | end |
152 | 174 | |
153 | -function CMD.draw_capsule(roleId, capsuleId, full, cares) | |
175 | +function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares) | |
154 | 176 | local capsule = capsules[capsuleId] or {} |
155 | 177 | if next(capsule) then |
156 | - local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, cares) | |
157 | - --if ret > 4 then | |
158 | - -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) | |
159 | - --end | |
178 | + local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, drawsNum, cares) | |
179 | + if ret > 5 then | |
180 | + --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify}) | |
181 | + broadCastSpecial(roleId, capsuleId, notify) | |
182 | + end | |
160 | 183 | return ret, reward, rewardByGoods, capsule:data(roleId) |
161 | 184 | end |
162 | - return 1 | |
185 | + return 2 | |
163 | 186 | end |
164 | 187 | |
165 | 188 | function CMD.register(roleId, capsuleId) |
166 | 189 | local capsule = capsules[capsuleId] or {} |
167 | - if next(capsule) then | |
168 | - return capsule:register(roleId) | |
169 | - end | |
170 | - return nil | |
190 | + return capsule:register(roleId) | |
191 | +end | |
192 | + | |
193 | +function CMD.goods_stock(capsuleId) | |
194 | + local capsule = capsules[capsuleId] or {} | |
195 | + return capsule:getGoodsAmount(), capsule:getProperty("token") | |
196 | +end | |
197 | + | |
198 | +function CMD.capsule_data(capsuleId) | |
199 | + local capsule = capsules[capsuleId] or {} | |
200 | + return capsule:data() | |
171 | 201 | end |
172 | 202 | |
173 | 203 | skynet.start(function() | ... | ... |