use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class MechanizedProductionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourceObject != null && sourceObject.getAttachedTo() != null) {
Permanent enchantedArtifact = game.getPermanentOrLKIBattlefield(sourceObject.getAttachedTo());
if (enchantedArtifact != null) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(enchantedArtifact, game);
token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Map<String, Integer> countNames = new HashMap<>();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), source.getControllerId(), game)) {
int counter = countNames.getOrDefault(permanent.getName(), 0);
countNames.put(permanent.getName(), counter + 1);
}
for (Entry<String, Integer> entry : countNames.entrySet()) {
if (entry.getValue() > 7) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
game.informPlayers(controller.getLogName() + " controls eight or more artifacts with the same name as one another (" + entry.getKey() + ").");
controller.won(game);
return true;
}
}
}
return true;
}
return false;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class CreateTokenCopyTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId;
if (getTargetPointer() instanceof FixedTarget) {
targetId = ((FixedTarget) getTargetPointer()).getTarget();
} else {
targetId = getTargetPointer().getFirst(game, source);
}
Permanent permanent;
if (savedPermanent != null) {
permanent = savedPermanent;
} else if (useLKI) {
permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
} else {
permanent = game.getPermanentOrLKIBattlefield(targetId);
}
// can target card or permanent
Card copyFrom;
CopyApplier applier = new EmptyCopyApplier();
if (permanent != null) {
// handle copies of copies
Permanent copyFromPermanent = permanent;
for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that our targetPermanent copies stats from
if (copyEffect.getSourceId().equals(permanent.getId())) {
MageObject object = ((CopyEffect) effect).getTarget();
if (object instanceof Permanent) {
copyFromPermanent = (Permanent) object;
if (copyEffect.getApplier() != null) {
applier = copyEffect.getApplier();
}
}
}
}
}
copyFrom = copyFromPermanent;
} else {
copyFrom = game.getCard(getTargetPointer().getFirst(game, source));
}
if (copyFrom == 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(copyFrom, game);
applier.apply(game, token, source, targetId);
if (becomesArtifact) {
token.addCardType(CardType.ARTIFACT);
}
if (isntLegendary) {
token.getSuperType().remove(SuperType.LEGENDARY);
}
if (startingLoyalty != -1) {
token.setStartingLoyalty(startingLoyalty);
}
if (additionalCardType != null) {
token.addCardType(additionalCardType);
}
if (hasHaste) {
token.addAbility(HasteAbility.getInstance());
}
if (gainsFlying) {
token.addAbility(FlyingAbility.getInstance());
}
if (tokenPower != Integer.MIN_VALUE) {
token.removePTCDA();
token.getPower().modifyBaseValue(tokenPower);
}
if (tokenToughness != Integer.MIN_VALUE) {
token.removePTCDA();
token.getToughness().modifyBaseValue(tokenToughness);
}
if (onlySubType != null) {
token.removeAllCreatureTypes();
token.addSubType(onlySubType);
}
if (additionalSubType != null) {
token.addSubType(additionalSubType);
}
if (color != null) {
token.getColor().setColor(color);
}
additionalAbilities.stream().forEach(token::addAbility);
if (!this.abilityClazzesToRemove.isEmpty()) {
List<Ability> abilitiesToRemoveTmp = new ArrayList<>();
// Find the ones to remove
for (Ability ability : token.getAbilities()) {
if (this.abilityClazzesToRemove.contains(ability.getClass())) {
abilitiesToRemoveTmp.add(ability);
}
}
// Remove them
for (Ability ability : abilitiesToRemoveTmp) {
// Remove subabilities
token.removeAbilities(ability.getSubAbilities());
// Remove the ability
token.removeAbility(ability);
}
}
token.putOntoBattlefield(number, game, source, playerId == null ? source.getControllerId() : playerId, tapped, attacking, attackedPlayer);
for (UUID tokenId : token.getLastAddedTokenIds()) {
// by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
addedTokenPermanents.add(tokenPermanent);
// add counters if necessary ie Ochre Jelly
if (counter != null && numberOfCounters > 0) {
tokenPermanent.addCounters(counter.createInstance(numberOfCounters), source.getControllerId(), source, game);
}
}
}
return true;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class HourOfEternityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> cardsToExile = new HashSet<>(this.getTargetPointer().getTargets(game, source).size());
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Card card = controller.getGraveyard().get(targetId, game);
if (card != null) {
cardsToExile.add(card);
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, null, "");
for (Card card : cardsToExile) {
if (game.getState().getZone(card.getId()) == Zone.EXILED) {
// create token and modify all attributes permanently (without game usage)
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
token.removePTCDA();
token.getPower().modifyBaseValue(4);
token.getToughness().modifyBaseValue(4);
token.getColor().setColor(ObjectColor.BLACK);
token.removeAllCreatureTypes();
token.addSubType(SubType.ZOMBIE);
token.putOntoBattlefield(1, game, source, source.getControllerId());
}
}
return true;
}
return false;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class PrototypePortalCreateTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return false;
}
if (!permanent.getImprinted().isEmpty()) {
Card card = game.getCard(permanent.getImprinted().get(0));
if (card != null) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
token.putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
}
return false;
}
use of mage.game.permanent.token.EmptyToken in project mage by magefree.
the class EmbalmEffect 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.WHITE);
token.addSubType(SubType.ZOMBIE);
token.getManaCost().clear();
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EMBALMED_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;
}
Aggregations