Commit 9687f887fe71e95705a97a5e1ef6282fd346a5a1

Authored by zhouhaihai
1 parent e852b350

建筑被动

src/adv/AdvBattle.lua
... ... @@ -7,6 +7,7 @@ function Battle:ctor(adv)
7 7 self.player = nil --玩家
8 8 self.isNewPlayer = false
9 9 self.enemys = {} --怪
  10 + self.builds = {} -- 建筑
10 11 self.cachePassiveEvent = {}
11 12 self:initPlayer()
12 13 self:initEnemys()
... ... @@ -23,6 +24,11 @@ function Battle:initAfter()
23 24 for _, enemy in ipairs(mapEnemys) do
24 25 enemy:initAfter(self.adv:getBlock(enemy.roomId, enemy.blockId, idx).event.enemy)
25 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 32 end
27 33 end
28 34 --[[
... ... @@ -98,6 +104,7 @@ function Battle:initEnemys()
98 104 end
99 105 end
100 106  
  107 +
101 108 function Battle:initMapEnemys(mapIdx)
102 109 self.enemys[mapIdx] = {}
103 110 local map = self.adv.maps[mapIdx]
... ... @@ -113,6 +120,10 @@ function Battle:initMapEnemys(mapIdx)
113 120 for _, enemy in ipairs(self.enemys[mapIdx]) do
114 121 enemy:triggerPassive(passiveC[1], passiveC[2])
115 122 end
  123 +
  124 + for _, build in ipairs(self.builds[mapIdx]) do
  125 + build:triggerPassive(passiveC[1], passiveC[2])
  126 + end
116 127 end
117 128 end
118 129 self.cachePassiveEvent[mapIdx] = nil
... ... @@ -138,6 +149,19 @@ function Battle:addEnemy(room, block, mapIdx)
138 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 150 table.insert(self.enemys[mapIdx], player)
140 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 165 end
142 166 end
143 167  
... ... @@ -150,6 +174,15 @@ function Battle:getEnemy(roomId, blockId, mapIdx)
150 174 end
151 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 186 function Battle:getEnemyById(id)
154 187 for idx, mapEnemys in pairs(self.enemys) do
155 188 for _, enemy in ipairs(mapEnemys) do
... ... @@ -178,6 +211,9 @@ function Battle:triggerPassive(condType, params, mapIdx)
178 211 for _, enemy in ipairs(self.enemys[mapIdx]) do
179 212 enemy:triggerPassive(condType, params)
180 213 end
  214 + for _, build in ipairs(self.builds[mapIdx]) do
  215 + build:triggerPassive(condType, params)
  216 + end
181 217 end
182 218 end
183 219  
... ... @@ -207,6 +243,9 @@ function Battle:afterRound()
207 243 for _, enemy in ipairs(self.enemys[mapIdx]) do
208 244 enemy:clearRound()
209 245 end
  246 + for _, build in ipairs(self.builds[mapIdx]) do
  247 + build:clearRound()
  248 + end
210 249 for i = #self.enemys[mapIdx], 1, -1 do
211 250 if self.enemys[mapIdx][i].isDead then
212 251 local enemy = table.remove(self.enemys[mapIdx], i)
... ... @@ -214,6 +253,12 @@ function Battle:afterRound()
214 253 enemy:clear()
215 254 end
216 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 263 self.player:triggerPassive(Passive.AFTER_ROUND)
219 264  
... ...
src/adv/AdvBlock.lua
... ... @@ -21,6 +21,10 @@ function Block:isMonster()
21 21 return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster)
22 22 end
23 23  
  24 +function Block:isBuild()
  25 + return self:getEventType() == AdvEventType.Build
  26 +end
  27 +
24 28 function Block:getEventType()
25 29 return self.event and self.event.etype
26 30 end
... ... @@ -83,7 +87,13 @@ function Block:randomEvent()
83 87 end
84 88 --建筑
85 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 97 end
88 98  
89 99 randomFunc[AdvEventType.Trap] = function()
... ...
src/adv/AdvPlayer.lua
... ... @@ -652,6 +652,73 @@ function Player:getDB()
652 652 return db
653 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 724 return table.pack(Player, Enemy)
658 725 \ No newline at end of file
... ...