From 48962a743d4a88b6510fee51ef13336bfb0541f8 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 28 Feb 2020 13:59:47 +0800 Subject: [PATCH] 路障系统提交 --- src/adv/Adv.lua | 29 +++++++++++++++++++++-------- src/adv/AdvBlock.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- src/adv/AdvMap.lua | 2 +- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 592f39d..a5ace10 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -1038,20 +1038,29 @@ function Adv:clickBlock(roomId, blockId, params) local status, errorCode = false, nil local clickEvent = false - if not block.isOpen then + + local function checkAroundBlocks(ignoreGuard) local canOpen = false --如果未开放是否可以开放 - local hadMonster = false -- 周围是否有解锁的怪未击败 for _, one in ipairs(map:getAroundBlocks(room, block)) do local _room, _block = one[1], one[2] - if _block.isOpen then canOpen = true end - if _block.isOpen and _block:isMonster() then - local enemy = self.battle:getEnemy(_room.roomId, _block.blockId) - if not enemy:hadBuff(Buff.DONT_DEFEND) then - hadMonster = true + if not ignoreGuard and _block:isGuard() then + if _block:isMonster() then + local enemy = self.battle:getEnemy(_room.roomId, _block.blockId) + if not enemy:hadBuff(Buff.DONT_DEFEND) then + return false + end + else + return false end + elseif _block:isWalk() then + canOpen = true end end - if canOpen and not hadMonster then --开放 + return canOpen + end + + if not block.isOpen then + if checkAroundBlocks() then --开放 self:getCurMap():openBlock(roomId, blockId, true, true) status = true end @@ -1061,6 +1070,10 @@ function Adv:clickBlock(roomId, blockId, params) if not block.event then return end + + if block:isHinder() then + if not checkAroundBlocks(true) then return end + end --可点击的事件 if not room.isBossRoom or block:isBoss() then if eventCallFunc[block.event.etype] then diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index e635299..ffb797f 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -11,7 +11,7 @@ function Block:ctor(room, blockId, event, isOpen, trapId) self.isOpen = isOpen and true or false self.trapId = trapId - self:updateEvent(event) + self:updateEvent(event, true) end function Block:isBoss() return self:getEventType() == AdvEventType.BOSS @@ -29,7 +29,7 @@ function Block:getEventType() return self.event and self.event.etype end -function Block:updateEvent(event) +function Block:updateEvent(event, isInit) self.event = event end @@ -181,6 +181,29 @@ function Block:randomEvent() end end +-- 获取event 数据 +function Block:getEventData() + local typToCsv = { + [AdvEventType.Monster] = "event_monsterCsv", + [AdvEventType.BOSS] = "event_monsterCsv", + [AdvEventType.Choose] = "event_chooseCsv", + [AdvEventType.Drop] = "event_dropCsv", + [AdvEventType.Build] = "event_buildingCsv", + [AdvEventType.Trader] = "event_traderCsv", + [AdvEventType.Trap] = "event_trapCsv", + [AdvEventType.Click] = "event_clickCsv", + [AdvEventType.Layer] = "event_layerCsv", + [AdvEventType.Task] = "event_questCsv", + [AdvEventType.LinkChoose] = "event_linkchooseCsv", + } + + local etype = self:getEventType() + if not etype then return end + if not self.event.id then return end + if not typToCsv[etype] then return end + + return csvdb[typToCsv[etype]][self.event.id] +end --事件有需要额外处理的部分 function Block:open() @@ -193,4 +216,25 @@ function Block:open() return true end +function Block:getObstacle() + local data = self:getEventData() + if not data then return 0 end + return data.obstacle or 0 +end + +-- 是否看守周围地板 +function Block:isGuard() + return self.isOpen and self:getObstacle() == 2 +end + +-- 是否是路障 +function Block:isHinder() + return self.isOpen and self:getObstacle() == 1 +end + +-- 玩家是否经过 -- 已经翻开 并且 不是路障 +function Block:isWalk() + return self.isOpen and not self:isHinder() +end + return Block \ No newline at end of file diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index 1713ccb..c6ba9a1 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -125,7 +125,7 @@ function Map:openBlockRand(num, isPlayer, ignoreBack) end --- 打开一个地块 翻开地块的入口方法 !!! +-- 打开一个地块 操作翻开地块的入口方法 !!! function Map:openBlock(roomId, blockId, isPlayer, ignoreBack) local room = self.rooms[roomId] if not room then return end -- libgit2 0.21.2