From 4f0a5faeacb8e70e036011cc850f53debe3d9aa5 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Mon, 6 Jan 2020 16:25:32 +0800 Subject: [PATCH] 营养剂 --- src/GlobalVar.lua | 2 ++ src/actions/AdvAction.lua | 29 ++++++++++++++++++++++++----- src/adv/Adv.lua | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/adv/AdvBattle.lua | 12 ++++++++++++ src/adv/AdvBlock.lua | 14 ++++++++++++-- src/adv/AdvBuff.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/adv/AdvMap.lua | 29 +++++++++++++++++++++++++++++ src/adv/AdvPassive.lua | 4 ++++ src/adv/AdvPlayer.lua | 23 ++++++++++++++++++++++- 9 files changed, 324 insertions(+), 14 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 55374e7..aef19f3 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -78,6 +78,7 @@ ItemId = { EquipUp = 11, -- 装备升级材料 DinerCoin = 12, --后勤物资 LoveUp = 14, --好感度提升道具 + OldCoin = 15, --古代金币 DinerSpTask = 20, -- 餐厅任务采购券 LoveBreak = 21, --好感度突破道具 PvpKey = 22, -- pvp钥匙 @@ -130,6 +131,7 @@ AdvBackEventType = { BattleBegin = 16, -- 战斗开始 Trap = 17, --陷阱 Layer = 18, --切换层 + MapShow = 19, -- 展示地图 } AdvScoreType = { diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 31a8fc9..b55d2ef 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -281,13 +281,32 @@ end function _M.usePotionRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) - local dishLevel = role.dinerData:getProperty("dishTree"):getv(msg.potionId, 0) - if dishLevel == 0 then - return - end + local potionId = msg.potionId -- 营养剂Id + local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标 + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) + if potionLv == 0 then return 1 end + + local potionSet = csvdb["adv_potionCsv"][potionId] + if not potionSet then return 2 end + + local potionData = potionSet[potionLv] + if not potionData then return 3 end + + local potionBag = role:getProperty("potionBag") + local own = potionBag[potionId] or 0 + if own <= 0 then return 4 end + local adv = role:getAdvData() - local status = adv:usePotion(msg.potionId, dishLevel, msg.target) -- target {roomId = 1, blockId = 1} 选择的目标 + + local status = adv:doActive(potionData.effect, target) -- target if not status then return end + + potionBag[potionId] = own - 1 + role:updateProperty({field = "potionBag", value = potionBag}) + adv:afterRound() + adv:saveDB() + role:checkTaskEnter("AdvUsePotion") + SendPacket(actionCodes.Adv_usePotionRpc, MsgPack.pack({events = adv:popBackEvents()})) return true end diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index d657f97..1ffc4d0 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -710,7 +710,10 @@ function Adv:clickBlock(roomId, blockId, params) local _room, _block = one[1], one[2] if _block.isOpen then canOpen = true end if _block.isOpen and _block:isMonster() then - hadMonster = true + local enemy = self.battle:getEnemy(_room.roomId, _block.blockId) + if not enemy:hadBuff(Buff.DONT_DEFEND) then + hadMonster = true + end end end if canOpen and not hadMonster then --开放 @@ -773,10 +776,172 @@ function Adv:useItem(itemId, count, target) return true end +function Adv:doActive(activeId, target) + local activeData = csvdb["adv_activeCsv"][activeId] + if not activeData then return end + + local targers = {} + + -- 筛选对象 + if activeData.usetype == 1 then -- 自己 + elseif activeData.usetype == 2 then -- 敌人 + if not target or not target.roomId or not target.blockId then return end + local block = self:getBlock(target.roomId, target.blockId) + if block:isBoss() then return end + local enemy = self.battle:getEnemy(target.roomId, target.blockId) + if not enemy then return end + local blocks = self:getCurMap():getBlocksBySize(target.roomId, target.blockId, activeData.scope) + for _, block in pairs(blocks) do + if block:isMonster() and not block:isBoss() then + local e = self.battle:getEnemy(block.room.roomId, block.blockId) + if e then + table.insert(targers, e) + end + end + end + elseif activeData.usetype == 3 then -- 地板 + if not target or not target.roomId or not target.blockId then return end + local block = self:getBlock(target.roomId, target.blockId) + if block:isBoss() then return end + local blocks = self:getCurMap():getBlocksBySize(target.roomId, target.blockId, activeData.scope) + for _, block in pairs(blocks) do + if not block:isBoss() then + table.insert(targers, block) + end + end + elseif activeData.usetype == 4 then -- 自己或者没有目标 + elseif activeData.usetype == 5 then -- 空地板 + if not target or not target.roomId or not target.blockId then return end + local block = self:getBlock(target.roomId, target.blockId) + if not block.isOpen or block:getEventType() then return end + local blocks = self:getCurMap():getBlocksBySize(target.roomId, target.blockId, activeData.scope) + for _, block in pairs(blocks) do + if not block:isBoss() then + table.insert(targers, block) + end + end + end + + local doActiveEffect = {} + + -- 1=map_buff_id:为范围内所有目标附加mapbuff + doActiveEffect[1] = function(_, buffId) + if not next(targers) and (activeData.usetype == 1 or activeData.usetype == 4)then + table.insert(targers, self.battle.player) + end + + for _, target in ipairs(targers) do + target:addBuff(buffId, self.battle.player) + end + + return true + end + -- 2=trader_id:召唤商人 + doActiveEffect[2] = function(_, traderId) + for _, target in ipairs(targers) do + if target.isOpen and not target:getEventType() then + target:updateEvent({ + etype = AdvEventType.Trader, + id = traderId, + }) + target:randomEvent() + self:backBlockChange(target.room.roomId, target.blockId) + end + end + return true + end + + -- 3=monster_id:替换怪物,仅使用方式为2时生效 + doActiveEffect[3] = function(_, monsterId) + for _, target in ipairs(targers) do + if not target.lock and not target.isDead then + self.battle:removeEnemyById(target.id) + self:getCurMap():addNewMonsterRand(monsterId, {target.roomId, target.blockId}) + self:backBlockChange(target.roomId, target.blockId) + end + end + return true + end + -- 4:显示本层 + doActiveEffect[4] = function(_) + self:getCurMap():showMap() + self:backMapShow() + return true + end + -- 5:放逐目标 + doActiveEffect[5] = function(_) + for _, target in ipairs(targers) do + if not target.lock and not target.isDead then + self.battle:removeEnemyById(target.id) + local block = self:getBlock(target.roomId, target.blockId) + block:clear() + self:backBlockChange(target.roomId, target.blockId) + end + end + return true + end + -- 6=陷阱id:移除陷阱,不填写id则移除所有陷阱 + doActiveEffect[6] = function(_, trapId) + if not next(targers) and activeData.usetype == 4 then + -- 全屏 + for _, room in pairs(self:getCurMap().rooms) do + for _, block in pairs(room.blocks) do + if block:getEventType() == AdvEventType.Trap then + block:updateEvent(nil) + self:backBlockChange(block.room.roomId, block.blockId) + end + end + end + else + for _ , target in ipairs(targers) do + if target:getEventType() == AdvEventType.Trap then + target:updateEvent(nil) + self:backBlockChange(target.room.roomId, target.blockId) + end + end + end + return true + end + + -- 7=道具燃烧效果 + doActiveEffect[7] = function(_) + for _ , target in ipairs(targers) do + if target:getEventType() == AdvEventType.Drop then + target:updateEvent(nil) + self:backBlockChange(target.room.roomId, target.blockId) + end + end + return true + end + + -- 8:翻开范围内的方格 + doActiveEffect[8] = function(_) + for _ , target in ipairs(targers) do + if not target.isOpen then + target:open() + self:backBlockChange(target.room.roomId, target.blockId) + end + end + return true + end + + for _, effect in ipairs(activeData.effect:toArray()) do + local cur = effect:toArray(true, "=") + if doActiveEffect[cur[1]] then + if not doActiveEffect[cur[1]](table.unpack(cur)) then + return + end + end + end + + return true +end + --使用技能 function Adv:usePotion(potionId, potionLevel, target) -- cost local potionData = csvdb["adv_potionCsv"][potionId][potionLevel] + local enemy = self.battle:getEnemy(target.roomId, target.blockId) if not enemy then return end --生效 @@ -788,9 +953,7 @@ function Adv:usePotion(potionId, potionLevel, target) else return end - self:afterRound() - self:saveDB() - self.owner:checkTaskEnter("AdvUsePotion") + return true end @@ -934,6 +1097,10 @@ function Adv:backLayer() self:pushBackEvent(AdvBackEventType.Layer, {}) end +function Adv:backMapShow() + self:pushBackEvent(AdvBackEventType.MapShow, {}) +end + function Adv:scoreChange(scoreType, pms) local cutTypes = {} local score = 0 diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index 8be6655..b845866 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -161,6 +161,18 @@ function Battle:triggerPassive(condType, params, mapIdx) end end +-- 只是从战斗中移除 从地图中移除 在外面操作 +function Battle:removeEnemyById(id) + local mapIdx = self.adv:getCurMapIdx() + for i = #self.enemys[mapIdx], 1, -1 do + if self.enemys[mapIdx][i].id == id then + local enemy = table.remove(self.enemys[mapIdx], i) + enemy:clear() + break + end + end +end + --回合 function Battle:afterRound() local mapIdx = self.adv:getCurMapIdx() diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index c8c644e..466d61d 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -36,8 +36,8 @@ function Block:clear() self.event = nil end ---事件有需要额外处理的部分 -function Block:open() + +function Block:randomEvent() local room = self.room local map = room.map local adv = map.adv @@ -118,6 +118,16 @@ function Block:open() randomFunc[self:getEventType()]() end end +end + + +--事件有需要额外处理的部分 +function Block:open() + if self.isOpen then return end + local room = self.room + local map = room.map + local adv = map.adv + self:randomEvent() adv.owner:checkTaskEnter("AdvOpenBlock") self.isOpen = true end diff --git a/src/adv/AdvBuff.lua b/src/adv/AdvBuff.lua index 15f1bbe..fc282a2 100644 --- a/src/adv/AdvBuff.lua +++ b/src/adv/AdvBuff.lua @@ -21,6 +21,11 @@ Buff.BATTLE_BUFF = 17 -- 切换为战斗中的buff Buff.CHANGE_DROP = 18 -- 转换掉落 Buff.BATTLE_PASSIVE = 19 -- 切换为战斗中的被动技 Buff.EXP_ADD = 20 -- 增加exp(每回合) +Buff.DONT_DEFEND = 21 -- 不看守地板 -- 怪周围点半可点击 + +Buff.EXP_UP = 24 -- 杀敌经验提高 +Buff.DISABLE_BUFF = 25 -- 禁用固有技 +Buff.ATTR_CHANGE_COND = 26 --属性变化(状态)有条件 --角色一些属性的变化 local function commonAttr(_Buff, attrName) @@ -34,6 +39,28 @@ local function commonAttr(_Buff, attrName) self.owner:reSetAttr(attrName) end end +local function commonAttCond(_Buff, attrName) + _Buff._init = function(self, data) --初始化变化值 + 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) + end + _Buff._initDB = function(self, data) + self._changeV = data.cv + end + _Buff._effectValue = function(self) + return self.buffData.effectValue1, self._changeV + end + _Buff._endBuff = function(self, data) + self.owner:reSetAttr(attrName) + end + _Buff._getDB = function(self) + return {cv = self._changeV} + end +end local BuffFactory = { [Buff.HP_CHANGE] = function(_Buff) @@ -108,6 +135,13 @@ local BuffFactory = { local attrName = AttsEnumEx[_Buff.buffData.effectValue3] commonAttr(_Buff, attrName) end, + + [Buff.ATTR_CHANGE] = 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 @@ -122,7 +156,7 @@ local BuffFactory = { [Buff.INJURED_CHANGE] = function(_Buff) _Buff._effectValue = function(self) - return self.buffData.effectValue1, self.buffData.effectValue2 + return self.buffData.effectValue1, self.buffData.effectValue2, self.buffData.effectValue3 end end, @@ -238,6 +272,18 @@ local BuffFactory = { return self.buffData.effectValue1 end end, + + [Buff.EXP_UP] = function(_Buff) + --cType 0 or nil 值 1 百分比 + _Buff._effectValue = function(self) + return self.buffData.effectValue1, self.buffData.effectValue2 + end + end, + [Buff.DISABLE_BUFF] = function(_Buff) + _Buff._effectValue = function(self) + return self.buffData.effectValue1 + end + end, } function Buff:ctor(owner, id) @@ -314,7 +360,7 @@ function Buff:afterRound() end function Buff:decRound() - if self.buffData.round == 0 then + if self.buffData.round <= 0 then return end self.round = self.round - 1 diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index d87e228..beb1122 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -17,6 +17,7 @@ function Map:ctor(adv, mapIdx, mapInfo) self.mapIdx = mapIdx self.mapId = mapInfo.mapId + self.isShow = mapInfo.isShow -- 是否全部展示 -- 客户端用 self.rooms = {} self:loadRooms(mapInfo.rooms) end @@ -36,6 +37,7 @@ end function Map:getDB() local map = {} map.mapId = self.mapId + map.isShow = self.isShow map.rooms = {} for roomId, room in pairs(self.rooms) do map.rooms[roomId] = room:getDB() @@ -43,6 +45,10 @@ function Map:getDB() return map end +function Map:showMap() + self.isShow = true +end + --结束本层的时候调用 function Map:checkOver() local mapCsv = csvdb["mapCsv"][self.mapId] @@ -159,6 +165,29 @@ function Map:getAroundBlocks(room, block) return blocks end +function Map:getBlocksBySize(roomId, blockId, size) + local blocks = {} + local room = self.rooms[roomId] + if not room then return end + local block = room.blocks[blockId] + if not block then return end + + local col, row = room:tranLtoG(block.col, block.row) + + size = math.floor(size / 2) + for c = col - size, col + size do + for r = row - size, row + size do + local rroom, rblock = self:getRBByPos(c, r) + if rroom then + table.insert(blocks, rblock) + end + end + end + return blocks +end + + + -----------------------------随机地图----------------------------- createMap = function(self, mapId) diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 21097f0..6481543 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -235,6 +235,10 @@ function Passive:canEffect(effType, effValue) if self.owner.lock and effType ~= 3 then -- 锁定的只能触发翻开自己格子的固有技 return end + --禁用被动技 + if self.owner:getPassiveIdx(self) <= self.owner:getDisablePassiveCount() then + return + end return true end diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index e2470c5..fe5d409 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -58,7 +58,6 @@ function BaseObject:afterRound() end end - function BaseObject:clearRound() for i = #self.passives, 1, -1 do if self.passives[i].isDel then @@ -102,6 +101,24 @@ function BaseObject:addPassive(params) self.battle.adv:backPassive(self.id, skillId) end +function BaseObject:getPassiveIdx(passive) + for idx, passive_ in ipairs(self.passives) do + if passive_ == passive then + return idx + end + end +end + +function BaseObject:getDisablePassiveCount() + local count = 0 + for _, buff in ipairs(self.buffs) do + if not buff.isDel and buff:getType() == Buff.DISABLE_BUFF then + count = count + buff:effect() + end + end + return count +end + function BaseObject:addBuff(buffId, releaser) local buffData = csvdb["adv_map_buffCsv"][buffId] if not buffData then return end @@ -454,6 +471,10 @@ function Player:initData(data) end function Player:addExp(value) + -- buff 经验加成 + local up = self:getCommonBuffEffect(Buff.EXP_UP) + value = math.ceil((value + up[0]) * (1 + up[1])) + if value <= 0 then return end local newExp = self.exp + value local level = self.level -- libgit2 0.21.2