Commit 9687f887fe71e95705a97a5e1ef6282fd346a5a1

Authored by zhouhaihai
1 parent e852b350

建筑被动

src/adv/AdvBattle.lua
@@ -7,6 +7,7 @@ function Battle:ctor(adv) @@ -7,6 +7,7 @@ function Battle:ctor(adv)
7 self.player = nil --玩家 7 self.player = nil --玩家
8 self.isNewPlayer = false 8 self.isNewPlayer = false
9 self.enemys = {} --怪 9 self.enemys = {} --怪
  10 + self.builds = {} -- 建筑
10 self.cachePassiveEvent = {} 11 self.cachePassiveEvent = {}
11 self:initPlayer() 12 self:initPlayer()
12 self:initEnemys() 13 self:initEnemys()
@@ -23,6 +24,11 @@ function Battle:initAfter() @@ -23,6 +24,11 @@ function Battle:initAfter()
23 for _, enemy in ipairs(mapEnemys) do 24 for _, enemy in ipairs(mapEnemys) do
24 enemy:initAfter(self.adv:getBlock(enemy.roomId, enemy.blockId, idx).event.enemy) 25 enemy:initAfter(self.adv:getBlock(enemy.roomId, enemy.blockId, idx).event.enemy)
25 end 26 end
  27 + end
  28 + for idx, mapBuilds in pairs(self.builds) do
  29 + for _, build in ipairs(mapBuilds) do
  30 + build:initAfter(self.adv:getBlock(build.roomId, build.blockId, idx).event.build)
  31 + end
26 end 32 end
27 end 33 end
28 --[[ 34 --[[
@@ -98,6 +104,7 @@ function Battle:initEnemys() @@ -98,6 +104,7 @@ function Battle:initEnemys()
98 end 104 end
99 end 105 end
100 106
  107 +
101 function Battle:initMapEnemys(mapIdx) 108 function Battle:initMapEnemys(mapIdx)
102 self.enemys[mapIdx] = {} 109 self.enemys[mapIdx] = {}
103 local map = self.adv.maps[mapIdx] 110 local map = self.adv.maps[mapIdx]
@@ -113,6 +120,10 @@ function Battle:initMapEnemys(mapIdx) @@ -113,6 +120,10 @@ function Battle:initMapEnemys(mapIdx)
113 for _, enemy in ipairs(self.enemys[mapIdx]) do 120 for _, enemy in ipairs(self.enemys[mapIdx]) do
114 enemy:triggerPassive(passiveC[1], passiveC[2]) 121 enemy:triggerPassive(passiveC[1], passiveC[2])
115 end 122 end
  123 +
  124 + for _, build in ipairs(self.builds[mapIdx]) do
  125 + build:triggerPassive(passiveC[1], passiveC[2])
  126 + end
116 end 127 end
117 end 128 end
118 self.cachePassiveEvent[mapIdx] = nil 129 self.cachePassiveEvent[mapIdx] = nil
@@ -138,6 +149,19 @@ function Battle:addEnemy(room, block, mapIdx) @@ -138,6 +149,19 @@ function Battle:addEnemy(room, block, mapIdx)
138 local player = Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy, mapIdx) 149 local player = Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy, mapIdx)
139 table.insert(self.enemys[mapIdx], player) 150 table.insert(self.enemys[mapIdx], player)
140 return player 151 return player
  152 + elseif block:isBuild() then
  153 + if not block.event.build then
  154 + local buildCsv = csvdb["event_buildCsv"][block.event.id]
  155 + local build = {}
  156 + build.passives = {}
  157 + for _, id in ipairs(buildCsv.passive:toArray(true, "=")) do
  158 + table.insert(build.passives, {id = id})
  159 + end
  160 + block.event.build = build
  161 + end
  162 + local player = Build.new(self, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.build, mapIdx)
  163 + table.insert(self.builds[mapIdx], player)
  164 + return player
141 end 165 end
142 end 166 end
143 167
@@ -150,6 +174,15 @@ function Battle:getEnemy(roomId, blockId, mapIdx) @@ -150,6 +174,15 @@ function Battle:getEnemy(roomId, blockId, mapIdx)
150 end 174 end
151 end 175 end
152 176
  177 +function Battle:getBuild(roomId, blockId, mapIdx)
  178 + mapIdx = mapIdx or self.adv:getCurMapIdx()
  179 + for _, build in ipairs(self.builds[mapIdx] or {}) do
  180 + if build.roomId == roomId and build.blockId == blockId then
  181 + return build
  182 + end
  183 + end
  184 +ends
  185 +
153 function Battle:getEnemyById(id) 186 function Battle:getEnemyById(id)
154 for idx, mapEnemys in pairs(self.enemys) do 187 for idx, mapEnemys in pairs(self.enemys) do
155 for _, enemy in ipairs(mapEnemys) do 188 for _, enemy in ipairs(mapEnemys) do
@@ -178,6 +211,9 @@ function Battle:triggerPassive(condType, params, mapIdx) @@ -178,6 +211,9 @@ function Battle:triggerPassive(condType, params, mapIdx)
178 for _, enemy in ipairs(self.enemys[mapIdx]) do 211 for _, enemy in ipairs(self.enemys[mapIdx]) do
179 enemy:triggerPassive(condType, params) 212 enemy:triggerPassive(condType, params)
180 end 213 end
  214 + for _, build in ipairs(self.builds[mapIdx]) do
  215 + build:triggerPassive(condType, params)
  216 + end
181 end 217 end
182 end 218 end
183 219
@@ -207,6 +243,9 @@ function Battle:afterRound() @@ -207,6 +243,9 @@ function Battle:afterRound()
207 for _, enemy in ipairs(self.enemys[mapIdx]) do 243 for _, enemy in ipairs(self.enemys[mapIdx]) do
208 enemy:clearRound() 244 enemy:clearRound()
209 end 245 end
  246 + for _, build in ipairs(self.builds[mapIdx]) do
  247 + build:clearRound()
  248 + end
210 for i = #self.enemys[mapIdx], 1, -1 do 249 for i = #self.enemys[mapIdx], 1, -1 do
211 if self.enemys[mapIdx][i].isDead then 250 if self.enemys[mapIdx][i].isDead then
212 local enemy = table.remove(self.enemys[mapIdx], i) 251 local enemy = table.remove(self.enemys[mapIdx], i)
@@ -214,6 +253,12 @@ function Battle:afterRound() @@ -214,6 +253,12 @@ function Battle:afterRound()
214 enemy:clear() 253 enemy:clear()
215 end 254 end
216 end 255 end
  256 + for i = #self.builds[mapIdx], 1, -1 do
  257 + if self.builds[mapIdx][i].isDead then
  258 + local build = table.remove(self.builds[mapIdx], i)
  259 + build:clear()
  260 + end
  261 + end
217 262
218 self.player:triggerPassive(Passive.AFTER_ROUND) 263 self.player:triggerPassive(Passive.AFTER_ROUND)
219 264
src/adv/AdvBlock.lua
@@ -21,6 +21,10 @@ function Block:isMonster() @@ -21,6 +21,10 @@ function Block:isMonster()
21 return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster) 21 return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster)
22 end 22 end
23 23
  24 +function Block:isBuild()
  25 + return self:getEventType() == AdvEventType.Build
  26 +end
  27 +
