From ccbafe671db4e819e1f896ec4918eba5949e49b9 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 10 Jan 2020 16:26:59 +0800 Subject: [PATCH] 冒险神器和buff --- src/GlobalVar.lua | 11 +++++++++++ src/ProtocolCode.lua | 3 +++ src/actions/AdvAction.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/adv/Adv.lua | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------- src/adv/AdvBattle.lua | 23 ++++++++++++----------- src/adv/AdvBuff.lua | 423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------ src/adv/AdvPlayer.lua | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- src/adv/AdvTask.lua | 3 +-- src/models/Role.lua | 6 +++++- src/models/RolePlugin.lua | 36 ++++++++++++++++++++++++++++++++++++ 10 files changed, 727 insertions(+), 291 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 93d085b..8896a89 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -16,6 +16,15 @@ AttsEnum = { pierce = 10, -- 穿透 } +--冒险属性 +AdvAttsEnum = { + hp = 1, -- 血量 + atk = 2, -- 攻击 + def = 3, -- 物理防御 + hit = 4, -- 命中 + miss = 5, -- 闪避 +} + AttsEnumEx = { [1] = "hp", -- 血量 [2] = "atk", -- 攻击 @@ -78,6 +87,7 @@ ItemId = { DinerCoin = 12, --后勤物资 LoveUp = 14, --好感度提升道具 OldCoin = 15, --古代金币 + AdvPoint = 16, -- 探险点 DinerSpTask = 20, -- 餐厅任务采购券 LoveBreak = 21, --好感度突破道具 PvpKey = 22, -- pvp钥匙 @@ -131,6 +141,7 @@ AdvBackEventType = { Trap = 17, --陷阱 Layer = 18, --切换层 MapShow = 19, -- 展示地图 + ChooseArtifact = 20, -- 等待选择神器 } AdvScoreType = { diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index b7aba9c..9b21996 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -56,6 +56,9 @@ actionCodes = { Adv_workshopRpc = 162, Adv_wheelSurfRpc = 163, Adv_finishAchievRpc = 164, + Adv_chooseArtifactRpc = 165, + Adv_wearArtifactRpc = 166, + Adv_upArtifactRpc = 167, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 51581b0..b0dcc72 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -259,6 +259,7 @@ function _M.clickBlockRpc(agent, data) local msg = MsgPack.unpack(data) local adv = role:getAdvData() + if adv:isWaitChooseArtifact() then return end local status = adv:clickBlock(msg.roomId, msg.blockId, msg) if not status then return end SendPacket(actionCodes.Adv_clickBlockRpc, MsgPack.pack({events = adv:popBackEvents()})) @@ -278,6 +279,7 @@ function _M.useItemRpc(agent, data) if not itemData then return end local adv = role:getAdvData() + if adv:isWaitChooseArtifact() then return end --重置数量 if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end if not adv:cost({[itemId] = count}, {}, true) then return true end @@ -324,7 +326,8 @@ function _M.usePotionRpc(agent, data) if own <= 0 then return 4 end local adv = role:getAdvData() - + if adv:isWaitChooseArtifact() then return end + local status = adv:doActive(potionData.effect, target) -- target if not status then return end @@ -338,6 +341,67 @@ function _M.usePotionRpc(agent, data) return true end +-- 选择神器 +function _M.chooseArtifactRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local adv = role:getAdvData() + + if not msg.idx then return end + if not adv:isWaitChooseArtifact() then return end + local status = adv:chooseArtifact(msg.idx) + if not status then return end + adv:saveDB() + + SendPacket(actionCodes.Adv_chooseArtifactRpc, '') + return true +end + +-- 穿戴神器 +function _M.wearArtifactRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local slot = msg.slot + local id = msg.id + + local adv = role:getAdvData() + + if math.illegalNum(slot, 1, 5) then return end + if not adv:isHaveArtifact(id) then return end + if not adv:isWaitChooseArtifact() then return end + + local status = adv:wearArtifact(slot, id) + if not status then return end + adv:saveDB() + + SendPacket(actionCodes.Adv_wearArtifactRpc, '') + return true +end + +-- 升级神器 +function _M.upArtifactRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + + local adv = role:getAdvData() + local curLevel = adv:isHaveArtifact(id) + if not curLevel then return end + if not role:isArtifactOpen(id, adv:isEndless(), curLevel + 1) then return end + local cost = csvdb["adv_artifactCsv"][curLevel].exp:toNumMap() + if not adv:cost(cost, {}, true) then return end + + local status = adv:artifactLevelUp(id) + if not status then return end + adv:cost(cost, {}) + + if status == 1 then -- 现在穿着呢。更新下 + adv:saveDB() + end + SendPacket(actionCodes.Adv_upArtifactRpc, '') + return true +end + --退出 function _M.exitAdvRpc(agent, data) local role = agent.role @@ -361,6 +425,7 @@ function _M.startBattleRpc(agent, data) if not enemyId then return end local adv = role:getAdvData() + if adv:isWaitChooseArtifact() then return end local enemy = adv.battle:getEnemyById(enemyId) if enemy.monsterId ~= monsterId or enemy.roomId ~= roomId or enemy.blockId ~= blockId or enemy.lock or enemy.isDead then return end @@ -387,6 +452,7 @@ function _M.endBattleRpc(agent, data) if not player or not player.hp or not player.sp or not enemyId or not key then return end local adv = role:getAdvData() + if adv:isWaitChooseArtifact() then return end -- 校验 if not adv.__battleCache then return end if adv.__battleCache.enemyId ~= enemyId then return end diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 4f214fe..be845d9 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -33,6 +33,7 @@ function Adv:initByInfo(advInfo) self.lastEnemyId = advInfo.lastEId or 1 self.mapStack = advInfo.mstack or {} self.lchoose = advInfo.lch or {} + self.waitArtifact = advInfo.waitAF self.maps = {} for id, map in ipairs(advInfo.maps or {}) do self.maps[id] = AdvMap.new(self, id, map) @@ -87,6 +88,7 @@ function Adv:clear() self.lchoose = {} self.maps = {} self.battle = nil + self.waitArtifact = nil end function Adv:saveDB(notNotify) @@ -100,6 +102,7 @@ function Adv:saveDB(notNotify) advInfo.lastEId = self.lastEnemyId advInfo.mstack = self.mapStack advInfo.lch = self.lchoose + advInfo.waitAF = self.waitArtifact advInfo.maps = {} self.battle:saveDB() @@ -159,7 +162,146 @@ function Adv:getBlock(roomId, blockId, mapIdx) end end +function Adv:isHaveArtifact(id) + return self.owner:getProperty("advAFGet")[id] +end + +function Adv:awardArtifact(id, params) + if self:isHaveArtifact(id) then return end + self.owner:changeUpdates({{type = "advAFGet", field = id, value = 1}}, params.notNotify) +end + + +function Adv:delArtifactEffect(effect) + for _, eff in ipairs(effect:toArray()) do + local etype, id = table.unpack(eff:toArray(true, "=")) + if etype == 1 then + self.battle.player:addPassive({id = id}) + elseif etype == 2 then + self.battle.player:addBuff(id) + end + end +end + +function Adv:addArtifactEffect(effect) + for _, eff in ipairs(effect:toArray()) do + local etype, id = table.unpack(eff:toArray(true, "=")) + if etype == 1 then + self.battle.player:delPassiveById(id) + elseif etype == 2 then + self.battle.player:delBuffById(id) + end + end +end + +function Adv:wearArtifact(slot, id) + local advAFGet = self.owner:getProperty("advAFGet") + local advAFWear = self.owner:getProperty("advAFWear") + + local curWear = {} + for _, _id in pairs(advAFWear) do + curWear[_id] = 1 + end + if curWear[id] then return end + + if advAFWear[slot] then + local oldData = csvdb["adv_artifactCsv"][advAFWear[slot]][advAFGet[advAFWear[slot]]] + self:delArtifactEffect(oldData.effect) + if oldData.comboId ~= 0 then + local comboData = csvdb["adv_artifact_comboCsv"][oldData.comboId] + if comboData then + local isHaveCombo = true + for _, _id in ipairs(comboData.artifactid:toArray(true)) do + if not curWear[_id] then + isHaveCombo = false + break + end + end + if isHaveCombo then + self:delArtifactEffect(comboData.effect) + end + end + end + curWear[advAFWear[slot]] = nil + end + + curWear[id] = 1 + local newData = csvdb["adv_artifactCsv"][id][advAFGet[id]] + self:addArtifactEffect(newData.effect) + if newData.comboId ~= 0 then + local comboData = csvdb["adv_artifact_comboCsv"][newData.comboId] + if comboData then + local isHaveCombo = true + for _, _id in ipairs(comboData.artifactid:toArray(true)) do + if not curWear[_id] then + isHaveCombo = false + break + end + end + if isHaveCombo then + self:addArtifactEffect(comboData.effect) + end + end + end + self.owner:changeUpdates({{type = "advAFWear", field = slot, value = id}}) + return true +end + +function Adv:artifactLevelUp(id) + local advAFGet = self.owner:getProperty("advAFGet") + local advAFWear = self.owner:getProperty("advAFWear") + local status = 0 + if advAFWear[id] then -- 穿着呢 + local oldData = csvdb["adv_artifactCsv"][id][advAFGet[id]] + local newData = csvdb["adv_artifactCsv"][id][advAFGet[id] + 1] + self:delArtifactEffect(oldData.effect) + self:addArtifactEffect(newData.effect) + status = 1 + end + self.owner:changeUpdates({{type = "advAFGet", field = id, value = advAFGet[id] + 1}}) + return status +end + +function Adv:waitChooseArtifact() + local chooses = {} + local pool = {} + local count = 3 --需要多少个 + + for id, temp in pairs(csvdb["adv_artifactCsv"]) do + if not self:isHaveArtifact(id) and self.owner:isArtifactOpen(id, self:isEndless()) then + table.insert(pool, id) + end + end + + for i = 1, count do + if len(pool) <= 0 then + table.insert(chooses, {ItemId.AdvPoint, 48}) + else + local idx = math.randomInt(1, #pool) + table.insert(chooses, pool[idx]) + table.remove(pool, idx) + end + end + self.waitArtifact = chooses + self:backChooseArtifact() +end + +function Adv:isWaitChooseArtifact() + return self.waitArtifact +end + +function Adv:chooseArtifact(index) + if not self.waitArtifact or not self.waitArtifact[index] then return end + local itemId = type(self.waitArtifact[index]) == "table" and self.waitArtifact[index][1] or self.waitArtifact[index] + local count = type(self.waitArtifact[index]) == "table" and self.waitArtifact[index][2] or 1 + self:award({[itemId] = count}) + return true +end + +function Adv:isEndless() + return AdvCommon.isEndless(self.chapterId) +end --关卡通关,非层 score < 0 失败 function Adv:over(success, isAllPass) @@ -183,6 +325,7 @@ function Adv:over(success, isAllPass) self:clear() self.owner:checkTaskEnter("AdvScore", {score = score}) self.owner:updateProperty({field = "advItems", value = ""}) + self.owner:updateProperty({field = "advAFGet", value = {}}) self:backEnd(success, score, scoreInfo, reward) end @@ -244,136 +387,34 @@ function Adv:award(gift, params) tgift = gift end local items = self.owner:getProperty("advItems") + local oldItems = items for itemId, count in pairs(tgift) do if count > 0 then + local buffAdd = self.battle.player:getRewardChange(itemId) + count = math.max(0, (count + buffAdd[0]) * (1 + buffAdd[1])) --附加 buff 的影响 self:scoreChange(AdvScoreType.Item, {itemId, count}) self:checkTask(Adv.TaskType.Item, count, itemId) self:checkAchievement(Adv.AchievType.GetItem, count, itemId) end + tgift[itemId] = count local origin = items:getv(itemId, 0) local nums = origin + count - if csvdb["adv_artifactCsv"][itemId] then - nums = self:checkArtifact(itemId, origin, count, nums) - end - if nums <= 0 then - items = items:delk(itemId) - nums = 0 - else - items = items:setv(itemId, nums) - end - end - - self.owner:updateProperty({field = "advItems", value = items, notNotify = params.notNotify}) - return tgift -end - -function Adv:delArtifactEffect(effectType, effects) - if effectType == 1 then - for _, id in ipairs(effects:toArray(true, "=")) do - self.battle.player:delPassiveById(id) - end - elseif effectType == 2 then - for _, id in ipairs(effects:toArray(true, "=")) do - self.battle.player:delBuffById(id) - end - end -end - -function Adv:addArtifactEffect(effectType, effects) - if effectType == 1 then - for _, id in ipairs(effects:toArray(true, "=")) do - self.battle.player:addPassive({id = id}) - end - elseif effectType == 2 then - for _, id in ipairs(effects:toArray(true, "=")) do - self.battle.player:addBuff(id) - end - end -end --- 检查神器 -function Adv:checkArtifact(itemId, origin, count, nums) - local artifactData = csvdb["adv_artifactCsv"][itemId] - if count == 0 or not artifactData then return nums end - local advItems = self.owner:getProperty("advItems") - if count < 0 then --删除 - nums = 0 - local curData = artifactData[origin] - if curData then - -- 删除自己的效果 - self:delArtifactEffect(curData.type, curData.effect) - - --删除组合效果 - if curData.comboId ~= 0 then - local comboLv = advItems:getv(curData.comboId, 0) - if comboLv ~= 0 then - --删除自己的组合效果 - if curData.comboType == 1 or curData.comboType == 2 then - self:delArtifactEffect(curData.comboType, curData.comboEffect) - elseif curData.comboType == 3 then - self:delArtifactEffect(curData.type, curData.comboEffect) - end - - -- 删除组合的组合效果 - local comboData = (csvdb["adv_artifactCsv"][curData.comboId] or {})[comboLv] - if comboData then - if comboData.comboType == 1 or comboData.comboType == 2 then - self:delArtifactEffect(comboData.comboType, comboData.comboEffect) - elseif comboData.comboType == 3 then - self:delArtifactEffect(comboData.type, comboData.comboEffect) - self:addArtifactEffect(comboData.type, comboData.effect) - end - end - end - end - end - else - nums = math.max(0, math.min(nums, #artifactData)) - if nums == origin then return nums end - if origin == 0 then --初始获得 - local curData = artifactData[nums] - local addSelfEffect = true - --查看是否有组合 - if curData.comboId ~= 0 then - local comboLv = advItems:getv(curData.comboId, 0) - if comboLv ~= 0 then - --自己的组合效果 - if curData.comboType == 1 or curData.comboType == 2 then - self:addArtifactEffect(curData.comboType, curData.comboEffect) - elseif curData.comboType == 3 then - self:addArtifactEffect(curData.type, curData.comboEffect) - addSelfEffect = false - end - - --对方的组合效果 - local comboData = (csvdb["adv_artifactCsv"][curData.comboId] or {})[comboLv] - if comboData then - if comboData.comboType == 1 or comboData.comboType == 2 then - self:addArtifactEffect(comboData.comboType, comboData.comboEffect) - elseif comboData.comboType == 3 then - self:delArtifactEffect(comboData.type, comboData.effect) - self:addArtifactEffect(comboData.type, comboData.comboEffect) - end - end - end - end - if addSelfEffect then - self:addArtifactEffect(curData.type, curData.effect) - end - else --升级 - local originData = artifactData[origin] - local curData = artifactData[nums] - - if originData then - self:delArtifactEffect(originData.type, originData.effect) - end - - if curData then - self:addArtifactEffect(curData.type, curData.effect) + if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 + self:awardArtifact(itemId, params) + else + if nums <= 0 then + items = items:delk(itemId) + nums = 0 + else + items = items:setv(itemId, nums) end end end - return nums + if items ~= oldItems then + self.owner:updateProperty({field = "advItems", value = items, notNotify = params.notNotify}) + end + return tgift end @@ -397,7 +438,9 @@ function Adv:cost(item, params, check) if next(less) and not self.owner:checkItemEnough(less) then return end --不够 if check then return true end self:award(advCost, params) - self.owner:costItems(less, params) + if next(less) then + self.owner:costItems(less, params) + end return true end @@ -411,7 +454,7 @@ local function clickOut(self, room, block, params) local advPass = self.owner:getProperty("advPass") - if AdvCommon.isEndless(self.chapterId) then + if self:isEndless() then -- 刷新最高层 if self.owner:getProperty("advElM") < self.level then self.owner:updateProperty({field = "advElM", value = self.level}) @@ -427,8 +470,8 @@ local function clickOut(self, room, block, params) self:checkAchievement(Adv.AchievType.OverWin, 1, self.level) local levellimit = csvdb["adv_chapterCsv"][self.chapterId].limitlevel - if params.relay or (not AdvCommon.isEndless(self.chapterId) and (self.level >= levellimit or not self.owner:advChapterIsOpen(self.chapterId, self.level + 1))) then --关卡结束 - self:over(true, not AdvCommon.isEndless(self.chapterId) and self.level >= levellimit) + if params.relay or (not self:isEndless() and (self.level >= levellimit or not self.owner:advChapterIsOpen(self.chapterId, self.level + 1))) then --关卡结束 + self:over(true, not self:isEndless() and self.level >= levellimit) else self:initByChapter(self.chapterId, self.level + 1, true, true) self:backNext() --下一关 @@ -522,6 +565,9 @@ local function chooseCommon(self, room, block, chooseData, choose) clearBlock = false end, [4] = function() --无事发生 + end, + [11] = function() -- 获得神器 + self:waitChooseArtifact() --等待获取神器 end } assert(doEffect[effect[1]], "error effect, event_[link]chooseCsv id :" .. block.event.id) @@ -1078,6 +1124,10 @@ function Adv:backMapShow() self:pushBackEvent(AdvBackEventType.MapShow, {}) end +function Adv:backChooseArtifact() + self:pushBackEvent(AdvBackEventType.ChooseArtifact, {}) +end + function Adv:scoreChange(scoreType, pms) local cutTypes = {} local score = 0 diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index b845866..eb912be 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -41,29 +41,30 @@ function Battle:initPlayer() local player = advTeam.player if not player then player = {} + player.level = 1 + player.exp = 0 + player.sp = 100 + player.growth = {} player.passives = {} - local heroLevel = 0 + for slot, heroId in pairs(advTeam.heros) do local hero = self.adv.owner.heros[heroId] if hero then - heroLevel = heroLevel + hero:getProperty("level") local advSkillId = csvdb["unitCsv"][self.adv.owner.heros[heroId]:getProperty("type")]["adv"] if advSkillId > 1000 then table.insert(player.passives, {id = advSkillId, level = hero:getSkillLevel(4)}) end end end - player.growth = (self.adv.owner:getRealBattleValue(advTeam.heros) / 80) ^ 0.52 + math.floor(heroLevel / 50) / 50 - player.level = 1 - player.exp = 0 - player.sp = 100 - local activeRelation = self.adv.owner:getHeroActiveRelation() - local baseAttr = csvdb["adv_unitCsv"][self.adv.chapterId] - for _, attr in pairs(AttsEnumEx) do - if baseAttr[attr] then - player[attr] = baseAttr[attr] + player.growth * (player.level - 1) + + local attrs = self.adv.owner:getTeamBattleInfo(advTeam).heros + for attrName, _ in pairs(AdvAttsEnum) do + for _, hero in pairs(attrs) do + player[attrName] = (player[attrName] or 0) + hero[attrName] end + palyer.growth[attrName] = player[attrName] * 0.025 end + player.hpMax = player.hp or 0 self.isNewPlayer = true advTeam.player = player diff --git a/src/adv/AdvBuff.lua b/src/adv/AdvBuff.lua index bbc95c4..9050b25 100644 --- a/src/adv/AdvBuff.lua +++ b/src/adv/AdvBuff.lua @@ -27,6 +27,9 @@ Buff.EXP_UP = 24 -- 杀敌经验提高 Buff.DISABLE_BUFF = 25 -- 禁用固有技 Buff.ATTR_CHANGE_COND = 26 --属性变化(状态)有条件 Buff.CHANGE_DROP_TO_CLICK = 27 --掉落转换为click +Buff.SP_MAX_CHANGE = 28, -- 魔法上限 +Buff.ITEM_GET_UP = 29, -- 获得道具数量增加 +Buff.Buff_EFFECT_CHANGE = 30, -- 改变 buff 效果 --角色一些属性的变化 local function commonAttr(_Buff, attrName) @@ -34,26 +37,46 @@ local function commonAttr(_Buff, attrName) self.owner:reSetAttr(attrName) end _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 + return self.buffData.effectValue1, self:doEffectChange(self.buffData.effectValue2) * self.layer, attrName + end + _Buff._overlay = function(self) + self.owner:reSetAttr(attrName) + end + _Buff._uncover = function(self) + self.owner:reSetAttr(attrName) end _Buff._endBuff = function(self, data) self.owner:reSetAttr(attrName) end + _Buff._effectChange = function(self) + self.owner:reSetAttr(attrName) + end end local function commonAttCond(_Buff, attrName) _Buff._init = function(self, data) --初始化变化值 + self._changeV = self:_calculate() + self.owner:reSetAttr(attrName) + end + _Buff._overlay = function(self) + self._changeV = (self._changeV or 0) + self:_calculate() + self.owner:reSetAttr(attrName) + end + _Buff._uncover = function(self) + self._changeV = self._changeV - self._changeV / (self.layer + 1) + self.owner:reSetAttr(attrName) + end + _Buff._calculate = function(self) local effectCount = 0 if self.buffData.effectValue4 == 0 then effectCount = self.owner.battle.adv.owner:getProperty("advItems"):getv(ItemId.OldCoin, 0) end - self._changeV = self.buffData.effectValue2 * effectCount / self.buffData.effectValue5 - self.owner:reSetAttr(attrName) + return self.buffData.effectValue2 * effectCount / tonumber(self.buffData.effectValue5) end _Buff._initDB = function(self, data) self._changeV = data.cv end _Buff._effectValue = function(self) - return self.buffData.effectValue1, self._changeV + return self.buffData.effectValue1, self._changeV, attrName end _Buff._endBuff = function(self, data) self.owner:reSetAttr(attrName) @@ -66,19 +89,29 @@ end local BuffFactory = { [Buff.HP_CHANGE] = function(_Buff) _Buff._init = function(self, data) --初始化变化值 - self._changeV = 0 + self._changeV = self:_calculate() + end + _Buff._overlay = function(self) + self._changeV = (self._changeV or 0) + self:_calculate() + end + _Buff._uncover = function(self) + self._changeV = self._changeV - self._changeV / (self.layer + 1) + end + _Buff._calculate = function(self) + local curValue = 0 if self.buffData.effectValue1 == 0 then --固定值 - self._changeV = self.buffData.effectValue2 + curValue = self.buffData.effectValue2 elseif self.buffData.effectValue1 == 1 then local baseOwner = self.buffData.effectValue4 == 1 and self.owner or self.release local attrs = {[0] = "hp", [1] = "hpMax", [2] = "atk"} - self._changeV = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100 + curValue = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100 end - if self._changeV < 0 then + if curValue < 0 then if self.release then - self._changeV = -self.release:getHurtValue(-self._changeV) + curValue = -self.release:getHurtValue(-curValue) end end + return curValue end _Buff._initDB = function(self, data) self._changeV = data.cv @@ -92,8 +125,9 @@ local BuffFactory = { end end _Buff._effectValue = function(self) - return self._changeV + return self:doEffectChange(self._changeV) end + _Buff._getDB = function(self) return {cv = self._changeV} end @@ -101,33 +135,60 @@ local BuffFactory = { [Buff.HP_MAX_CHANGE] = function(_Buff) _Buff._init = function(self, data) --初始化变化值 - self._changeV = 0 + self._changeV = self:_calculate() + self:_hpChange() + end + _Buff._overlay = function(self) + self._changeV = (self._changeV or 0) + self:_calculate() + self:_hpChange() + end + + _Buff._uncover = function(self) + self._changeV = self._changeV - self._changeV / (self.layer + 1) + self.owner:reSetHpMax() + end + + -- 提高生命上限的时候要相应提高生命值 + _Buff._hpChange = function(self) + local oldHpMax = self.owner.hpMax + self.owner:reSetHpMax() + + local curValue = self.owner.hpMax - oldHpMax + if curValue > 0 then + self.owner:recover(curValue, self.release) -- 防止release不存在,地图点buff + elseif curValue < 0 then + self.owner:hurt(self.release and self.release:getHurtValue(-curValue) or -curValue, self.release, {hurtType = 2, buffId = self.id}) + end + end + + _Buff._calculate = function(self) + local curValue = 0 if self.buffData.effectValue1 == 0 then --固定值 - self._changeV = self.buffData.effectValue2 + curValue = self.buffData.effectValue2 elseif self.buffData.effectValue1 == 1 then local baseOwner = self.buffData.effectValue4 == 1 and self.owner or self.release local attrs = {[0] = "hp", [1] = "hpMax", [2] = "atk"} - self._changeV = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100 - end - local old = self.owner.hpMax - self.owner.hpMax = math.max(1, self.owner.hpMax + self._changeV) - self._changeV = self.owner.hpMax - old - if self._changeV > 0 then - self.owner:recover(self._changeV, self.release) -- 防止release不存在,地图点buff - elseif self._changeV < 0 then - self.owner:hurt(self.release and self.release:getHurtValue(-self._changeV) or -self._changeV, self.release, {hurtType = 2, buffId = self.id}) - self.owner.hp = math.min(self.owner.hpMax, self.owner.hp) + curValue = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100 end + return curValue + end + + _Buff._effectValue = function(self) + return self:doEffectChange(self._changeV) + end + + _Buff._endBuff = function(self) + self.owner:reSetHpMax() end + + _Buff._effectChange = function(self) + self.owner:reSetHpMax() + end + _Buff._initDB = function(self, data) self._changeV = data.cv end - _Buff._endBuff = function(self, data) - if self._changeV then - self.owner.hpMax = math.max(1, self.owner.hpMax - self._changeV) - self.owner.hp = math.min(self.owner.hpMax, self.owner.hp) - end - end + _Buff._getDB = function(self) return {cv = self._changeV} end @@ -137,61 +198,23 @@ local BuffFactory = { commonAttr(_Buff, attrName) end, - [Buff.ATTR_CHANGE] = function(_Buff) + [Buff.ATTR_CHANGE_COND] = function(_Buff) local attrName = AttsEnumEx[_Buff.buffData.effectValue3] commonAttCond(_Buff, attrName) end, - [Buff.BACK_HURT] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2, self.buffData.effectValue3 - end - end, - - [Buff.HURT_CHANGE] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 - end - end, - - [Buff.INJURED_CHANGE] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2, self.buffData.effectValue3 - end - end, - - [Buff.HURT_TRANSFER] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 - end - end, - - [Buff.HURT_ABSORB] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 - end - end, - - [Buff.CHANGE_DROP] = function(_Buff) - _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 - end - end, - [Buff.CHANGE_DROP_TO_CLICK] = function(_Buff) _Buff._effectValue = function(self) + -- id return self.buffData.effectValue1 end end, [Buff.IMMNUE_BUFF] = function(_Buff) - _Buff._init = function(self, data) - self.count = self.buffData.effectValue3 - end _Buff._canEffect = function(self, buffId, buffGroup) local cType, aim = self.buffData.effectValue1, self.buffData.effectValue2 - if (cType == 0 and buffId == aim) or (cType == 1 and buffGroup == aim) then + if buffData.dispel == 0 and (not cType or (cType == 0 and buffId == aim) or (cType == 1 and buffData.group == aim)) then return true end end @@ -199,17 +222,19 @@ local BuffFactory = { [Buff.CLEAR_BUFF] = function(_Buff) _Buff._init = function(self, data) - self.count = self.buffData.effectValue3 for _, buff in ipairs(self.buffs) do -- 挂上就清除一下子 - if not buff.isDel and self:canEffect(buff.id, buff:getGroup()) then - buff.isDel = true - self:effect() + if not buff.isDel and self:canEffect(buff.id) and not self.isDel then + if not buff.isDel and not self.isDel then + self:effect() + buff:uncover() + end end end end - _Buff._canEffect = function(self, buffId, buffGroup) + _Buff._canEffect = function(self, buffId) + local buffData = csvdb["adv_map_buffCsv"][buffId] local cType, aim = self.buffData.effectValue1, self.buffData.effectValue2 - if (cType == 0 and buffId == aim) or (cType == 1 and buffGroup == aim) then + if buffData.dispel == 0 and (not cType or (cType == 0 and buffId == aim) or (cType == 1 and buffData.group == aim)) then return true end end @@ -221,78 +246,114 @@ local BuffFactory = { self.owner.battle.adv:openBlockRand(roomNum) end _Buff._effectValue = function(self) - return self.buffData.effectValue1 + -- 数量 + return self.buffData.effectValue1 * self.layer end end, [Buff.SP_CHANGE] = function(_Buff) - --cType 0 or nil 值 1 百分比 _Buff._afterRound = function(self) - local value, cType = self:effect() + local cType, value = self:effect() self.owner:changeSp(value, cType) end _Buff._effectValue = function(self) - return self.buffData.effectValue2, self.buffData.effectValue1 + -- 值/% 数量 + return self.buffData.effectValue1, self:doEffectChange(self.buffData.effectValue2) * self.layer end end, - [Buff.HP_CHANGE_NOW] = function(_Buff) - _Buff._init = function(self, data) --初始化变化值 - self._changeV = 0 - if self.buffData.effectValue1 == 0 then --固定值 - self._changeV = self.buffData.effectValue2 - elseif self.buffData.effectValue1 == 1 then - local baseOwner = self.buffData.effectValue4 == 1 and self.owner or self.release - local attrs = {[0] = "hp", [1] = "hpMax", [2] = "atk"} - self._changeV = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100 - end - if self._changeV < 0 then - self._changeV = self.release and -self.release:getHurtValue(-self._changeV) or self._changeV - end - end - _Buff._initDB = function(self, data) - self._changeV = data.cv - end + [Buff.EXP_ADD] = function(_Buff) _Buff._afterRound = function(self) local value = self:effect() - if value > 0 then - self.owner:recover(value, self.release) - elseif value < 0 then - self.owner:hurt(-value, self.release, {hurtType = self.buffData.effectValue5 == "1" and 6 or 2, buffId = self.id}) - end + self.owner.battle.player:addExp(value) end _Buff._effectValue = function(self) - return self._changeV - end - _Buff._getDB = function(self) - return {cv = self._changeV} + -- 经验值 + return self.buffData.effectValue1 * self.layer end end, - [Buff.EXP_ADD] = function(_Buff) - --cType 0 or nil 值 1 百分比 - _Buff._afterRound = function(self) - local value = self:effect() - self.owner.battle.player:addExp(value) - end + [Buff.DISABLE_BUFF] = function(_Buff) _Buff._effectValue = function(self) return self.buffData.effectValue1 end end, - [Buff.EXP_UP] = function(_Buff) - --cType 0 or nil 值 1 百分比 + [Buff.SP_MAX_CHANGE] = function(_Buff) + _Buff._init = function(self, data) --初始化变化值 + self:_spChange() + end + _Buff._overlay = function(self) + self:_spChange() + end + + _Buff._uncover = function(self) + self.owner:reSetSpMax() + end + + _Buff._spChange = function(self) + local oldSpMax = self.owner.spMax + self.owner:reSetSpMax() + + local curValue = self.owner.spMax - oldSpMax + self.owner:changeSp(curValue) + end + + _Buff._endBuff = function(self) + self.owner:reSetSpMax() + end + + _Buff._effectValue = function(self) + return self.buffData.effectValue1, self.buffData.effectValue2 * self.layer + end + end + + [Buff.ITEM_GET_UP] = function(_Buff) _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 + -- 值/% 数量 id + return self.buffData.effectValue1, self.buffData.effectValue2 * self.layer, self.buffData.effectValue3 end end, - [Buff.DISABLE_BUFF] = function(_Buff) + + -- 影响到的buff类型 1=生命变化、2=生命上限、3=属性变化、6=伤害变化、7=受伤变化、15=回魔、16=生命变化 (胡博文) + [Buff.Buff_EFFECT_CHANGE] = function(_Buff) + _Buff._init = function(self) + -- 先给自己的buff 搞一下子 + for _, buff in ipairs(self.owner.buffs) do + if not buff.isDel and buff.classify == self.buffData.effectValue1 then + buff:effectChange() + end + end + end _Buff._effectValue = function(self) - return self.buffData.effectValue1 + return self.buffData.effectValue1, self.buffData.effectValue2 * self.layer + end + _Buff._overlay = function(self) + self:_init() + end + _Buff._uncover = function(self) + self:_init() end end, } +-- 同样的返回 effectValue1, effectValue2 * self.layer 类型的buff +local function CommonFuncBackEffect12(_Buff) + _Buff._effectValue = function(self) + return self.buffData.effectValue1, self:doEffectChange(self.buffData.effectValue2) * self.layer + end +end + +BuffFactory[Buff.BACK_HURT] = CommonFuncBackEffect12 -- 值/% 数量 +BuffFactory[Buff.HURT_CHANGE] = CommonFuncBackEffect12 -- 值/% 数量 +BuffFactory[Buff.INJURED_CHANGE] = CommonFuncBackEffect12 -- 值/% 数量 +BuffFactory[Buff.HURT_TRANSFER] = CommonFuncBackEffect12 -- 值/% 数量 +BuffFactory[Buff.HURT_ABSORB] = CommonFuncBackEffect12 -- 值/% 数量 +BuffFactory[Buff.CHANGE_DROP] = CommonFuncBackEffect12 -- id 数量 +BuffFactory[Buff.EXP_UP] = CommonFuncBackEffect12 -- 值/% 数量 +-- 历史遗留问题 +BuffFactory[Buff.HP_CHANGE_NOW] = BuffFactory[Buff.HP_CHANGE] + function Buff:ctor(owner, id) self.owner = owner self.id = id @@ -301,6 +362,7 @@ function Buff:ctor(owner, id) self.roundSpace = 0 --生效间隔 self.round = 0 --剩余的回合 self.count = -1 -- 可生效的次数 -1 无次数限制 + self.layer = 1 -- 当前buff 层数 if BuffFactory[self.buffData.type] then BuffFactory[self.buffData.type](self) @@ -322,6 +384,8 @@ end function Buff:initNew(release, data) self.release = release or self.owner self.round = self.buffData.round + self.roundSpace = 0 --生效间隔 + self.layer = 1 if self.buffData.effectTime > 0 then self.count = self.buffData.effectTime end @@ -339,11 +403,11 @@ function Buff:initByDB(data) end end self.round = data.round - self.roundSpace = data.roundSp -- 可以优化为0的时候不记录 + self.roundSpace = data.roundSp if data.count then self.count = data.count end - + self.layer = data.layer or 1 if self._initDB then self:_initDB(data) end @@ -352,6 +416,13 @@ end function Buff:afterRound() if self.isDel or self.owner.isDead then return end + + -- keepTerm 检查 + if not self:checkKeep() then + self.isDel = true + return + end + if self.roundSpace > 0 then self.roundSpace = self.roundSpace - 1 self:decRound() @@ -366,6 +437,56 @@ function Buff:afterRound() self:decRound() end +-- 只使用owner 和 buffData +function Buff:checkKeep() + if self.buffData.keepTerm == "" then return true end + --[[ + 1=怪物id; + 2=建筑id; + 3=事件id + 4=队伍为特定属性时 + --]] + + local checkFunc = {} + checkFunc[1] = function(_, enemyId) + local enemys = self.owner.battle.player:getTeam(2) + for _, enemy in pairs(enemys) do + if enemy.monsterId == enemyId then + return true + end + end + return false + end + checkFunc[2] = function(_, buildId) + for roomId, room in pairs(self.owner.battle.adv:getCurMap().rooms) do + for blockId, block in pairs(room.blocks) do + if block.isOpen and block:getEventType() == AdvEventType.Build and block.event.id == buildId then + return true + end + end + end + return false + end + checkFunc[3] = function(_, chooseId) + for roomId, room in pairs(self.owner.battle.adv:getCurMap().rooms) do + for blockId, block in pairs(room.blocks) do + if block.isOpen and (block:getEventType() == AdvEventType.Choose or block:getEventType() == AdvEventType.LinkChoose) and block.event.id == chooseId then + return true + end + end + end + return false + end + checkFunc[4] = function(_, teamAttr) + local role = self.owner.battle.adv.owner + return role:getHerosCamp(role:getProperty("advTeam").heros) == teamAttr + end + + local keepTerm = self.buffData.keepTerm:toArray(true, "=") + if not checkFunc[keepTerm[1]] then return true end + return checkFunc[keepTerm[1]](table.unpack(keepTerm)) +end + function Buff:decRound() if self.buffData.round <= 0 then return @@ -415,8 +536,69 @@ function Buff:decCount() end end -function Buff:getGroup() - return self.buffData.group +function Buff:getOverlay() + if self.buffData.overlay == "" then + return false + end + local otype, layer = table.unpack(self.buffData.overlay:toArray(true, "=")) + if otype == 1 then -- 叠加 + return true, layer or 0 -- 0 叠加无数层 + end + return false +end + +-- 叠加 +function Buff:overlay(releaser, data) + local otype, maxLayer = self:getOverlay() + if self.isDel or not otype then -- 新获得的 (不可叠加相当于新获得的) + self.isDel = false + self:endBuff() + self:initNew(releaser, data) + else + -- 重置回合 次数 + self.roundSpace = 0 + self.round = self.buffData.round + if self.buffData.effectTime > 0 then + self.count = self.buffData.effectTime + else + self.count = -1 + end + + self.release = releaser or self.release + -- 叠加层数 + self.layer = self.layer + 1 + if maxLayer ~= 0 then + self.layer = math.min(maxLayer, self.layer) + end + if self._overlay then + self:_overlay() + end + end +end + +-- 扣减层数 +function Buff:uncover() + if self.layer <= 1 then + self.isDel = true + end + + self.layer = self.layer - 1 + if self._uncover then + self:_uncover() + end +end + +-- buff 效果增益减益 +function Buff:effectChange() + if self._effectChange then + self:_effectChange() + end +end + +function Buff:doEffectChange(effect) + if not self.buffData.classify then return effect end + local change = self.owner:getBuffEffectChange(self.buffData.classify) + return effect * (1 + change) end function Buff:getDB() @@ -435,6 +617,7 @@ function Buff:getDB() if self.count ~= -1 then db.count = self.count end + db.layer = self.layer return db end diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index 63edd3d..2651a83 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -31,6 +31,7 @@ function BaseObject:initData(data) self._miss = data._miss or self.miss self._hit = data._hit or self.hit self._def = data._def or self.def + self._hpMax = data._hpMax or self.hpMax end -- 角色初始化完以后才是 技能和被动技能 方便初始化 buff 的 释放对象 function BaseObject:initAfter(data) @@ -124,30 +125,51 @@ function BaseObject:addBuff(buffId, releaser) if not buffData then return end for _, buff in ipairs(self.buffs) do if not buff.isDel and (buff:getType() == Buff.CLEAR_BUFF or buff:getType() == Buff.IMMNUE_BUFF) then - if buff:canEffect(buffId, buffData.group) then + if buff:canEffect(buffId) then buff:effect() return end end end - table.insert(self.buffs, Buff.create(self, releaser, {id = buffId})) - + local oldBuff = self:getBuffById(buffId) + if oldBuff then + if not oldBuff:checkKeep() then return end + oldBuff:overlay(releaser, {}) -- 叠加 + else + -- 不能保持的buff 也加不上去 + if not Buff.checkKeep({ + owner = self, + buffData = buffData, + }) then return end + table.insert(self.buffs, Buff.create(self, releaser, {id = buffId})) + end self.battle.adv:backBuff(self.id, buffId) end +function BaseObject:getBuffById(bId) + for idx, buff in ipairs(self.buffs) do + if buff.id == bId then + return buff + end + end +end + function BaseObject:delBuffById(bId) - for _, buff in ipairs(self.buffs) do - if not buff.isDel and buff.id == bId then - buff.isDel = true + for idx, buff in ipairs(self.buffs) do + if buff.id == bId then + self.battle.adv:backBuff(self.id, buff.id, true) + buff:endBuff() + table.remove(self.buffs, idx) return buff end end end function BaseObject:delPassiveById(pId) - for _, passive in ipairs(self.passives) do - if not passive.isDel and passive.id == pId then - passive.isDel = true + for idx, passive in ipairs(self.passives) do + if passive.id == pId then + passive:endPassive() + table.remove(self.passives, idx) return passive end end @@ -171,12 +193,12 @@ end -- 通用的buff 效果汇总 -- 0 固定 1百分比 两种分类 -function BaseObject:getCommonBuffEffect(bType) +function BaseObject:getCommonBuffEffect(bType, otherCond) local effect, count = {[0] = 0, [1] = 0}, 0 for _, buff in ipairs(self.buffs) do if not buff.isDel and buff:getType() == bType then - local cType, value = buff:effect() - if cType then + local cType, value, cond = buff:effect() + if cType and (not otherCond or otherCond == cond) then effect[cType] = effect[cType] + value count = count + 1 end @@ -186,15 +208,13 @@ function BaseObject:getCommonBuffEffect(bType) return effect, count --效果 和生效的buff 个数 end --伤害反弹 -function BaseObject:getBackHurtBuff(isAtk) +function BaseObject:getBackHurtBuff() local effect = {[0] = 0, [1] = 0} for _, buff in ipairs(self.buffs) do if not buff.isDel and buff:getType() == Buff.BACK_HURT then - local cType, value, aType = buff:effect() -- aType 0 全部 1 普通攻击 + local cType, value = buff:effect() -- aType 0 全部 1 普通攻击 if cType then - if aType == 0 or isAtk then - effect[cType] = effect[cType] + value - end + effect[cType] = effect[cType] + value end end end @@ -211,12 +231,50 @@ function BaseObject:getInjuredChange() local change = self:getCommonBuffEffect(Buff.INJURED_CHANGE) return change end +-- 奖励道具变化 +function BaseObject:getRewardChange(itemId) + local change = self:getCommonBuffEffect(Buff.ITEM_GET_UP, itemId) + return change +end + +-- buff 增益 检疫 +function BaseObject:getBuffEffectChange(classify) + local effect = 0 + for _, buff in ipairs(self.buffs) do + if not buff.isDel and buff:getType() == Buff_EFFECT_CHANGE then + local cType, value = buff:effect() + if cType and cType == classify then + effect = effect + value + end + end + end + effect = effect / 100 + return effect +end + +function BaseObject:getAttrBuffChange(attr) + local AttrBuff = { + [Buff.ATTR_CHANGE] = 1, + [Buff.ATTR_CHANGE_COND] = 1, + } + local effect, count = {[0] = 0, [1] = 0}, 0 + for _, buff in ipairs(self.buffs) do + if not buff.isDel and AttrBuff[buff:getType()] then + local cType, value, attrName = buff:effect() + if cType and attr == attrName then + effect[cType] = effect[cType] + value + count = count + 1 + end + end + end + effect[1] = effect[1] / 100 + return effect, count +end --重新计算属性 function BaseObject:reSetAttr(field) local old = self[field] self[field] = self["_" .. field] --重置一下 - local fieldToBuff = {atk = Buff.ATK_CHANGE, hit = Buff.HIT_CHANGE, miss = Buff.MISS_CHANGE, def = Buff.DEF_CHANGE} - local effect = self:getCommonBuffEffect(fieldToBuff[field]) + local effect = self:getAttrBuffChange(field) self[field] = math.ceil((self[field] + effect[0]) * (1 + effect[1])) local delta = self[field] - old if delta ~= 0 then @@ -228,6 +286,21 @@ function BaseObject:reSetAttr(field) end end +-- 重新计算 血量上限 +function BaseObject:reSetHpMax() + self.hpMax = self._hpMax + for _, buff in ipairs(self.buffs) do + if not buff.isDel and buff:getType() == Buff.HP_MAX_CHANGE then + local cv = buff:effect() + if cv then + self.hpMax = self.hpMax + cv + end + end + end + self.hpMax = math.max(1, self.hpMax) + self.hp = math.min(self.hpMax, self.hp) +end + --计算打出伤害加成后的值 function BaseObject:getHurtValue(value) value = value or self.atk @@ -306,7 +379,7 @@ function BaseObject:hurt(value, releaser, params) if value == 0 then return end -- 反弹伤害 if params.hurtType ~= 3 and params.hurtType ~= 5 and releaser and not releaser.isDead then - local backEffect = self:getBackHurtBuff(params.hurtType == 1) + local backEffect = self:getBackHurtBuff() local backValue = math.max(0, value * backEffect[1] + backEffect[0]) releaser:hurt(backValue, releaser, {hurtType = 3}) end @@ -408,9 +481,8 @@ end function BaseObject:getDB() local db = {} - db.hpMax = self.hpMax db.hp = self.hp - local baseAttr = {"atk", "miss", "hit", "def"} + local baseAttr = {"atk", "miss", "hit", "def", "hpMax"} for _, field in pairs(baseAttr) do db[field] = self[field] db["_"..field] = self["_" .. field] @@ -465,9 +537,11 @@ end function Player:initData(data) Player.super.initData(self, data) self.level = data.level or 1 --level 每增加1级 属性增长 growth * baseAttr - self.growth = data.growth or 0 + self.growth = data.growth self.exp = data.exp or 0 self.sp = data.sp or 100 + self.spMax = data.spMax or 100 + self._spMax = data._spMax or 100 end function Player:addExp(value) @@ -488,15 +562,14 @@ function Player:addExp(value) end local delta = level - self.level if delta > 0 then - local baseAttr = csvdb["adv_unitCsv"][self.battle.adv.chapterId] - for _, attr in pairs(AttsEnumEx) do - if baseAttr[attr] then - self[attr] = self[attr] + self.growth * delta - if attr == "hp" then - self.hpMax = self.hpMax + self.growth * delta - else - self["_" .. attr] = self["_" .. attr] + self.growth * delta - end + for _, attr in pairs(AdvAttsEnum) do + if attr == "hp" then + self[attr] = self[attr] + self.growth[attr] * delta + self._hpMax = self._hpMax + self.growth[attr] * delta + self:reSetHpMax() + else + self["_" .. attr] = self["_" .. attr] + self.growth[attr] * delta + self:reSetAttr(attr) end end end @@ -512,10 +585,19 @@ function Player:changeSp(value, cType) elseif cType == 1 then self.sp = self.sp + self.sp * value / 100 end - self.sp = math.floor(math.max(0, self.sp)) + self.sp = math.floor(math.min(self.spMax, math.max(0, self.sp))) self.battle.adv:pushBackEvent(AdvBackEventType.SpChange) end +-- 重新计算 魔法上限 +function BaseObject:reSetSpMax() + self.spMax = self._spMax + local change = self:getCommonBuffEffect(Buff.SP_MAX_CHANGE) + self.spMax = math.ceil((self.spMax + change[0]) * (1 + change[1])) + self.spMax = math.max(1, self.spMax) + self.sp = math.min(self.spMax, self.sp) +end + --战斗结束了扣战斗buff次数 function Player:effectBattleBuff() for _, buff in ipairs(self.buffs) do @@ -535,9 +617,10 @@ end function Player:getDB() local db = Player.super.getDB(self) - for _ , field in pairs({"level", "exp", "growth", "sp"}) do + for _ , field in pairs({"level", "exp", "growth", "sp", "spMax"}) do db[field] = self[field] end + db["_spMax"] = self._spMax return db end diff --git a/src/adv/AdvTask.lua b/src/adv/AdvTask.lua index d408cb3..417fee6 100644 --- a/src/adv/AdvTask.lua +++ b/src/adv/AdvTask.lua @@ -260,8 +260,7 @@ function AdvTask.bind(Adv) if status == -1 or count < achievData.pt then return end local reward = self.owner:award(achievData.reward) - self.owner:changeUpdates({{type = "advAchiev", field = {chapterId, "pts", taskId}, value = -1}}, notNotify) - + insertChange(chapterId, taskId, -1) return true, reward end diff --git a/src/models/Role.lua b/src/models/Role.lua index c44570b..cc929fd 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -65,7 +65,9 @@ Role.schema = { advL = {"table", {0, 0}}, -- 冒险队等级 {lv, winCount} advElM = {"number", 0}, -- 无尽模式通关的最高层数 endless max layer advElS = {"number", globalCsv.adv_endless_season}, -- 无尽模式记录的赛季 endless season - advAFOpen = {"table", {}}, -- 解锁的神器 + advAFOpen = {"table", {}}, -- 解锁的神器 {[id] = 1} + advAFGet = {"table", {}}, -- 当前拥有的神器 {[id] = 等级} + advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id} --挂机相关 hangPass = {"table", {}}, -- 挂机通过的最大关卡 @@ -244,6 +246,8 @@ function Role:data() advAchiev = self:getProperty("advAchiev"), advL = self:getProperty("advL"), advElM = self:getProperty("advElM"), + advAFGet = self:getProperty("advAFGet"), + advAFWear = self:getProperty("advAFWear"), hangPass = self:getProperty("hangPass"), hangTeam = self:getProperty("hangTeam"), diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 60929c9..20c3497 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -641,6 +641,25 @@ function RolePlugin.bind(Role) return result end + function Role:getHerosCamp(heros) + local had = {} + for _, id in pairs(heros or {}) do + local hero = self.heros[id] + if hero then + local camp = csvdb["unitCsv"][hero:getProperty("type")].camp + had[camp] = (had[camp] or 0) + 1 + end + end + local curCamp = 0 + for camp , count in pairs(had) do + if count >= 3 then + curCamp = camp + break + end + end + return curCamp + end + function Role:getRealBattleValue(heros, activeRelation) -- 获取队伍战斗力 羁绊加成 heros = heros or {} local activeRelation = activeRelation or self:getHeroActiveRelation(heros) @@ -673,6 +692,23 @@ function RolePlugin.bind(Role) return self:getProperty("funcLv")[func] or 1 end + -- 参数有level 则是检查是否可以升级 + function Role:isArtifactOpen(id, isEndless, level) + local isCheckLevel = not not level + level = level or 1 + local curData = (csvdb["adv_artifactCsv"][id] or {})[level] + if not curData then return false end + + if curData.unlock == 1 then -- 获得解锁 + return self:getProperty("advAFOpen")[id] and true or false + elseif temp[1].unlock == 2 then -- 特殊神器 不可解锁 + return isCheckLevel + elseif temp[1].unlock == 3 then + return isEndless + end + return true + end + function Role:funcOpen(func, count) count = count or 1 if csvdb["itemCsv"][func] and csvdb["itemCsv"][func].type == ItemType.FuncOpen then -- libgit2 0.21.2