Commit ae20365b9f8e493f40751cda54e073a9aad4281e
1 parent
3dab5751
Revert "修改冒险战斗逻辑"
This reverts commit 3dab575106bbb79aa7bc6cae13eef2e8f91387b8.
Showing
4 changed files
with
61 additions
and
22 deletions
Show diff stats
src/ProtocolCode.lua
@@ -30,6 +30,7 @@ actionCodes = { | @@ -30,6 +30,7 @@ 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, | ||
33 | 34 | ||
34 | Hero_loadInfos = 201, | 35 | Hero_loadInfos = 201, |
35 | Hero_updateProperty = 202, | 36 | Hero_updateProperty = 202, |
src/actions/AdvAction.lua
@@ -97,4 +97,15 @@ function _M.exitAdvRpc(agent, data) | @@ -97,4 +97,15 @@ 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 | + | ||
100 | return _M | 111 | return _M |
101 | \ No newline at end of file | 112 | \ No newline at end of file |
src/adv/Adv.lua
@@ -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:doBattle(room.roomId, block.blockId) | 702 | + self.battle:battleBegin(room.roomId, block.blockId) |
703 | return true | 703 | return true |
704 | end | 704 | end |
705 | 705 | ||
@@ -882,8 +882,13 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -882,8 +882,13 @@ 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 and block.event.etype == AdvEventType.Out then | ||
886 | - needChange = false | 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 | ||
887 | end | 892 | end |
888 | if status and needChange then --出去了就不计算回合了 | 893 | if status and needChange then --出去了就不计算回合了 |
889 | self:backBlockChange(roomId, blockId) | 894 | self:backBlockChange(roomId, blockId) |
@@ -893,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -893,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) | ||
893 | return status | 898 | return status |
894 | end | 899 | end |
895 | 900 | ||
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 | + | ||
896 | --使用道具产生效果 | 917 | --使用道具产生效果 |
897 | function Adv:useItem(itemId, count, target) | 918 | function Adv:useItem(itemId, count, target) |
898 | count = count or 1 | 919 | count = count or 1 |
src/adv/AdvBattle.lua
@@ -8,7 +8,6 @@ function Battle:ctor(adv) | @@ -8,7 +8,6 @@ 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 = {} -- 临时战斗数据 | ||
12 | self:initPlayer() | 11 | self:initPlayer() |
13 | self:initEnemys() | 12 | self:initEnemys() |
14 | self:initAfter() | 13 | self:initAfter() |
@@ -22,6 +21,10 @@ function Battle:initAfter() | @@ -22,6 +21,10 @@ function Battle:initAfter() | ||
22 | for _, enemy in pairs(self.enemys) do | 21 | for _, enemy in pairs(self.enemys) do |
23 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) | 22 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
24 | end | 23 | end |
24 | + if self.adv.advTeam.enemyId then | ||
25 | + local enemy = self:getEnemyById(self.adv.advTeam.enemyId) | ||
26 | + self.enemy = enemy | ||
27 | + end | ||
25 | end | 28 | end |
26 | 29 | ||
27 | function Battle:initPlayer() | 30 | function Battle:initPlayer() |
@@ -101,17 +104,23 @@ function Battle:getRBByEnemyId(enemyId) | @@ -101,17 +104,23 @@ function Battle:getRBByEnemyId(enemyId) | ||
101 | return enemy.roomId, enemy.blockId | 104 | return enemy.roomId, enemy.blockId |
102 | end | 105 | end |
103 | 106 | ||
104 | ---战斗逻辑 | ||
105 | -function Battle:doBattle(roomId, blockId) | ||
106 | - self.tempDB = {} -- 清理上次战斗的残余数据 | 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 | ||
107 | local enemy = self:getEnemy(roomId, blockId) | 118 | local enemy = self:getEnemy(roomId, blockId) |
108 | if enemy then | 119 | if enemy then |
109 | self.enemy = enemy | 120 | self.enemy = enemy |
110 | self.player:battleBegin() | 121 | self.player:battleBegin() |
111 | self.enemy:battleBegin() | 122 | self.enemy:battleBegin() |
112 | - while not enemy.isDead and not self.player.isDead do | ||
113 | - self:doBattleTurn() | ||
114 | - end | 123 | + self:doBattleTurn() |
115 | end | 124 | end |
116 | end | 125 | end |
117 | 126 | ||
@@ -132,9 +141,9 @@ function Battle:doBattleTurn() | @@ -132,9 +141,9 @@ function Battle:doBattleTurn() | ||
132 | local deadPlayer = enemy.isDead and enemy or self.player | 141 | local deadPlayer = enemy.isDead and enemy or self.player |
133 | deadPlayer:battleEnd() | 142 | deadPlayer:battleEnd() |
134 | self.enemy = nil | 143 | self.enemy = nil |
144 | + else | ||
145 | + self.adv:backTurnEnd() | ||
135 | end | 146 | end |
136 | - self.adv:backTurnEnd() | ||
137 | - self:getTempDB() | ||
138 | end | 147 | end |
139 | 148 | ||
140 | --战斗内角色回合逻辑 | 149 | --战斗内角色回合逻辑 |
@@ -180,23 +189,20 @@ function Battle:afterRound() | @@ -180,23 +189,20 @@ function Battle:afterRound() | ||
180 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) | 189 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) |
181 | end | 190 | end |
182 | 191 | ||
192 | + | ||
183 | if self.player.isDead then | 193 | if self.player.isDead then |
184 | self.adv:over(false) | 194 | self.adv:over(false) |
185 | end | 195 | end |
186 | end | 196 | end |
187 | 197 | ||
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 | ||
200 | self.adv.advTeam.player = self.player:getDB() | 206 | self.adv.advTeam.player = self.player:getDB() |
201 | for _, enemy in ipairs(self.enemys) do | 207 | for _, enemy in ipairs(self.enemys) do |
202 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | 208 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |