Commit 7c55db1f30c88e6393b799a121199f43c773c6df
1 parent
69d686f8
Buff逻辑完善,buff生效次数和争斗内buff生命周期逻辑新增
Showing
3 changed files
with
171 additions
and
59 deletions
Show diff stats
src/adv/AdvBattle.lua
| @@ -102,17 +102,22 @@ function Battle:playerAtk(roomId, blockId) | @@ -102,17 +102,22 @@ function Battle:playerAtk(roomId, blockId) | ||
| 102 | while not enemy.isDead and not self.player.isDead do | 102 | while not enemy.isDead and not self.player.isDead do |
| 103 | -- 玩家先出手 | 103 | -- 玩家先出手 |
| 104 | self.adv:backAtk(nil, enemy.id) | 104 | self.adv:backAtk(nil, enemy.id) |
| 105 | - enemy:hurt(self.player:getHurtValue(), self.player, {hurtType = 1}) | ||
| 106 | - self.player:afterTurn() | 105 | + self:doBattleTurn(self.player, enemy) |
| 107 | --是否无法反击 | 106 | --是否无法反击 |
| 108 | if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then | 107 | if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then |
| 109 | self.adv:backAtk(enemy.id, nil) | 108 | self.adv:backAtk(enemy.id, nil) |
| 110 | - self.player:hurt(enemy:getHurtValue(), enemy, {hurtType = 1}) | ||
| 111 | - enemy:afterTurn() | 109 | + self:doBattleTurn(enemy, self.player) |
| 112 | end | 110 | end |
| 113 | end | 111 | end |
| 114 | end | 112 | end |
| 115 | end | 113 | end |
| 114 | +--战斗内回合逻辑 | ||
| 115 | +function Battle:doBattleTurn(atkPlayer, hurtPlayer) | ||
| 116 | + atkPlayer:beforeTurn() | ||
| 117 | + hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) | ||
| 118 | + atkPlayer:afterTurn() | ||
| 119 | + atkPlayer:clearTurn() | ||
| 120 | +end | ||
| 116 | --触发全员被动技能 | 121 | --触发全员被动技能 |
| 117 | function Battle:triggerPassive(condType, params) | 122 | function Battle:triggerPassive(condType, params) |
| 118 | self.player:triggerPassive(condType, params) | 123 | self.player:triggerPassive(condType, params) |
src/adv/AdvBuff.lua
| @@ -51,13 +51,17 @@ local BuffFactory = { | @@ -51,13 +51,17 @@ local BuffFactory = { | ||
| 51 | _Buff._initDB = function(self, data) | 51 | _Buff._initDB = function(self, data) |
| 52 | self._changeV = data.cv | 52 | self._changeV = data.cv |
| 53 | end | 53 | end |
| 54 | - _Buff._afterRount = function(self) | ||
| 55 | - if self._changeV > 0 then | ||
| 56 | - self.owner:recover(self._changeV, self.release) | ||
| 57 | - elseif self._changeV < 0 then | ||
| 58 | - self.owner:hurt(-self._changeV, self.release, {hurtType = 2}) | 54 | + _Buff._afterRound = function(self) |
| 55 | + local value = self:effect() | ||
| 56 | + if value > 0 then | ||
| 57 | + self.owner:recover(value, self.release) | ||
| 58 | + elseif value < 0 then | ||
| 59 | + self.owner:hurt(-value, self.release, {hurtType = 2}) | ||
| 59 | end | 60 | end |
| 60 | end | 61 | end |
| 62 | + _Buff._effectValue = function(self) | ||
| 63 | + return self._changeV | ||
| 64 | + end | ||
| 61 | _Buff._getDB = function(self) | 65 | _Buff._getDB = function(self) |
| 62 | return {cv = self._changeV} | 66 | return {cv = self._changeV} |
| 63 | end | 67 | end |
| @@ -146,43 +150,73 @@ local BuffFactory = { | @@ -146,43 +150,73 @@ local BuffFactory = { | ||
| 146 | _Buff._init = function(self, data) | 150 | _Buff._init = function(self, data) |
| 147 | self.count = self.buffData.effectValue3 | 151 | self.count = self.buffData.effectValue3 |
| 148 | end | 152 | end |
| 149 | - _Buff._effectValue = function(self) | ||
| 150 | - return self.buffData.effectValue1, self.buffData.effectValue2 | 153 | + _Buff._canEffect = function(self, buffId, buffGroup) |
| 154 | + local cType, aim = self.buffData.effectValue1, self.buffData.effectValue2 | ||
| 155 | + if (cType == 0 and buffId == aim) or (cType == 1 and buffGroup == aim) then | ||
| 156 | + return true | ||
| 157 | + end | ||
| 151 | end | 158 | end |
| 152 | end, | 159 | end, |
| 153 | 160 | ||
| 154 | [Buff.CLEAR_BUFF] = function(_Buff) | 161 | [Buff.CLEAR_BUFF] = function(_Buff) |
| 155 | _Buff._init = function(self, data) | 162 | _Buff._init = function(self, data) |
| 156 | self.count = self.buffData.effectValue3 | 163 | self.count = self.buffData.effectValue3 |
| 157 | - self:_afterRount() -- 挂上就清除一下子 | 164 | + self:_afterRound() -- 挂上就清除一下子 |
| 158 | end | 165 | end |
| 159 | - _Buff._afterRount = function(self) | ||
| 160 | - local cType, aim = self:effectValue() | 166 | + _Buff._afterRound = function(self) |
| 161 | for _, buff in ipairs(self.buffs) do | 167 | for _, buff in ipairs(self.buffs) do |
| 162 | - if not buff.isDel and ((cType == 0 and buff.id == aim) or (cType == 1 and buff:getGroup() == aim)) then | 168 | + if not buff.isDel and self:canEffect(buff.id, buff:getGroup()) then |
| 163 | buff.isDel = true | 169 | buff.isDel = true |
| 164 | - self:decCount() | 170 | + self:effect() |
| 165 | end | 171 | end |
| 166 | end | 172 | end |
| 167 | end | 173 | end |
| 168 | - _Buff._effectValue = function(self) | ||
| 169 | - return self.buffData.effectValue1, self.buffData.effectValue2 | 174 | + _Buff._canEffect = function(self, buffId, buffGroup) |
| 175 | + local cType, aim = self.buffData.effectValue1, self.buffData.effectValue2 | ||
| 176 | + if (cType == 0 and buffId == aim) or (cType == 1 and buffGroup == aim) then | ||
| 177 | + return true | ||
| 178 | + end | ||
| 170 | end | 179 | end |
| 171 | end, | 180 | end, |
| 172 | 181 | ||
| 173 | [Buff.OPEN_BLOCK] = function(_Buff) | 182 | [Buff.OPEN_BLOCK] = function(_Buff) |
| 174 | - _Buff._afterRount = function(self) | ||
| 175 | - self.owner.battle.adv:openBlockRand(self.buffData.effectValue1) | 183 | + _Buff._afterRound = function(self) |
| 184 | + local roomNum = self:effect() | ||
| 185 | + self.owner.battle.adv:openBlockRand(roomNum) | ||
| 186 | + end | ||
| 187 | + _Buff._effectValue = function(self) | ||
| 188 | + return self.buffData.effectValue1 | ||
| 176 | end | 189 | end |
| 177 | end, | 190 | end, |
| 178 | 191 | ||
| 179 | [Buff.POWER_CHANGE] = function(_Buff) | 192 | [Buff.POWER_CHANGE] = function(_Buff) |
| 180 | - _Buff._afterRount = function(self) | ||
| 181 | - self.owner.battle.adv:changePower(self.buffData.effectValue2, self.buffData.effectValue1) | 193 | + --cType 0 or nil 值 1 百分比 |
| 194 | + _Buff._afterRound = function(self) | ||
| 195 | + local value, cType = self:effect() | ||
| 196 | + self.owner.battle.adv:changePower(value, cType) | ||
| 197 | + end | ||
| 198 | + _Buff._effectValue = function(self) | ||
| 199 | + return self.buffData.effectValue1, self.buffData.effectValue2 | ||
| 182 | end | 200 | end |
| 183 | end | 201 | end |
| 184 | } | 202 | } |
| 185 | 203 | ||
| 204 | +function Buff:ctor(owner, id) | ||
| 205 | + self.owner = owner | ||
| 206 | + self.id = id | ||
| 207 | + self.buffData = csvdb["adv_buffCsv"][self.id] | ||
| 208 | + self.isDel = false | ||
| 209 | + self.ifRoundEnd = false | ||
| 210 | + self.roundSpace = 0 --生效间隔 | ||
| 211 | + self.turnSpace = 0 --生效间隔 | ||
| 212 | + self.round = 0 --剩余的回合 | ||
| 213 | + self.turn = 0 --剩余战斗内回合 | ||
| 214 | + self.count = -1 -- 可生效的次数 -1 无次数限制 | ||
| 215 | + | ||
| 216 | + if BuffFactory[self.buffData.type] then | ||
| 217 | + BuffFactory[self.buffData.type](self) | ||
| 218 | + end | ||
| 219 | +end | ||
| 186 | 220 | ||
| 187 | function Buff.create(owner, release, data) | 221 | function Buff.create(owner, release, data) |
| 188 | local buff = Buff.new(owner, data.id) | 222 | local buff = Buff.new(owner, data.id) |
| @@ -196,16 +230,15 @@ function Buff.load(owner, data) | @@ -196,16 +230,15 @@ function Buff.load(owner, data) | ||
| 196 | return buff | 230 | return buff |
| 197 | end | 231 | end |
| 198 | 232 | ||
| 199 | -function Buff:ctor(owner, id) | ||
| 200 | - self.owner = owner | ||
| 201 | - self.id = id | ||
| 202 | - self.buffData = csvdb["adv_buffCsv"][self.id] | ||
| 203 | - self.isDel = false | ||
| 204 | - self.round = 0 --剩余的回合 | ||
| 205 | - self.count = -1 -- 可生效的次数 -1 无次数限制 | ||
| 206 | - | ||
| 207 | - if BuffFactory[self.buffData.type] then | ||
| 208 | - BuffFactory[self.buffData.type](self) | 233 | +function Buff:initNew(release, data) |
| 234 | + self.release = release | ||
| 235 | + self.round = self.buffData.round | ||
| 236 | + self.turn = self.buffData.turn | ||
| 237 | + if self.buffData.effectTime > 0 then | ||
| 238 | + self.count = self.buffData.effectTime | ||
| 239 | + end | ||
| 240 | + if self._init then | ||
| 241 | + self:_init(data) | ||
| 209 | end | 242 | end |
| 210 | end | 243 | end |
| 211 | 244 | ||
| @@ -218,6 +251,7 @@ function Buff:initByDB(data) | @@ -218,6 +251,7 @@ function Buff:initByDB(data) | ||
| 218 | end | 251 | end |
| 219 | end | 252 | end |
| 220 | self.round = data.round | 253 | self.round = data.round |
| 254 | + self.roundSpace = data.roundSp -- 可以优化为0的时候不记录 | ||
| 221 | if data.count then | 255 | if data.count then |
| 222 | self.count = data.count | 256 | self.count = data.count |
| 223 | end | 257 | end |
| @@ -227,32 +261,89 @@ function Buff:initByDB(data) | @@ -227,32 +261,89 @@ function Buff:initByDB(data) | ||
| 227 | end | 261 | end |
| 228 | end | 262 | end |
| 229 | 263 | ||
| 230 | -function Buff:initNew(release, data) | ||
| 231 | - self.release = release | ||
| 232 | - self.round = self.buffData.round | ||
| 233 | - if self._init then | ||
| 234 | - self:_init(data) | 264 | +function Buff:battleBegin() |
| 265 | + self.turn = self.buffData.turn | ||
| 266 | + self.ifRoundEnd = self.buffData.turn ~= 0 -- turn类型buff战斗结束后移除 | ||
| 267 | +end | ||
| 268 | + | ||
| 269 | +function Buff:beforeTurn() | ||
| 270 | + if self.isDel or self.owner.isDead then return end | ||
| 271 | + if self.turnSpace > 0 then | ||
| 272 | + return | ||
| 273 | + end | ||
| 274 | + if self._beforeTurn then | ||
| 275 | + self:_beforeTurn() | ||
| 276 | + end | ||
| 277 | +end | ||
| 278 | + | ||
| 279 | +function Buff:afterTurn() | ||
| 280 | + if self.isDel or self.owner.isDead then return end | ||
| 281 | + if self.turnSpace > 0 then | ||
| 282 | + self.turnSpace = self.turnSpace - 1 | ||
| 283 | + self:decTurn() | ||
| 284 | + return | ||
| 285 | + end | ||
| 286 | + if self._afterTurn then | ||
| 287 | + self:_afterTurn() | ||
| 288 | + end | ||
| 289 | + if self.buffData.turnTime > 0 then | ||
| 290 | + self.turnSpace = self.buffData.turnTime | ||
| 291 | + end | ||
| 292 | + self:decTurn() | ||
| 293 | +end | ||
| 294 | + | ||
| 295 | +function Buff:decTurn() | ||
| 296 | + if self.buffData.turn == 0 then | ||
| 297 | + return | ||
| 298 | + end | ||
| 299 | + self.turn = self.turn - 1 | ||
| 300 | + if self.turn <= 0 then | ||
| 301 | + self.isDel = true | ||
| 235 | end | 302 | end |
| 236 | end | 303 | end |
| 237 | 304 | ||
| 238 | function Buff:afterRound() | 305 | function Buff:afterRound() |
| 239 | - if self.isDel or self.owner.isDead then return end | ||
| 240 | - if self._afterRount then | ||
| 241 | - self:_afterRount() | 306 | + if self.isDel or self.owner.isDead then return end |
| 307 | + if self.roundSpace > 0 then | ||
| 308 | + self.roundSpace = self.turnSpace - 1 | ||
| 309 | + self:decRound() | ||
| 310 | + return | ||
| 311 | + end | ||
| 312 | + if self._afterRound then | ||
| 313 | + self:_afterRound() | ||
| 314 | + end | ||
| 315 | + if self.ifRoundEnd then -- turn类型buff战斗结束后移除 | ||
| 316 | + self.isDel = true | ||
| 317 | + return | ||
| 242 | end | 318 | end |
| 319 | + if self.buffData.roundTime > 0 then | ||
| 320 | + self.turnSpace = self.buffData.roundTime | ||
| 321 | + end | ||
| 322 | + self:decRound() | ||
| 323 | +end | ||
| 243 | 324 | ||
| 244 | - if self.buffData.round ~= 0 then | ||
| 245 | - self.round = self.round - 1 | ||
| 246 | - if self.round <= 0 then | ||
| 247 | - self.isDel = true | ||
| 248 | - end | 325 | +function Buff:decRound() |
| 326 | + if self.buffData.round == 0 then | ||
| 327 | + return | ||
| 328 | + end | ||
| 329 | + self.round = self.round - 1 | ||
| 330 | + if self.round <= 0 then | ||
| 331 | + self.isDel = true | ||
| 332 | + end | ||
| 333 | +end | ||
| 334 | + | ||
| 335 | +function Buff:canEffect(...) | ||
| 336 | + if not self._canEffect then | ||
| 337 | + return true | ||
| 249 | end | 338 | end |
| 339 | + return self:_canEffect(...) | ||
| 250 | end | 340 | end |
| 251 | 341 | ||
| 252 | -function Buff:effectValue() | 342 | +function Buff:effect() |
| 253 | if self._effectValue then | 343 | if self._effectValue then |
| 254 | return self:_effectValue() | 344 | return self:_effectValue() |
| 255 | end | 345 | end |
| 346 | + self:decCount() | ||
| 256 | end | 347 | end |
| 257 | --删除buff 时调用 | 348 | --删除buff 时调用 |
| 258 | function Buff:endBuff() | 349 | function Buff:endBuff() |
| @@ -289,6 +380,7 @@ function Buff:getDB() | @@ -289,6 +380,7 @@ function Buff:getDB() | ||
| 289 | if self.buffData.round ~= 0 then | 380 | if self.buffData.round ~= 0 then |
| 290 | db.round = self.round | 381 | db.round = self.round |
| 291 | end | 382 | end |
| 383 | + db.roundSp = self.roundSpace | ||
| 292 | if self.count ~= -1 then | 384 | if self.count ~= -1 then |
| 293 | db.count = self.count | 385 | db.count = self.count |
| 294 | end | 386 | end |
src/adv/AdvPlayer.lua
| @@ -40,13 +40,19 @@ function BaseObject:initAfter(data) | @@ -40,13 +40,19 @@ function BaseObject:initAfter(data) | ||
| 40 | end | 40 | end |
| 41 | end | 41 | end |
| 42 | 42 | ||
| 43 | +function BaseObject:beforeTurn() | ||
| 44 | + for _, buff in ipairs(self.buffs) do | ||
| 45 | + buff:beforeTurn() | ||
| 46 | + end | ||
| 47 | +end | ||
| 48 | + | ||
| 43 | function BaseObject:afterTurn() | 49 | function BaseObject:afterTurn() |
| 44 | for _, passive in ipairs(self.passives) do | 50 | for _, passive in ipairs(self.passives) do |
| 45 | passive:afterTurn() | 51 | passive:afterTurn() |
| 46 | end | 52 | end |
| 47 | - -- for _, buff in ipairs(self.buffs) do | ||
| 48 | - -- buff:afterTurn(self) | ||
| 49 | - -- end | 53 | + for _, buff in ipairs(self.buffs) do |
| 54 | + buff:afterTurn() | ||
| 55 | + end | ||
| 50 | end | 56 | end |
| 51 | 57 | ||
| 52 | function BaseObject:afterRound() | 58 | function BaseObject:afterRound() |
| @@ -58,6 +64,16 @@ function BaseObject:afterRound() | @@ -58,6 +64,16 @@ function BaseObject:afterRound() | ||
| 58 | end | 64 | end |
| 59 | end | 65 | end |
| 60 | 66 | ||
| 67 | +function BaseObject:clearTurn() | ||
| 68 | + for i = #self.buffs, 1, -1 do | ||
| 69 | + if self.buffs[i].isDel then | ||
| 70 | + self.battle.adv:backBuff(self.id, self.buffs[i].id, true) | ||
| 71 | + self.buffs[i]:endBuff() | ||
| 72 | + table.remove(self.buffs, i) | ||
| 73 | + end | ||
| 74 | + end | ||
| 75 | +end | ||
| 76 | + | ||
| 61 | function BaseObject:clearRound() | 77 | function BaseObject:clearRound() |
| 62 | for i = #self.passives, 1, -1 do | 78 | for i = #self.passives, 1, -1 do |
| 63 | if self.passives[i].isDel then | 79 | if self.passives[i].isDel then |
| @@ -82,9 +98,9 @@ function BaseObject:battleBegin() | @@ -82,9 +98,9 @@ function BaseObject:battleBegin() | ||
| 82 | for _, passive in ipairs(self.passives) do | 98 | for _, passive in ipairs(self.passives) do |
| 83 | passive:battleBegin() | 99 | passive:battleBegin() |
| 84 | end | 100 | end |
| 85 | - -- for _, buff in ipairs(self.buffs) do | ||
| 86 | - -- buff:afterRound(self) | ||
| 87 | - -- end | 101 | + for _, buff in ipairs(self.buffs) do |
| 102 | + buff:battleBegin() | ||
| 103 | + end | ||
| 88 | end | 104 | end |
| 89 | 105 | ||
| 90 | function BaseObject:addPassive(params) | 106 | function BaseObject:addPassive(params) |
| @@ -102,10 +118,9 @@ function BaseObject:addBuff(buffId, releaser) | @@ -102,10 +118,9 @@ function BaseObject:addBuff(buffId, releaser) | ||
| 102 | local buffData = csvdb["adv_buffCsv"][buffId] | 118 | local buffData = csvdb["adv_buffCsv"][buffId] |
| 103 | if not buffData then return end | 119 | if not buffData then return end |
| 104 | for _, buff in ipairs(self.buffs) do | 120 | for _, buff in ipairs(self.buffs) do |
| 105 | - if not buff.isDel and (buff:getType() == CLEAR_BUFF or buff:getType() == IMMNUE_BUFF) then | ||
| 106 | - local cType, aim = buff:effectValue() -- 0=buffid 1=buff组 | ||
| 107 | - if (cType == 0 and buffId == aim) or (cType == 1 and buffData.group == aim) then -- buff 剔除 | ||
| 108 | - buff:decCount() --减少次数 | 121 | + if not buff.isDel and (buff:getType() == Buff.CLEAR_BUFF or buff:getType() == Buff.IMMNUE_BUFF) then |
| 122 | + if buff:canEffect(buffId, buffData.group) then | ||
| 123 | + buff:effect() | ||
| 109 | return | 124 | return |
| 110 | end | 125 | end |
| 111 | end | 126 | end |
| @@ -136,7 +151,7 @@ function BaseObject:getCommonBuffEffect(bType) | @@ -136,7 +151,7 @@ function BaseObject:getCommonBuffEffect(bType) | ||
| 136 | local effect, count = {[0] = 0, [1] = 0}, 0 | 151 | local effect, count = {[0] = 0, [1] = 0}, 0 |
| 137 | for _, buff in ipairs(self.buffs) do | 152 | for _, buff in ipairs(self.buffs) do |
| 138 | if not buff.isDel and buff:getType() == bType then | 153 | if not buff.isDel and buff:getType() == bType then |
| 139 | - local cType, value = buff:effectValue() | 154 | + local cType, value = buff:effect() |
| 140 | if cType then | 155 | if cType then |
| 141 | effect[cType] = effect[cType] + value | 156 | effect[cType] = effect[cType] + value |
| 142 | count = count + 1 | 157 | count = count + 1 |
| @@ -151,7 +166,7 @@ function BaseObject:getBackHurtBuff(isAtk) | @@ -151,7 +166,7 @@ function BaseObject:getBackHurtBuff(isAtk) | ||
| 151 | local effect = {[0] = 0, [1] = 0} | 166 | local effect = {[0] = 0, [1] = 0} |
| 152 | for _, buff in ipairs(self.buffs) do | 167 | for _, buff in ipairs(self.buffs) do |
| 153 | if not buff.isDel and buff:getType() == Buff.BACK_HURT then | 168 | if not buff.isDel and buff:getType() == Buff.BACK_HURT then |
| 154 | - local cType, value, aType = buff:effectValue() -- aType 0 全部 1 普通攻击 | 169 | + local cType, value, aType = buff:effect() -- aType 0 全部 1 普通攻击 |
| 155 | if cType then | 170 | if cType then |
| 156 | if aType == 0 or isAtk then | 171 | if aType == 0 or isAtk then |
| 157 | effect[cType] = effect[cType] + value | 172 | effect[cType] = effect[cType] + value |
| @@ -176,7 +191,7 @@ end | @@ -176,7 +191,7 @@ end | ||
| 176 | function BaseObject:reSetAttr(field) | 191 | function BaseObject:reSetAttr(field) |
| 177 | local old = self[field] | 192 | local old = self[field] |
| 178 | self[field] = self["_" .. field] --重置一下 | 193 | self[field] = self["_" .. field] --重置一下 |
| 179 | - local fieldToBuff = {atk = Buff.IMMNUE_ATK, hit = Buff.HIT_CHANGE, miss = Buff.MISS_CHANGE, def = Buff.DEF_CHANGE} | 194 | + local fieldToBuff = {atk = Buff.ATK_CHANGE, hit = Buff.HIT_CHANGE, miss = Buff.MISS_CHANGE, def = Buff.DEF_CHANGE} |
| 180 | local effect = self:getCommonBuffEffect(fieldToBuff[field]) | 195 | local effect = self:getCommonBuffEffect(fieldToBuff[field]) |
| 181 | self[field] = math.ceil((self[field] + effect[0]) * (1 + effect[1])) | 196 | self[field] = math.ceil((self[field] + effect[0]) * (1 + effect[1])) |
| 182 | local delta = self[field] - old | 197 | local delta = self[field] - old |