diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index c61e7f7..d607260 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -1184,9 +1184,6 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) end end, [3] = function() --发现怪物 - if block:getEventType() == AdvEventType.Build then - self.battle:removeBuildByPos(room.roomId, block.blockId) - end self:getCurMap():addNewMonsterRand(effect[2], {room, block}) self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]}) clearBlock = false @@ -1208,52 +1205,35 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) etype = AdvEventType.Trader, id = effect[2] }) - block:randomEvent() self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]}) clearBlock = false end, [7] = function() -- 建筑 - if block:getEventType() == AdvEventType.Build then - self.battle:removeBuildByPos(room.roomId, block.blockId) - end block:updateEvent({ etype = AdvEventType.Build, id = effect[2] }) - block:randomEvent() clearBlock = false end, [8] = function() -- 选择 - if block:getEventType() == AdvEventType.Build then - self.battle:removeBuildByPos(room.roomId, block.blockId) - end block:updateEvent({ etype = AdvEventType.Choose, id = effect[2] }) - block:randomEvent() clearBlock = false end, [9] = function() -- click - if block:getEventType() == AdvEventType.Build then - self.battle:removeBuildByPos(room.roomId, block.blockId) - end block:updateEvent({ etype = AdvEventType.Click, id = effect[2] }) - block:randomEvent() clearBlock = false end, [10] = function() -- 陷阱 - if block:getEventType() == AdvEventType.Build then - self.battle:removeBuildByPos(room.roomId, block.blockId) - end block:updateEvent({ etype = AdvEventType.Trap, id = effect[2] }) - block:randomEvent() clearBlock = false end, [11] = function() -- 获得神器 @@ -1270,6 +1250,18 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) self:getCurMap():showMap() self:backMapShow() end, + [14] = function() -- 指定地块召唤 指定类型的id + local change = self:getCurMap():layEventToStage(effect[2], effect[3], effect[4], effect[5]) + for _, one in ipairs(change) do + self:backBlockChange(one[1].roomId, one[2].blockId) + end + end, + [15] = function() -- 移除指定事件 + local change = self:getCurMap():clearEventById(effect[2], effect[3], effect[4]) + for _, one in ipairs(change) do + self:backBlockChange(one[1].roomId, one[2].blockId) + end + end, } assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1]) doEffect[effect[1]]() @@ -1624,7 +1616,6 @@ function Adv:doActive(activeId, target) etype = AdvEventType.Trader, id = traderId, }) - target:randomEvent() self:backBlockChange(target.room.roomId, target.blockId) self:pushBackEvent(AdvBackEventType.Trader, {id = traderId}) end @@ -1636,7 +1627,6 @@ function Adv:doActive(activeId, target) doActiveEffect[3] = function(_, monsterId) for _, target in ipairs(targers) do if not target.lock and not target.isDead then - self.battle:removeEnemyById(target.id) self:getCurMap():addNewMonsterRand(monsterId, {self:getRoom(target.roomId), self:getBlock(target.roomId, target.blockId)}) self:backBlockChange(target.roomId, target.blockId) self:pushBackEvent(AdvBackEventType.Monster, {id = monsterId}) diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index fc05893..4b24f0c 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -33,8 +33,31 @@ function Block:getEventType() return self.event and self.event.etype end +function Block:getStageType() + return self.room:getStageType(self.blockId) +end + function Block:updateEvent(event, isInit) + if not isInit then + -- 有些事件删除 需要处理 + if self:isBuild() then + self.room.map.adv.battle:removeBuildByPos(self.room.roomId, self.blockId) + elseif self:isMonster() then + if block.event.mId then + self.room.map.adv.battle:removeEnemyById(block.event.mId) + end + end + end self.event = event + if not isInit and self.event then + -- 判断下类型是不是错的 + if not self:getEventData() then + self:clear() + assert(false, "updateEvent error, : event " .. (event.etype or "nil")) + return + end + self:randomEvent() + end end function Block:clear() @@ -74,7 +97,9 @@ function Block:randomEvent() randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster] --掉落 randomFunc[AdvEventType.Drop] = function() - self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true) + if not self.event.item then + self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true) + end end --交易 randomFunc[AdvEventType.Trader] = function() diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index 7f1a9f9..72a9e2b 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -123,17 +123,101 @@ function Map:addNewMonsterRand(monsterId, where) end local event = { - type = AdvEventType.Monster, + etype = AdvEventType.Monster, id = monsterId, } block:updateEvent(event) - local enemy = self.adv.battle:addEnemy(room, block) - enemy:triggerPassive(Passive.BORN_ONCE) - return room, block end +-- 在指定地块类型上 放置指定类型事件id +function Map:layEventToStage(eventType, eventId, count, stage) + local pool = {} + for _, room_ in pairs(self.rooms) do + for _, block_ in pairs(room_.blocks) do + if block_.isOpen and not block_.event and block_:getStageType() == stage then + table.insert(pool, {room_, block_}) + end + end + end + if not next(pool) then return {} end + local change = {} + count = math.min(#pool, count) + for i = 1, count do + local idx = math.randomInt(1, #pool) + local room, block = pool[idx][1], pool[idx][2] + table.remove(pool, idx) + + local event = { + etype = eventType, + id = eventId, + } + block:updateEvent(event) + table.insert(change, {room, block}) + end + return change +end + +-- 地图中指定事件 切换为另一个事件 +function Map:eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count) + count = count or 1 + local pool = {} + for _, room_ in pairs(self.rooms) do + for _, block_ in pairs(room_.blocks) do + if block_.isOpen and block_:getEventType() == eventTypeF and block_.event.id == eventIdF then + table.insert(pool, {room_, block_}) + end + end + end + if not next(pool) then return {} end + local change = {} + count = math.min(#pool, count) + for i = 1, count do + local idx = math.randomInt(1, #pool) + local room, block = pool[idx][1], pool[idx][2] + table.remove(pool, idx) + + local event = { + etype = eventTypeT, + id = eventIdT, + } + block:updateEvent(event) + table.insert(change, {room, block}) + end + return change +end + +function Map:clearEventById(eventType, eventId, count) + count = count or 0 + eventId = eventId or 0 + + local pool = {} + for _, room_ in pairs(self.rooms) do + for _, block_ in pairs(room_.blocks) do + if block_.isOpen and block_:getEventType() == eventType and (eventId == 0 or block_.event.id == eventId) then + table.insert(pool, {room_, block_}) + end + end + end + if not next(pool) then return {} end + local change = {} + if count == 0 then + count = #pool + else + count = math.min(#pool, count) + end + for i = 1, count do + local idx = math.randomInt(1, #pool) + local room, block = pool[idx][1], pool[idx][2] + table.remove(pool, idx) + + block:updateEvent(nil) + table.insert(change, {room, block}) + end + return change +end + -- 随机翻开 num 个 以开放的房间的 地块 function Map:openBlockRand(num, isPlayer, ignoreBack) local pool = {} diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 29fc9e2..6213df9 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -479,4 +479,29 @@ function Passive:effect10(count, triggerPms) end end +-- 将地图上的A事件替换成B事件 +function Passive:effect11(eventTypeF, triggerPms, eventIdF, eventTypeT, eventIdT, count) + local change = self.owner.battle.adv:getCurMap():eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count) + for _, one in ipairs(change) do + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId) + end +end + +-- 在指定地点召唤event项目 +function Passive:effect12(eventType, triggerPms, eventId, count, stage) + local change = self.owner.battle.adv:getCurMap():layEventToStage(eventType, eventId, count, stage) + for _, one in ipairs(change) do + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId) + end +end + +-- 移除指定项目 +function Passive:effect13(eventType, triggerPms, eventId, count) + local change = self.owner.battle.adv:getCurMap():clearEventById(eventType, eventId, count) + for _, one in ipairs(change) do + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId) + end +end + + return Passive \ No newline at end of file diff --git a/src/adv/AdvRoom.lua b/src/adv/AdvRoom.lua index 1896e1f..79437b4 100644 --- a/src/adv/AdvRoom.lua +++ b/src/adv/AdvRoom.lua @@ -13,14 +13,15 @@ function Room:ctor(map, roomId, csvData, info, isPath, isNewRelay, mapType) self.isBossRoom = false -- boss房间 --击败boss 以后重置为false self.isShow = false self.battleAfterCall = {} + self.csvData = csvData self.blocks = {} - self:loadBlocks(csvData, info, isNewRelay, mapType) + self:loadBlocks(info, isNewRelay, mapType) end -function Room:loadBlocks(csvData, info, isNewRelay, mapType) +function Room:loadBlocks(info, isNewRelay, mapType) local isFirstOpen = false - for blockId, _ in pairs(csvData["blocks"]) do + for blockId, _ in pairs(self.csvData["blocks"]) do self.blocks[blockId] = Block.new(self, blockId, info.event[blockId], info.open == 1 or info.open[blockId], info.trap[blockId]) if not self.isPath and self.blocks[blockId]:isBoss() then self.isBossRoom = true @@ -47,6 +48,12 @@ function Room:loadBlocks(csvData, info, isNewRelay, mapType) end end +function Room:getStageType(blockId) + if not self.blocks[blockId] then return end + if not self.csvData["blocks"][blockId] then return end + return self.csvData["blocks"][blockId] +end + function Room:initBattleAfter() for _, callback in ipairs(self.battleAfterCall) do callback() -- libgit2 0.21.2