use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.
the class EzurisPredationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
/*
* Players can't cast spells or activate any abilities in between the
* Beasts entering the battlefield and fighting the other creatures.
* Ifthe Beasts entering the battlefield cause any abilities to trigger,
* those abilities will be put onto the stack after Ezuri's Predation is
* finished resolving.
* You choose which Beast is fighting which creature
* an opponent controls. Each of the "fights" happens at the same time.
* If Ezuri's Predation creates more than one token for any given
* creature (due to an effect such as the one Doubling Season creates),
* the extra tokens won't fight any creature.
*/
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCreaturePermanent filterCreature = new FilterCreaturePermanent();
filterCreature.add(TargetController.OPPONENT.getControllerPredicate());
List<Permanent> creaturesOfOpponents = game.getBattlefield().getActivePermanents(filterCreature, source.getControllerId(), source.getSourceId(), game);
Set<MageObjectReference> morSet = new HashSet<>();
if (!creaturesOfOpponents.isEmpty()) {
CreateTokenEffect effect = new CreateTokenEffect(new PhyrexianBeastToken(), creaturesOfOpponents.size());
effect.apply(game, source);
for (UUID tokenId : effect.getLastAddedTokenIds()) {
Permanent token = game.getPermanent(tokenId);
if (token != null) {
if (creaturesOfOpponents.isEmpty()) {
break;
}
Permanent opponentCreature = creaturesOfOpponents.iterator().next();
creaturesOfOpponents.remove(opponentCreature);
// can be multiple tokens, so must be used custom BATCH_FIGHT event
token.fight(opponentCreature, source, game, false);
morSet.add(new MageObjectReference(token, game));
morSet.add(new MageObjectReference(opponentCreature, game));
game.informPlayers(token.getLogName() + " fights " + opponentCreature.getLogName());
}
}
String data = UUID.randomUUID().toString();
game.getState().setValue("batchFight_" + data, morSet);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_FIGHT, getId(), source, source.getControllerId(), data, 0));
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.
the class GiltLeafAmbushCreateTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
CreateTokenEffect effect = new CreateTokenEffect(new ElfWarriorToken(), 2);
effect.apply(game, source);
if (ClashEffect.getInstance().apply(game, source)) {
for (UUID tokenId : effect.getLastAddedTokenIds()) {
Permanent token = game.getPermanent(tokenId);
if (token != null) {
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(DeathtouchAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(new FixedTarget(tokenId));
game.addEffect(continuousEffect, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.
the class LastStandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Target opponent loses 2 life for each Swamp you control
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (opponent != null) {
int swamps = game.getBattlefield().count(filterSwamp, source.getSourceId(), source.getControllerId(), game);
opponent.loseLife(swamps * 2, game, source, false);
}
// Last Stand deals damage equal to the number of Mountains you control to target creature.
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creature != null) {
int mountains = game.getBattlefield().count(filterMountain, source.getSourceId(), source.getControllerId(), game);
if (mountains > 0) {
creature.damage(mountains, source.getSourceId(), source, game, false, true);
}
}
// Create a 1/1 green Saproling creature token for each Forest you control.
int forests = game.getBattlefield().count(filterForest, source.getSourceId(), source.getControllerId(), game);
if (forests > 0) {
new CreateTokenEffect(new SaprolingToken(), forests).apply(game, source);
}
// You gain 2 life for each Plains you control.
int plains = game.getBattlefield().count(filterPlains, source.getSourceId(), source.getControllerId(), game);
controller.gainLife(plains * 2, game, source);
// Draw a card for each Island you control, then discard that many cards
int islands = game.getBattlefield().count(filterIsland, source.getSourceId(), source.getControllerId(), game);
if (islands > 0) {
controller.drawCards(islands, source, game);
controller.discard(islands, false, false, source, game);
}
}
return false;
}
use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.
the class RapaciousOneTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
this.getEffects().clear();
this.addEffect(new CreateTokenEffect(new EldraziSpawnToken(), event.getAmount()));
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateTokenEffect in project mage by magefree.
the class ValdukKeeperOfTheFlameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
EquipmentAttachedCount eamount = new EquipmentAttachedCount();
int value = eamount.calculate(game, source, this);
AuraAttachedCount aamount = new AuraAttachedCount();
value += aamount.calculate(game, source, this);
CreateTokenEffect effect = new CreateTokenEffect(new ValdukElementalToken(), value);
if (effect.apply(game, source)) {
effect.exileTokensCreatedAtNextEndStep(game, source);
return true;
}
}
return false;
}
Aggregations