Commit 058a0cbbe407333a382d8607303db2ca6b236b8d
1 parent
ea357636
抽卡
Showing
3 changed files
with
133 additions
and
5 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/HeroAction.lua
... | ... | @@ -15,6 +15,7 @@ local tconcat = table.concat |
15 | 15 | local table_unpack = table.unpack |
16 | 16 | |
17 | 17 | local _M = {} |
18 | + | |
18 | 19 | function _M.levelUpRpc( agent, data ) |
19 | 20 | local role = agent.role |
20 | 21 | local msg = MsgPack.unpack(data) |
... | ... | @@ -610,8 +611,6 @@ end |
610 | 611 | function _M.getResetRewardRpc(agent, data) |
611 | 612 | local role = agent.role |
612 | 613 | local msg = MsgPack.unpack(data) |
613 | - | |
614 | - local msg = MsgPack.unpack(data) | |
615 | 614 | |
616 | 615 | local hero = role.heros[msg.id] |
617 | 616 | if not hero then return end |
... | ... | @@ -679,4 +678,130 @@ function _M.getResetRewardRpc(agent, data) |
679 | 678 | return true |
680 | 679 | end |
681 | 680 | |
681 | + | |
682 | +local function randomDrawCondition(pool, condition) | |
683 | + local value = {} | |
684 | + for idx, field in ipairs(condition) do | |
685 | + local lpool = {} | |
686 | + local curIdx = 1 | |
687 | + while pool[field .. "_" .. curIdx] do | |
688 | + table.insert(lpool, {pool[field .. "_" .. curIdx]}) | |
689 | + curIdx = curIdx + 1 | |
690 | + end | |
691 | + if next(lpool) then | |
692 | + value[idx] = math.randWeight(lpool, 1) | |
693 | + end | |
694 | + end | |
695 | + return value | |
696 | +end | |
697 | + | |
698 | + | |
699 | +local function fillDrawPool(curPool, resultPool, isNeedFunc) | |
700 | + for itemId, oneData in pairs(csvdb["build_poolCsv"]) do | |
701 | + if oneData["pool_" .. curPool] and oneData["pool_" .. curPool] ~= "" then | |
702 | + local itemData = csvdb["itemCsv"][itemId] | |
703 | + if itemData and isNeedFunc(itemData) then | |
704 | + for _, one in ipairs(oneData["pool_" .. pool]:toTableArray(true)) do | |
705 | + table.insert(resultPool, {itemId, one[1], one[2]}) -- itemId, count, 概率 | |
706 | + end | |
707 | + end | |
708 | + end | |
709 | + end | |
710 | +end | |
711 | + | |
712 | +function _M.drawHeroRpc(agent, data) | |
713 | + local role = agent.role | |
714 | + local msg = MsgPack.unpack(data) | |
715 | + | |
716 | + local pool = msg.pool -- 1 2 3 | |
717 | + local drawType = msg.type -- 1 单抽 2 十连 | |
718 | + | |
719 | + local buildTypeData = csvdb["build_typeCsv"][pool] | |
720 | + if not buildTypeData then return end | |
721 | + | |
722 | + local costs = {{"draw_card", "draw_coin"}, {"draw10_card", "draw10_coin"}} -- 抽取消耗 | |
723 | + local drawCount = {1, 10} -- 抽取次数 | |
724 | + | |
725 | + local costT = costs[drawType] | |
726 | + if not costT then return end | |
727 | + local cost = buildTypeData[costT[1]]:toNumMap() | |
728 | + if not role:checkItemEnough(cost) then | |
729 | + cost = buildTypeData[costT[2]]:toNumMap() | |
730 | + if not role:checkItemEnough(cost) then | |
731 | + return | |
732 | + end | |
733 | + end | |
734 | + | |
735 | + -- 开始抽 | |
736 | + local rateTypes = {"unitRate", "fragmentRate", "itemRate"} | |
737 | + | |
738 | + local typePool = {} | |
739 | + for _, rateType in ipairs(rateTypes) do | |
740 | + table.insert(typePool, {buildTypeData[rateType]}) | |
741 | + end | |
742 | + local rateType = math.randWeight(typePool, 1) | |
743 | + | |
744 | + local resultPool = {} | |
745 | + | |
746 | + local fillPoolFunc = { | |
747 | + unitRate = function() | |
748 | + local condition = {"rare", "camp", "job"} | |
749 | + local values = randomDrawCondition(csvdb["build_unitCsv"][pool], condition) | |
750 | + fillDrawPool(pool, resultPool, function(itemData) | |
751 | + if itemData.type ~= ItemType.Hero then return end | |
752 | + local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero] | |
753 | + if not heroData then return end | |
754 | + for idx, field in ipairs(condition) do | |
755 | + if heroData[field] ~= values[idx] then return end | |
756 | + end | |
757 | + return true | |
758 | + end) | |
759 | + end, | |
760 | + fragmentRate = function() | |
761 | + local condition = {"rare", "camp", "job"} | |
762 | + local values = randomDrawCondition(csvdb["build_fragmentCsv"][pool], condition) | |
763 | + fillDrawPool(pool, resultPool, function(itemData) | |
764 | + if itemData.type ~= ItemType.HeroFragment then return end | |
765 | + local heroData = csvdb["unitCsv"][itemData.id] | |
766 | + if not heroData then return end | |
767 | + for idx, field in ipairs(condition) do | |
768 | + if heroData[field] ~= values[idx] then return end | |
769 | + end | |
770 | + return true | |
771 | + end) | |
772 | + end, | |
773 | + itemRate = function() | |
774 | + fillDrawPool(pool, resultPool, function(itemData) | |
775 | + if itemData.type == ItemType.HeroFragment or itemData.type == ItemType.Hero then return end | |
776 | + return true | |
777 | + end) | |
778 | + end, | |
779 | + } | |
780 | + | |
781 | + if not fillPoolFunc[rateTypes[rateType]] then return end | |
782 | + fillPoolFunc[rateTypes[rateType]]() | |
783 | + if not next(resultPool) then return end | |
784 | + role:costItems(cost) | |
785 | + | |
786 | + local reward = {} | |
787 | + for i = 1, drawCount[drawType] do | |
788 | + local idx = math.randWeight(resultPool, 3) | |
789 | + local temp = resultPool[idx] | |
790 | + local itemData = csvdb["itemCsv"][temp[1]] | |
791 | + if itemData.type == ItemType.Hero and role:isHaveHero(itemData.id - ItemStartId.Hero) then | |
792 | + local fragId = itemData.id - ItemStartId.Hero | |
793 | + local heroData = csvdb["unitCsv"][fragId] | |
794 | + local count = globalCsv.draw_unit_tofragment[heroData.rare] * temp[2] | |
795 | + role:award({[fragId] = count}) | |
796 | + table.insert(reward, {id = fragId, count = count, from = temp[1], fcount = temp[2]}) | |
797 | + else | |
798 | + role:award({[temp[1]] = temp[2]}) | |
799 | + table.insert(reward, {id = temp[1], count = temp[2]}) | |
800 | + end | |
801 | + end | |
802 | + | |
803 | + SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组 | |
804 | + return true | |
805 | +end | |
806 | + | |
682 | 807 | return _M |
683 | 808 | \ No newline at end of file | ... | ... |
src/adv/AdvPassive.lua
... | ... | @@ -246,13 +246,15 @@ function Passive:effect(trigger) |
246 | 246 | self["effect" .. effType](self, effValue, trigger) |
247 | 247 | end |
248 | 248 | end |
249 | - if self.count <= 0 and self.passiveData.refresh == 1 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 | |
250 | - self.isDel = true | |
251 | - end | |
249 | + | |
252 | 250 | if self.count > 0 then |
253 | 251 | self.count = self.count < 999 and self.count - 1 or self.count |
254 | 252 | self.round = self.passiveData.round |
255 | 253 | end |
254 | + | |
255 | + if self.count <= 0 and self.passiveData.refresh == 1 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 | |
256 | + self.isDel = true | |
257 | + end | |
256 | 258 | end |
257 | 259 | |
258 | 260 | function Passive:afterRound() | ... | ... |