mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
refactor: common class DrawCardTargetControllerEffect
tests for Ob Nixilis the Hate-Twisted; Dream Fracture resolves #12292
This commit is contained in:
parent
cd11a8f7e9
commit
b4da526770
13 changed files with 250 additions and 392 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
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;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author xenohedron
|
||||
*/
|
||||
public class DrawCardTargetControllerEffect extends OneShotEffect {
|
||||
|
||||
protected DynamicValue amount;
|
||||
|
||||
public DrawCardTargetControllerEffect(int amount) {
|
||||
this(StaticValue.get(amount));
|
||||
this.staticText = "its controller draws " + CardUtil.numberToText(amount, "a")
|
||||
+ (amount == 1 ? " card" : " cards");
|
||||
}
|
||||
|
||||
public DrawCardTargetControllerEffect(DynamicValue amount) {
|
||||
super(Outcome.DrawCard);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
protected DrawCardTargetControllerEffect(final DrawCardTargetControllerEffect effect) {
|
||||
super(effect);
|
||||
amount = effect.amount.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawCardTargetControllerEffect copy() {
|
||||
return new DrawCardTargetControllerEffect(this);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
if (targetController != null) {
|
||||
targetController.drawCards(amount.calculate(game, source, this), source, game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue