use of mage.game.stack.Spell in project mage by magefree.
the class CemeteryGatekeeperTriggeredAbility method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
Effect effect = getEffects().get(0);
UUID targetId = (UUID) effect.getValue("targetId");
GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
UUID exileId = (UUID) effect.getValue("exileId");
if (targetId != null && eventType != null && exileId != null) {
if (eventType == GameEvent.EventType.LAND_PLAYED) {
Permanent permanent = game.getPermanent(targetId);
return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
} else if (eventType == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getSpellOrLKIStack(targetId);
return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class CemeteryProtectorTriggeredAbility method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
Effect effect = getEffects().get(0);
UUID targetId = (UUID) effect.getValue("targetId");
GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
UUID exileId = (UUID) effect.getValue("exileId");
if (targetId != null && eventType != null && exileId != null) {
if (eventType == GameEvent.EventType.LAND_PLAYED) {
Permanent permanent = game.getPermanent(targetId);
return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
} else if (eventType == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getSpellOrLKIStack(targetId);
return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class CephalidShrineEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null && mageObject != null) {
game.getState().setValue("cephalidShrine" + mageObject, spell);
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class CephalidShrineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
// even if the cost is 0, we still offer
Cost cost = ManaUtil.createManaCost(count, true);
if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
return false;
} else {
game.getStack().counter(spell.getId(), source, game);
game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
return true;
}
}
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class CavernOfSoulsCantCounterEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
CavernOfSoulsWatcher watcher = game.getState().getWatcher(CavernOfSoulsWatcher.class, source.getSourceId());
Spell spell = game.getStack().getSpell(event.getTargetId());
return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game));
}
Aggregations