use of mage.game.permanent.token.Token in project mage by magefree.
the class XornReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event instanceof CreateTokenEvent) {
CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
TreasureToken treasureToken = null;
Map<Token, Integer> tokens = tokenEvent.getTokens();
for (Token token : tokens.keySet()) {
if (token instanceof TreasureToken) {
treasureToken = (TreasureToken) token;
break;
}
}
if (treasureToken == null) {
treasureToken = new TreasureToken();
}
tokens.put(treasureToken, tokens.getOrDefault(treasureToken, 0) + 1);
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class FlickerformReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// Exile enchanted creature and all Auras attached to it.
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment == null) {
enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent enchantedCreature = game.getPermanent(enchantment.getAttachedTo());
if (enchantedCreature != null) {
UUID exileZoneId = UUID.randomUUID();
enchantedCreature.moveToExile(exileZoneId, enchantment.getName(), source, game);
for (UUID attachementId : enchantedCreature.getAttachments()) {
Permanent attachment = game.getPermanent(attachementId);
if (attachment != null && filter.match(attachment, game)) {
attachment.moveToExile(exileZoneId, enchantment.getName(), source, game);
}
}
if (!(enchantedCreature instanceof Token)) {
// At the beginning of the next end step, return that card to the battlefield under its owner's control.
// If you do, return the other cards exiled this way to the battlefield under their owners' control attached to that creature
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new FlickerformReturnEffect(enchantedCreature.getId(), exileZoneId));
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class NahiriTheLithomancerSecondAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Token token = new KorSoldierToken();
if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
// TODO: Make sure the Equipment can legally enchant the token, preferably on targetting.
Target target = new TargetControlledPermanent(0, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Attach an Equipment you control to the created " + tokenPermanent.getIdName() + '?', source, game)) {
if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
Permanent equipmentPermanent = game.getPermanent(target.getFirstTarget());
if (equipmentPermanent != null) {
Permanent attachedTo = game.getPermanent(equipmentPermanent.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(equipmentPermanent.getId(), source, game);
}
tokenPermanent.addAttachment(equipmentPermanent.getId(), source, game);
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class RiptideReplicatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (subType == null) {
return false;
}
int x = (new CountersSourceCount(CounterType.CHARGE)).calculate(game, source, this);
Token token = new RiptideReplicatorToken(color, subType, x);
return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class SmashingSuccessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null && permanent.isPhasedIn() && !permanent.isPhasedOutIndirectly()) {
if (permanent.isArtifact(game)) {
if (permanent.destroy(source, game, false)) {
Token token = new TreasureToken();
token.putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
} else {
return permanent.destroy(source, game, false);
}
}
return false;
}
Aggregations