use of mage.game.stack.Spell in project mage by magefree.
the class ReturnToHandSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
MageObject mageObject;
if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
mageObject = game.getObject(source.getSourceId());
} else {
mageObject = source.getSourceObjectIfItStillExists(game);
}
if (mageObject == null) {
return true;
}
switch(game.getState().getZone(mageObject.getId())) {
case BATTLEFIELD:
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isPhasedIn()) {
return controller.moveCards(permanent, Zone.HAND, source, game);
}
break;
case GRAVEYARD:
Card card = (Card) mageObject;
return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
case STACK:
Spell spell = game.getSpell(source.getSourceId());
return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
}
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class ReturnToHandTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> copyIds = new ArrayList<>();
Set<Card> cards = new LinkedHashSet<>();
if (multitargetHandling) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
MageObject mageObject = game.getObject(targetId);
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
} else {
for (UUID targetId : targetPointer.getTargets(game, source)) {
MageObject mageObject = game.getObject(targetId);
if (mageObject != null) {
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
}
for (UUID copyId : copyIds) {
game.getStack().remove(game.getSpell(copyId), game);
}
return controller.moveCards(cards, Zone.HAND, source, game);
}
use of mage.game.stack.Spell in project mage by magefree.
the class ImproviseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Spell spell = game.getStack().getSpell(source.getSourceId());
if (controller != null && spell != null) {
for (UUID artifactId : this.getTargetPointer().getTargets(game, source)) {
Permanent perm = game.getPermanent(artifactId);
if (perm == null) {
continue;
}
if (!perm.isTapped() && perm.tap(source, game)) {
ManaPool manaPool = controller.getManaPool();
manaPool.addMana(Mana.ColorlessMana(1), game, source);
manaPool.unlockManaType(ManaType.COLORLESS);
if (!game.isSimulation()) {
game.informPlayers("Improvise: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay {1}");
}
// can't use mana abilities after that (improvise cost must be payed after mana abilities only)
spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
}
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class ReboundCastSpellFromExileEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Spell sourceSpell = game.getStack().getSpell(source.getSourceId());
if (sourceSpell != null && sourceSpell.isCopy()) {
return false;
} else {
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
Player player = game.getPlayer(sourceCard.getOwnerId());
if (player != null) {
// Add the delayed triggered effect
ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(source.getSourceId(), source.getSourceId());
game.addDelayedTriggeredAbility(trigger, source);
player.moveCardToExileWithInfo(sourceCard, sourceCard.getId(), player.getName() + " Rebound", source, game, Zone.STACK, true);
return true;
}
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class ReplicateCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Spell spell = (Spell) this.getValue("ReplicateSpell");
int replicateCount = (Integer) this.getValue("ReplicateCount");
if (spell != null && replicateCount > 0) {
// reset replicate now so the copies don't report x times Replicate
Card card = game.getCard(spell.getSourceId());
if (card != null) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof ReplicateAbility) {
if (ability.isActivated()) {
((ReplicateAbility) ability).resetReplicate();
}
}
}
}
// create the copies
spell.createCopyOnStack(game, source, source.getControllerId(), true, replicateCount);
return true;
}
}
return false;
}
Aggregations