refactor: common logic for getting controller of target object (#13038)

This commit is contained in:
xenohedron 2024-10-26 20:23:34 -04:00 committed by GitHub
parent 6cc2306784
commit 737e67963d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 53 additions and 126 deletions

View file

@ -6,8 +6,6 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player;
/**
@ -39,16 +37,7 @@ public class GainLifeTargetControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player targetController = null;
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
targetController = game.getPlayer(permanent.getControllerId());
} else {
Spell spell = game.getSpellOrLKIStack(getTargetPointer().getFirst(game, source));
if (spell != null) {
targetController = game.getPlayer(spell.getControllerId());
}
}
Player targetController = getTargetPointer().getControllerOfFirstTargetOrLKI(game, source);
if (targetController != null) {
targetController.gainLife(amount.calculate(game, source, this), game, source);
return true;