mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Finished modular keyword ability from Darksteel.
This commit is contained in:
parent
46195cec41
commit
37d487464f
2 changed files with 127 additions and 30 deletions
127
Mage/src/mage/abilities/keyword/ModularAbility.java
Normal file
127
Mage/src/mage/abilities/keyword/ModularAbility.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.common.DiesTriggeredAbility;
|
||||
import mage.abilities.effects.EntersBattlefieldEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.common.FilterArtifactPermanent;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetArtifactPermanent;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 702.41. Modular
|
||||
*
|
||||
* 702.41a Modular represents both a static ability and a triggered ability.
|
||||
* "Modular N" means "This permanent enters the battlefield with N +1/+1
|
||||
* counters on it" and "When this permanent is put into a graveyard
|
||||
* from the battlefield, you may put a +1/+1 counter on target artifact
|
||||
* creature for each +1/+1 counter on this permanent."
|
||||
* 702.41b If a creature has multiple instances of modular, each one works separately.
|
||||
*
|
||||
*
|
||||
* @author Loki, LevelX2
|
||||
*/
|
||||
|
||||
public class ModularAbility extends DiesTriggeredAbility {
|
||||
private int amount;
|
||||
|
||||
public ModularAbility(Card card, int amount) {
|
||||
super(new ModularDistributeCounterEffect(), true);
|
||||
this.amount = amount;
|
||||
card.addAbility(new ModularStaticAbility(amount));
|
||||
}
|
||||
|
||||
public ModularAbility(ModularAbility ability) {
|
||||
super(ability);
|
||||
this.amount = ability.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModularAbility copy() {
|
||||
return new ModularAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Modular " + amount + " <i>(This enters the battlefield with " + amount + " +1/+1 counter on it. When it dies, you may put its +1/+1 counters on target artifact creature.)</i>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ModularStaticAbility extends StaticAbility<ModularStaticAbility> {
|
||||
|
||||
public ModularStaticAbility(int amount) {
|
||||
super(Constants.Zone.BATTLEFIELD, new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(amount))));
|
||||
}
|
||||
|
||||
public ModularStaticAbility(final ModularStaticAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModularStaticAbility copy() {
|
||||
return new ModularStaticAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ModularDistributeCounterEffect extends OneShotEffect<ModularDistributeCounterEffect> {
|
||||
private static final FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact creature");
|
||||
static {
|
||||
filter.add(new CardTypePredicate(CardType.CREATURE));
|
||||
}
|
||||
|
||||
public ModularDistributeCounterEffect() {
|
||||
super(Outcome.BoostCreature);
|
||||
this.staticText = "you may put a +1/+1 counter on target artifact creature for each +1/+1 counter on this permanent";
|
||||
}
|
||||
|
||||
public ModularDistributeCounterEffect(final ModularDistributeCounterEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModularDistributeCounterEffect copy() {
|
||||
return new ModularDistributeCounterEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
|
||||
if (sourcePermanent != null) {
|
||||
int numberOfCounters = sourcePermanent.getCounters().getCount(CounterType.P1P1);
|
||||
if (numberOfCounters > 0) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
Target target = new TargetArtifactPermanent(filter);
|
||||
player.chooseTarget(outcome, target, source, game);
|
||||
Permanent targetArtifact = game.getPermanent(target.getFirstTarget());
|
||||
if (targetArtifact != null) {
|
||||
targetArtifact.addCounters(CounterType.P1P1.createInstance(numberOfCounters), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.effects.EntersBattlefieldEffect;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.counters.CounterType;
|
||||
|
||||
/**
|
||||
* Modular keyword static part
|
||||
* @author Loki
|
||||
*/
|
||||
public class ModularStaticAbility extends StaticAbility<ModularStaticAbility> {
|
||||
private int amount;
|
||||
|
||||
public ModularStaticAbility(int amount) {
|
||||
super(Constants.Zone.BATTLEFIELD, new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(amount))));
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public ModularStaticAbility(final ModularStaticAbility ability) {
|
||||
super(ability);
|
||||
this.amount = ability.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModularStaticAbility copy() {
|
||||
return new ModularStaticAbility(this);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue