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

Method payLife

forge-game/src/main/java/forge/game/player/Player.java:570–622  ·  view source on GitHub ↗
(final int lifePayment, final SpellAbility cause, final boolean effect)

Source from the content-addressed store, hash-verified

568 }
569
570 public final boolean payLife(final int lifePayment, final SpellAbility cause, final boolean effect) {
571 // fast check for pay zero life
572 if (lifePayment <= 0) {
573 cause.setPaidLife(0);
574 return true;
575 }
576
577 if (!canPayLife(lifePayment, effect, cause)) {
578 return false;
579 }
580
581 // Replacement only matters when life payment is greater than 0
582 Map<AbilityKey, Object> replaceParams = AbilityKey.mapFromAffected(this);
583 replaceParams.put(AbilityKey.Amount, lifePayment);
584 replaceParams.put(AbilityKey.Cause, cause);
585 replaceParams.put(AbilityKey.EffectOnly, effect);
586 // copy replacement params?
587 if (cause.isReplacementAbility() && effect) {
588 replaceParams.putAll(cause.getReplacingObjects());
589 }
590 switch (getGame().getReplacementHandler().run(ReplacementType.PayLife, replaceParams)) {
591 case Replaced:
592 return true;
593 case Prevented:
594 case Skipped:
595 return false;
596 default:
597 break;
598 }
599
600 final int lost = loseLife(lifePayment, false, false);
601 cause.setPaidLife(lifePayment);
602
603 final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(this);
604 runParams.put(AbilityKey.LifeAmount, lifePayment);
605 game.getTriggerHandler().runTrigger(TriggerType.PayLife, runParams, false);
606
607 if (lost > 0) { // Run triggers if player actually lost life
608 boolean runAll = false;
609 Map<Player, Integer> lossMap = cause.getLoseLifeMap();
610 if (lossMap == null) {
611 lossMap = Maps.newHashMap();
612 runAll = true;
613 }
614 lossMap.put(this, lost);
615 if (runAll) {
616 final Map<AbilityKey, Object> runParams2 = AbilityKey.mapFromPIMap(lossMap);
617 game.getTriggerHandler().runTrigger(TriggerType.LifeLostAll, runParams2, false);
618 }
619 }
620
621 return true;
622 }
623
624 public final boolean canPayEnergy(final int energyPayment) {
625 int cnt = getCounters(CounterEnumType.ENERGY);

Callers 3

payAsDecidedMethod · 0.80
doneMethod · 0.80
payManaCostMethod · 0.80

Calls 15

canPayLifeMethod · 0.95
mapFromAffectedMethod · 0.95
getGameMethod · 0.95
loseLifeMethod · 0.95
mapFromPlayerMethod · 0.95
mapFromPIMapMethod · 0.95
setPaidLifeMethod · 0.80
isReplacementAbilityMethod · 0.80
getReplacingObjectsMethod · 0.80
getReplacementHandlerMethod · 0.80
runTriggerMethod · 0.80
getTriggerHandlerMethod · 0.80

Tested by

no test coverage detected