fixed implementation of Tetravus to allow for multiple counters/tokens in a single turn

The tokens were also incorrectly implemented
This commit is contained in:
Evan Kranzler 2018-06-13 20:58:31 -04:00
parent 6bb8b68952
commit 0a635ac341
2 changed files with 157 additions and 41 deletions

View file

@ -1,35 +1,40 @@
package mage.cards.t;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.StaticAbility;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.condition.common.SourceHasCounterCondition;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.ExileTargetCost;
import mage.abilities.costs.common.RemoveCountersSourceCost;
import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.DoIfCostPaid;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.TetraviteToken;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;
/**
*
* @author MarcoMarin
* @author TheElk801
*/
public final class Tetravus extends CardImpl {
@ -41,15 +46,24 @@ public final class Tetravus extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Tetravus enters the battlefield with three +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)), "{this} enters the battlefield with three +1/+1 counters on it"));
this.addAbility(new EntersBattlefieldAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)),
"with three +1/+1 counters on it"
));
// At the beginning of your upkeep, you may remove any number of +1/+1 counters from Tetravus. If you do, create that many 1/1 colorless Tetravite artifact creature tokens. They each have flying and "This creature can't be enchanted."
this.addAbility(new ConditionalTriggeredAbility(new BeginningOfUpkeepTriggeredAbility(new DoIfCostPaid(new CreateTokenEffect(new TetraviteToken()),
new RemoveCountersSourceCost(CounterType.P1P1.createInstance(1))), TargetController.YOU, true),
new SourceHasCounterCondition(CounterType.P1P1, 1), "At the beginning of your upkeep, you may remove any number of +1/+1 counters from Tetravus. If you do, create that many 1/1 colorless Tetravite artifact creature tokens. They each have flying and \"This creature can't be enchanted.\""));
this.addAbility(new BeginningOfUpkeepTriggeredAbility(
new TetravusCreateTokensEffect(),
TargetController.YOU, true
));
// At the beginning of your upkeep, you may exile any number of tokens created with Tetravus. If you do, put that many +1/+1 counters on Tetravus.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new DoIfCostPaid(new AddCountersSourceEffect(CounterType.P1P1.createInstance(1)),
new ExileTargetCost(new TargetControlledPermanent(new FilterControlledPermanent("Tetravite")))), TargetController.YOU, true));
this.addAbility(new BeginningOfUpkeepTriggeredAbility(
new TetravusAddCountersEffect(),
TargetController.YOU, true
));
}
@ -63,27 +77,120 @@ public final class Tetravus extends CardImpl {
}
}
class CantBeEnchantedAbility extends StaticAbility {
class TetravusCreateTokensEffect extends OneShotEffect {
public CantBeEnchantedAbility() {
super(Zone.BATTLEFIELD, null);
public TetravusCreateTokensEffect() {
super(Outcome.Benefit);
this.staticText = "remove any number of +1/+1 counters from {this}. "
+ "If you do, create that many 1/1 colorless Tetravite artifact creature tokens. "
+ "They each have flying and \"This creature can't be enchanted.\"";
}
public CantBeEnchantedAbility(final CantBeEnchantedAbility ability) {
super(ability);
public TetravusCreateTokensEffect(final TetravusCreateTokensEffect effect) {
super(effect);
}
@Override
public CantBeEnchantedAbility copy() {
return new CantBeEnchantedAbility(this);
public TetravusCreateTokensEffect copy() {
return new TetravusCreateTokensEffect(this);
}
public boolean canTarget(MageObject source, Game game) {
if (source.isEnchantment()
&& source.hasSubtype(SubType.AURA, game)) {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (player == null || permanent == null) {
return false;
}
int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1);
if (countersToRemove == 0) {
return false;
}
countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game);
Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove));
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) {
CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove);
effect.apply(game, source);
Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
Set<UUID> tokensCreated;
if (object != null) {
tokensCreated = (Set<UUID>) object;
} else {
tokensCreated = new HashSet<>();
}
for (UUID tokenId : effect.getLastAddedTokenIds()) {
if (tokenId != null) {
tokensCreated.add(tokenId);
}
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
return false;
}
return true;
}
class TetravusAddCountersEffect extends OneShotEffect {
public TetravusAddCountersEffect() {
super(Outcome.Benefit);
this.staticText = "exile any number of tokens created with {this}. "
+ "If you do, put that many +1/+1 counters on {this}";
}
public TetravusAddCountersEffect(final TetravusAddCountersEffect effect) {
super(effect);
}
@Override
public TetravusAddCountersEffect copy() {
return new TetravusAddCountersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (player == null || permanent == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("tokens created with " + permanent.getName());
filter.add(new TetravusPredicate(new MageObjectReference(permanent, game)));
filter.add(new TokenPredicate());
ExileTargetCost cost = new ExileTargetCost(new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true));
if (cost.pay(source, game, source.getSourceId(), player.getId(), true)) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(cost.getPermanents().size())).apply(game, source);
}
return false;
}
}
class TetravusPredicate implements Predicate<Permanent> {
private final MageObjectReference mor;
public TetravusPredicate(MageObjectReference mor) {
this.mor = mor;
}
@Override
public boolean apply(Permanent input, Game game) {
if (mor == null) {
return false;
}
Permanent permanent = mor.getPermanent(game);
if (permanent == null) {
return false;
}
Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
if (object == null) {
return false;
}
Set<UUID> tokensCreated = (Set<UUID>) object;
return tokensCreated.contains(input.getId());
}
@Override
public String toString() {
return "";
}
}

View file

@ -1,14 +1,17 @@
package mage.game.permanent.token;
import mage.constants.CardType;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.StaticAbility;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.keyword.FlyingAbility;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
@ -17,7 +20,7 @@ import mage.game.Game;
public final class TetraviteToken extends TokenImpl {
public TetraviteToken() {
super("Tetravite", "1/1 colorless Tetravite artifact creature token");
super("Tetravite", "1/1 colorless Tetravite artifact creature token with flying and \"This creature cant be enchanted.\"");
cardType.add(CardType.CREATURE);
cardType.add(CardType.ARTIFACT);
subtype.add(SubType.TETRAVITE);
@ -25,7 +28,7 @@ public final class TetraviteToken extends TokenImpl {
toughness = new MageInt(1);
this.addAbility(FlyingAbility.getInstance());
this.addAbility(new CantBeEnchantedAbility());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TetraviteTokenEffect()));
}
public TetraviteToken(final TetraviteToken token) {
@ -37,24 +40,30 @@ public final class TetraviteToken extends TokenImpl {
}
}
class CantBeEnchantedAbility extends StaticAbility {
class TetraviteTokenEffect extends ContinuousRuleModifyingEffectImpl {
public CantBeEnchantedAbility() {
super(Zone.BATTLEFIELD, null);
public TetraviteTokenEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "this creature can't be enchanted";
}
public CantBeEnchantedAbility(final CantBeEnchantedAbility ability) {
super(ability);
public TetraviteTokenEffect(final TetraviteTokenEffect effect) {
super(effect);
}
@Override
public CantBeEnchantedAbility copy() {
return new CantBeEnchantedAbility(this);
public TetraviteTokenEffect copy() {
return new TetraviteTokenEffect(this);
}
public boolean canTarget(MageObject source, Game game) {
return !(source.isEnchantment()
&& source.hasSubtype(SubType.AURA, game));
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ATTACH
|| event.getType() == GameEvent.EventType.STAY_ATTACHED;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getTargetId().equals(source.getSourceId());
}
}