--块类型 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) 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:getEventType() return self.event and self.event.etype end function Block:updateEvent(event) self.event = event end function Block:clear() if self:getEventType() == AdvEventType.Trap then self.trapId = self.event.id end self.event = nil end --事件有需要额外处理的部分 function Block:open() 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) 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索引 for i = 1, 10 do local numS, rangeS = "num" .. i, "range" .. i if data[numS] and data[rangeS] then for j = 1, data[numS] do table.insert(self.event.shop, data[rangeS]:randWeight(true)) end else break end end end --建筑 randomFunc[AdvEventType.Build] = function() local data = csvdb["event_buildingCsv"][self.event.id] self.event.effect = data["range"]:randWeight(true) --随出建筑效果 if self.event.effect[1] == 1 then --获得某道具 local reward = csvdb["event_dropCsv"][self.event.effect[2]]["range"]:randWeight(true) self.event.effect[2] = reward[1] self.event.effect[3] = reward[2] end end randomFunc[AdvEventType.Trap] = function() local data = csvdb["event_trapCsv"][self.event.id] 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 adv.owner:checkTaskEnter("AdvOpenBlock") self.isOpen = true end return Block