(int toLose, final boolean damage, final boolean manaBurn)
| 506 | } |
| 507 | |
| 508 | public final int loseLife(int toLose, final boolean damage, final boolean manaBurn) { |
| 509 | // Rule 118.4 |
| 510 | // this is for players being able to pay 0 life nothing to do |
| 511 | // no trigger for lost no life |
| 512 | if (toLose <= 0 || !canLoseLife()) { |
| 513 | return 0; |
| 514 | } |
| 515 | int oldLife = life; |
| 516 | |
| 517 | final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this); |
| 518 | repParams.put(AbilityKey.Amount, toLose); |
| 519 | repParams.put(AbilityKey.IsDamage, damage); |
| 520 | |
| 521 | switch (getGame().getReplacementHandler().run(ReplacementType.LifeReduced, repParams)) { |
| 522 | case NotReplaced: |
| 523 | break; |
| 524 | case Updated: |
| 525 | // check if this is still the affected player |
| 526 | if (this.equals(repParams.get(AbilityKey.Affected))) { |
| 527 | toLose = (int) repParams.get(AbilityKey.Amount); |
| 528 | // there is nothing that changes lifegain into lifeloss this way |
| 529 | if (toLose <= 0) { |
| 530 | return 0; |
| 531 | } |
| 532 | } else { |
| 533 | return 0; |
| 534 | } |
| 535 | break; |
| 536 | default: |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | life -= toLose; |
| 541 | view.updateLife(this); |
| 542 | if (manaBurn) { |
| 543 | game.fireEvent(new GameEventManaBurn(PlayerView.get(this), true, toLose)); |
| 544 | } else { |
| 545 | game.fireEvent(new GameEventPlayerLivesChanged(this, oldLife, life)); |
| 546 | } |
| 547 | |
| 548 | boolean firstLost = lifeLostThisTurn == 0; |
| 549 | lifeLostThisTurn += toLose; |
| 550 | |
| 551 | final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(this); |
| 552 | runParams.put(AbilityKey.LifeAmount, toLose); |
| 553 | runParams.put(AbilityKey.FirstTime, firstLost); |
| 554 | game.getTriggerHandler().runTrigger(TriggerType.LifeLost, runParams, false); |
| 555 | |
| 556 | return toLose; |
| 557 | } |
| 558 | |
| 559 | public final boolean canLoseLife() { |
| 560 | return isInGame() && !StaticAbilityCantGainLosePayLife.anyCantLoseLife(this); |
no test coverage detected