Commit cd2a7a672cb5e4645827f08bff0c03fb3511ae4d

Authored by zhangqijia
1 parent d10a9a36

fix: 一番赏奖励中加入得奖者的名字 字段 name=name

src/actions/CapsuleAction.lua
@@ -96,11 +96,11 @@ function _M.drawRpc(agent, data) @@ -96,11 +96,11 @@ function _M.drawRpc(agent, data)
96 local full = msg.full -- 0=单次,1=十连抽 2=全收 96 local full = msg.full -- 0=单次,1=十连抽 2=全收
97 local cares = msg.cares 97 local cares = msg.cares
98 98
99 - local ret, reward, change, capsule 99 + local ret, reward, change, rewardByGoods, capsule
100 if typ == 1 then 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 else 102 else
103 - ret, reward, capsule= role:drawCapsule(capsuleId, full, cares) 103 + ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares)
104 end 104 end
105 if ret < 4 then 105 if ret < 4 then
106 return ret 106 return ret
@@ -110,9 +110,12 @@ function _M.drawRpc(agent, data) @@ -110,9 +110,12 @@ function _M.drawRpc(agent, data)
110 SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) 110 SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward))
111 end 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 return true 119 return true
117 end 120 end
118 121
src/models/Capsule.lua
@@ -27,14 +27,7 @@ CapsuleType = { @@ -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 Capsule.schema = { 33 Capsule.schema = {
@@ -57,51 +50,6 @@ Capsule.schema = { @@ -57,51 +50,6 @@ Capsule.schema = {
57 drawEndTime = {"number", 0}, --抽完时间 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 function Capsule:getResetFields() 53 function Capsule:getResetFields()
106 return { 54 return {
107 id = self:getProperty("id"), 55 id = self:getProperty("id"),
@@ -115,8 +63,11 @@ function Capsule:getResetFields() @@ -115,8 +63,11 @@ function Capsule:getResetFields()
115 goods = {}, 63 goods = {},
116 specials = {}, 64 specials = {},
117 incentive = {}, 65 incentive = {},
  66 + incentiveRecord = {},
118 specialsRecord= {}, 67 specialsRecord= {},
119 resetTimes = 0, 68 resetTimes = 0,
  69 + hideTime = 0,
  70 + drawEndTime = 0,
120 } 71 }
121 end 72 end
122 73
@@ -184,6 +135,51 @@ function Capsule:init() @@ -184,6 +135,51 @@ function Capsule:init()
184 self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) 135 self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive})
185 end 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 function Capsule:getOnlineCount() 183 function Capsule:getOnlineCount()
188 local register = self:getProperty("register") or {} 184 local register = self:getProperty("register") or {}
189 local reg, onlookers = 0, 0 185 local reg, onlookers = 0, 0
@@ -280,6 +276,7 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) @@ -280,6 +276,7 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now)
280 while(count > 0 and next(rewardRecord)) do 276 while(count > 0 and next(rewardRecord)) do
281 local roleId = math.randWeight(rewardRecord, "amount") 277 local roleId = math.randWeight(rewardRecord, "amount")
282 if roleId then 278 if roleId then
  279 +
283 local tmp = rewardRecord[roleId] 280 local tmp = rewardRecord[roleId]
284 tmp["amount"] = tmp["amount"] - 1 281 tmp["amount"] = tmp["amount"] - 1
285 282
@@ -287,10 +284,12 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) @@ -287,10 +284,12 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now)
287 284
288 tmp = rewardByRole[roleId] 285 tmp = rewardByRole[roleId]
289 if not tmp then 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 else 289 else
292 if not tmp[spKey] then 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 else 293 else
295 tmp[spKey].amount = tmp[spKey].amount + 1 294 tmp[spKey].amount = tmp[spKey].amount + 1
296 end 295 end
@@ -528,7 +527,7 @@ function Capsule:checkSpecialReward( now) @@ -528,7 +527,7 @@ function Capsule:checkSpecialReward( now)
528 return notify 527 return notify
529 end 528 end
530 529
531 -function Capsule:checkIncentive(roleId, now) 530 +function Capsule:checkIncentive(roleId, name, now)
532 local goods = self:getProperty("goods") or {} 531 local goods = self:getProperty("goods") or {}
533 local recordByRole = self:getProperty("recordByRole") or {} 532 local recordByRole = self:getProperty("recordByRole") or {}
534 local roleRecord = recordByRole[roleId] or {} 533 local roleRecord = recordByRole[roleId] or {}
@@ -548,7 +547,7 @@ function Capsule:checkIncentive(roleId, now) @@ -548,7 +547,7 @@ function Capsule:checkIncentive(roleId, now)
548 end 547 end
549 end 548 end
550 if last then 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 end 551 end
553 end 552 end
554 553
@@ -563,7 +562,7 @@ function Capsule:checkIncentive(roleId, now) @@ -563,7 +562,7 @@ function Capsule:checkIncentive(roleId, now)
563 562
564 local count = math.floor(amount / incentive["amount"]["np"]) 563 local count = math.floor(amount / incentive["amount"]["np"])
565 local tmpCount = count * incentive["amount"]["np"] 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 --填充v.calculated 字段,标识已经用于每x抽的计算中。 567 --填充v.calculated 字段,标识已经用于每x抽的计算中。
569 for _, v in pairs(roleRecord) do 568 for _, v in pairs(roleRecord) do
@@ -587,7 +586,7 @@ function Capsule:checkIncentive(roleId, now) @@ -587,7 +586,7 @@ function Capsule:checkIncentive(roleId, now)
587 if incentive["probabilities"] then 586 if incentive["probabilities"] then
588 local probabilities = math.randomInt(1, 100) 587 local probabilities = math.randomInt(1, 100)
589 if probabilities <= incentive["probabilities"]["np"] then 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 end 591 end
593 end 592 end
@@ -616,6 +615,7 @@ function Capsule:drawByCount(roleId, count) @@ -616,6 +615,7 @@ function Capsule:drawByCount(roleId, count)
616 local notify= {} 615 local notify= {}
617 notify[roleId] = {} 616 notify[roleId] = {}
618 617
  618 + local name = getNameByRoleId(roleId)
