Commit 0eb317fbb1fbead847c33488e037cafb582f1af2

Authored by zhangqijia
1 parent cd2a7a67

fix: 一番赏奖励抽奖的bug与功能完善

1. 增加获取扭蛋机信息的协议
2. 特殊赏奖励发放
3. 增加抽扭蛋机消耗 --暂时屏蔽
4. 激励奖暂时屏蔽
src/ProtocolCode.lua
@@ -279,10 +279,11 @@ actionCodes = { @@ -279,10 +279,11 @@ actionCodes = {
279 Capsule_joinRpc = 851, --扭蛋机详情 279 Capsule_joinRpc = 851, --扭蛋机详情
280 Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中 280 Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中
281 Capsule_drawRpc = 854, --抽扭蛋机 281 Capsule_drawRpc = 854, --抽扭蛋机
282 - Capsule_switchRoomRpc = 855, --切换扭蛋机房间 282 + --Capsule_switchRoomRpc = 855, --切换扭蛋机房间
283 Capsule_notifyChange = 856, -- 通知信息变动 283 Capsule_notifyChange = 856, -- 通知信息变动
284 Capsule_payReward = 857, -- 特殊赏 奖励通知 284 Capsule_payReward = 857, -- 特殊赏 奖励通知
285 Capsule_exitRpc = 858, -- 退出 285 Capsule_exitRpc = 858, -- 退出
  286 + Capsule_getDataRpc = 859, --获取扭蛋机信息
286 } 287 }
287 288
288 rpcResponseBegin = 10000 289 rpcResponseBegin = 10000
src/actions/CapsuleAction.lua
@@ -93,40 +93,83 @@ function _M.drawRpc(agent, data) @@ -93,40 +93,83 @@ function _M.drawRpc(agent, data)
93 local roleId = role:getProperty("id") 93 local roleId = role:getProperty("id")
94 local capsuleId = msg.capsule_id 94 local capsuleId = msg.capsule_id
95 local typ = msg.typ --0=独享,1= 公开 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 local cares = msg.cares 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 if typ == 1 then 129 if typ == 1 then
101 ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) 130 ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares)
102 else 131 else
103 ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) 132 ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares)
104 end 133 end
105 - if ret < 4 then 134 + if ret < 5 then
106 return ret 135 return ret
107 end 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 end 144 end
112 145
  146 + -- rewardByGoods是抽到的扭蛋信息,reward是抽扭蛋后获得的所有奖励信息。
113 if rewardByGoods and next(rewardByGoods) then 147 if rewardByGoods and next(rewardByGoods) then
114 reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) 148 reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}})
115 SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) 149 SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule}))
116 else 150 else
117 - return 5 151 + return ret
118 end 152 end
119 return true 153 return true
120 end 154 end
121 155
122 -function _M.switchRoomRpc(agent, data) 156 +function _M.getData(agent, data)
123 local role = agent.role 157 local role = agent.role
124 local msg = MsgPack.unpack(data) 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 return true 171 return true
  172 +
130 end 173 end
131 174
132 return _M 175 return _M
133 \ No newline at end of file 176 \ No newline at end of file
src/models/Capsule.lua
@@ -36,6 +36,7 @@ Capsule.schema = { @@ -36,6 +36,7 @@ Capsule.schema = {
36 name = {"string"}, 36 name = {"string"},
37 typ = {"number", 1}, -- 1=共享,2=独享 37 typ = {"number", 1}, -- 1=共享,2=独享
38 coin = {"number", 0}, --货币代号 38 coin = {"number", 0}, --货币代号
  39 + token = {"table", {}}, --抽一次,货币=消耗
39 register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 40 register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名
40 record = {"table", {}}, --抽取记录 列表 41 record = {"table", {}}, --抽取记录 列表
41 recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record} 42 recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record}
@@ -56,6 +57,7 @@ function Capsule:getResetFields() @@ -56,6 +57,7 @@ function Capsule:getResetFields()
56 room = self:getProperty("room"), 57 room = self:getProperty("room"),
57 typ = self:getProperty("typ"), 58 typ = self:getProperty("typ"),
58 coin = 0, 59 coin = 0,
  60 + token = {},
