(int lifeGain, final Card source, final SpellAbility sa)
| 451 | } |
| 452 | |
| 453 | public final boolean gainLife(int lifeGain, final Card source, final SpellAbility sa) { |
| 454 | if (!canGainLife() || lifeGain <= 0) { |
| 455 | return false; |
| 456 | } |
| 457 | |
| 458 | final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this); |
| 459 | repParams.put(AbilityKey.LifeGained, lifeGain); |
| 460 | repParams.put(AbilityKey.SourceSA, sa); |
| 461 | |
| 462 | switch (getGame().getReplacementHandler().run(ReplacementType.GainLife, repParams)) { |
| 463 | case NotReplaced: |
| 464 | break; |
| 465 | case Updated: |
| 466 | // check if this is still the affected player |
| 467 | if (this.equals(repParams.get(AbilityKey.Affected))) { |
| 468 | lifeGain = (int) repParams.get(AbilityKey.LifeGained); |
| 469 | } else { |
| 470 | return false; |
| 471 | } |
| 472 | break; |
| 473 | default: |
| 474 | return false; |
| 475 | } |
| 476 | |
| 477 | if (lifeGain <= 0) { |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | int oldLife = life; |
| 482 | life += lifeGain; |
| 483 | view.updateLife(this); |
| 484 | boolean firstGain = lifeGainedTimesThisTurn == 0; |
| 485 | lifeGainedThisTurn += lifeGain; |
| 486 | lifeGainedTimesThisTurn++; |
| 487 | |
| 488 | // team mates need to be notified about life gained |
| 489 | for (final Player p : getTeamMates(true)) { |
| 490 | p.addLifeGainedByTeamThisTurn(lifeGain); |
| 491 | } |
| 492 | |
| 493 | final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(this); |
| 494 | runParams.put(AbilityKey.LifeAmount, lifeGain); |
| 495 | runParams.put(AbilityKey.Source, source); |
| 496 | runParams.put(AbilityKey.SourceSA, sa); |
| 497 | runParams.put(AbilityKey.FirstTime, firstGain); |
| 498 | game.getTriggerHandler().runTrigger(TriggerType.LifeGained, runParams, false); |
| 499 | |
| 500 | game.fireEvent(new GameEventPlayerLivesChanged(this, oldLife, life)); |
| 501 | return true; |
| 502 | } |
| 503 | |
| 504 | public final boolean canGainLife() { |
| 505 | return isInGame() && !StaticAbilityCantGainLosePayLife.anyCantGainLife(this); |
no test coverage detected