From 3dab575106bbb79aa7bc6cae13eef2e8f91387b8 Mon Sep 17 00:00:00 2001 From: suhongyang <1609423485@qq.com> Date: Tue, 9 Jul 2019 10:54:21 +0800 Subject: [PATCH] 修改冒险战斗逻辑 --- src/ProtocolCode.lua | 1 - src/actions/AdvAction.lua | 11 ----------- src/adv/Adv.lua | 27 +++------------------------ src/adv/AdvBattle.lua | 44 +++++++++++++++++++------------------------- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 7116486..a0311c6 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -30,7 +30,6 @@ actionCodes = { Adv_useItemRpc = 154, Adv_useSkillRpc = 155, Adv_exitAdvRpc = 156, - Adv_nextTurnRpc = 157, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index eb5c534..dc6e95c 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -97,15 +97,4 @@ 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() - if not status then return 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 1c75c9d..dd27dc1 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -699,7 +699,7 @@ end --战斗 普通攻击 local function clickMonster(self, room, block, params) - self.battle:battleBegin(room.roomId, block.blockId) + self.battle:doBattle(room.roomId, block.blockId) return true end @@ -882,13 +882,8 @@ function Adv:clickBlock(roomId, blockId, params) end end local needChange = true - if clickEvent and block.event then - if block.event.etype == AdvEventType.Out then - needChange = false - end - if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then - needChange = false - end + if clickEvent and block.event and block.event.etype == AdvEventType.Out then + needChange = false end if status and needChange then --出去了就不计算回合了 self:backBlockChange(roomId, blockId) @@ -898,22 +893,6 @@ function Adv:clickBlock(roomId, blockId, params) return status end ---继续战斗 -function Adv:nextBattleTurn() - local enemy = self.battle.enemy - if not enemy 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 diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index 92614a4..856d1b5 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -8,6 +8,7 @@ function Battle:ctor(adv) self.isNewPlayer = false self.enemy = nil self.enemys = {} --怪 + self.tempDB = {} -- 临时战斗数据 self:initPlayer() self:initEnemys() self:initAfter() @@ -21,10 +22,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 function Battle:initPlayer() @@ -104,23 +101,17 @@ 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) - if self.enemy then - self.enemy:reset(self.adv.rooms[self.enemy.roomId].blocks[self.enemy.blockId].event.enemy) - end +--战斗逻辑 +function Battle:doBattle(roomId, blockId) + self.tempDB = {} -- 清理上次战斗的残余数据 local enemy = self:getEnemy(roomId, blockId) if enemy then self.enemy = enemy self.player:battleBegin() self.enemy:battleBegin() - self:doBattleTurn() + while not enemy.isDead and not self.player.isDead do + self:doBattleTurn() + end end end @@ -141,9 +132,9 @@ function Battle:doBattleTurn() local deadPlayer = enemy.isDead and enemy or self.player deadPlayer:battleEnd() self.enemy = nil - else - self.adv:backTurnEnd() end + self.adv:backTurnEnd() + self:getTempDB() end --战斗内角色回合逻辑 @@ -189,20 +180,23 @@ function Battle:afterRound() self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) end - if self.player.isDead then self.adv:over(false) 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.tempDB, 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] -- libgit2 0.21.2