Commit a734980c94eb05cdc42df1dc0b674c2bab44ae71
1 parent
d78bc768
冒险战斗数据打完以前不存储
Showing
3 changed files
with
28 additions
and
22 deletions
Show diff stats
src/adv/Adv.lua
... | ... | @@ -900,11 +900,11 @@ end |
900 | 900 | |
901 | 901 | --继续战斗 |
902 | 902 | function Adv:nextBattleTurn() |
903 | - local enemyId = self.battle.battleEnemyId | |
904 | - if not enemyId then | |
905 | - return | |
903 | + local enemy = self.battle.enemy | |
904 | + if not enemy then | |
905 | + return | |
906 | 906 | end |
907 | - local roomId, blockId = self.battle:getRBByEnemyId(enemyId) | |
907 | + local roomId, blockId = self.battle:getRBByEnemyId(enemy.id) | |
908 | 908 | self.battle:doBattleTurn() |
909 | 909 | if self.battle:isBattleEnd() then |
910 | 910 | self:backBlockChange(roomId, blockId) | ... | ... |
src/adv/AdvBattle.lua
... | ... | @@ -6,7 +6,7 @@ function Battle:ctor(adv) |
6 | 6 | self.adv = adv |
7 | 7 | self.player = nil --玩家 |
8 | 8 | self.isNewPlayer = false |
9 | - self.battleEnemyId = nil | |
9 | + self.enemy = nil | |
10 | 10 | self.enemys = {} --怪 |
11 | 11 | self:initPlayer() |
12 | 12 | self:initEnemys() |
... | ... | @@ -21,9 +21,9 @@ function Battle:initAfter() |
21 | 21 | for _, enemy in pairs(self.enemys) do |
22 | 22 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
23 | 23 | end |
24 | - if self.adv.advTeam.enemy then | |
25 | - local enemy = self:getEnemy(self.adv.advTeam.enemy.roomId, self.adv.advTeam.enemy.blockId) | |
26 | - self.battleEnemyId = enemy.id | |
24 | + if self.adv.advTeam.enemyId then | |
25 | + local enemy = self:getEnemyById(self.adv.advTeam.enemyId) | |
26 | + self.enemy = enemy | |
27 | 27 | end |
28 | 28 | end |
29 | 29 | |
... | ... | @@ -105,29 +105,28 @@ function Battle:getRBByEnemyId(enemyId) |
105 | 105 | end |
106 | 106 | |
107 | 107 | function Battle:isBattleEnd() |
108 | - if not self.battleEnemyId then | |
108 | + if not self.enemy then | |
109 | 109 | return true |
110 | 110 | end |
111 | 111 | end |
112 | 112 | |
113 | 113 | --战斗开始 |
114 | 114 | function Battle:battleBegin(roomId, blockId) |
115 | - if self.battleEnemyId then | |
116 | - self.battleEnemyId = nil | |
117 | - -- TODO 清理上次战斗遗留数据 | |
115 | + if self.enemy then | |
116 | + self.enemy:reset(self.adv.rooms[self.enemy.roomId].blocks[self.enemy.blockId].event.enemy) | |
118 | 117 | end |
119 | 118 | local enemy = self:getEnemy(roomId, blockId) |
120 | 119 | if enemy then |
121 | - self.battleEnemyId = enemy.id | |
120 | + self.enemy = enemy | |
122 | 121 | self.player:battleBegin() |
123 | - enemy:battleBegin() | |
122 | + self.enemy:battleBegin() | |
124 | 123 | self:doBattleTurn() |
125 | 124 | end |
126 | 125 | end |
127 | 126 | |
128 | 127 | -- 战斗内一回合 |
129 | 128 | function Battle:doBattleTurn() |
130 | - local enemy = self:getEnemyById(self.battleEnemyId) | |
129 | + local enemy = self.enemy | |
131 | 130 | if not enemy then return end |
132 | 131 | -- 玩家先出手 |
133 | 132 | self.adv:backAtk(nil, enemy.id) |
... | ... | @@ -141,7 +140,7 @@ function Battle:doBattleTurn() |
141 | 140 | if enemy.isDead or self.player.isDead then |
142 | 141 | local deadPlayer = enemy.isDead and enemy or self.player |
143 | 142 | deadPlayer:battleEnd() |
144 | - self.battleEnemyId = nil | |
143 | + self.enemy = nil | |
145 | 144 | else |
146 | 145 | self.adv:backTurnEnd() |
147 | 146 | end |
... | ... | @@ -198,17 +197,17 @@ end |
198 | 197 | |
199 | 198 | --写入数据 |
200 | 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 | |
201 | 206 | self.adv.advTeam.player = self.player:getDB() |
202 | 207 | for _, enemy in ipairs(self.enemys) do |
203 | 208 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |
204 | 209 | block.event.enemy = enemy:getDB() |
205 | 210 | end |
206 | - if self.battleEnemyId then | |
207 | - local enemy = self:getEnemyById(self.battleEnemyId) | |
208 | - self.adv.advTeam.enemy = {roomId = enemy.roomId, blockId = enemy.blockId} | |
209 | - else | |
210 | - self.adv.advTeam.enemy = nil | |
211 | - end | |
212 | 211 | end |
213 | 212 | |
214 | 213 | return Battle |
215 | 214 | \ No newline at end of file | ... | ... |
src/adv/AdvPlayer.lua
... | ... | @@ -45,6 +45,13 @@ function BaseObject:initAfter(data) |
45 | 45 | end |
46 | 46 | end |
47 | 47 | |
48 | +function BaseObject:reset(data) | |
49 | + self.passives = {} | |
50 | + self.buffs = {} | |
51 | + self:initData(data) | |
52 | + self:initAfter(data) | |
53 | +end | |
54 | + | |
48 | 55 | function BaseObject:beforeTurn() |
49 | 56 | for _, buff in ipairs(self.buffs) do |
50 | 57 | buff:beforeTurn() | ... | ... |