diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 9720179..c61e7f7 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -157,6 +157,11 @@ function Adv:initByChapter(params) self.battle.player:afterLayer() -- 玩家的buff 清理一下 end + -- 不是中继层 加上 层 和 地图的buff和被动 + if not self.isRelay then + self.battle:initMapEffect() + end + -- 中继进入奖励 if relayData and isEnter then self:awardRelay(relayData, notNotify) @@ -1440,6 +1445,7 @@ local function clickLayer(self, room, block, params) self.maps[mapIdx] = AdvMap.new(self, mapIdx, mapId) self.battle:initMapEnemys(mapIdx, true) + self.battle:initMapEffect(true) self.maps[mapIdx]:initBattleAfter() self:checkAchievement(Adv.AchievType.EnterILayer, 1, mapId) end @@ -1648,7 +1654,7 @@ function Adv:doActive(activeId, target) doActiveEffect[5] = function(_) for _, target in ipairs(targers) do if not target.lock and not target.isDead then - target.isDead = true + target:kill() self:backBlockChange(target.roomId, target.blockId) end end diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index ff7fe10..5b01fb9 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -125,7 +125,7 @@ function Battle:initMapEnemys(mapIdx, after) if map then for _, room in pairs(map.rooms) do for _, block in pairs(room.blocks) do - self:addEnemy(room, block, mapIdx) + self:addEnemy(room, block, mapIdx, true) end end end @@ -146,9 +146,10 @@ function Battle:initMapEnemys(mapIdx, after) self.cachePassiveEvent[mapIdx] = nil end -function Battle:addEnemy(room, block, mapIdx) +function Battle:addEnemy(room, block, mapIdx, init) mapIdx = mapIdx or self.adv:getCurMapIdx() + local isNew, player, data if block:isMonster() then if not block.event.enemy then local enemyCsv = csvdb["event_monsterCsv"][block.event.id] @@ -162,14 +163,15 @@ function Battle:addEnemy(room, block, mapIdx) table.insert(enemy.passives, {id = id}) end block.event.enemy = enemy + isNew = true end if not block.event.mId then block.event.mId = self.adv.lastEnemyId self.adv.lastEnemyId = self.adv.lastEnemyId + 1 end - local player = Enemy.new(self, block.event.mId, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy, mapIdx) + data = block.event.enemy + player = Enemy.new(self, block.event.mId, 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_buildingCsv"][block.event.id] @@ -179,11 +181,28 @@ function Battle:addEnemy(room, block, mapIdx) table.insert(build.passives, {id = id}) end block.event.build = build + isNew = true end - local player = Build.new(self, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.build, mapIdx) + data = block.event.build + 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 + if not init then + player:initAfter(data) + + -- 游戏中新创建的 加上地图 floor 效果 + if isNew then + local passives, buffs = self:getMapEffect(2, true, mapIdx) + for _, passive in ipairs(passives) do + player:addPassive({id = passive}) + end + + for _, buff in ipairs(buffs) do + enemy:addBuff(buff) + end + end + end + return player end function Battle:getEnemy(roomId, blockId, mapIdx) @@ -323,7 +342,7 @@ function Battle:battleBegin(roomId, blockId, params) if not player then return end -- 玩家没死就是怪死了 if player.hp > 0 then - enemy:hurt(enemy.hp, self.player, {hurtType = 5}) + enemy:kill() self.player:effectBattleBuff() self.adv.owner:checkTaskEnter("AdvBattleWin", {id = self.adv.chapterId}) @@ -341,6 +360,63 @@ function Battle:battleBegin(roomId, blockId, params) end +function Battle:getMapEffect(ctype, ilayer, mapIdx) + mapIdx = mapIdx or self.adv:getCurMapIdx() + local mapData = self.adv.maps[mapIdx]:getMapInfoCsv() or {} + local floorData = self.adv:getCurFloorData() or {} + + local passives = {} + local buffs = {} + + for _type, temp in ipairs({mapData, floorData}) do + for _, one in ipairs((temp.passive or ""):toTableArray(true)) do + passives[one[1]] = passives[one[1]] or {} + if ilayer and one[1] == 1 and _type == 2 then + else + table.insert(passives[one[1]], one[2]) + end + end + for _, one in ipairs((temp.buff or ""):toTableArray(true)) do + buffs[one[1]] = buffs[one[1]] or {} + if ilayer and one[1] == 1 and _type == 2 then + else + table.insert(buffs[one[1]], one[2]) + end + end + end + if ctype then + passives = passives[ctype] or {} + buffs = buffs[ctype] or {} + end + return passives, buffs +end +-- 夹层玩家 不重复加 floor +function Battle:initMapEffect(ilayer) + local passives, buffs = self:getMapEffect(nil, ilayer) + local mapIdx = self.adv:getCurMapIdx() + + for _, passive in ipairs(passives[1] or {}) do + self.player:addPassive({id = passive}) + end + + for _, passive in ipairs(passives[2] or {}) do + for _, enemy in ipairs(self.enemys[mapIdx]) do + enemy:addPassive({id = passive}) + end + end + + for _, buff in ipairs(buffs[1] or {}) do + self.palyer:addBuff(buff) + end + + for _, buff in ipairs(buffs[2] or {}) do + for _, enemy in ipairs(self.enemys[mapIdx]) do + enemy:addBuff(buff) + end + end +end + + --写入数据 function Battle:saveDB() for idx, mapEnemys in pairs(self.enemys) do diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index 28cb7bb..fc05893 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -63,7 +63,6 @@ function Block:randomEvent() enemy:unlock() else enemy = adv.battle:addEnemy(room, self, map.mapIdx) - enemy:initAfter(self.event.enemy) end enemy:triggerPassive(Passive.BORN_ONCE) @@ -146,7 +145,6 @@ function Block:randomEvent() build:unlock() else build = adv.battle:addEnemy(room, self, map.mapIdx) - build:initAfter(self.event.build) end build:triggerPassive(Passive.BORN_ONCE) end diff --git a/src/adv/AdvBuff.lua b/src/adv/AdvBuff.lua index 3a72e0f..44ad345 100644 --- a/src/adv/AdvBuff.lua +++ b/src/adv/AdvBuff.lua @@ -570,7 +570,7 @@ end function Buff:afterLayer() -- 持续一层 - if self.buffData.round == 0 then + if self.buffData.round == 0 or self.buffData.mapLock == 1 then self.isDel = true end end diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index b88a419..7f1a9f9 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -49,6 +49,11 @@ function Map:initBattleAfter() end end + +function Map:getMapInfoCsv() + return csvdb["mapCsv"][self.mapId] +end + function Map:getDB() local map = {} map.mapId = self.mapId @@ -124,7 +129,6 @@ function Map:addNewMonsterRand(monsterId, where) block:updateEvent(event) local enemy = self.adv.battle:addEnemy(room, block) - enemy:initAfter(event.enemy) enemy:triggerPassive(Passive.BORN_ONCE) return room, block diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 5bbb568..29fc9e2 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -316,7 +316,7 @@ function Passive:effect(triggerPms) self.round = self.passiveData.round end - if self.count <= 0 and self.passiveData.refresh == 1 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 + if self.count <= 0 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 self.isDel = true end end @@ -334,6 +334,12 @@ function Passive:afterRound() end end +function Passive:afterLayer() + if self.passiveData.mapLock == 1 or self.passiveData.floorType == 1 then + self.isDel = true + end +end + -- 可以触发 function Passive:canTrigger( ) return self.count > 0 and self.delay <= 0 diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index 5bac324..d6f7100 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -85,27 +85,26 @@ function BaseObject:clear() self.passives = {} end -function BaseObject:battleBegin() - for _, passive in ipairs(self.passives) do - passive:battleBegin() - end -end - -function BaseObject:battleEnd() - for _, buff in ipairs(self.buffs) do - buff:battleEnd() - end -end - function BaseObject:addPassive(params) local skillId = params.id local skillData = csvdb["adv_map_passiveCsv"][skillId] if not skillData then return end local level = params.level or 1 if not skillData[level] then return end + + if self:getPassiveById(skillId) then return end -- 被动技不能重复 + table.insert(self.passives, Passive.new(self, { id = skillId, level = level })) end +function BaseObject:getPassiveById(bId) + for idx, passive in ipairs(self.passives) do + if passive.id == bId then + return passive + end + end +end + function BaseObject:getPassiveIdx(passive) for idx, passive_ in ipairs(self.passives) do if passive_ == passive then @@ -535,6 +534,10 @@ function Enemy:isEnemy() return true end +function Enemy:kill() + self:hurt(self.hp, self.battle.player, {hurtType = 5}) +end + local Player = class("Player", BaseObject) function Player:ctor(battle, data) Player.super.ctor(self, battle) @@ -648,11 +651,18 @@ function Player:effectBattleBuff() end function Player:afterLayer() + for _, passive in ipairs(self.passives) do + if not passive.isDel then + passive:afterLayer() + end + end for _, buff in ipairs(self.buffs) do if not buff.isDel then buff:afterLayer() end end + + self:clearRound() end function Player:addBuff(buffId, releaser) -- libgit2 0.21.2