619 while (goods and next(goods) and count > 0) do 619 while (goods and next(goods) and count > 0) do
620 local good_id = math.randWeight(goods, "weight") 620 local good_id = math.randWeight(goods, "weight")
621 if good_id then 621 if good_id then
@@ -624,7 +624,7 @@ function Capsule:drawByCount(roleId, count) @@ -624,7 +624,7 @@ function Capsule:drawByCount(roleId, count)
624 good.amount = good.amount - 1 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 table.insert(record, tmpNotify) 628 table.insert(record, tmpNotify)
629 629
630 --作为奖励记录+通知 630 --作为奖励记录+通知
@@ -650,7 +650,7 @@ function Capsule:drawByCount(roleId, count) @@ -650,7 +650,7 @@ function Capsule:drawByCount(roleId, count)
650 recordByRole[roleId] = roleRecord 650 recordByRole[roleId] = roleRecord
651 self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) 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 for k, v in pairs(tmpNotify) do 654 for k, v in pairs(tmpNotify) do
655 if not notify[roleId][k] then 655 if not notify[roleId][k] then
656 notify[roleId][k] = v 656 notify[roleId][k] = v
@@ -662,17 +662,19 @@ function Capsule:drawByCount(roleId, count) @@ -662,17 +662,19 @@ function Capsule:drawByCount(roleId, count)
662 local speciNotify = self:checkSpecialReward(now) 662 local speciNotify = self:checkSpecialReward(now)
663 rewardToNtyFunc(notify, speciNotify) 663 rewardToNtyFunc(notify, speciNotify)
664 664
665 - local reward = {} 665 + local reward, rewardByGoods = {}, {}
666 for key, val in pairs(notify) do 666 for key, val in pairs(notify) do
667 if key == roleId then 667 if key == roleId then
668 - for _, v in pairs(val) do 668 + for k, v in pairs(val) do
669 for id, count in pairs(v.award:toNumMap()) do 669 for id, count in pairs(v.award:toNumMap()) do
670 reward[id] = (reward[id] or 0) + count 670 reward[id] = (reward[id] or 0) + count
671 end 671 end
  672 + rewardByGoods[k] = v
672 end 673 end
673 end 674 end
  675 +
674 end 676 end
675 - return reward, notify 677 + return reward, rewardByGoods, notify
676 end 678 end
677 679
678 function Capsule:drawAll(roleId) 680 function Capsule:drawAll(roleId)
@@ -682,12 +684,13 @@ function Capsule:drawAll(roleId) @@ -682,12 +684,13 @@ function Capsule:drawAll(roleId)
682 local roleRecord = recordByRole[roleId] or {} 684 local roleRecord = recordByRole[roleId] or {}
683 local now = skynet.timex() 685 local now = skynet.timex()
684 686
  687 + local name = getNameByRoleId(roleId)
