From 6826fdf62f261659fe2120ca0ebe8ee80e08a83b Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Tue, 17 Nov 2020 17:16:00 +0800 Subject: [PATCH] 被动触发 --- src/adv/Adv.lua | 38 +++++++++++++++++++++++--------------- src/adv/AdvMap.lua | 51 ++++++++++++++++++++++++++++++++++++++++++--------- src/adv/AdvPassive.lua | 40 +++++++++++++++++++++++++++++++++++++++- src/adv/AdvPlayer.lua | 2 +- 4 files changed, 105 insertions(+), 26 deletions(-) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 084f68a..8f72405 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -1883,23 +1883,31 @@ end -- 地图上物品变化 function Adv:mapItemChange(ctype) + local blocks = {} + for roomId, room in pairs(self:getCurMap().rooms) do + for blockId, block in pairs(room.blocks) do + table.insert(blocks, block) + end + end + self:blockDropChange(ctype, blocks) +end + +function Adv:blockDropChange(ctype, blocks) local clist = csvdb["transform_itemCsv"][ctype] if clist then - for roomId, room in pairs(self:getCurMap().rooms) do - for blockId, block in pairs(room.blocks) do - if block:getEventType() == AdvEventType.Drop and block.event.item then - local id = block.event.item[1] - local count = block.event.item[2] - local changeTo = nil - if clist[id] then - changeTo = {clist[id].toId, math.ceil(count * clist[id].num)} - elseif clist[-1] then - changeTo = {clist[-1].toId, math.ceil(count * clist[-1].num)} - end - if changeTo and changeTo[1] ~= 0 and changeTo[2] ~= 0 then - block.event.item = changeTo - self:backBlockChange(roomId, blockId, ctype) - end + for _, block in ipairs(blocks) do + if block:getEventType() == AdvEventType.Drop and block.event.item then + local id = block.event.item[1] + local count = block.event.item[2] + local changeTo = nil + if clist[id] then + changeTo = {clist[id].toId, math.ceil(count * clist[id].num)} + elseif clist[-1] then + changeTo = {clist[-1].toId, math.ceil(count * clist[-1].num)} + end + if changeTo and changeTo[1] ~= 0 and changeTo[2] ~= 0 then + block.event.item = changeTo + self:backBlockChange(block.room.roomId, block.blockId, ctype) end end end diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index b783b08..51fc2c9 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -256,7 +256,7 @@ function Map:openBlock(roomId, blockId, isPlayer, ignoreBack) if status then if isPlayer then - self.adv.battle:triggerPassive(Passive.OPEN_BLOCK) + self.adv.battle:triggerPassive(Passive.OPEN_BLOCK, {roomId = roomId, blockId = blockId}) self.adv.owner:checkTaskEnter("AdvOpenBlock") -- 潜行检查 @@ -292,21 +292,38 @@ function Map:openBlocksByRoom(roomId, isPlayer, ignoreBack) end end -function Map:openBlocksIsMonsterByRoom(roomId, isPlayer, ignoreBack) +function Map:openBlocksIsMonsterByRoom(roomId, count, isPlayer, ignoreBack) local room = self.rooms[roomId] if not room then return end - local enemys = {} + local allBlock = {} for blockId, block in pairs(room.blocks) do - if block:isMonster() then - if self:openBlock(roomId, blockId, isPlayer, ignoreBack) then - local e = self.adv.battle:getEnemy(block.room.roomId, block.blockId) - if e then - table.insert(enemys, e) - end + if block:isMonster() and not block.isOpen then + table.insert(allBlock, blockId) + end + end + + local enemys = {} + local openBlock = function(blockId) + if self:openBlock(roomId, blockId, isPlayer, ignoreBack) then + local e = self.adv.battle:getEnemy(roomId, blockId) + if e then + table.insert(enemys, e) end end end + + if not count or count == -1 or count >= len(allBlock) then + for _, blockId in ipairs(allBlock) do + openBlock(blockId) + end + else + for i = 1, count do + local idx = math.randomInt(1, len(allBlock)) + openBlock(allBlock[idx]) + table.remove(allBlock, idx) + end + end return enemys end @@ -327,6 +344,22 @@ function Map:getRBByPos(c, r) end end +function Map:getDistance(froomId, fblockId, troomId, tblockId) + local distance = -1 + local room1 = self.rooms[froomId] + local room2 = self.rooms[troomId] + if room1 and room2 then + local block1 = room1[fblockId] + local block2 = room2[tblockId] + if block1 and block2 then + local c1, r1 = room1:tranLtoG(block1.col, block1.row) + local c2, r2 = room2:tranLtoG(block2.col, block2.row) + distance = math.max(math.abs(c1 - c2), math.abs(r1 - r2)) + end + end + return distance +end + function Map:getAroundBlocks(room, block) local blocks = {} local range = {1, -1} diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index d9d536c..ceb0831 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -7,6 +7,8 @@ Filter.HP_LOW = 4 -- 血量 0 then @@ -561,5 +582,22 @@ function Passive:effect14(value, triggerPms, enemyId) end end +--15=翻开房间内的count 个怪 并且增加一个buff +function Passive:effect15(count, triggerPms, buffId) + local roomId = self.owner.roomId + if not roomId then return end + local enemys = self.owner.battle.adv:getCurMap():openBlocksIsMonsterByRoom(roomId, count) + for _, e in ipairs(enemys) do + e:addBuff(buffId) + end +end + +--16=转变 value 范围内的掉落物 为 id count +function Passive:effect16(value, triggerPms, changeType) + if not self.owner.roomId or not self.owner.blockId then return end + local blocks = self.owner.battle.adv:getCurMap():getBlocksBySize(self.owner.roomId, self.owner.blockId, value) + self.owner.battle.adv:blockDropChange(changeType, blocks) +end + return Passive \ No newline at end of file diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index 304e0a3..c240e44 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -417,7 +417,7 @@ function BaseObject:hurt(value, releaser, params) if self.hp == 0 then self:triggerPassive(Passive.SELF_DEAD) for _, team in ipairs(self:getTeam(1, true)) do - team:triggerPassive(Passive.TEAM_DEAD) + team:triggerPassive(Passive.TEAM_DEAD, {trigger = self}) end if (params.hurtType == 6 or params.hurtType == 2) and self ~= self.battle.player then -- libgit2 0.21.2