use of mage.game.stack.Spell in project mage by magefree.
the class KrarkTheThumblessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = game.getSpellOrLKIStack(getTargetPointer().getFirst(game, source));
if (player == null || spell == null) {
return false;
}
if (player.flipCoin(source, game, true)) {
spell.createCopyOnStack(game, source, player.getId(), true);
return true;
}
if (spell.isCopy()) {
game.getStack().remove(spell, game);
return true;
}
return game.getSpell(spell.getId()) != null && player.moveCards(spell, Zone.HAND, source, game);
}
use of mage.game.stack.Spell in project mage by magefree.
the class ManaCanBeSpentAsAnyColorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ObjectColor colorless = new ObjectColor();
// permaments
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
perm.getColor(game).setColor(colorless);
}
List<Card> affectedCards = new ArrayList<>();
// spells
for (MageObject object : game.getStack()) {
if (object instanceof Spell) {
game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
Card card = ((Spell) object).getCard();
affectedCards.add(card);
}
}
// exile
affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
// command
affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
// hand
affectedCards.addAll(player.getHand().getCards(game));
// library
affectedCards.addAll(player.getLibrary().getCards(game));
// graveyard
affectedCards.addAll(player.getGraveyard().getCards(game));
}
// apply colors to all cards
affectedCards.forEach(card -> {
game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
// mdf cards
if (card instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// split cards
if (card instanceof SplitCard) {
SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// double faces cards
if (card.getSecondCardFace() != null) {
game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
}
});
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class NullstoneGargoyleTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getSpell(event.getTargetId());
if (spell.isCreature(game)) {
return false;
}
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher != null && watcher.getNumberOfNonCreatureSpells() == 1) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class NovaPentacleEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// check source
MageObject object = game.getObject(event.getSourceId());
if (object == null) {
game.informPlayers("Couldn't find source of damage");
return false;
}
if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
return false;
}
this.redirectTarget = source.getTargets().get(0);
// check player
Player player = game.getPlayer(event.getTargetId());
if (player != null) {
return player.getId().equals(source.getControllerId());
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class PsychicTheftWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
return;
}
map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
Aggregations