From ae20365b9f8e493f40751cda54e073a9aad4281e Mon Sep 17 00:00:00 2001 From: suhongyang <1609423485@qq.com> Date: Tue, 9 Jul 2019 14:37:10 +0800 Subject: [PATCH] Revert "修改冒险战斗逻辑" --- src/ProtocolCode.lua | 1 + src/actions/AdvAction.lua | 11 +++++++++++ src/adv/Adv.lua | 27 ++++++++++++++++++++++++--- src/adv/AdvBattle.lua | 44 +++++++++++++++++++++++++------------------- 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index a0311c6..7116486 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -30,6 +30,7 @@ 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 dc6e95c..eb5c534 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -97,4 +97,15 @@ 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 dd27dc1..1c75c9d 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:doBattle(room.roomId, block.blockId) + self.battle:battleBegin(room.roomId, block.blockId) return true end @@ -882,8 +882,13 @@ function Adv:clickBlock(roomId, blockId, params) end end local needChange = true - if clickEvent and block.event and block.event.etype == AdvEventType.Out then - needChange = false + 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 end if status and needChange then --出去了就不计算回合了 self:backBlockChange(roomId, blockId) @@ -893,6 +898,22 @@ 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 856d1b5..92614a4 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -8,7 +8,6 @@ function Battle:ctor(adv) self.isNewPlayer = false self.enemy = nil self.enemys = {} --怪 - self.tempDB = {} -- 临时战斗数据 self:initPlayer() self:initEnemys() self:initAfter() @@ -22,6 +21,10 @@ 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() @@ -101,17 +104,23 @@ function Battle:getRBByEnemyId(enemyId) return enemy.roomId, enemy.blockId end ---战斗逻辑 -function Battle:doBattle(roomId, blockId) - self.tempDB = {} -- 清理上次战斗的残余数据 +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 local enemy = self:getEnemy(roomId, blockId) if enemy then self.enemy = enemy self.player:battleBegin() self.enemy:battleBegin() - while not enemy.isDead and not self.player.isDead do - self:doBattleTurn() - end + self:doBattleTurn() end end @@ -132,9 +141,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 --战斗内角色回合逻辑 @@ -180,23 +189,20 @@ 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