diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index 7921a44..e89b862 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -7,6 +7,7 @@ function Battle:ctor(adv) self.player = nil --玩家 self.isNewPlayer = false self.enemys = {} --怪 + self.builds = {} -- 建筑 self.cachePassiveEvent = {} self:initPlayer() self:initEnemys() @@ -23,6 +24,11 @@ function Battle:initAfter() for _, enemy in ipairs(mapEnemys) do enemy:initAfter(self.adv:getBlock(enemy.roomId, enemy.blockId, idx).event.enemy) end + end + for idx, mapBuilds in pairs(self.builds) do + for _, build in ipairs(mapBuilds) do + build:initAfter(self.adv:getBlock(build.roomId, build.blockId, idx).event.build) + end end end --[[ @@ -98,6 +104,7 @@ function Battle:initEnemys() end end + function Battle:initMapEnemys(mapIdx) self.enemys[mapIdx] = {} local map = self.adv.maps[mapIdx] @@ -113,6 +120,10 @@ function Battle:initMapEnemys(mapIdx) for _, enemy in ipairs(self.enemys[mapIdx]) do enemy:triggerPassive(passiveC[1], passiveC[2]) end + + for _, build in ipairs(self.builds[mapIdx]) do + build:triggerPassive(passiveC[1], passiveC[2]) + end end end self.cachePassiveEvent[mapIdx] = nil @@ -138,6 +149,19 @@ function Battle:addEnemy(room, block, mapIdx) local player = Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy, mapIdx) table.insert(self.enemys[mapIdx], player) return player + elseif block:isBuild() then + if not block.event.build then + local buildCsv = csvdb["event_buildCsv"][block.event.id] + local build = {} + build.passives = {} + for _, id in ipairs(buildCsv.passive:toArray(true, "=")) do + table.insert(build.passives, {id = id}) + end + block.event.build = build + end + local player = Build.new(self, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.build, mapIdx) + table.insert(self.builds[mapIdx], player) + return player end end @@ -150,6 +174,15 @@ function Battle:getEnemy(roomId, blockId, mapIdx) end end +function Battle:getBuild(roomId, blockId, mapIdx) + mapIdx = mapIdx or self.adv:getCurMapIdx() + for _, build in ipairs(self.builds[mapIdx] or {}) do + if build.roomId == roomId and build.blockId == blockId then + return build + end + end +ends + function Battle:getEnemyById(id) for idx, mapEnemys in pairs(self.enemys) do for _, enemy in ipairs(mapEnemys) do @@ -178,6 +211,9 @@ function Battle:triggerPassive(condType, params, mapIdx) for _, enemy in ipairs(self.enemys[mapIdx]) do enemy:triggerPassive(condType, params) end + for _, build in ipairs(self.builds[mapIdx]) do + build:triggerPassive(condType, params) + end end end @@ -207,6 +243,9 @@ function Battle:afterRound() for _, enemy in ipairs(self.enemys[mapIdx]) do enemy:clearRound() end + for _, build in ipairs(self.builds[mapIdx]) do + build:clearRound() + end for i = #self.enemys[mapIdx], 1, -1 do if self.enemys[mapIdx][i].isDead then local enemy = table.remove(self.enemys[mapIdx], i) @@ -214,6 +253,12 @@ function Battle:afterRound() enemy:clear() end end + for i = #self.builds[mapIdx], 1, -1 do + if self.builds[mapIdx][i].isDead then + local build = table.remove(self.builds[mapIdx], i) + build:clear() + end + end self.player:triggerPassive(Passive.AFTER_ROUND) diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index 0c0ef2d..49a4671 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -21,6 +21,10 @@ 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 @@ -83,7 +87,13 @@ function Block:randomEvent() 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() diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index 383c8e0..35f6011 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -652,6 +652,73 @@ function Player:getDB() return db end +-- 建筑 拥有被动技 +local Build = class("Build", BaseObject) + +function Build:ctor(battle, id, roomId, blockId, lock, build, mapIdx) + Enemy.super.ctor(self, battle) + self.id = id + self.monsterId = monsterId --数据id + self.roomId = roomId + self.blockId = blockId + self.lock = lock + self.mapIdx = mapIdx + self:initData(build) +end + +function Build:initData(data) +end + +function Build:addBuff(buffId, releaser) +end + +function Build:hurt() +end + +--0 全部 1 怪物 2 玩家 +function Build:getTeam(nType, noSelf, mapIdx, includeLock) + noSelf = false -- 不管怎么都取不到自己 + mapIdx = mapIdx or self.battle.adv:getCurMapIdx() + nType = nType or 0 + local team = {} + local function addPlayer() + if not noSelf or self.battle.player ~= self then + if not self.battle.player.isDead then + table.insert(team, self.battle.player) + end + end + end + local function addEnemy() + for _, enemy in pairs(self.battle.enemys[mapIdx]) do + if not noSelf or enemy ~= self then + if not enemy.isDead and (includeLock or not enemy.lock) then -- 已经翻开的 + table.insert(team, enemy) + end + end + end + end + if nType == 0 then + addPlayer() + addEnemy() + elseif nType == 1 then + addEnemy() + elseif nType == 2 then + addPlayer() + end + return team +end +function Enemy:unlock() + self.lock = nil +end + +function Enemy:getDB() + local db = {} + db.passives = {} + for _, passive in ipairs(self.passives) do + table.insert(db.passives, passive:getDB()) + end + return db +end return table.pack(Player, Enemy) \ No newline at end of file -- libgit2 0.21.2