From a80fee7cca90aa07aa063f7fc79a3a81c152d9b5 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Thu, 19 Nov 2020 11:58:34 +0800 Subject: [PATCH] 光环 --- src/adv/Adv.lua | 35 ++++++++++++++++++----------------- src/adv/AdvBattle.lua | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/adv/AdvBuff.lua | 48 +++++++++++++++++++++++++++++++++++++++--------- src/adv/AdvPlayer.lua | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 255 insertions(+), 31 deletions(-) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 3c2a908..0fe09aa 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -102,6 +102,9 @@ function Adv:initByChapter(params) self.cacheUnlock = self.cacheUnlock or {} self.shopStatus = self.shopStatus or {} self.support = self.support or {} + if self.battle then + self.battle:overBattle() + end self.battle = nil -- 清掉 老的 battle self.logid = self.owner:getActionUcode() @@ -211,7 +214,7 @@ function Adv:saveDB(notNotify) advInfo.logid = self.logid advInfo.maps = {} - self.battle:saveDB() + self.battle:saveDB(advInfo) for id , map in ipairs(self.maps) do advInfo.maps[id] = map:getDB() @@ -468,6 +471,11 @@ function Adv:initBattle(notDb) if notDb and self.level ~= 1 then self.battle.player:attrChangeCondBuffCheck(1) end + + -- 初始化 + if notDb then + self.battle:newBattle() + end end function Adv:triggerPassive(condType, params) @@ -1084,7 +1092,9 @@ local function clickOut(self, room, block, params, isExit) end if #self.mapStack > 1 then -- 处于夹层中 + local oldMapIdx = self:getCurMapIdx() table.remove(self.mapStack) --退出夹层 + self.battle:iLayerChange(oldMapIdx) self:backLayer(-1) else --处于底层 @@ -1119,7 +1129,6 @@ local function clickOut(self, room, block, params, isExit) end local isHaveRelay = self:isHaveRelay(self.level) - self.owner:getProperty("advTeam").player = self.battle.player:getDB() -- 临时缓存住 battle 的player if isHaveRelay and not self.isRelay then self:initByChapter({ chapterId = self.chapterId, @@ -1562,6 +1571,7 @@ local function clickClick(self, room, block, params) end local function clickLayer(self, room, block, params) + local oldMapIdx = self:getCurMapIdx() if block.event.mapIdx then table.insert(self.mapStack, block.event.mapIdx) --进入夹层 else @@ -1577,6 +1587,7 @@ local function clickLayer(self, room, block, params) self.maps[mapIdx]:initBattleAfter() self:checkAchievement(Adv.AchievType.EnterILayer, 1, mapId) end + self.battle:iLayerChange(oldMapIdx) self:backLayer(1) return true end @@ -2101,21 +2112,11 @@ function Adv:scoreChange(scoreType, score) end function Adv:getScore() - self.score[AdvScoreType.Level] = math.floor(self.score[AdvScoreType.Level] or 0) - self.score[AdvScoreType.Task] = math.floor(self.score[AdvScoreType.Task] or 0) - self.score[AdvScoreType.Kill] = math.floor(self.score[AdvScoreType.Kill] or 0) - self.score[AdvScoreType.KillBoss] = math.floor(self.score[AdvScoreType.KillBoss] or 0) - self.score[AdvScoreType.ItemBack] = math.floor(self.score[AdvScoreType.ItemBack] or 0) - self.score[AdvScoreType.Event] = math.floor(self.score[AdvScoreType.Event] or 0) - self.score[AdvScoreType.Story] = math.floor(self.score[AdvScoreType.Story] or 0) - - return self.score[AdvScoreType.Level] - + self.score[AdvScoreType.Task] - + self.score[AdvScoreType.Kill] - + self.score[AdvScoreType.KillBoss] - + self.score[AdvScoreType.ItemBack] - + self.score[AdvScoreType.Event] - + self.score[AdvScoreType.Story] + local allScore = 0 + for _, score in pairs(self.score) do + allScore = allScore + math.floor(score) + end + return allScore end function Adv:popBackEvents() diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index 4b422c8..db4e810 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -8,6 +8,7 @@ function Battle:ctor(adv) self.isNewPlayer = false self.enemys = {} --怪 self.builds = {} -- 建筑 + self.auras = {} -- 光环 self.cachePassiveEvent = {} self:initPlayer() self:initEnemys() @@ -198,8 +199,10 @@ function Battle:addEnemy(room, block, mapIdx, init) end for _, buff in ipairs(buffs) do - enemy:addBuff(buff) + player:addBuff(buff) end + -- 新生成的怪 加上 已有的光环buff + player:checkAuraBuff(self:checkDiffAuraBuff({}, self:getAurasByMap())) end end return player @@ -347,6 +350,8 @@ function Battle:afterRound() self.player:triggerPassive(Passive.AFTER_ROUND) + self:checkAura() + if self.player.isDead then self.adv:over(false, nil, -2) end @@ -435,8 +440,116 @@ function Battle:initMapEffect(ilayer) end +-- 夹层 进入退出 接口 清理玩家身上的老光环 添加新的光环 +function Battle:iLayerChange(oldMapIdx) + local auras = self:getActiveAuras() + local playerBuffs = self:checkDiffAuraBuff(self:getAurasByMap(oldMapIdx), auras) + local enemyBuffs = self:checkDiffAuraBuff(self:getAurasByMap(), auras) + self.player:checkAuraBuff(playerBuffs) + for _, enemy in pairs(self.player:getTeam(2)) do + enemy:checkAuraBuff(enemyBuffs) + end + self:setMapAuras(auras) +end + +-- 新的 关卡 关闭旧的战斗模块 清理 玩家身上的光环效果 +function Battle:overBattle() + local buffs = self:checkDiffAuraBuff(self:getAurasByMap(), {}) + self.player:checkAuraBuff(buffs) + self.adv.owner:getProperty("advTeam").player = self.player:getDB() -- 临时缓存住 battle 的player +end + +-- 初始化 新的 关卡 +function Battle:newBattle() + local auras = self:getActiveAuras() + local buffs = self:checkDiffAuraBuff({}, auras) + self:setMapAuras(auras) +end + +-- 过了回合 检查光环 +function Battle:checkAura() + local auras = self:getActiveAuras() + local buffs = self:checkDiffAuraBuff(self:getAurasByMap(), auras) + self.player:checkAuraBuff(buffs) + for _, enemy in pairs(self.player:getTeam(2)) do + enemy:checkAuraBuff(buffs) + end + self:setMapAuras(auras) +end + +-- 查找差异buff +function Battle:checkDiffAuraBuff(oldAuras, newAuras) + local auras = {} + for aurasId , count in pairs(oldAuras) do + auras[aurasId] = -count + end + for aurasId , count in pairs(newAuras) do + auras[aurasId] = (auras[aurasId] or 0) + count + end + + local buffs = {} + for aurasId , count in pairs(auras) do + local auraData = csvdb["adv_map_haloCsv"][aurasId] + if auraData then + for _, effect in ipairs(auraData.effect:toTableArray(true)) do + temp = buffs + for i = 1, #effect do + temp[effect[i]] = temp[effect[i]] or {} + temp = temp[effect[i]] + end + temp.count = (temp.count or 0) + count + if newAuras[aurasId] then + -- 加上 未消失标记 + temp.exist = true + end + end + end + end + return buffs +end + +-- 获取所有生效的 光环 +function Battle:getActiveAuras() + local auras = {} + for _, one in pairs(self.player:getAuras()) do + auras[one] = (auras[one] or 0) + 1 + end + for _, enemy in pairs(self.player:getTeam(2)) do + for _, one in pairs(enemy:getAuras()) do + auras[one] = (auras[one] or 0) + 1 + end + end + for _, build in pairs(self:getBuilds()) do + for _, one in pairs(build:getAuras()) do + auras[one] = (auras[one] or 0) + 1 + end + end + return auras +end + +function Battle:setMapAuras(auras) + self.auras[self.adv:getCurMapIdx()] = auras +end + +function Battle:getAurasByMap(mapIdx) + mapIdx = mapIdx or self.adv:getCurMapIdx() + local auras = self.auras[mapIdx] or {} + return auras +end + +function Battle:getBuilds() + local team = {} + for _, build in pairs(self.builds[self.adv:getCurMapIdx()]) do + if not build.isDead and not build.lock then -- 已经翻开的 + table.insert(team, build) + end + end + return team +end + + --写入数据 -function Battle:saveDB() +function Battle:saveDB(advInfo) for idx, mapEnemys in pairs(self.enemys) do for _, enemy in ipairs(mapEnemys) do local block = self.adv:getBlock(enemy.roomId, enemy.blockId, idx) @@ -453,6 +566,7 @@ function Battle:saveDB() end end end + advInfo.auras = self.auras end return Battle \ No newline at end of file diff --git a/src/adv/AdvBuff.lua b/src/adv/AdvBuff.lua index 612d259..426a30c 100644 --- a/src/adv/AdvBuff.lua +++ b/src/adv/AdvBuff.lua @@ -460,7 +460,18 @@ function Buff:initNew(release, data) end end -function Buff:createAfter() +function Buff:createAfter(layer) + layer = layer or 1 + local otype, maxLayer = self:getOverlay() + if otype then + self.layer = layer + if maxLayer ~= 0 then + self.layer = math.min(maxLayer, self.layer) + end + else + self.layer = 1 + end + if self._init then self:_init() end @@ -647,12 +658,13 @@ function Buff:getOverlay() end -- 叠加 -function Buff:overlay(releaser, data) +function Buff:overlay(releaser, data, layer) local otype, maxLayer = self:getOverlay() if self.isDel or not otype then -- 新获得的 (不可叠加相当于新获得的) - self.isDel = false self:endBuff() + self.isDel = false self:initNew(releaser, data) + self:createAfter(layer) else -- 重置回合 次数 self.roundSpace = 0 @@ -665,7 +677,7 @@ function Buff:overlay(releaser, data) self.release = releaser or self.release -- 叠加层数 - self.layer = self.layer + 1 + self.layer = self.layer + layer if maxLayer ~= 0 then self.layer = math.min(maxLayer, self.layer) end @@ -676,14 +688,32 @@ function Buff:overlay(releaser, data) end -- 扣减层数 -function Buff:uncover() - if self.layer <= 1 then +function Buff:uncover(layer, isAura) + layer = layer or 1 + local oldLayer = self.layer + + self.layer = self.layer - layer + + if self.layer <= 0 then self.isDel = true end - self.layer = self.layer - 1 - if self._uncover then - self:_uncover() + if isAura then + if layer == -1 then + self.layer = 0 + self.isDel = true + else + self.layer = math.max(1, self.layer) + self.isDel = false + end + end + + if self.isDel then return end + + if oldLayer ~= self.layer then + if self._uncover then + self:_uncover() + end end end diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index de3fbac..a463731 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -143,7 +143,8 @@ function BaseObject:getDisablePassiveCount() return count end -function BaseObject:addBuff(buffId, releaser) +function BaseObject:addBuff(buffId, releaser, layer) + layer = layer or 1 local buffData = csvdb["adv_map_buffCsv"][buffId] if not buffData then return end for _, buff in ipairs(self.buffs) do @@ -157,7 +158,7 @@ function BaseObject:addBuff(buffId, releaser) local oldBuff = self:getBuffById(buffId) if oldBuff then if not oldBuff:checkKeep() then return end - oldBuff:overlay(releaser, {}) -- 叠加 + oldBuff:overlay(releaser, {}, layer) -- 叠加 else -- 不能保持的buff 也加不上去 if not Buff.checkKeep({ @@ -167,7 +168,7 @@ function BaseObject:addBuff(buffId, releaser) }) then return end local buff = Buff.create(self, releaser, {id = buffId}) table.insert(self.buffs, buff) - buff:createAfter() + buff:createAfter(layer) end self:triggerPassive(Passive.GET_BUFF, {trigger = releaser, buffId = buffId}) self:triggerPassive(Passive.PLAYER_BUFF_CLASSIFY, {trigger = releaser, classify = buffData.classify}) @@ -224,6 +225,30 @@ end function BaseObject:reSetSpMax() end +function BaseObject:checkAuraBuff(buffs) +end + +function BaseObject:getAuras() + local auras = {} + if self:is("Enemy") then + local halo = csvdb["event_monsterCsv"][self.monsterId].halo + if halo then + for _, one in ipairs(halo:toArray(true, "=")) do + table.insert(auras, one) + end + end + elseif self:is("Build") then + local halo = csvdb["event_buildingCsv"][self.id].halo + if halo then + for _, one in ipairs(halo:toArray(true, "=")) do + table.insert(auras, one) + end + end + end + + return auras +end + -- 通用的buff 效果汇总 -- 0 固定 1百分比 两种分类 function BaseObject:getCommonBuffEffect(bType, otherCond) @@ -625,6 +650,33 @@ function Enemy:getClassify() return csvdb["event_monsterCsv"][self.monsterId].classify end +-- 0=所有 1=怪物 2=玩家 +function Enemy:checkAuraBuff(buffs) + local needBuffs = {} + + for buffId, info in pairs(buffs[0] or {}) do + needBuffs[buffId] = needBuffs[buffId] or {} + needBuffs[buffId].count = (needBuffs[buffId].count or 0) + info.count + needBuffs[buffId].exist = info.exist + end + + for buffId, info in pairs(buffs[1] or {}) do + needBuffs[buffId] = needBuffs[buffId] or {} + needBuffs[buffId].count = (needBuffs[buffId].count or 0) + info.count + needBuffs[buffId].exist = info.exist + end + + for buffId, info in pairs(needBuffs) do + if info.count < 0 then + local buff = self:getBuffById(buffId) + if buff then + buff:uncover(info.exist and -info.count or -1, true) + end + elseif count > 0 then + self:addBuff(buffId, nil, info.count) + end + end +end function Enemy:kill() self:hurt(self.hp, self.battle.player, {hurtType = 5}) @@ -775,6 +827,33 @@ function Player:addBuff(buffId, releaser) end return status end +-- 0=所有 1=怪物 2=玩家 +function Player:checkAuraBuff(buffs) + local needBuffs = {} + + for buffId, info in pairs(buffs[0] or {}) do + needBuffs[buffId] = needBuffs[buffId] or {} + needBuffs[buffId].count = (needBuffs[buffId].count or 0) + info.count + needBuffs[buffId].exist = info.exist + end + + for buffId, info in pairs(buffs[2] or {}) do + needBuffs[buffId] = needBuffs[buffId] or {} + needBuffs[buffId].count = (needBuffs[buffId].count or 0) + info.count + needBuffs[buffId].exist = info.exist + end + + for buffId, info in pairs(needBuffs) do + if info.count < 0 then + local buff = self:getBuffById(buffId) + if buff then + buff:uncover(info.exist and -info.count or -1, true) + end + elseif info.count > 0 then + self:addBuff(buffId, nil, info.count) + end + end +end function Player:isPlayer() return true -- libgit2 0.21.2