24 function Block:getEventType() 28 function Block:getEventType()
25 return self.event and self.event.etype 29 return self.event and self.event.etype
26 end 30 end
@@ -83,7 +87,13 @@ function Block:randomEvent() @@ -83,7 +87,13 @@ function Block:randomEvent()
83 end 87 end
84 --建筑 88 --建筑
85 randomFunc[AdvEventType.Build] = function() 89 randomFunc[AdvEventType.Build] = function()
86 - 90 + local build = adv.battle:getBuild(room.roomId, self.blockId, map.mapIdx)
  91 + if build then
  92 + build:unlock()
  93 + else
  94 + build = adv.battle:addEnemy(room, self, map.mapIdx)
  95 + end
  96 + build:triggerPassive(Passive.BORN_ONCE)
87 end 97 end
88 98
89 randomFunc[AdvEventType.Trap] = function() 99 randomFunc[AdvEventType.Trap] = function()
src/adv/AdvPlayer.lua
@@ -652,6 +652,73 @@ function Player:getDB() @@ -652,6 +652,73 @@ function Player:getDB()
652 return db 652 return db
653 end 653 end
654 654
  655 +-- 建筑 拥有被动技
  656 +local Build = class("Build", BaseObject)
  657 +
  658 +function Build:ctor(battle, id, roomId, blockId, lock, build, mapIdx)
  659 + Enemy.super.ctor(self, battle)
  660 + self.id = id
  661 + self.monsterId = monsterId --数据id
  662 + self.roomId = roomId
  663 + self.blockId = blockId
  664 + self.lock = lock
  665 + self.mapIdx = mapIdx
  666 + self:initData(build)
  667 +end
  668 +
  669 +function Build:initData(data)
  670 +end
  671 +
  672 +function Build:addBuff(buffId, releaser)
  673 +end
  674 +
  675 +function Build:hurt()
  676 +end
  677 +
  678 +--0 全部 1 怪物 2 玩家
  679 +function Build:getTeam(nType, noSelf, mapIdx, includeLock)
  680 + noSelf = false -- 不管怎么都取不到自己
  681 + mapIdx = mapIdx or self.battle.adv:getCurMapIdx()
  682 + nType = nType or 0
  683 + local team = {}
  684 + local function addPlayer()
  685 + if not noSelf or self.battle.player ~= self then
  686 + if not self.battle.player.isDead then
  687 + table.insert(team, self.battle.player)
  688 + end
  689 + end
  690 + end
  691 + local function addEnemy()
  692 + for _, enemy in pairs(self.battle.enemys[mapIdx]) do
  693 + if not noSelf or enemy ~= self then
  694 + if not enemy.isDead and (includeLock or not enemy.lock) then -- 已经翻开的
  695 + table.insert(team, enemy)
  696 + end
  697 + end
  698 + end
  699 + end
  700 + if nType == 0 then
  701 + addPlayer()
  702 + addEnemy()
  703 + elseif nType == 1 then
  704 + addEnemy()
  705 + elseif nType == 2 then
  706 + addPlayer()
  707 + end
  708 + return team
  709 +end
  710 +function Enemy:unlock()
  711 + self.lock = nil
  712 +end
  713 +
  714 +function Enemy:getDB()
  715 + local db = {}
  716 + db.passives = {}
  717 + for _, passive in ipairs(self.passives) do
  718 + table.insert(db.passives, passive:getDB())
  719 + end
  720 + return db
  721 +end
655 722
656 723
657 return table.pack(Player, Enemy) 724 return table.pack(Player, Enemy)
658 \ No newline at end of file 725 \ No newline at end of file