59 register = {}, 61 register = {},
60 record = {}, 62 record = {},
61 recordByRole = {}, 63 recordByRole = {},
@@ -132,7 +134,7 @@ function Capsule:init() @@ -132,7 +134,7 @@ function Capsule:init()
132 end 134 end
133 --货币类型 135 --货币类型
134 local coin = ichibankuji["token"]:toArray(true, "=") 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 end 138 end
137 139
138 function Capsule:isShow() 140 function Capsule:isShow()
@@ -233,11 +235,11 @@ function Capsule:confirmed(cares) @@ -233,11 +235,11 @@ function Capsule:confirmed(cares)
233 for k, v in pairs(cares) do 235 for k, v in pairs(cares) do
234 if v.typ == 1 then 236 if v.typ == 1 then
235 if goods[k] and goods[k].amount ~= v.count then 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 end 239 end
238 else 240 else
239 if specials[k] and specials[k].amount ~= v.count then 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 end 243 end
242 end 244 end
243 end 245 end
@@ -282,8 +284,8 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) @@ -282,8 +284,8 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now)
282 284
283 if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end 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 local name = getNameByRoleId(roleId) 289 local name = getNameByRoleId(roleId)
288 tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} 290 tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now}
289 else 291 else
@@ -372,7 +374,7 @@ function Capsule:getCore(record) @@ -372,7 +374,7 @@ function Capsule:getCore(record)
372 if not roleRecord[v.roleId]then 374 if not roleRecord[v.roleId]then
373 roleRecord[v.roleId] = {amount = v.amount } 375 roleRecord[v.roleId] = {amount = v.amount }
374 else 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 end 378 end
377 end 379 end
378 380
@@ -416,7 +418,7 @@ function Capsule:getLast(record) @@ -416,7 +418,7 @@ function Capsule:getLast(record)
416 if not roleRecord[v.roleId]then 418 if not roleRecord[v.roleId]then
417 roleRecord[v.roleId] = {amount = v.amount } 419 roleRecord[v.roleId] = {amount = v.amount }
418 else 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 end 422 end
421 end 423 end
422 424
@@ -443,7 +445,7 @@ function Capsule:getJoker(record) @@ -443,7 +445,7 @@ function Capsule:getJoker(record)
443 if not roleRecord[v.roleId]then 445 if not roleRecord[v.roleId]then
444 roleRecord[v.roleId] = {amount = v.amount } 446 roleRecord[v.roleId] = {amount = v.amount }
445 else 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 end 449 end
448 end 450 end
449 451
@@ -470,7 +472,7 @@ function Capsule:getKing(record) @@ -470,7 +472,7 @@ function Capsule:getKing(record)
470 if not roleRecord[v.roleId]then 472 if not roleRecord[v.roleId]then
471 roleRecord[v.roleId] = {amount = v.amount } 473 roleRecord[v.roleId] = {amount = v.amount }
472 else 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 end 476 end
475 end 477 end
476 478
@@ -522,8 +524,7 @@ function Capsule:checkSpecialReward( now) @@ -522,8 +524,7 @@ function Capsule:checkSpecialReward( now)
522 local kingReward = self:getKing(record) 524 local kingReward = self:getKing(record)
523 rewardToNtyFunc(notify, kingReward) 525 rewardToNtyFunc(notify, kingReward)
524 526
525 - --广播出去TODO  
526 - --rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) 527 +
527 return notify 528 return notify
528 end 529 end
529 530
@@ -562,7 +563,7 @@ function Capsule:checkIncentive(roleId, name, now) @@ -562,7 +563,7 @@ function Capsule:checkIncentive(roleId, name, now)
562 563
563 local count = math.floor(amount / incentive["amount"]["np"]) 564 local count = math.floor(amount / incentive["amount"]["np"])
564 local tmpCount = count * incentive["amount"]["np"] 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 --填充v.calculated 字段,标识已经用于每x抽的计算中。 568 --填充v.calculated 字段,标识已经用于每x抽的计算中。
568 for _, v in pairs(roleRecord) do 569 for _, v in pairs(roleRecord) do
@@ -594,7 +595,8 @@ function Capsule:checkIncentive(roleId, name, now) @@ -594,7 +595,8 @@ function Capsule:checkIncentive(roleId, name, now)
594 incentiveRecord[roleId] = incentiveByRole 595 incentiveRecord[roleId] = incentiveByRole
595 self:setProperty("incentiveRecord", incentiveRecord) 596 self:setProperty("incentiveRecord", incentiveRecord)
596 597
597 - return notify 598 + --TODO 先屏蔽
  599 + return {}
