mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
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:
parent
6bb8b68952
commit
0a635ac341
2 changed files with 157 additions and 41 deletions
|
|
@ -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;
|
||||
}
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue