Commit 7f21f75b100ba2998f541ff0ed40c088cb25fd5f
1 parent
49df162b
fix: 一番赏 增加rank,刷新机制完善,修复capsuled 55行报错。
Showing
2 changed files
with
123 additions
and
39 deletions
Show diff stats
src/models/Capsule.lua
| ... | ... | @@ -145,6 +145,56 @@ function Capsule:isShow() |
| 145 | 145 | return true |
| 146 | 146 | end |
| 147 | 147 | |
| 148 | +function Capsule:resetTimeOut(curTime, now) | |
| 149 | + now = now or skynet.timex() | |
| 150 | + local cur4Time = curTime or (specTime({hour = 4},now)) | |
| 151 | + | |
| 152 | + local interval | |
| 153 | + if cur4Time > now then | |
| 154 | + interval = cur4Time - now | |
| 155 | + elseif cur4Time < now then | |
| 156 | + local nextTime = dayLater(now) | |
| 157 | + interval = nextTime - now | |
| 158 | + elseif cur4Time == now then | |
| 159 | + self:init() | |
| 160 | + self:create() | |
| 161 | + | |
| 162 | + local nextTime = dayLater(now) | |
| 163 | + interval = nextTime - now | |
| 164 | + end | |
| 165 | + interval = (interval + 1)* 100 | |
| 166 | + skynet.timeout(interval, handler(self,self.resetTimeOut)) | |
| 167 | +end | |
| 168 | + | |
| 169 | +function Capsule:reset4TimeOut(curTime, now) | |
| 170 | + now = now or skynet.timex() | |
| 171 | + local interval | |
| 172 | + if curTime > now then | |
| 173 | + interval = curTime - now | |
| 174 | + elseif curTime < now then | |
| 175 | + local nextTime = dayLater(now) | |
| 176 | + interval = nextTime - now | |
| 177 | + elseif curTime == now then | |
| 178 | + self:init() | |
| 179 | + self:create() | |
| 180 | + | |
| 181 | + return false | |
| 182 | + end | |
| 183 | + interval = (interval + 1)* 100 | |
| 184 | + skynet.timeout(interval, handler(self,self.reset4TimeOut)) | |
| 185 | +end | |
| 186 | + | |
| 187 | +function Capsule:checkTime(resetArr, now) | |
| 188 | + if resetArr[1] == "3" then | |
| 189 | + local cur4Time = specTime({hour = 4},now) | |
| 190 | + if now == cur4Time then return true end | |
| 191 | + self:resetTimeOut(cur4Time, now) | |
| 192 | + elseif resetArr[1] == "4" then | |
| 193 | + if now == resetArr[2] then return true end | |
| 194 | + self:reset4TimeOut(resetArr[2], now) | |
| 195 | + end | |
| 196 | +end | |
| 197 | + | |
| 148 | 198 | function Capsule:refreshing(now) |
| 149 | 199 | local id = self:getProperty("id") |
| 150 | 200 | local room = self:getProperty("room") |
| ... | ... | @@ -173,11 +223,10 @@ function Capsule:refreshing(now) |
| 173 | 223 | end |
| 174 | 224 | return false |
| 175 | 225 | |
| 176 | - elseif resetArr[1] == "3" then | |
| 177 | - | |
| 178 | - elseif resetArr[1] == "4" then | |
| 179 | - if now >= resetArr[2] then return true end | |
| 226 | + else | |
| 227 | + self:checkTime(resetArr, now) | |
| 180 | 228 | end |
| 229 | + | |
| 181 | 230 | end |
| 182 | 231 | |
| 183 | 232 | return false |
| ... | ... | @@ -490,17 +539,32 @@ function Capsule:getKing(record,now) |
| 490 | 539 | |
| 491 | 540 | local specials = self:getProperty("specials") or {} |
| 492 | 541 | local specialsRecord = self:getProperty("specialsRecord") or {} |
| 542 | + local rank = self:getProperty("rank") or {} | |
| 543 | + if not next(rank) then return nil end | |
| 493 | 544 | |
| 494 | 545 | local roleRecord = {} |
| 495 | - for _, v in ipairs(record) do | |
| 496 | - if not roleRecord[v.roleId]then | |
| 497 | - roleRecord[v.roleId] = {amount = v.amount } | |
| 498 | - else | |
| 499 | - roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount} | |
| 500 | - end | |
| 546 | + | |
| 547 | + for roleId, count in pairs(rank) do | |
| 548 | + table.insert(roleRecord, {roleId = roleId, count = count}) | |
| 549 | + end | |
| 550 | + table.sort(roleRecord, function(a, b) return a.count > b.count end) | |
| 551 | + | |
| 552 | + --tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | |
| 553 | + | |
| 554 | + local count = math.min(special["amount"], #roleRecord) | |
| 555 | + | |
| 556 | + local rewardByRole = {} | |
| 557 | + local index = 1 | |
| 558 | + while (count > 0 ) do | |
| 559 | + count = count - 1 | |
| 560 | + local tmp = roleRecord[index] | |
| 561 | + if not tmp then break end | |
| 562 | + index = index + 1 | |
| 563 | + | |
| 564 | + local name = getNameByRoleId(tmp.roleId) | |
| 565 | + rewardByRole[tmp.roleId][spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = special["award"], amount = 1, SpecialType.KING, create_time= now} | |
| 501 | 566 | end |
| 502 | 567 | |
| 503 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.KING,now) | |
| 504 | 568 | special["amount"] = count |
| 505 | 569 | specials[spKey] = special |
| 506 | 570 | |
| ... | ... | @@ -614,6 +678,8 @@ function Capsule:drawByCount(roleId, count) |
| 614 | 678 | |
| 615 | 679 | local goods = self:getProperty("goods") or {} |
| 616 | 680 | local record = self:getProperty("record") or {} |
| 681 | + local rank = self:getProperty("rank") or {} | |
| 682 | + local rankRole = rank[roleId] or 0 | |
| 617 | 683 | local recordByRole = self:getProperty("recordByRole") or {} |
| 618 | 684 | local roleRecord = recordByRole[roleId] or {} |
| 619 | 685 | |
| ... | ... | @@ -636,6 +702,9 @@ function Capsule:drawByCount(roleId, count) |
| 636 | 702 | if good and good.amount > 0 then |
| 637 | 703 | good.amount = good.amount - 1 |
| 638 | 704 | |
| 705 | + --插入rank | |
| 706 | + rankRole = rankRole + 1 | |
| 707 | + | |
| 639 | 708 | --插入记录 |
| 640 | 709 | local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} |
| 641 | 710 | table.insert(record, tmpNotify) |
| ... | ... | @@ -659,8 +728,9 @@ function Capsule:drawByCount(roleId, count) |
| 659 | 728 | end |
| 660 | 729 | |
| 661 | 730 | end |
| 731 | + rank[roleId] = rankRole | |
| 662 | 732 | recordByRole[roleId] = roleRecord |
| 663 | - self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | |
| 733 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) | |
| 664 | 734 | |
| 665 | 735 | local tmpNotify = self:checkIncentive(roleId, name, now) |
| 666 | 736 | for k, v in pairs(tmpNotify) do |
| ... | ... | @@ -692,6 +762,8 @@ end |
| 692 | 762 | function Capsule:drawAll(roleId) |
| 693 | 763 | local goods = self:getProperty("goods") or {} |
| 694 | 764 | local record = self:getProperty("record") or {} |
| 765 | + local rank = self:getProperty("rank") or {} | |
| 766 | + local rankRole = rank[roleId] or 0 | |
| 695 | 767 | local recordByRole = self:getProperty("recordByRole") or {} |
| 696 | 768 | local roleRecord = recordByRole[roleId] or {} |
| 697 | 769 | local now = skynet.timex() |
| ... | ... | @@ -701,6 +773,9 @@ function Capsule:drawAll(roleId) |
| 701 | 773 | notify[roleId] = {} |
| 702 | 774 | for good_id, good in pairs(goods) do |
| 703 | 775 | if good.amount > 0 then |
| 776 | + --插入rank | |
| 777 | + rankRole = rankRole + good.amount | |
| 778 | + | |
| 704 | 779 | --插入记录 |
| 705 | 780 | 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} |
| 706 | 781 | for i = 1, good.amount do |
| ... | ... | @@ -725,8 +800,9 @@ function Capsule:drawAll(roleId) |
| 725 | 800 | end |
| 726 | 801 | |
| 727 | 802 | end |
| 803 | + rank[roleId] = rankRole | |
| 728 | 804 | recordByRole[roleId] = roleRecord |
| 729 | - self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | |
| 805 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) | |
| 730 | 806 | |
| 731 | 807 | local tmpNotify = self:checkIncentive(roleId, name, now) |
| 732 | 808 | for k, v in pairs(tmpNotify) do | ... | ... |
src/services/capsuled.lua
| ... | ... | @@ -51,7 +51,9 @@ function getNameByRoleId(roleId) |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 53 | function broadCastCapsule(roleId, capsuleId, broadInfo) |
| 54 | - local capsule = capsules[capsuleId] or {} | |
| 54 | + local capsule = capsules[capsuleId] | |
| 55 | + if not capsule then print("not capsule :" .. capsuleId) return end | |
| 56 | + | |
| 55 | 57 | local register = capsule:getProperty("register") or {} |
| 56 | 58 | if next(capsule) then |
| 57 | 59 | for id, _ in pairs(register) do |
| ... | ... | @@ -63,21 +65,22 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) |
| 63 | 65 | end |
| 64 | 66 | |
| 65 | 67 | function broadCastSpecial(roleId, capsuleId, broadInfo) |
| 66 | - local capsule = capsules[capsuleId] or {} | |
| 68 | + local capsule = capsules[capsuleId] | |
| 69 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return end | |
| 70 | + | |
| 67 | 71 | local register = capsule:getProperty("register") or {} |
| 68 | - if next(capsule) then | |
| 69 | - for id, _ in pairs(register) do | |
| 70 | - if id ~= roleId then | |
| 71 | - if broadInfo[id] then | |
| 72 | - rpcRole(id, "paySpecialReward", id, broadInfo[id]) | |
| 73 | - end | |
| 72 | + for id, _ in pairs(register) do | |
| 73 | + if id ~= roleId then | |
| 74 | + if broadInfo[id] then | |
| 75 | + rpcRole(id, "paySpecialReward", id, broadInfo[id]) | |
| 74 | 76 | end |
| 75 | 77 | end |
| 76 | 78 | end |
| 77 | 79 | end |
| 78 | 80 | |
| 79 | 81 | local function add(roleId, capsuleId) |
| 80 | - local capsule = capsules[capsuleId] or {} | |
| 82 | + local capsule = capsules[capsuleId] | |
| 83 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return end | |
| 81 | 84 | if next(capsule) then |
| 82 | 85 | capsule:join(roleId) |
| 83 | 86 | broadCastCapsule(roleId, capsuleId, {notifyType= NotifyChangeType.JOIN, roleId = roleId}) |
| ... | ... | @@ -183,11 +186,11 @@ end |
| 183 | 186 | |
| 184 | 187 | function CMD.exit(roleId, capsuleId) |
| 185 | 188 | if capsuleId then |
| 186 | - local capsule = capsules[capsuleId] or {} | |
| 187 | - if next(capsule) then | |
| 188 | - capsule:exit(roleId) | |
| 189 | - broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) | |
| 190 | - end | |
| 189 | + local capsule = capsules[capsuleId] | |
| 190 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return end | |
| 191 | + | |
| 192 | + capsule:exit(roleId) | |
| 193 | + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) | |
| 191 | 194 | else |
| 192 | 195 | for _, capsule in pairs(capsules) do |
| 193 | 196 | if next(capsule) then |
| ... | ... | @@ -199,30 +202,35 @@ function CMD.exit(roleId, capsuleId) |
| 199 | 202 | end |
| 200 | 203 | |
| 201 | 204 | function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares) |
| 202 | - local capsule = capsules[capsuleId] or {} | |
| 203 | - if next(capsule) then | |
| 204 | - local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, drawsNum, cares) | |
| 205 | - if ret > 5 then | |
| 206 | - --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify}) | |
| 207 | - broadCastSpecial(roleId, capsuleId, notify) | |
| 208 | - end | |
| 209 | - return ret, reward, rewardByGoods, capsule:data(roleId) | |
| 205 | + local capsule = capsules[capsuleId] | |
| 206 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return 2 end | |
| 207 | + | |
| 208 | + local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, drawsNum, cares) | |
| 209 | + if ret > 5 then | |
| 210 | + --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify}) | |
| 211 | + broadCastSpecial(roleId, capsuleId, notify) | |
| 210 | 212 | end |
| 211 | - return 2 | |
| 213 | + return ret, reward, rewardByGoods, capsule:data(roleId) | |
| 212 | 214 | end |
| 213 | 215 | |
| 214 | 216 | function CMD.register(roleId, capsuleId) |
| 215 | - local capsule = capsules[capsuleId] or {} | |
| 217 | + local capsule = capsules[capsuleId] | |
| 218 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | |
| 219 | + | |
| 216 | 220 | return capsule:register(roleId) |
| 217 | 221 | end |
| 218 | 222 | |
| 219 | 223 | function CMD.goods_stock(capsuleId) |
| 220 | - local capsule = capsules[capsuleId] or {} | |
| 224 | + local capsule = capsules[capsuleId] | |
| 225 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return 0 end | |
| 226 | + | |
| 221 | 227 | return capsule:getGoodsAmount(), capsule:getProperty("token") |
| 222 | 228 | end |
| 223 | 229 | |
| 224 | 230 | function CMD.capsule_data(roleId, capsuleId) |
| 225 | - local capsule = capsules[capsuleId] or {} | |
| 231 | + local capsule = capsules[capsuleId] | |
| 232 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | |
| 233 | + | |
| 226 | 234 | return capsule:data(roleId) |
| 227 | 235 | end |
| 228 | 236 | ... | ... |