Commit 3dab575106bbb79aa7bc6cae13eef2e8f91387b8

Authored by suhongyang
1 parent a734980c

修改冒险战斗逻辑

src/ProtocolCode.lua
@@ -30,7 +30,6 @@ actionCodes = { @@ -30,7 +30,6 @@ actionCodes = {
30 Adv_useItemRpc = 154, 30 Adv_useItemRpc = 154,
31 Adv_useSkillRpc = 155, 31 Adv_useSkillRpc = 155,
32 Adv_exitAdvRpc = 156, 32 Adv_exitAdvRpc = 156,
33 - Adv_nextTurnRpc = 157,  
34 33
35 Hero_loadInfos = 201, 34 Hero_loadInfos = 201,
36 Hero_updateProperty = 202, 35 Hero_updateProperty = 202,
src/actions/AdvAction.lua
@@ -97,15 +97,4 @@ function _M.exitAdvRpc(agent, data) @@ -97,15 +97,4 @@ function _M.exitAdvRpc(agent, data)
97 return true 97 return true
98 end 98 end
99 99
100 ---继续战斗  
101 -function _M.nextTurnRpc(agent, data)  
102 - local role = agent.role  
103 - local msg = MsgPack.unpack(data)  
104 - local adv = role:getAdvData()  
105 - local status = adv:nextBattleTurn()  
106 - if not status then return end  
107 - SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv:popBackEvents()}))  
108 - return true  
109 -end  
110 -  
111 return _M 100 return _M
112 \ No newline at end of file 101 \ No newline at end of file
@@ -699,7 +699,7 @@ end @@ -699,7 +699,7 @@ end
699 699
700 --战斗 普通攻击 700 --战斗 普通攻击
701 local function clickMonster(self, room, block, params) 701 local function clickMonster(self, room, block, params)
702 - self.battle:battleBegin(room.roomId, block.blockId) 702 + self.battle:doBattle(room.roomId, block.blockId)
703 return true 703 return true
704 end 704 end
705 705
@@ -882,13 +882,8 @@ function Adv:clickBlock(roomId, blockId, params) @@ -882,13 +882,8 @@ function Adv:clickBlock(roomId, blockId, params)
882 end 882 end
883 end 883 end
884 local needChange = true 884 local needChange = true
885 - if clickEvent and block.event then  
886 - if block.event.etype == AdvEventType.Out then  
887 - needChange = false  
888 - end  
889 - if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then  
890 - needChange = false  
891 - end 885 + if clickEvent and block.event and block.event.etype == AdvEventType.Out then
  886 + needChange = false
892 end 887 end
893 if status and needChange then --出去了就不计算回合了 888 if status and needChange then --出去了就不计算回合了
894 self:backBlockChange(roomId, blockId) 889 self:backBlockChange(roomId, blockId)
@@ -898,22 +893,6 @@ function Adv:clickBlock(roomId, blockId, params) @@ -898,22 +893,6 @@ function Adv:clickBlock(roomId, blockId, params)
898 return status 893 return status
899 end 894 end
900 895
901 ---继续战斗  
902 -function Adv:nextBattleTurn()  
903 - local enemy = self.battle.enemy  
904 - if not enemy then  
905 - return  
906 - end  
907 - local roomId, blockId = self.battle:getRBByEnemyId(enemy.id)  
908 - self.battle:doBattleTurn()  
909 - if self.battle:isBattleEnd() then  
910 - self:backBlockChange(roomId, blockId)  
911 - self:afterRound()  
912 - end  
913 - self:saveDB()  
914 - return true  
915 -end  
916 -  
917 --使用道具产生效果 896 --使用道具产生效果
918 function Adv:useItem(itemId, count, target) 897 function Adv:useItem(itemId, count, target)
919 count = count or 1 898 count = count or 1
src/adv/AdvBattle.lua
@@ -8,6 +8,7 @@ function Battle:ctor(adv) @@ -8,6 +8,7 @@ function Battle:ctor(adv)
8 self.isNewPlayer = false 8 self.isNewPlayer = false
9 self.enemy = nil 9 self.enemy = nil
10 self.enemys = {} --怪 10 self.enemys = {} --怪
  11 + self.tempDB = {} -- 临时战斗数据
