From 9104a922a7fc39f1a9660fcae0a5eb1c27cd4f59 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Mon, 29 Jun 2020 20:28:32 +0800 Subject: [PATCH] 多重掉落 --- src/adv/Adv.lua | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- src/adv/AdvMap.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- src/adv/AdvPassive.lua | 6 ++++-- 3 files changed, 119 insertions(+), 36 deletions(-) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index ce9c5f0..063fc75 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -8,6 +8,7 @@ local Adv = class("Adv") local AdvTask = import(".AdvTask") --任务相关数据搞出去 AdvTask.bind(Adv) + function Adv:ctor(owner) assert(owner, "Adv instance must have owner(role)") self.owner = owner @@ -1805,45 +1806,77 @@ function Adv:enemyDead(enemy, escape) end local changeV = self.battle.player:addExp(monsterData.exp) self:backDead(enemyId, changeV) - if enemy:hadBuff(Buff.CHANGE_DROP_TO_CLICK) then -- 掉落转为 click - local clickId = buff:effect() - block:updateEvent({ - etype = AdvEventType.Click, - id = clickId - }) - self.battle.player:triggerPassive(Passive.BATTLE_WIN) - else - local item = block.event.item - if not item then - local buff = enemy:hadBuff(Buff.CHANGE_DROP) - if buff then - item = table.pack(buff:effect()) - else - if monsterData.dropid == 0 then - item = {0, 0} + + local toClick = enemy:hadBuff(Buff.CHANGE_DROP_TO_CLICK) + if toClick then + toClick = toClick:effect() + end + + local changItem = enemy:hadBuff(Buff.CHANGE_DROP) + if changItem then + changItem = table.pack(changItem:effect()) + end + + local addMult = 0 + local dropBuff = enemy:hadBuff(Buff.DROP_BUFF_BY_ENEMY) -- 根据敌人数量变化个数 + if dropBuff then + local team = enemy:getTeam(1, true) + addMult = addMult + 0.2 * #team + end + + local dropIds = monsterData.dropid:toArray(true, "=") + local drops = {} + local cCcount = 0 -- 需要改变为click 的个数 + for _, dropId in ipairs(dropIds) do + local dropData = csvdb["event_dropCsv"][dropId] + if dropData then + local cur = dropData["range"]:randWeight(true) + if cur and cur[1] ~= 0 then + if toClick then + cCcount = cCcount + 1 else - local dropData = csvdb["event_dropCsv"][monsterData.dropid] - item = dropData["range"]:randWeight(true) + local item = changItem and changItem or cur + item[2] = math.floor(item[2] * (1 + addMult)) + drops[#drops + 1] = item end end - end - if item[1] == 0 then - block:clear() - self.battle.player:triggerPassive(Passive.BATTLE_WIN) - else - local buff = enemy:hadBuff(Buff.DROP_BUFF_BY_ENEMY) -- 根据敌人数量变化个数 - if buff then - local team = enemy:getTeam(1, true) - item[2] = math.floor(item[2] * (1 + 0.2 * #team)) - end - block:updateEvent({ - etype = AdvEventType.Drop, - item = item - }) - self.battle.player:triggerPassive(Passive.BATTLE_WIN, {itemId = item[1], count = item[2]}) + end + -- 这些奖励可能会有被动加成 + self.battle.player:triggerPassive(Passive.BATTLE_WIN, {drops = drops}) + + -- 自身带的掉落是不会被改变的 也不会被加成 + if block.event.item and block.event.item[1] ~= 0 then + drops[#drops + 1] = block.event.item + end + + -- 清空当前的格子 + block:clear() + + -- 掉落走一波 + local blocks = self:getCurMap():getEmptyBlocks(roomId, blockId, #drops) + for _i, cblock in ipairs(blocks) do + cblock:updateEvent({ + etype = AdvEventType.Drop, + item = drops[_i] + }) + if cblock ~= block then + self:backBlockChange(cblock.room.roomId, cblock.blockId) + end + end + + -- 转换的click走一波 + local blocks = self:getCurMap():getEmptyBlocks(roomId, blockId, cCcount) + for _i, cblock in ipairs(blocks) do + cblock:updateEvent({ + etype = AdvEventType.Click, + id = clickId + }) + if cblock ~= block then + self:backBlockChange(cblock.room.roomId, cblock.blockId) end end + self:checkTask(Adv.TaskType.Kill, 1, enemyId) self:checkTask(Adv.TaskType.KillAll) self:checkAchievement(Adv.AchievType.Kill, 1, enemyId) diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index 2627722..fcde56a 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -349,6 +349,55 @@ function Map:getBlocksBySize(roomId, blockId, size) return blocks end +-- 找周围的空格子 最多 49 个 +function Map:getEmptyBlocks(roomId, blockId, count) + local blocks = {} + if count == 0 then return blocks end + local room = self.rooms[roomId] + if not room then return end + local block = room.blocks[blockId] + if not block then return end + + local col, row = room:tranLtoG(block.col, block.row) + + -- 找周围49个格子 + for range = 0, 3 do + if range == 0 then + if block.isOpen and not block:getEventType() then + blocks[#blocks + 1] = block + if #blocks >= count then + return blocks + end + end + else + for _, c in ipairs({col - range , col + range}) do + for r = row - range, row + range do + local rroom, rblock = self:getRBByPos(c, r) + if rroom and rblock.isOpen and not rblock:getEventType() then + blocks[#blocks + 1] = rblock + if #blocks >= count then + return blocks + end + end + end + end + + for _, r in ipairs({row - range , row + range}) do + for c = col - range + 1, col + range - 1 do + local rroom, rblock = self:getRBByPos(c, r) + if rroom and rblock.isOpen and not rblock:getEventType() then + blocks[#blocks + 1] = rblock + if #blocks >= count then + return blocks + end + end + end + end + end + end + return blocks +end + function Map:getEnemysBySize(roomId, blockId, size) local blocks = self:getBlocksBySize(roomId, blockId, size) local enemys = {} @@ -514,7 +563,6 @@ createMap = function(self, mapId, isEnter, isNewRelay) --交易所 randomFunc[AdvEventType.Trader] = function() -- if self.adv.isRelay and isNewRelay then return false end - if self.adv.isRelay then return false end return randomCommon() end --建筑 diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 12e5839..6cc604e 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -485,8 +485,10 @@ end --10=战斗额外掉落次数 function Passive:effect10(count, triggerPms) - if triggerPms.count then - self.owner.battle.adv:award({[triggerPms.itemId] = triggerPms.count * count}, {log = {desc = "passive", int1 = self.id}}) + if triggerPms.drops then + for _, drop in pairs(triggerPms.drops) do + drop[2] = drop[2] + math.floor(drop[2] * count) + end end end -- libgit2 0.21.2