mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Changed target handling of ModularAbility.
This commit is contained in:
parent
de8cef8e1e
commit
f601c01cab
1 changed files with 17 additions and 4 deletions
|
@ -4,6 +4,7 @@ import mage.Constants;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
import mage.Constants.Zone;
|
import mage.Constants.Zone;
|
||||||
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.StaticAbility;
|
import mage.abilities.StaticAbility;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
import mage.abilities.common.DiesTriggeredAbility;
|
||||||
|
@ -15,9 +16,9 @@ import mage.counters.CounterType;
|
||||||
import mage.filter.common.FilterArtifactPermanent;
|
import mage.filter.common.FilterArtifactPermanent;
|
||||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.Target;
|
|
||||||
import mage.target.common.TargetArtifactPermanent;
|
import mage.target.common.TargetArtifactPermanent;
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,10 +38,15 @@ import mage.target.common.TargetArtifactPermanent;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ModularAbility extends DiesTriggeredAbility {
|
public class ModularAbility extends DiesTriggeredAbility {
|
||||||
|
private static final FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact creature");
|
||||||
|
static {
|
||||||
|
filter.add(new CardTypePredicate(CardType.CREATURE));
|
||||||
|
}
|
||||||
private int amount;
|
private int amount;
|
||||||
|
|
||||||
public ModularAbility(Card card, int amount) {
|
public ModularAbility(Card card, int amount) {
|
||||||
super(new ModularDistributeCounterEffect(), true);
|
super(new ModularDistributeCounterEffect(), true);
|
||||||
|
this.addTarget(new TargetArtifactPermanent(filter));
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
card.addAbility(new ModularStaticAbility(amount));
|
card.addAbility(new ModularStaticAbility(amount));
|
||||||
}
|
}
|
||||||
|
@ -50,6 +56,15 @@ public class ModularAbility extends DiesTriggeredAbility {
|
||||||
this.amount = ability.amount;
|
this.amount = ability.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
|
MageObject before = game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD);
|
||||||
|
if (before != null && ((Permanent) before).getCounters().getCount(CounterType.P1P1) > 0) {
|
||||||
|
return super.checkTrigger(event, game);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModularAbility copy() {
|
public ModularAbility copy() {
|
||||||
return new ModularAbility(this);
|
return new ModularAbility(this);
|
||||||
|
@ -112,9 +127,7 @@ class ModularDistributeCounterEffect extends OneShotEffect<ModularDistributeCoun
|
||||||
if (numberOfCounters > 0) {
|
if (numberOfCounters > 0) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Target target = new TargetArtifactPermanent(filter);
|
Permanent targetArtifact = game.getPermanent(targetPointer.getFirst(game, source));
|
||||||
player.chooseTarget(outcome, target, source, game);
|
|
||||||
Permanent targetArtifact = game.getPermanent(target.getFirstTarget());
|
|
||||||
if (targetArtifact != null) {
|
if (targetArtifact != null) {
|
||||||
targetArtifact.addCounters(CounterType.P1P1.createInstance(numberOfCounters), game);
|
targetArtifact.addCounters(CounterType.P1P1.createInstance(numberOfCounters), game);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue