MCPcopy Create free account
hub / github.com/Card-Forge/forge / gainLife

Method gainLife

forge-game/src/main/java/forge/game/player/Player.java:453–502  ·  view source on GitHub ↗
(int lifeGain, final Card source, final SpellAbility sa)

Source from the content-addressed store, hash-verified

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);

Callers 7

setLifeMethod · 0.95
resolveMethod · 0.95
resolveMethod · 0.95
resolveMethod · 0.95
dealDamageMethod · 0.80
payAsDecidedMethod · 0.80
resolveMethod · 0.80

Calls 15

canGainLifeMethod · 0.95
mapFromAffectedMethod · 0.95
getGameMethod · 0.95
getTeamMatesMethod · 0.95
mapFromPlayerMethod · 0.95
getReplacementHandlerMethod · 0.80
runTriggerMethod · 0.80
getTriggerHandlerMethod · 0.80
runMethod · 0.65
getMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected