Commit 01ff9b4b57a066d7a2d6b145a12ad5a616a6ebb0
1 parent
7f21f75b
fix: 一番赏 优化; 抽奖记录分页;抽扭蛋机,返回值更新
1. 每次获取最新的20条record,然后再通过指令增量获取抽奖记录 2. 抽扭蛋机,返回值更新,{usual={},special={},incentive={},capsule={}}
Showing
5 changed files
with
151 additions
and
82 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/CapsuleAction.lua
... | ... | @@ -96,7 +96,7 @@ function _M.drawRpc(agent, data) |
96 | 96 | local full = msg.full or 0-- 0=单次,1=十连抽 2=全收 |
97 | 97 | local cares = msg.cares |
98 | 98 | |
99 | - local ret, token, reward, change, rewardByGoods, capsule | |
99 | + local ret, token, change, drawReward, capsule | |
100 | 100 | |
101 | 101 | --检查库存 |
102 | 102 | if typ == 1 then |
... | ... | @@ -127,26 +127,24 @@ function _M.drawRpc(agent, data) |
127 | 127 | |
128 | 128 | --开始抽奖 |
129 | 129 | if typ == 1 then |
130 | - ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | |
130 | + ret, drawReward, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | |
131 | 131 | else |
132 | - ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) | |
132 | + ret, drawReward, capsule = role:drawCapsule(capsuleId, full, cares) | |
133 | 133 | end |
134 | 134 | if ret < 5 then |
135 | 135 | return ret |
136 | 136 | end |
137 | 137 | |
138 | - --dump(rewardByGoods) | |
139 | - --dump(capsule) | |
140 | - | |
141 | 138 | if ret == 5 then |
142 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule})) | |
139 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = drawReward, capsule = capsule})) | |
143 | 140 | return true |
144 | 141 | end |
145 | 142 | |
146 | - -- rewardByGoods是抽到的扭蛋信息,reward是抽扭蛋后获得的所有奖励信息。 | |
147 | - if rewardByGoods and next(rewardByGoods) then | |
148 | - reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | |
149 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) | |
143 | + if drawReward["reward"] and next(drawReward["reward"]) then | |
144 | + _, change = role:award(drawReward["reward"], {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | |
145 | + drawReward["capsule"] = capsule | |
146 | + dump(drawReward) | |
147 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(drawReward)) | |
150 | 148 | else |
151 | 149 | return ret |
152 | 150 | end |
... | ... | @@ -195,4 +193,24 @@ function _M.convertCapsuleRpc(agent, data) |
195 | 193 | return true |
196 | 194 | end |
197 | 195 | |
196 | +function _M.pageRecordRpc(agent, data) | |
197 | + local role = agent.role | |
198 | + local msg = MsgPack.unpack(data) | |
199 | + local idx = msg.idx | |
200 | + local up = msg.up or 0 | |
201 | + local capsuleId = msg.capsule_id | |
202 | + local typ = msg.typ --0=独享,1= 公开 | |
203 | + | |
204 | + local record | |
205 | + if typ == 1 then | |
206 | + record = skynet.call(agent.capsule_serv, "lua", "page_record", capsuleId, up, idx) | |
207 | + else | |
208 | + record = role:pageRecord(capsuleId, up, idx) | |
209 | + end | |
210 | + if not record then return 1 end | |
211 | + | |
212 | + SendPacket(actionCodes.Capsule_pageRecordRpc, MsgPack.pack({record = record})) | |
213 | + return true | |
214 | +end | |
215 | + | |
198 | 216 | return _M |
199 | 217 | \ No newline at end of file | ... | ... |
src/models/Capsule.lua
... | ... | @@ -673,6 +673,30 @@ function Capsule:checkIncentive(roleId, name, now) |
673 | 673 | return {} |
674 | 674 | end |
675 | 675 | |
676 | +local rewardCollect = function(reward, goods) | |
677 | + for _, v in pairs(goods) do | |
678 | + for id, count in pairs(v.award:toNumMap()) do | |
679 | + reward[id] = (reward[id] or 0) + count | |
680 | + end | |
681 | + end | |
682 | +end | |
683 | + | |
684 | +local rewardCollectByRoleId = function(roleId, reward, goods) | |
685 | + local tmp = {} | |
686 | + for key, val in pairs(goods) do | |
687 | + if roleId == key then | |
688 | + for k, v in pairs(val) do | |
689 | + for id, count in pairs(v.award:toNumMap()) do | |
690 | + reward[id] = (reward[id] or 0) + count | |
691 | + end | |
692 | + | |
693 | + end | |
694 | + tmp = val | |
695 | + end | |
696 | + end | |
697 | + return tmp | |
698 | +end | |
699 | + | |
676 | 700 | function Capsule:drawByCount(roleId, count) |
677 | 701 | if count <= 0 then return nil end |
678 | 702 | |
... | ... | @@ -689,9 +713,8 @@ function Capsule:drawByCount(roleId, count) |
689 | 713 | local goods_id = ichibankuji["goods_id"] |
690 | 714 | local now = skynet.timex() |
691 | 715 | |
692 | - --奖励, 通知信息 | |
693 | - local notify= {} | |
694 | - notify[roleId] = {} | |
716 | + --奖励,普通奖品信息 | |
717 | + local goodsByUsual= {} | |
695 | 718 | |
696 | 719 | local name = getNameByRoleId(roleId) |
697 | 720 | while (goods and next(goods) and count > 0) do |
... | ... | @@ -710,10 +733,10 @@ function Capsule:drawByCount(roleId, count) |
710 | 733 | table.insert(record, tmpNotify) |
711 | 734 | |
712 | 735 | --作为奖励记录+通知 |
713 | - if not notify[roleId][good_id] then | |
714 | - notify[roleId][good_id] = tmpNotify | |
736 | + if not goodsByUsual[good_id] then | |
737 | + goodsByUsual[good_id] = tmpNotify | |
715 | 738 | else |
716 | - notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 | |
739 | + goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + 1 | |
717 | 740 | end |
718 | 741 | |
719 | 742 | --记录角色的抽奖记录 计算激励奖需要用到 |
... | ... | @@ -728,35 +751,28 @@ function Capsule:drawByCount(roleId, count) |
728 | 751 | end |
729 | 752 | |
730 | 753 | end |
754 | + | |
755 | + --奖励池重新赋值 | |
731 | 756 | rank[roleId] = rankRole |
732 | 757 | recordByRole[roleId] = roleRecord |
733 | 758 | self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) |
734 | 759 | |
735 | - local tmpNotify = self:checkIncentive(roleId, name, now) | |
736 | - for k, v in pairs(tmpNotify) do | |
737 | - if not notify[roleId][k] then | |
738 | - notify[roleId][k] = v | |
739 | - else | |
740 | - notify[roleId][k].amount = notify[roleId][k].amount + v.amount | |
741 | - end | |
742 | - end | |
760 | + --奖励收集 | |
761 | + local reward = {} | |
762 | + rewardCollect(reward, goodsByUsual) | |
743 | 763 | |
744 | - local speciNotify = self:checkSpecialReward(now) | |
745 | - rewardToNtyFunc(notify, speciNotify) | |
746 | - | |
747 | - local reward, rewardByGoods = {}, {} | |
748 | - for key, val in pairs(notify) do | |
749 | - if key == roleId then | |
750 | - for k, v in pairs(val) do | |
751 | - for id, count in pairs(v.award:toNumMap()) do | |
752 | - reward[id] = (reward[id] or 0) + count | |
753 | - end | |
754 | - rewardByGoods[k] = v | |
755 | - end | |
756 | - end | |
764 | + local goodsByIncentive = self:checkIncentive(roleId, name, now) | |
765 | + rewardCollect(reward, goodsByIncentive) | |
757 | 766 | |
767 | + local goodsAmount = self:getGoodsAmount() | |
768 | + if goodsAmount == 0 then | |
769 | + self:setProperty("drawEndTime", now) | |
758 | 770 | end |
759 | - return reward, rewardByGoods, notify | |
771 | + | |
772 | + local goodsBySpecial = self:checkSpecialReward(now, goodsAmount) | |
773 | + local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial) | |
774 | + | |
775 | + return {reward = reward, usual = goodsByUsual, incentive = goodsByIncentive, specials = goodsBySpecial, special = specialByRole} | |
760 | 776 | end |
761 | 777 | |
762 | 778 | function Capsule:drawAll(roleId) |
... | ... | @@ -769,8 +785,7 @@ function Capsule:drawAll(roleId) |
769 | 785 | local now = skynet.timex() |
770 | 786 | |
771 | 787 | local name = getNameByRoleId(roleId) |
772 | - local notify = {} | |
773 | - notify[roleId] = {} | |
788 | + local goodsByUsual = {} | |
774 | 789 | for good_id, good in pairs(goods) do |
775 | 790 | if good.amount > 0 then |
776 | 791 | --插入rank |
... | ... | @@ -783,10 +798,10 @@ function Capsule:drawAll(roleId) |
783 | 798 | end |
784 | 799 | |
785 | 800 | --作为奖励记录+通知 |
786 | - if not notify[roleId][good_id] then | |
787 | - notify[roleId][good_id] = tmpNotify | |
801 | + if not goodsByUsual[good_id] then | |
802 | + goodsByUsual[good_id] = tmpNotify | |
788 | 803 | else |
789 | - notify[roleId][good_id].amount = notify[roleId][good_id].amount + good.award | |
804 | + goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + good.award | |
790 | 805 | end |
791 | 806 | |
792 | 807 | --记录角色的抽奖记录 |
... | ... | @@ -804,37 +819,22 @@ function Capsule:drawAll(roleId) |
804 | 819 | recordByRole[roleId] = roleRecord |
805 | 820 | self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) |
806 | 821 | |
807 | - local tmpNotify = self:checkIncentive(roleId, name, now) | |
808 | - for k, v in pairs(tmpNotify) do | |
809 | - if not notify[roleId][k] then | |
810 | - notify[roleId][k] = v | |
811 | - else | |
812 | - notify[roleId][k].amount = notify[roleId][k].amount + v.amount | |
813 | - end | |
814 | - end | |
815 | - | |
816 | - local goodsAmount = self:getGoodsAmount() | |
817 | - local speciNotify = self:checkSpecialReward(now, goodsAmount) | |
818 | - rewardToNtyFunc(notify, speciNotify) | |
819 | - | |
820 | - local reward, rewardByGoods = {}, {} | |
821 | - for key, val in pairs(notify) do | |
822 | - if key == roleId then | |
823 | - for k, v in pairs(val) do | |
824 | - for id, count in pairs(v.award:toNumMap()) do | |
825 | - reward[id] = (reward[id] or 0) + count | |
826 | - end | |
827 | - rewardByGoods[k] = v | |
828 | - end | |
829 | - end | |
822 | + --奖励收集 | |
823 | + local reward = {} | |
824 | + rewardCollect(reward, goodsByUsual) | |
830 | 825 | |
831 | - end | |
826 | + local goodsByIncentive = self:checkIncentive(roleId, name, now) | |
827 | + rewardCollect(reward, goodsByIncentive) | |
832 | 828 | |
829 | + local goodsAmount = self:getGoodsAmount() | |
833 | 830 | if goodsAmount == 0 then |
834 | 831 | self:setProperty("drawEndTime", now) |
835 | 832 | end |
836 | 833 | |
837 | - return reward, rewardByGoods, notify | |
834 | + local goodsBySpecial = self:checkSpecialReward(now, goodsAmount) | |
835 | + local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial) | |
836 | + | |
837 | + return {reward = reward, usual = goodsByUsual, incentive = goodsByIncentive, specials = goodsBySpecial, special = specialByRole} | |
838 | 838 | end |
839 | 839 | |
840 | 840 | --@param |
... | ... | @@ -865,6 +865,33 @@ function Capsule:draw(roleId, full, cares) |
865 | 865 | end |
866 | 866 | end |
867 | 867 | |
868 | +function Capsule:pageRecord(up, idx) | |
869 | + local record = self:getProperty("record") or {} | |
870 | + if not next(record) then return nil end | |
871 | + | |
872 | + --默认取20条 | |
873 | + idx = idx or #record | |
874 | + up = up or 0 | |
875 | + | |
876 | + local count = 0 | |
877 | + local tmpRecord = {} | |
878 | + if up == 1 then | |
879 | + --向上获取索引更大的 从上往下拉 | |
880 | + count = math.min(#record - idx, 20) | |
881 | + for i = idx, count do | |
882 | + tmpRecord[i] = record[i] | |
883 | + end | |
884 | + else | |
885 | + --向下获取索引更小的 从下往上拉 | |
886 | + count = math.max(idx - 20, 0) | |
887 | + for i = count, idx do | |
888 | + tmpRecord[i] = record[i] | |
889 | + end | |
890 | + end | |
891 | + | |
892 | + return tmpRecord | |
893 | +end | |
894 | + | |
868 | 895 | |
869 | 896 | function Capsule:data(roleId) |
870 | 897 | return { |
... | ... | @@ -875,7 +902,7 @@ function Capsule:data(roleId) |
875 | 902 | coin = self:getProperty("coin"), |
876 | 903 | onlineCount = self:getOnlineCount(), |
877 | 904 | playerStatus = self:getRegisterByRoleId(roleId), |
878 | - record = self:getProperty("record"), | |
905 | + record = self:pageRecord() or {}, | |
879 | 906 | rank = self:getProperty("rank"), |
880 | 907 | goods = self:getProperty("goods"), |
881 | 908 | specials = self:getProperty("specials"), | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -3165,16 +3165,19 @@ function RolePlugin.bind(Role) |
3165 | 3165 | end |
3166 | 3166 | |
3167 | 3167 | function Role:drawCapsule(capsuleId, full, cares) |
3168 | - local capsule = self.capsules[capsuleId] or {} | |
3169 | - if next(capsule) then | |
3170 | - local roleId = self:getProperty("id") | |
3171 | - return capsule:draw(roleId, full, cares) | |
3172 | - end | |
3173 | - return 3 | |
3168 | + local capsule = self.capsules[capsuleId] | |
3169 | + if not capsule then return nil end | |
3170 | + | |
3171 | + local roleId = self:getProperty("id") | |
3172 | + local ret, drawReward = capsule:draw(roleId, full, cares) | |
3173 | + drawReward["specials"] = nil | |
3174 | + return ret, drawReward, capsule:data(roleId) | |
3174 | 3175 | end |
3175 | 3176 | |
3176 | 3177 | function Role:joinCapsule(capsuleId) |
3177 | - local capsule = self.capsules[capsuleId] or {} | |
3178 | + local capsule = self.capsules[capsuleId] | |
3179 | + if not capsule then return nil end | |
3180 | + | |
3178 | 3181 | return capsule:data() |
3179 | 3182 | end |
3180 | 3183 | |
... | ... | @@ -3188,12 +3191,16 @@ function RolePlugin.bind(Role) |
3188 | 3191 | end |
3189 | 3192 | |
3190 | 3193 | function Role:goodStock(capsuleId) |
3191 | - local capsule = self.capsules[capsuleId] or {} | |
3194 | + local capsule = self.capsules[capsuleId] | |
3195 | + if not capsule then return 0 end | |
3196 | + | |
3192 | 3197 | return capsule:getGoodsAmount(), capsule:getProperty("token") |
3193 | 3198 | end |
3194 | 3199 | |
3195 | 3200 | function Role:getCapsuleData(capsuleId) |
3196 | - local capsule = self.capsules[capsuleId] or {} | |
3201 | + local capsule = self.capsules[capsuleId] | |
3202 | + if not capsule then return nil end | |
3203 | + | |
3197 | 3204 | return capsule:data() |
3198 | 3205 | end |
3199 | 3206 | |
... | ... | @@ -3220,6 +3227,13 @@ function RolePlugin.bind(Role) |
3220 | 3227 | end |
3221 | 3228 | end |
3222 | 3229 | end |
3230 | + | |
3231 | + function Role:pageRecord(capsuleId, up, idx) | |
3232 | + local capsule = self.capsules[capsuleId] | |
3233 | + if not capsule then return nil end | |
3234 | + | |
3235 | + return capsule:pageRecord(up, idx) | |
3236 | + end | |
3223 | 3237 | end |
3224 | 3238 | |
3225 | 3239 | return RolePlugin |
3226 | 3240 | \ No newline at end of file | ... | ... |
src/services/capsuled.lua
... | ... | @@ -65,6 +65,7 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) |
65 | 65 | end |
66 | 66 | |
67 | 67 | function broadCastSpecial(roleId, capsuleId, broadInfo) |
68 | + if not broadInfo or not next(broadInfo) then return end | |
68 | 69 | local capsule = capsules[capsuleId] |
69 | 70 | if not capsule then skynet.error("not capsule: " .. capsuleId) return end |
70 | 71 | |
... | ... | @@ -205,12 +206,13 @@ function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares) |
205 | 206 | local capsule = capsules[capsuleId] |
206 | 207 | if not capsule then skynet.error("not capsule: " .. capsuleId) return 2 end |
207 | 208 | |
208 | - local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, drawsNum, cares) | |
209 | + local ret, drawReward = capsule:draw(roleId, full, drawsNum, cares) | |
209 | 210 | if ret > 5 then |
210 | 211 | --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify}) |
211 | - broadCastSpecial(roleId, capsuleId, notify) | |
212 | + broadCastSpecial(roleId, capsuleId, drawReward["specials"]) | |
212 | 213 | end |
213 | - return ret, reward, rewardByGoods, capsule:data(roleId) | |
214 | + drawReward["specials"] = nil | |
215 | + return ret, drawReward, capsule:data(roleId) | |
214 | 216 | end |
215 | 217 | |
216 | 218 | function CMD.register(roleId, capsuleId) |
... | ... | @@ -234,6 +236,13 @@ function CMD.capsule_data(roleId, capsuleId) |
234 | 236 | return capsule:data(roleId) |
235 | 237 | end |
236 | 238 | |
239 | +function CMD.page_record(capsuleId, up, idx) | |
240 | + local capsule = capsules[capsuleId] | |
241 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | |
242 | + | |
243 | + return capsule:pageRecord(up, idx) | |
244 | +end | |
245 | + | |
237 | 246 | skynet.start(function() |
238 | 247 | skynet.dispatch("lua", function(session, address, cmd, ...) |
239 | 248 | local f = CMD[string.lower(cmd)] | ... | ... |