--块类型 local AdvCommon = require "adv.AdvCommon" local Passive = require "adv.AdvPassive" local Block = class("AdvBlock") function Block:ctor(room, blockId, event, isOpen, trapId) self.room = room self.blockId = blockId self.col, self.row = AdvCommon.getCrById(self.blockId) self.isOpen = isOpen and true or false self.trapId = trapId self:updateEvent(event, true) end function Block:isBoss() return self:getEventType() == AdvEventType.BOSS end function Block:isMonster() return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster) end function Block:isBuild() return self:getEventType() == AdvEventType.Build end function Block:getEventType() return self.event and self.event.etype end function Block:updateEvent(event, isInit) self.event = event end function Block:clear() if self:getEventType() == AdvEventType.Trap then self.trapId = self.event.id elseif self:getEventType() == AdvEventType.Build then local build = self.room.map.adv.battle:getBuild(self.room.roomId, self.blockId, self.room.map.mapIdx) if build then build.isDead = true end end self.event = nil end function Block:randomEvent() local room = self.room local map = room.map local adv = map.adv --如果翻开有数据处理在这里处理 local randomFunc = {} --怪 randomFunc[AdvEventType.Monster] = function() self.event.mId = adv.lastEnemyId --给怪一个有序id 回合逻辑时使用 adv.lastEnemyId = adv.lastEnemyId + 1 local enemy = adv.battle:getEnemy(room.roomId, self.blockId, map.mapIdx) if enemy then enemy:unlock(self.event.mId) else enemy = adv.battle:addEnemy(room, self, map.mapIdx) end enemy:triggerPassive(Passive.BORN_ONCE) adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy}) for _, monster in pairs(adv.battle.player:getTeam(2)) do adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy}) end end randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster] --掉落 randomFunc[AdvEventType.Drop] = function() self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true) end --交易 randomFunc[AdvEventType.Trader] = function() local data = csvdb["event_traderCsv"][self.event.id] self.event.shop = {} self.event.status = "" --购买次数状态 1 就是购买过了 -- 购买id就是shop索引 local needDiscount = data.discount -- 需要的折扣数量 local curHad = {} local advShop = adv.owner:getProperty("advShop") local function randomGoods(range, gcount) local pool = range:toTableArray(true) -- {{id, weight}, ... } local function randomOneGood() for i = #pool, 1, -1 do local curId = pool[i][1] local curData = csvdb["event_trader_goodsCsv"][curId] if not curData then table.remove(pool, i) else if curData.restrict == 1 then -- 冒险内限制 if curData.restrictnum <= ((adv.shopStatus[curId] or 0) + (curHad[curId] or 0)) then table.remove(pool, i) end elseif curData.restrict == 2 then -- 角色限制 if curData.restrictnum <= ((advShop[curId] or 0) + (curHad[curId] or 0)) then table.remove(pool, i) end end end end if #pool <= 0 then return false end local idx = math.randWeight(pool, 2) local getId = pool[idx][1] local getData = csvdb["event_trader_goodsCsv"][getId] if getData.restrict ~= 0 then curHad[getId] = (curHad[getId] or 0) + 1 end if getData.discount ~= "" and needDiscount > 0 then needDiscount = needDiscount - 1 table.insert(self.event.shop, {getId, getData.discount:randWeight()}) else table.insert(self.event.shop, {getId}) end return true end for i = 1, gcount do if not randomOneGood() then break end end end for i = 1, 10 do local numS, rangeS = "num" .. i, "range" .. i if data[numS] and data[rangeS] then randomGoods(data[rangeS], data[numS]) else break end end end --建筑 randomFunc[AdvEventType.Build] = function() local build = adv.battle:getBuild(room.roomId, self.blockId, map.mapIdx) if build then build:unlock() else build = adv.battle:addEnemy(room, self, map.mapIdx) end build:triggerPassive(Passive.BORN_ONCE) end randomFunc[AdvEventType.Trap] = function() local data = csvdb["event_trapCsv"][self.event.id] -- 因为一些神器效果 提前触发被动 adv.battle.player:triggerPassive(Passive.CLICK_TRAP) local buffs = data.effect:toArray(true, "=") for _, buffId in ipairs(buffs) do adv.battle.player:addBuff(buffId) end if data.target == 1 then-- 给所有敌人同样增加buff local enemys = adv.battle.player:getTeam(2) for k , enemy in ipairs(enemys) do for _, buffId in ipairs(buffs) do enemy:addBuff(buffId) end end end if data.specialEff ~= "" then local effect = data.specialEff:toArray(true, "=") if effect[1] == 1 then self.room.map.adv:mapItemChange(effect[2]) end end adv:checkAchievement(adv.AchievType.Trap, 1, self.event.id) adv:backTrap() self:clear() end if self.event then -- 随机出具体的事件 if randomFunc[self:getEventType()] then randomFunc[self:getEventType()]() end 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() if self.isOpen then return end local room = self.room local map = room.map local adv = map.adv self:randomEvent() self.isOpen = true 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