685 local notify = {} 688 local notify = {}
686 notify[roleId] = {} 689 notify[roleId] = {}
687 for good_id, good in pairs(goods) do 690 for good_id, good in pairs(goods) do
688 if good.amount > 0 then 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 table.insert(record, notify) 694 table.insert(record, notify)
692 695
693 --作为奖励记录+通知 696 --作为奖励记录+通知
@@ -711,7 +714,7 @@ function Capsule:drawAll(roleId) @@ -711,7 +714,7 @@ function Capsule:drawAll(roleId)
711 recordByRole[roleId] = roleRecord 714 recordByRole[roleId] = roleRecord
712 self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) 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 for k, v in pairs(tmpNotify) do 718 for k, v in pairs(tmpNotify) do
716 if not notify[roleId][k] then 719 if not notify[roleId][k] then
717 notify[roleId][k] = v 720 notify[roleId][k] = v
@@ -723,17 +726,19 @@ function Capsule:drawAll(roleId) @@ -723,17 +726,19 @@ function Capsule:drawAll(roleId)
723 local speciNotify = self:checkSpecialReward(now) 726 local speciNotify = self:checkSpecialReward(now)
724 rewardToNtyFunc(notify, speciNotify) 727 rewardToNtyFunc(notify, speciNotify)
725 728
726 - local reward = {} 729 + local reward, rewardByGoods = {}, {}
727 for key, val in pairs(notify) do 730 for key, val in pairs(notify) do
728 if key == roleId then 731 if key == roleId then
729 - for _, v in pairs(val) do 732 + for k, v in pairs(val) do
730 for id, count in pairs(v.award:toNumMap()) do 733 for id, count in pairs(v.award:toNumMap()) do
731 reward[id] = (reward[id] or 0) + count 734 reward[id] = (reward[id] or 0) + count
732 end 735 end
  736 + rewardByGoods[k] = v
733 end 737 end
734 end 738 end
  739 +
735 end 740 end
736 - return reward, notify 741 + return reward, rewardByGoods, notify
737 end 742 end
738 743
739 --@param 744 --@param
@@ -776,7 +781,6 @@ function Capsule:data(roleId) @@ -776,7 +781,6 @@ function Capsule:data(roleId)
776 onlineCount = self:getOnlineCount(), 781 onlineCount = self:getOnlineCount(),
777 playerStatus = self:getRegisterByRoleId(roleId), 782 playerStatus = self:getRegisterByRoleId(roleId),
778 record = self:getProperty("record"), 783 record = self:getProperty("record"),
779 - --recordByRole = self:getProperty("recordByRole"),  
780 rank = self:getProperty("rank"), 784 rank = self:getProperty("rank"),
781 goods = self:getProperty("goods"), 785 goods = self:getProperty("goods"),
782 specials = self:getProperty("specials"), 786 specials = self:getProperty("specials"),
src/models/RolePlugin.lua
@@ -3170,6 +3170,7 @@ function RolePlugin.bind(Role) @@ -3170,6 +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 end 3174 end
3174 3175
3175 function Role:joinCapsule(capsuleId) 3176 function Role:joinCapsule(capsuleId)
src/services/capsuled.lua
@@ -19,25 +19,22 @@ NotifyChangeType = { @@ -19,25 +19,22 @@ NotifyChangeType = {
19 INCENTIVE = 5, 19 INCENTIVE = 5,
20 } 20 }
21 21
22 -function rpcRole(roleId, funcName, ...) 22 +local function rpcRole(roleId, funcName, ...)
23 local fields = ... 23 local fields = ...
24 local agent = datacenter.get("agent", roleId) 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 else 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 end 30 end
39 end 31 end
40 32
  33 +function getNameByRoleId(roleId)
  34 + return rpcRole(roleId, "getProperty", "name")
  35 +
  36 +end
  37 +
41 function broadCastCapsule(roleId, capsuleId, broadInfo) 38 function broadCastCapsule(roleId, capsuleId, broadInfo)
42 local capsule = capsules[capsuleId] or {} 39 local capsule = capsules[capsuleId] or {}
43 local register = capsule:getProperty("register") or {} 40 local register = capsule:getProperty("register") or {}
@@ -156,13 +153,13 @@ end @@ -156,13 +153,13 @@ end
156 function CMD.draw_capsule(roleId, capsuleId, full, cares) 153 function CMD.draw_capsule(roleId, capsuleId, full, cares)
157 local capsule = capsules[capsuleId] or {} 154 local capsule = capsules[capsuleId] or {}
158 if next(capsule) then 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 --if ret > 4 then 157 --if ret > 4 then
161 -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) 158 -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify})
162 --end 159 --end
163 - return ret, reward, capsule:data(roleId) 160 + return ret, reward, rewardByGoods, capsule:data(roleId)
164 end 161 end
165 - return nil 162 + return 1
166 end 163 end
167 164
168 function CMD.register(roleId, capsuleId) 165 function CMD.register(roleId, capsuleId)
@@ -180,4 +177,5 @@ skynet.start(function() @@ -180,4 +177,5 @@ skynet.start(function()
180 end) 177 end)
181 178
182 skynet.register("capsuled") 179 skynet.register("capsuled")
  180 + globalCsv = csvdb["GlobalDefineCsv"]
183 end) 181 end)
184 \ No newline at end of file 182 \ No newline at end of file