use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class EncoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
Set<MageObjectReference> addedTokens = new HashSet<>();
int opponentCount = OpponentsCount.instance.calculate(game, source, this);
if (opponentCount < 1) {
return false;
}
token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
while (it.hasNext()) {
for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (game.getPlayer(playerId) == null) {
continue;
}
UUID tokenId = it.next();
MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
addedTokens.add(mageObjectReference);
}
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
return true;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class MomirEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int value = source.getManaCostsToPay().getX();
if (game.isSimulation()) {
// Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
Token token = new CreatureToken(value, value + 1);
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
// should this be random across card names
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
List<CardInfo> options = CardRepository.instance.findCards(criteria);
if (options == null || options.isEmpty()) {
game.informPlayers("No random creature card with mana value of " + value + " was found.");
return false;
}
// search for a random non custom set creature
EmptyToken token = null;
while (!options.isEmpty()) {
int index = RandomUtil.nextInt(options.size());
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
options.remove(index);
} else {
Card card = options.get(index).getCard();
if (card != null) {
token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
break;
} else {
options.remove(index);
}
}
}
if (token != null) {
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
return false;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class EternalizeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
Player controller = game.getPlayer(card.getOwnerId());
if (controller == null) {
return false;
}
// create token and modify all attributes permanently (without game usage)
EmptyToken token = new EmptyToken();
// needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
CardUtil.copyTo(token).from(card, game);
token.getColor().setColor(ObjectColor.BLACK);
token.addSubType(SubType.ZOMBIE);
token.getManaCost().clear();
token.removePTCDA();
token.getPower().modifyBaseValue(4);
token.getToughness().modifyBaseValue(4);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ETERNALIZED_CREATURE, token.getId(), source, controller.getId()));
token.putOntoBattlefield(1, game, source, controller.getId(), false, false, null);
// Also it can never get active or? But it's not mentioned in the reminder text.
return true;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class Spell method resolve.
@Override
public boolean resolve(Game game) {
boolean result;
Player controller = game.getPlayer(getControllerId());
if (controller == null) {
return false;
}
this.resolving = true;
if (commandedBy != null && !commandedBy.equals(getControllerId())) {
Player turnController = game.getPlayer(commandedBy);
if (turnController != null) {
turnController.controlPlayersTurn(game, controller.getId());
}
}
if (this.isInstantOrSorcery(game)) {
int index = 0;
result = false;
boolean legalParts = false;
boolean notTargeted = true;
// check for legal parts
for (SpellAbility spellAbility : this.spellAbilities) {
// if only a spliced spell has targets and all targets ar illegal, the complete spell is countered
if (hasTargets(spellAbility, game)) {
notTargeted = false;
legalParts |= spellAbilityHasLegalParts(spellAbility, game);
}
}
// resolve if legal parts
if (notTargeted || legalParts) {
for (SpellAbility spellAbility : this.spellAbilities) {
// legality of targets is checked only as the spell begins to resolve, not in between modes (spliced spells handeled correctly?)
if (spellAbilityCheckTargetsAndDeactivateModes(spellAbility, game)) {
for (UUID modeId : spellAbility.getModes().getSelectedModes()) {
spellAbility.getModes().setActiveMode(modeId);
result |= spellAbility.resolve(game);
}
index++;
}
}
if (game.getState().getZone(card.getMainCard().getId()) == Zone.STACK) {
if (isCopy()) {
// copied spell, only remove from stack
game.getStack().remove(this, game);
} else {
controller.moveCards(card, Zone.GRAVEYARD, ability, game);
}
}
return result;
}
// 20091005 - 608.2b
if (!game.isSimulation()) {
game.informPlayers(getName() + " has been fizzled.");
}
counter(null, /*this.getSpellAbility()*/
game);
return false;
} else if (this.isEnchantment(game) && this.hasSubtype(SubType.AURA, game)) {
if (ability.getTargets().stillLegal(ability, game)) {
boolean bestow = SpellAbilityCastMode.BESTOW.equals(ability.getSpellAbilityCastMode());
if (bestow) {
// before put to play:
// Must be removed first time, after that will be removed by continous effect
// Otherwise effects like evolve trigger from creature comes into play event
card.removeCardType(CardType.CREATURE);
card.addSubType(game, SubType.AURA);
}
UUID permId;
boolean flag;
if (isCopy()) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game, this);
// The token that a resolving copy of a spell becomes isn’t said to have been “created.” (2020-09-25)
if (token.putOntoBattlefield(1, game, ability, getControllerId(), false, false, null, false)) {
permId = token.getLastAddedToken();
flag = true;
} else {
permId = null;
flag = false;
}
} else {
permId = card.getId();
flag = controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null);
}
if (flag) {
if (bestow) {
// card will be copied during putOntoBattlefield, so the card of CardPermanent has to be changed
// TODO: Find a better way to prevent bestow creatures from being effected by creature affecting abilities
Permanent permanent = game.getPermanent(permId);
if (permanent instanceof PermanentCard) {
// after put to play:
// restore removed stats (see "before put to play" above)
// otherwise spell ability without bestow will be set
permanent.setSpellAbility(ability);
card.addCardType(CardType.CREATURE);
card.getSubtype().remove(SubType.AURA);
}
}
if (isCopy()) {
Permanent token = game.getPermanent(permId);
if (token == null) {
return false;
}
for (Ability ability2 : token.getAbilities()) {
if (!bestow || ability2 instanceof BestowAbility) {
ability2.getTargets().get(0).add(ability.getFirstTarget(), game);
ability2.getEffects().get(0).apply(game, ability2);
return ability2.resolve(game);
}
}
return false;
}
return ability.resolve(game);
}
if (bestow) {
card.addCardType(game, CardType.CREATURE);
}
return false;
}
// Aura has no legal target and its a bestow enchantment -> Add it to battlefield as creature
if (SpellAbilityCastMode.BESTOW.equals(this.getSpellAbility().getSpellAbilityCastMode())) {
if (controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent instanceof PermanentCard) {
((PermanentCard) permanent).getCard().addCardType(game, CardType.CREATURE);
((PermanentCard) permanent).getCard().removeSubType(game, SubType.AURA);
return true;
}
}
return false;
} else {
// 20091005 - 608.2b
if (!game.isSimulation()) {
game.informPlayers(getName() + " has been fizzled.");
}
counter(null, /*this.getSpellAbility()*/
game);
return false;
}
} else if (isCopy()) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game, this);
// The token that a resolving copy of a spell becomes isn’t said to have been “created.” (2020-09-25)
token.putOntoBattlefield(1, game, ability, getControllerId(), false, false, null, false);
return true;
} else {
return controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null);
}
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class EsixFractalBloomWatcher method copyPermanentToToken.
private static Token copyPermanentToToken(Permanent permanent, Game game, Ability source) {
CopyApplier applier = new EmptyCopyApplier();
// handle copies of copies
Permanent copyFromPermanent = permanent;
for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (!(effect instanceof CopyEffect)) {
continue;
}
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that our targetPermanent copies stats from
if (!copyEffect.getSourceId().equals(permanent.getId())) {
continue;
}
MageObject object = ((CopyEffect) effect).getTarget();
if (!(object instanceof Permanent)) {
continue;
}
copyFromPermanent = (Permanent) object;
if (copyEffect.getApplier() != null) {
applier = copyEffect.getApplier();
}
}
// create token and modify all attributes permanently (without game usage)
EmptyToken token = new EmptyToken();
// needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
CardUtil.copyTo(token).from(copyFromPermanent, game);
applier.apply(game, token, source, permanent.getId());
return token;
}
Aggregations