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
src/actions/AdvAction.lua
... | ... | @@ -97,4 +97,15 @@ function _M.exitAdvRpc(agent, data) |
97 | 97 | return true |
98 | 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 | 111 | return _M |
101 | 112 | \ No newline at end of file | ... | ... |
src/adv/Adv.lua
... | ... | @@ -699,7 +699,7 @@ end |
699 | 699 | |
700 | 700 | --战斗 普通攻击 |
701 | 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 | 703 | return true |
704 | 704 | end |
705 | 705 | |
... | ... | @@ -882,8 +882,13 @@ function Adv:clickBlock(roomId, blockId, params) |
882 | 882 | end |
883 | 883 | end |
884 | 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 | 892 | end |
888 | 893 | if status and needChange then --出去了就不计算回合了 |
889 | 894 | self:backBlockChange(roomId, blockId) |
... | ... | @@ -893,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) |
893 | 898 | return status |
894 | 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 | 918 | function Adv:useItem(itemId, count, target) |
898 | 919 | count = count or 1 | ... | ... |
src/adv/AdvBattle.lua
... | ... | @@ -8,7 +8,6 @@ function Battle:ctor(adv) |
8 | 8 | self.isNewPlayer = false |
9 | 9 | self.enemy = nil |
10 | 10 | self.enemys = {} --怪 |
11 | - self.tempDB = {} -- 临时战斗数据 | |
12 | 11 | self:initPlayer() |
13 | 12 | self:initEnemys() |
14 | 13 | self:initAfter() |
... | ... | @@ -22,6 +21,10 @@ function Battle:initAfter() |
22 | 21 | for _, enemy in pairs(self.enemys) do |
23 | 22 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
24 | 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 | 28 | end |
26 | 29 | |
27 | 30 | function Battle:initPlayer() |
... | ... | @@ -101,17 +104,23 @@ function Battle:getRBByEnemyId(enemyId) |
101 | 104 | return enemy.roomId, enemy.blockId |
102 | 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 | 118 | local enemy = self:getEnemy(roomId, blockId) |
108 | 119 | if enemy then |
109 | 120 | self.enemy = enemy |
110 | 121 | self.player:battleBegin() |
111 | 122 | self.enemy:battleBegin() |
112 | - while not enemy.isDead and not self.player.isDead do | |
113 | - self:doBattleTurn() | |
114 | - end | |
123 | + self:doBattleTurn() | |
115 | 124 | end |
116 | 125 | end |
117 | 126 | |
... | ... | @@ -132,9 +141,9 @@ function Battle:doBattleTurn() |
132 | 141 | local deadPlayer = enemy.isDead and enemy or self.player |
133 | 142 | deadPlayer:battleEnd() |
134 | 143 | self.enemy = nil |
144 | + else | |
145 | + self.adv:backTurnEnd() | |
135 | 146 | end |
136 | - self.adv:backTurnEnd() | |
137 | - self:getTempDB() | |
138 | 147 | end |
139 | 148 | |
140 | 149 | --战斗内角色回合逻辑 |
... | ... | @@ -180,23 +189,20 @@ function Battle:afterRound() |
180 | 189 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) |
181 | 190 | end |
182 | 191 | |
192 | + | |
183 | 193 | if self.player.isDead then |
184 | 194 | self.adv:over(false) |
185 | 195 | end |
186 | 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 | 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 | 206 | self.adv.advTeam.player = self.player:getDB() |
201 | 207 | for _, enemy in ipairs(self.enemys) do |
202 | 208 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | ... | ... |