diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 44dc569..d851e16 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -99,7 +99,7 @@ AdvBackEventType = { Next = 7, --进入下一层 End = 8, -- 结束 BlockChange = 9, -- 块改变 - PowerChange = 10, --体力改变 + SpChange = 10, --体力改变 Dead = 11, --怪死亡 DefChange = 12, -- 防御变化 Passive = 13, -- 獲得被動 diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 18b0433..077cf00 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -35,8 +35,6 @@ actionCodes = { Adv_useItemRpc = 154, Adv_usePotionRpc = 155, Adv_exitAdvRpc = 156, - Adv_nextTurnRpc = 157, - Adv_specialSkillRpc = 158, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 4d2d91a..30f9fac 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -90,17 +90,6 @@ function _M.usePotionRpc(agent, data) return true end ---使用战斗技能 -function _M.specialSkillRpc(agent, data) - local role = agent.role - local msg = MsgPack.unpack(data) - local adv = role:getAdvData() - local status = adv:useSpecialSkill(msg.skillId) - -- if not status then return end - SendPacket(actionCodes.Adv_specialSkillRpc, MsgPack.pack({})) - return true -end - --退出 function _M.exitAdvRpc(agent, data) local role = agent.role @@ -111,18 +100,5 @@ function _M.exitAdvRpc(agent, data) return true end ---继续战斗 -function _M.nextTurnRpc(agent, data) - local role = agent.role - local msg = MsgPack.unpack(data) - local adv = role:getAdvData() - local status = adv:nextBattleTurn(msg.turn) - if not status then -- 数据不同步则发送缓存数据 - SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv.tempBackEvents})) - return true - end - SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv:popBackEvents()})) - return true -end return _M \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 5399422..3a085fb 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -112,7 +112,6 @@ local function randomAdvMap(role, chapterId, level, notNotify) local lastMapId = advInfo.mapId --非同一层不连续随出同一张类似的地图 local lastChapterId = advInfo.chapter local lastScore = advInfo.score or {} -- 分数 - local power = advInfo.power or 100 --MP local pool = {} for _, mapId in ipairs(raw_pool) do @@ -139,7 +138,6 @@ local function randomAdvMap(role, chapterId, level, notNotify) advInfo.chapter = chapterId advInfo.level = level advInfo.mapId = mapId - advInfo.power = power advInfo.score = lastScore advInfo.enemyId = 1 --怪递增的索引 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁 @@ -947,22 +945,6 @@ function Adv:clickBlock(roomId, blockId, params) return status end ---继续战斗 -function Adv:nextBattleTurn(turn) - local enemy = self.battle.enemy - if not enemy or self.battle:checkTurn(turn) then - return - end - local roomId, blockId = self.battle:getRBByEnemyId(enemy.id) - self.battle:doBattleTurn() - if self.battle:isBattleEnd() then - self:backBlockChange(roomId, blockId) - self:afterRound() - end - self:saveDB() - return true -end - --使用道具产生效果 function Adv:useItem(itemId, count, target) count = count or 1 @@ -994,9 +976,6 @@ end function Adv:usePotion(potionId, potionLevel, target) -- cost local potionData = csvdb["adv_potionCsv"][potionId][potionLevel] - -- if self.advInfo.power < skillData.cost then return end - -- self.advInfo.power = self.advInfo.power - skillData.cost - -- target local enemy = self.battle:getEnemy(target.roomId, target.blockId) if not enemy then return end --生效 @@ -1013,29 +992,6 @@ function Adv:usePotion(potionId, potionLevel, target) return true end ---使用战斗技能 -function Adv:useSpecialSkill(skillId) - if not csvdb["adv_skill_specialCsv"][skillId] or self.battle:isBattleEnd() then return end - local skillLevel = nil - for slot, heroId in pairs(self.advTeam.heros) do - if self.owner.heros[heroId] then - if csvdb["unitCsv"][self.owner.heros[heroId]:getSkinId()]["adv"] == skillId then - skillLevel = self.owner.heros[heroId]:getSkillLevel(2) - break - end - end - end - if not skillLevel or not csvdb["adv_skill_specialCsv"][skillId][skillLevel] then return end - local skillData = csvdb["adv_skill_specialCsv"][skillId][skillLevel] - --cost - if self.advInfo.power < skillData.cost then return end - self:changePower( -skillData.cost, 0) - -- self.advInfo.power = self.advInfo.power - skillData.cost - local enemy = self.battle.enemy - self.battle.player:addSpecialSkill(skillId, skillLevel, enemy) - return true -end - --敌人死亡 function Adv:enemyDead(roomId, blockId, escape) local room = self.rooms[roomId] @@ -1072,17 +1028,6 @@ function Adv:enemyDead(roomId, blockId, escape) self:backBlockChange(roomId, blockId) end ---cType 0 or nil 值 1 百分比 -function Adv:changePower(value, cType) - cType = cType or 0 - if cType == 0 then - self.advInfo.power = self.advInfo.power + value - elseif cType == 1 then - self.advInfo.power = self.advInfo.power + self.advInfo.power * value / 100 - end - self.advInfo.power = math.floor(math.max(0, self.advInfo.power)) - self:pushBackEvent(AdvBackEventType.PowerChange) -end function Adv:pushBackEvent(btype, params) table.insert(self.backEvents, {btype = btype, params = params}) @@ -1144,14 +1089,6 @@ function Adv:backDead(enemyId) self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) end -function Adv:backTurnEnd() - self:pushBackEvent(AdvBackEventType.TurnEnd, {}) -end - -function Adv:backBattleBegin() - self:pushBackEvent(AdvBackEventType.BattleBegin, {}) -end - function Adv:backTrap() self:pushBackEvent(AdvBackEventType.Trap, {}) end diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index 8581925..ab5e865 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -6,7 +6,6 @@ function Battle:ctor(adv) self.adv = adv self.player = nil --玩家 self.isNewPlayer = false - self.enemy = nil self.enemys = {} --怪 self.tempData = {} -- 临时回合数据 self:initPlayer() @@ -22,10 +21,6 @@ function Battle:initAfter() for _, enemy in pairs(self.enemys) do enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) end - if self.adv.advTeam.enemyId then - local enemy = self:getEnemyById(self.adv.advTeam.enemyId) - self.enemy = enemy - end end --[[ 队伍总属性 = 基础属性 + 等级 × 成长率 @@ -56,6 +51,7 @@ function Battle:initPlayer() player.growth = (self.adv.owner:getRealBattleValue(self.adv.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"][math.floor(self.adv.advInfo.chapter / 100)] for _, attr in pairs(AttsEnumEx) do @@ -121,75 +117,6 @@ function Battle:getRBByEnemyId(enemyId) return enemy.roomId, enemy.blockId end -function Battle:isBattleEnd() - if not self.enemy then - return true - end -end - ---战斗开始 -function Battle:battleBegin(roomId, blockId, isQuick) - self.tempData = {} -- 清理上次战斗数据 - if self.enemy then - self.player:reset(self.adv.advTeam.player) - self.enemy:reset(self.adv.rooms[self.enemy.roomId].blocks[self.enemy.blockId].event.enemy) - end - local enemy = self:getEnemy(roomId, blockId) - if enemy then - self.adv:backBattleBegin() - self.enemy = enemy - self.player:battleBegin() - self.enemy:battleBegin() - if not isQuick then - self:doBattleTurn() - return - end - while not enemy.isDead and not self.player.isDead do - self:doBattleTurn() - end - end -end - --- 检查回合数同步 -function Battle:checkTurn(turn) - if self.tempData[turn] then - return true - end -end - --- 战斗内一回合 -function Battle:doBattleTurn() - local enemy = self.enemy - -- 玩家先出手 - self.adv:backAtk(nil, enemy.id) - self:doPlayerTurn(self.player, enemy) - --是否无法攻击 - if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then - self.adv:backAtk(enemy.id, nil) - self:doPlayerTurn(enemy, self.player) - end - -- 判定死亡 - if enemy.isDead or self.player.isDead then - local deadPlayer = enemy.isDead and enemy or self.player - deadPlayer:battleEnd() - self.enemy = nil - else - self.adv:backTurnEnd() - end - self:getTempDB() -end - ---战斗内角色回合逻辑 -function Battle:doPlayerTurn(atkPlayer, hurtPlayer) - atkPlayer:beforeTurn() - if #(atkPlayer.skillOrder) > 0 then - atkPlayer:releaseSpecialSkill() - else - hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) - end - atkPlayer:afterTurn() - atkPlayer:clearTurn() -end --触发全员被动技能 function Battle:triggerPassive(condType, params) @@ -225,24 +152,9 @@ function Battle:afterRound() end end --- 写入临时数据 -function Battle:getTempDB() - local turnDB = {} - if self.enemy then - turnDB.enemy = self.enemy:getDB() - end - turnDB.player = self.player:getDB() - table.insert(self.tempData, turnDB) -end --写入数据 function Battle:getDB() - if not self.enemy then - self.adv.advTeam.enemyId = nil - else - self.adv.advTeam.enemyId = self.enemy.id - return - end self.adv.advTeam.player = self.player:getDB() for _, enemy in ipairs(self.enemys) do local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] diff --git a/src/adv/AdvBuff.lua b/src/adv/AdvBuff.lua index 6de938d..9bc4f25 100644 --- a/src/adv/AdvBuff.lua +++ b/src/adv/AdvBuff.lua @@ -15,7 +15,7 @@ Buff.IMMNUE_BUFF = 11 -- 免疫buff Buff.CLEAR_BUFF = 12 -- 清除buff Buff.CANT_SKILL = 13 -- 禁止技能 Buff.OPEN_BLOCK = 14 -- 翻开格子(每回合) -Buff.POWER_CHANGE = 15 -- MP变化(每回合) +Buff.SP_CHANGE = 15 -- sp变化(每回合) Buff.HP_CHANGE_NOW = 16 -- 生命变化(每回合生效,立刻生效) --角色一些属性的变化 @@ -59,14 +59,6 @@ local BuffFactory = { self.owner:hurt(-value, self.release, {hurtType = 2}) end end - _Buff._afterTurn = 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 = 2}) - end - end _Buff._effectValue = function(self) return self._changeV end @@ -177,24 +169,16 @@ local BuffFactory = { local roomNum = self:effect() self.owner.battle.adv:openBlockRand(roomNum) end - _Buff._afterTurn = function(self) - local roomNum = self:effect() - self.owner.battle.adv:openBlockRand(roomNum) - end _Buff._effectValue = function(self) return self.buffData.effectValue1 end end, - [Buff.POWER_CHANGE] = function(_Buff) + [Buff.SP_CHANGE] = function(_Buff) --cType 0 or nil 值 1 百分比 _Buff._afterRound = function(self) local value, cType = self:effect() - self.owner.battle.adv:changePower(value, cType) - end - _Buff._afterTurn = function(self) - local value, cType = self:effect() - self.owner.battle.adv:changePower(value, cType) + self.owner:changeSp(value, cType) end _Buff._effectValue = function(self) return self.buffData.effectValue2, self.buffData.effectValue1 @@ -213,7 +197,6 @@ local BuffFactory = { if self._changeV < 0 then self._changeV = -self.release:getHurtValue(-self._changeV) end - self:afterTurn() end _Buff._initDB = function(self, data) self._changeV = data.cv @@ -226,14 +209,6 @@ local BuffFactory = { self.owner:hurt(-value, self.release, {hurtType = 2}) end end - _Buff._afterTurn = 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 = 2}) - end - end _Buff._effectValue = function(self) return self._changeV end @@ -246,7 +221,7 @@ local BuffFactory = { function Buff:ctor(owner, id) self.owner = owner self.id = id - self.buffData = csvdb["adv_buffCsv"][self.id] + self.buffData = csvdb["adv_map_buffCsv"][self.id] self.isDel = false self.roundSpace = 0 --生效间隔 self.turnSpace = 0 --生效间隔 @@ -308,42 +283,6 @@ function Buff:battleEnd() end end -function Buff:beforeTurn() - if self.isDel or self.owner.isDead or self.buffData.turn == 0 then return end - if self.turnSpace > 0 then - return - end - if self._beforeTurn then - self:_beforeTurn() - end -end - -function Buff:afterTurn() - if self.isDel or self.owner.isDead or self.buffData.turn == 0 then return end - if self.turnSpace > 0 then - self.turnSpace = self.turnSpace - 1 - self:decTurn() - return - end - if self._afterTurn then - self:_afterTurn() - end - if self.buffData.turnTime > 0 then - self.turnSpace = self.buffData.turnTime - end - self:decTurn() -end - -function Buff:decTurn() - if self.buffData.turn == 0 then - return - end - self.turn = self.turn - 1 - if self.turn <= 0 then - self.isDel = true - end -end - function Buff:afterRound() if self.isDel or self.owner.isDead or self.buffData.round == 0 then return end if self.roundSpace > 0 then diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 2ce77da..5922cd6 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -196,13 +196,11 @@ function Passive:ctor(owner, data) self.owner = owner self.id = data.id self.level = data.level or 1 - self.passiveData = csvdb["adv_skill_passiveCsv"][self.id][self.level] + self.passiveData = csvdb["adv_map_passiveCsv"][self.id][self.level] self.isDel = false self.round = data.round or 0 --触发剩余回合数 self.count = data.count or self.passiveData.count --触发剩余次数 self.delay = data.delay or self.passiveData.delayRound --触发延迟回合数 - self.turn = 0 --战斗内回合数 - self.delayTurn = self.passiveData.delayTurn --战斗内延迟回合数 self.effects = self.passiveData.effect:toTableArray(true) self.filters = {} @@ -257,25 +255,6 @@ function Passive:effect(trigger) end end -function Passive:battleBegin() - if self.isDel or self.owner.isDead then return end - self.turn = 0 - self.delayTurn = self.passiveData.delayTurn -end - -function Passive:afterTurn() - if self.isDel or self.owner.isDead then return end - if self._afterTurn then - self:_afterTurn() --有的触发自己检测在这里检查 - end - if self.turn > 0 then --战斗内回合 - self.turn = self.turn - 1 - end - if self.delayTurn > 0 then - self.delayTurn = self.delayTurn - 1 - end -end - function Passive:afterRound() if self.isDel or self.owner.isDead then return end if self._afterRound then @@ -291,7 +270,7 @@ end -- 可以触发 function Passive:canTrigger( ) - return self.count > 0 and self.delay <= 0 and self.delayTurn <= 0 + return self.count > 0 and self.delay <= 0 end function Passive:trigger(condType, params) --触发检查 diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index 02140be..f38685b 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -49,21 +49,6 @@ function BaseObject:reset(data) self:initAfter(data) end -function BaseObject:beforeTurn() - for _, buff in ipairs(self.buffs) do - buff:beforeTurn() - end -end - -function BaseObject:afterTurn() - for _, passive in ipairs(self.passives) do - passive:afterTurn() - end - for _, buff in ipairs(self.buffs) do - buff:afterTurn() - end -end - function BaseObject:afterRound() for _, passive in ipairs(self.passives) do passive:afterRound(self) @@ -73,15 +58,6 @@ function BaseObject:afterRound() end end -function BaseObject:clearTurn() - for i = #self.buffs, 1, -1 do - if self.buffs[i].isDel then - self.battle.adv:backBuff(self.id, self.buffs[i].id, true) - self.buffs[i]:endBuff() - table.remove(self.buffs, i) - end - end -end function BaseObject:clearRound() for i = #self.passives, 1, -1 do @@ -117,7 +93,7 @@ end function BaseObject:addPassive(params) local skillId = params.id - local skillData = csvdb["adv_skill_passiveCsv"][skillId] + 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 @@ -127,7 +103,7 @@ function BaseObject:addPassive(params) end function BaseObject:addBuff(buffId, releaser) - local buffData = csvdb["adv_buffCsv"][buffId] + local buffData = csvdb["adv_map_buffCsv"][buffId] 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 @@ -332,14 +308,6 @@ function BaseObject:addSpecialSkill(skillId, skillLevel, target) table.insert(self.skillOrder, skillData) end -function BaseObject:releaseSpecialSkill() - local skillData = table.remove(self.skillOrder, 1) - local skillSet = csvdb["adv_skill_specialCsv"][skillData.id][skillData.level] - for _, skillId in ipairs(skillSet.skillId:toArray(true, "=")) do - self:releaseSkill(skillId, skillData.target) - end -end - function BaseObject:releaseSkill(skillId, target) if self:hadBuff(Buff.CANT_SKILL) then return end -- 针对 怪物 local skill = Skill.new(self, {id = skillId, target = target}) @@ -422,6 +390,9 @@ function BaseObject:triggerPassive(condType, params) end end +function BaseObject:changeSp() +end + local Enemy = class("Enemy", BaseObject) function Enemy:ctor(battle, mId, monsterId, roomId, blockId, lock, enemy) Enemy.super.ctor(self, battle) @@ -452,18 +423,34 @@ function Player:initData(data) self.level = data.level or 1 --level 每增加1级 属性增长 growth * baseAttr self.growth = data.growth or 0 self.exp = data.exp or 0 + self.sp = data.sp or 100 end function Player:addExp(value) -- todo end +--cType 0 or nil 值 1 百分比 +function Player:changeSp(value, cType) + cType = cType or 0 + if cType == 0 then + self.sp = self.sp + value + elseif cType == 1 then + self.sp = self.sp + self.sp * value / 100 + end + self.sp = math.floor(math.max(0, self.sp)) + self.battle.adv:pushBackEvent(AdvBackEventType.SpChange) +end + + function Player:getDB() local db = Player.super.getDB(self) - for _ , field in pairs({"level", "exp", "growth"}) do + for _ , field in pairs({"level", "exp", "growth", "sp"}) do db[field] = self[field] end return db end + + return table.pack(Player, Enemy) \ No newline at end of file diff --git a/src/adv/AdvSkill.lua b/src/adv/AdvSkill.lua index f8c04f6..d052aa3 100644 --- a/src/adv/AdvSkill.lua +++ b/src/adv/AdvSkill.lua @@ -5,7 +5,7 @@ function Skill:ctor(owner, data) self.id = data.id self.defaultTarget = data.target - self.skillData = csvdb["adv_skillCsv"][self.id] + self.skillData = csvdb["adv_map_skillCsv"][self.id] self.targets = self:initTargets() end -- libgit2 0.21.2