598 end 600 end
599 601
600 function Capsule:drawByCount(roleId, count) 602 function Capsule:drawByCount(roleId, count)
@@ -618,32 +620,32 @@ function Capsule:drawByCount(roleId, count) @@ -618,32 +620,32 @@ function Capsule:drawByCount(roleId, count)
618 local name = getNameByRoleId(roleId) 620 local name = getNameByRoleId(roleId)
619 while (goods and next(goods) and count > 0) do 621 while (goods and next(goods) and count > 0) do
620 local good_id = math.randWeight(goods, "weight") 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 end 645 end
  646 +
  647 + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight
  648 + count = count - 1
647 end 649 end
648 650
649 end 651 end
@@ -690,8 +692,8 @@ function Capsule:drawAll(roleId) @@ -690,8 +692,8 @@ function Capsule:drawAll(roleId)
690 for good_id, good in pairs(goods) do 692 for good_id, good in pairs(goods) do
691 if good.amount > 0 then 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 if not notify[roleId][good_id] then 699 if not notify[roleId][good_id] then
@@ -702,7 +704,7 @@ function Capsule:drawAll(roleId) @@ -702,7 +704,7 @@ function Capsule:drawAll(roleId)
702 704
703 --记录角色的抽奖记录 705 --记录角色的抽奖记录
704 if not roleRecord[good_id] then 706 if not roleRecord[good_id] then
705 - roleRecord[good_id] = notify 707 + roleRecord[good_id] = tmpNotify
706 else 708 else
707 roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount 709 roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount
708 end 710 end
@@ -749,24 +751,23 @@ end @@ -749,24 +751,23 @@ end
749 ]]-- 751 ]]--
750 752
751 function Capsule:draw(roleId, full, cares) 753 function Capsule:draw(roleId, full, cares)
752 - if self:getGoodsAmount() == 0 then return 2 end  
753 if self:getProperty("typ") == 1 then 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 if cares then 759 if cares then
759 local change = self:confirmed(cares) 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 end 762 end
762 end 763 end
763 764
764 if full == 0 then 765 if full == 0 then
765 - return 5, self:drawByCount(roleId, 1) 766 + return 6, self:drawByCount(roleId, 1)
766 elseif full == 1 then 767 elseif full == 1 then
767 - return 5, self:drawByCount(roleId, 10) 768 + return 6, self:drawByCount(roleId, 10)
768 elseif full == 2 then 769 elseif full == 2 then
769 - return 5, self:drawAll(roleId) 770 + return 6, self:drawAll(roleId)
770 end 771 end
771 end 772 end
772 773
src/models/RoleCross.lua
@@ -210,10 +210,22 @@ RoleCross.bind = function (Role) @@ -210,10 +210,22 @@ RoleCross.bind = function (Role)
210 return "成功" 210 return "成功"
211 end 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 end 229 end
218 230
219 end 231 end
@@ -376,9 +388,22 @@ function CMD.redPTag(roleId, tag, pms) @@ -376,9 +388,22 @@ function CMD.redPTag(roleId, tag, pms)
376 end 388 end
377 end 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 end 407 end
383 408
384 RoleCross.handle = function(cmd, roleId, ...) 409 RoleCross.handle = function(cmd, roleId, ...)
src/models/RoleLog.lua
@@ -161,7 +161,7 @@ local ItemReason = { @@ -161,7 +161,7 @@ local ItemReason = {
161 returner = 1410, -- 回归者奖励 161 returner = 1410, -- 回归者奖励
162 162
163 CapsuleReward = 1411, --扭蛋机奖励 163 CapsuleReward = 1411, --扭蛋机奖励
164 - specialsReward = 1412, --特殊赏 164 + CapsuleCoinCost = 1413, --抽扭蛋机消耗
165 } 165 }
166 166
167 167
src/models/RolePlugin.lua
@@ -3170,7 +3170,7 @@ function RolePlugin.bind(Role) @@ -3170,7 +3170,7 @@ function RolePlugin.bind(Role)
3170 local roleId = self:getProperty("id") 3170 local roleId = self:getProperty("id")
3171 return capsule:draw(roleId, full, cares) 3171 return capsule:draw(roleId, full, cares)
3172 end 3172 end
3173 - return 1 3173 + return 3
3174 end 3174 end
3175 3175
3176 function Role:joinCapsule(capsuleId) 3176 function Role:joinCapsule(capsuleId)
@@ -3186,6 +3186,16 @@ function RolePlugin.bind(Role) @@ -3186,6 +3186,16 @@ function RolePlugin.bind(Role)
3186 end 3186 end
3187 end 3187 end
3188 end 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 end 3199 end
3190 3200
3191 return RolePlugin 3201 return RolePlugin
3192 \ No newline at end of file 3202 \ No newline at end of file
src/services/capsuled.lua
@@ -16,22 +16,37 @@ NotifyChangeType = { @@ -16,22 +16,37 @@ NotifyChangeType = {
16 EXIT = 2, 16 EXIT = 2,
17 DRAW = 3, 17 DRAW = 3,
18 SPECIAL = 4, 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 local function rpcRole(roleId, funcName, ...) 28 local function rpcRole(roleId, funcName, ...)
23 local fields = ... 29 local fields = ...
24 local agent = datacenter.get("agent", roleId) 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 else 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 end 44 end
31 end 45 end
32 46
33 function getNameByRoleId(roleId) 47 function getNameByRoleId(roleId)
34 - return rpcRole(roleId, "getProperty", "name") 48 + local status, name = rpcRole(roleId, "getProperty", "name")
  49 + return name
35 50
36 end 51 end
37 52
@@ -47,16 +62,23 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) @@ -47,16 +62,23 @@ function broadCastCapsule(roleId, capsuleId, broadInfo)
47 end 62 end
48 end 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 end 75 end
53 76
54 -  
55 local function add(roleId, capsuleId) 77 local function add(roleId, capsuleId)
56 local capsule = capsules[capsuleId] or {} 78 local capsule = capsules[capsuleId] or {}
57 if next(capsule) then 79 if next(capsule) then
58 capsule:join(roleId) 80 capsule:join(roleId)
59 - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.JOIN, roleId = roleId}) 81 + broadCastCapsule(roleId, capsuleId, {notifyType= NotifyChangeType.JOIN, roleId = roleId})
60 return capsule:data(roleId) 82 return capsule:data(roleId)
61 end 83 end
62 print("id 不存在: ".. capsuleId) 84 print("id 不存在: ".. capsuleId)
@@ -138,36 +160,44 @@ function CMD.exit(roleId, capsuleId) @@ -138,36 +160,44 @@ function CMD.exit(roleId, capsuleId)
138 local capsule = capsules[capsuleId] or {} 160 local capsule = capsules[capsuleId] or {}
139 if next(capsule) then 161 if next(capsule) then
140 capsule:exit(roleId) 162 capsule:exit(roleId)
141 - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) 163 + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId})
142 end 164 end
143 else 165 else
144 for _, capsule in pairs(capsules) do 166 for _, capsule in pairs(capsules) do
145 if next(capsule) then 167 if next(capsule) then
146 capsule:exit(roleId) 168 capsule:exit(roleId)
147 - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) 169 + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId})
148 end 170 end
149 end 171 end
150 end 172 end
151 end 173 end
152 174
153 -function CMD.draw_capsule(roleId, capsuleId, full, cares) 175 +function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares)
154 local capsule = capsules[capsuleId] or {} 176 local capsule = capsules[capsuleId] or {}
155 if next(capsule) then 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 return ret, reward, rewardByGoods, capsule:data(roleId) 183 return ret, reward, rewardByGoods, capsule:data(roleId)
161 end 184 end
162 - return 1 185 + return 2
163 end 186 end
164 187
165 function CMD.register(roleId, capsuleId) 188 function CMD.register(roleId, capsuleId)
166 local capsule = capsules[capsuleId] or {} 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 end 201 end
172 202
173 skynet.start(function() 203 skynet.start(function()