use of mage.game.permanent.PermanentToken in project mage by magefree.
the class UnholyIndentureReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// copy from ReturnToBattlefieldUnderYourControlAttachedEffect
Object object = getValue("attachedTo");
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && object instanceof Permanent && !(object instanceof PermanentToken)) {
// not token
Card card = game.getCard(((Permanent) object).getId());
// Move the card only, if it is still in the next zone after the battlefield
if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {
Counters countersToAdd = new Counters();
countersToAdd.addCounter(CounterType.P1P1.createInstance());
game.setEnterWithCounters(card.getId(), countersToAdd);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, false, null);
return true;
}
}
return false;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class AetherSnapEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards tokens = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getSourceId(), game)) {
if (permanent instanceof PermanentToken) {
tokens.add(permanent);
}
if (permanent.getCounters(game).isEmpty()) {
continue;
}
Counters counters = permanent.getCounters(game).copy();
for (Counter counter : counters.values()) {
permanent.removeCounters(counter, source, game);
}
}
controller.moveCards(tokens, Zone.EXILED, source, game);
return true;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class ArboriaEffect method canAttack.
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
if (defenderId == null) {
return true;
}
CastSpellYourLastTurnWatcher watcher = game.getState().getWatcher(CastSpellYourLastTurnWatcher.class);
if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) {
return true;
}
PermanentsEnteredBattlefieldYourLastTurnWatcher watcher2 = game.getState().getWatcher(PermanentsEnteredBattlefieldYourLastTurnWatcher.class);
if (watcher2 != null && watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId) != null) {
for (Permanent permanent : watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId)) {
if (permanent != null && !(permanent instanceof PermanentToken)) {
return true;
}
}
}
return false;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class DeclarationInStoneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
Set<Card> cardsToExile = new HashSet<>();
int nonTokenCount = 0;
if (CardUtil.haveEmptyName(targetPermanent)) {
// face down creature
cardsToExile.add(targetPermanent);
if (!(targetPermanent instanceof PermanentToken)) {
nonTokenCount++;
}
} else {
if (cardsToExile.add(targetPermanent) && !(targetPermanent instanceof PermanentToken)) {
nonTokenCount++;
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, targetPermanent.getControllerId(), game)) {
if (!permanent.getId().equals(targetPermanent.getId()) && CardUtil.haveSameNames(permanent, targetPermanent)) {
cardsToExile.add(permanent);
// exiled count only matters for non-tokens
if (!(permanent instanceof PermanentToken)) {
nonTokenCount++;
}
}
}
}
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
game.getState().processAction(game);
if (nonTokenCount > 0) {
new ClueArtifactToken().putOntoBattlefield(nonTokenCount, game, source, targetPermanent.getControllerId(), false, false);
}
return true;
}
}
return false;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class OneOrMoreTest method test_ChooseModes_AsCustomOrder.
@Test
public void test_ChooseModes_AsCustomOrder() {
// user can select modes in any order, but resolves/targets must be standard (in same order as card's text)
addCard(Zone.BATTLEFIELD, playerA, "Island", 6);
// Choose one or more —
// 1 • Counter target spell
// 2 • Counter target activated or triggered ability.
// 3 • Return target nonland permanent to its owner's hand.
// 4 • Create a token that's a copy of target creature you control.
// 5 • Target player draws a card.
// Instant {4}{U}{U}
addCard(Zone.HAND, playerA, "Sublime Epiphany");
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Sublime Epiphany");
setModeChoice(playerA, "4");
setModeChoice(playerA, "5");
setModeChoice(playerA, "3");
// for 3
addTarget(playerA, "Silvercoat Lion");
// for 4
addTarget(playerA, "Silvercoat Lion");
// for 5
addTarget(playerA, playerB);
setModeChoice(playerA, null);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertHandCount(playerB, 1);
assertHandCount(playerA, "Silvercoat Lion", 1);
assertPowerToughness(playerA, "Silvercoat Lion", 2, 2);
Permanent perm = getPermanent("Silvercoat Lion");
Assert.assertTrue("Silvercoat Lion has to be a Token", perm instanceof PermanentToken);
}
Aggregations