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,11 +900,11 @@ end | ||
900 | 900 | ||
901 | --继续战斗 | 901 | --继续战斗 |
902 | function Adv:nextBattleTurn() | 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 | end | 906 | end |
907 | - local roomId, blockId = self.battle:getRBByEnemyId(enemyId) | 907 | + local roomId, blockId = self.battle:getRBByEnemyId(enemy.id) |
908 | self.battle:doBattleTurn() | 908 | self.battle:doBattleTurn() |
909 | if self.battle:isBattleEnd() then | 909 | if self.battle:isBattleEnd() then |
910 | self:backBlockChange(roomId, blockId) | 910 | self:backBlockChange(roomId, blockId) |
src/adv/AdvBattle.lua
@@ -6,7 +6,7 @@ function Battle:ctor(adv) | @@ -6,7 +6,7 @@ function Battle:ctor(adv) | ||
6 | self.adv = adv | 6 | self.adv = adv |
7 | self.player = nil --玩家 | 7 | self.player = nil --玩家 |
8 | self.isNewPlayer = false | 8 | self.isNewPlayer = false |
9 | - self.battleEnemyId = nil | 9 | + self.enemy = nil |
10 | self.enemys = {} --怪 | 10 | self.enemys = {} --怪 |
11 | self:initPlayer() | 11 | self:initPlayer() |
12 | self:initEnemys() | 12 | self:initEnemys() |
@@ -21,9 +21,9 @@ function Battle:initAfter() | @@ -21,9 +21,9 @@ function Battle:initAfter() | ||
21 | for _, enemy in pairs(self.enemys) do | 21 | for _, enemy in pairs(self.enemys) do |
22 | 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) |
23 | end | 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 | end | 27 | end |
28 | end | 28 | end |
29 | 29 | ||
@@ -105,29 +105,28 @@ function Battle:getRBByEnemyId(enemyId) | @@ -105,29 +105,28 @@ function Battle:getRBByEnemyId(enemyId) | ||
105 | end | 105 | end |
106 | 106 | ||
107 | function Battle:isBattleEnd() | 107 | function Battle:isBattleEnd() |
108 | - if not self.battleEnemyId then | 108 | + if not self.enemy then |
109 | return true | 109 | return true |
110 | end | 110 | end |
111 | end | 111 | end |
112 | 112 | ||
113 | --战斗开始 | 113 | --战斗开始 |
114 | function Battle:battleBegin(roomId, blockId) | 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 | end | 117 | end |
119 | local enemy = self:getEnemy(roomId, blockId) | 118 | local enemy = self:getEnemy(roomId, blockId) |
120 | if enemy then | 119 | if enemy then |
121 | - self.battleEnemyId = enemy.id | 120 | + self.enemy = enemy |
122 | self.player:battleBegin() | 121 | self.player:battleBegin() |
123 | - enemy:battleBegin() | 122 | + self.enemy:battleBegin() |
124 | self:doBattleTurn() | 123 | self:doBattleTurn() |
125 | end | 124 | end |
126 | end | 125 | end |
127 | 126 | ||
128 | -- 战斗内一回合 | 127 | -- 战斗内一回合 |
129 | function Battle:doBattleTurn() | 128 | function Battle:doBattleTurn() |
130 | - local enemy = self:getEnemyById(self.battleEnemyId) | 129 | + local enemy = self.enemy |
131 | if not enemy then return end | 130 | if not enemy then return end |
132 | -- 玩家先出手 | 131 | -- 玩家先出手 |
133 | self.adv:backAtk(nil, enemy.id) | 132 | self.adv:backAtk(nil, enemy.id) |
@@ -141,7 +140,7 @@ function Battle:doBattleTurn() | @@ -141,7 +140,7 @@ function Battle:doBattleTurn() | ||
141 | if enemy.isDead or self.player.isDead then | 140 | if enemy.isDead or self.player.isDead then |
142 | local deadPlayer = enemy.isDead and enemy or self.player | 141 | local deadPlayer = enemy.isDead and enemy or self.player |
143 | deadPlayer:battleEnd() | 142 | deadPlayer:battleEnd() |
144 | - self.battleEnemyId = nil | 143 | + self.enemy = nil |
145 | else | 144 | else |
146 | self.adv:backTurnEnd() | 145 | self.adv:backTurnEnd() |
147 | end | 146 | end |
@@ -198,17 +197,17 @@ end | @@ -198,17 +197,17 @@ end | ||
198 | 197 | ||
199 | --写入数据 | 198 | --写入数据 |
200 | 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 | ||
201 | self.adv.advTeam.player = self.player:getDB() | 206 | self.adv.advTeam.player = self.player:getDB() |
202 | for _, enemy in ipairs(self.enemys) do | 207 | for _, enemy in ipairs(self.enemys) do |
203 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | 208 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |
204 | block.event.enemy = enemy:getDB() | 209 | block.event.enemy = enemy:getDB() |
205 | end | 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 | end | 211 | end |
213 | 212 | ||
214 | return Battle | 213 | return Battle |
215 | \ No newline at end of file | 214 | \ No newline at end of file |
src/adv/AdvPlayer.lua
@@ -45,6 +45,13 @@ function BaseObject:initAfter(data) | @@ -45,6 +45,13 @@ function BaseObject:initAfter(data) | ||
45 | end | 45 | end |
46 | end | 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 | function BaseObject:beforeTurn() | 55 | function BaseObject:beforeTurn() |
49 | for _, buff in ipairs(self.buffs) do | 56 | for _, buff in ipairs(self.buffs) do |
50 | buff:beforeTurn() | 57 | buff:beforeTurn() |