Commit 3dab575106bbb79aa7bc6cae13eef2e8f91387b8
1 parent
a734980c
修改冒险战斗逻辑
Showing
4 changed files
with
22 additions
and
61 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/AdvAction.lua
... | ... | @@ -97,15 +97,4 @@ 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 | - | |
111 | 100 | return _M |
112 | 101 | \ 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:battleBegin(room.roomId, block.blockId) | |
702 | + self.battle:doBattle(room.roomId, block.blockId) | |
703 | 703 | return true |
704 | 704 | end |
705 | 705 | |
... | ... | @@ -882,13 +882,8 @@ function Adv:clickBlock(roomId, blockId, params) |
882 | 882 | end |
883 | 883 | end |
884 | 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 | 887 | end |
893 | 888 | if status and needChange then --出去了就不计算回合了 |
894 | 889 | self:backBlockChange(roomId, blockId) |
... | ... | @@ -898,22 +893,6 @@ function Adv:clickBlock(roomId, blockId, params) |
898 | 893 | return status |
899 | 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 | 897 | function Adv:useItem(itemId, count, target) |
919 | 898 | count = count or 1 | ... | ... |
src/adv/AdvBattle.lua
... | ... | @@ -8,6 +8,7 @@ function Battle:ctor(adv) |
8 | 8 | self.isNewPlayer = false |
9 | 9 | self.enemy = nil |
10 | 10 | self.enemys = {} --怪 |
11 | + self.tempDB = {} -- 临时战斗数据 | |
11 | 12 | self:initPlayer() |
12 | 13 | self:initEnemys() |
13 | 14 | self:initAfter() |
... | ... | @@ -21,10 +22,6 @@ function Battle:initAfter() |
21 | 22 | for _, enemy in pairs(self.enemys) do |
22 | 23 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
23 | 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 | 25 | end |
29 | 26 | |
30 | 27 | function Battle:initPlayer() |
... | ... | @@ -104,23 +101,17 @@ function Battle:getRBByEnemyId(enemyId) |
104 | 101 | return enemy.roomId, enemy.blockId |
105 | 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 | 107 | local enemy = self:getEnemy(roomId, blockId) |
119 | 108 | if enemy then |
120 | 109 | self.enemy = enemy |
121 | 110 | self.player:battleBegin() |
122 | 111 | self.enemy:battleBegin() |
123 | - self:doBattleTurn() | |
112 | + while not enemy.isDead and not self.player.isDead do | |
113 | + self:doBattleTurn() | |
114 | + end | |
124 | 115 | end |
125 | 116 | end |
126 | 117 | |
... | ... | @@ -141,9 +132,9 @@ function Battle:doBattleTurn() |
141 | 132 | local deadPlayer = enemy.isDead and enemy or self.player |
142 | 133 | deadPlayer:battleEnd() |
143 | 134 | self.enemy = nil |
144 | - else | |
145 | - self.adv:backTurnEnd() | |
146 | 135 | end |
136 | + self.adv:backTurnEnd() | |
137 | + self:getTempDB() | |
147 | 138 | end |
148 | 139 | |
149 | 140 | --战斗内角色回合逻辑 |
... | ... | @@ -189,20 +180,23 @@ function Battle:afterRound() |
189 | 180 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) |
190 | 181 | end |
191 | 182 | |
192 | - | |
193 | 183 | if self.player.isDead then |
194 | 184 | self.adv:over(false) |
195 | 185 | end |
196 | 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 | 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 | 200 | self.adv.advTeam.player = self.player:getDB() |
207 | 201 | for _, enemy in ipairs(self.enemys) do |
208 | 202 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | ... | ... |
-
mentioned in commit ae20365b9f8e493f40751cda54e073a9aad4281e