11 self:initPlayer() 12 self:initPlayer()
12 self:initEnemys() 13 self:initEnemys()
13 self:initAfter() 14 self:initAfter()
@@ -21,10 +22,6 @@ function Battle:initAfter() @@ -21,10 +22,6 @@ function Battle:initAfter()
21 for _, enemy in pairs(self.enemys) do 22 for _, enemy in pairs(self.enemys) do
22 enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) 23 enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy)
23 end 24 end
24 - if self.adv.advTeam.enemyId then  
25 - local enemy = self:getEnemyById(self.adv.advTeam.enemyId)  
26 - self.enemy = enemy  
27 - end  
28 end 25 end
29 26
30 function Battle:initPlayer() 27 function Battle:initPlayer()
@@ -104,23 +101,17 @@ function Battle:getRBByEnemyId(enemyId) @@ -104,23 +101,17 @@ function Battle:getRBByEnemyId(enemyId)
104 return enemy.roomId, enemy.blockId 101 return enemy.roomId, enemy.blockId
105 end 102 end
106 103
107 -function Battle:isBattleEnd()  
108 - if not self.enemy then  
109 - return true  
110 - end  
111 -end  
112 -  
113 ---战斗开始  
114 -function Battle:battleBegin(roomId, blockId)  
115 - if self.enemy then  
116 - self.enemy:reset(self.adv.rooms[self.enemy.roomId].blocks[self.enemy.blockId].event.enemy)  
117 - end 104 +--战斗逻辑
  105 +function Battle:doBattle(roomId, blockId)
  106 + self.tempDB = {} -- 清理上次战斗的残余数据
118 local enemy = self:getEnemy(roomId, blockId) 107 local enemy = self:getEnemy(roomId, blockId)
119 if enemy then 108 if enemy then
120 self.enemy = enemy 109 self.enemy = enemy
121 self.player:battleBegin() 110 self.player:battleBegin()
122 self.enemy:battleBegin() 111 self.enemy:battleBegin()
123 - self:doBattleTurn() 112 + while not enemy.isDead and not self.player.isDead do
  113 + self:doBattleTurn()
  114 + end
124 end 115 end
125 end 116 end
126 117
@@ -141,9 +132,9 @@ function Battle:doBattleTurn() @@ -141,9 +132,9 @@ function Battle:doBattleTurn()
141 local deadPlayer = enemy.isDead and enemy or self.player 132 local deadPlayer = enemy.isDead and enemy or self.player
142 deadPlayer:battleEnd() 133 deadPlayer:battleEnd()
143 self.enemy = nil 134 self.enemy = nil
144 - else  
145 - self.adv:backTurnEnd()  
146 end 135 end
  136 + self.adv:backTurnEnd()
  137 + self:getTempDB()
147 end 138 end
148 139
149 --战斗内角色回合逻辑 140 --战斗内角色回合逻辑
@@ -189,20 +180,23 @@ function Battle:afterRound() @@ -189,20 +180,23 @@ function Battle:afterRound()
189 self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) 180 self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4})
190 end 181 end
191 182
192 -  
193 if self.player.isDead then 183 if self.player.isDead then
194 self.adv:over(false) 184 self.adv:over(false)
195 end 185 end
196 end 186 end
197 187
  188 +--战斗每回合写入临时数据
  189 +function Battle:getTempDB()
  190 + local turnDB = {}
  191 + if self.enemy then
  192 + turnDB.enemy = self.enemy:getDB()
  193 + end
  194 + turnDB.player = self.player:getDB()
  195 + table.insert(self.tempDB, turnDB)
  196 +end
  197 +
198 --写入数据 198 --写入数据
199 function Battle:getDB() 199 function Battle:getDB()
200 - if not self.enemy then  
201 - self.adv.advTeam.enemyId = nil  
202 - else  
203 - self.adv.advTeam.enemyId = self.enemy.id  
204 - return  
205 - end  
206 self.adv.advTeam.player = self.player:getDB() 200 self.adv.advTeam.player = self.player:getDB()
207 for _, enemy in ipairs(self.enemys) do 201 for _, enemy in ipairs(self.enemys) do
208 local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] 202 local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId]