use of mage.game.stack.Spell in project mage by magefree.
the class JusticeEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject sourceObject = game.getObject(event.getSourceId());
if (sourceObject != null && sourceObject.getColor(game).isRed()) {
if (sourceObject instanceof Permanent && sourceObject.isCreature(game) || sourceObject instanceof Spell) {
this.getEffects().get(0).setValue("damageAmount", event.getAmount());
this.getEffects().get(0).setTargetPointer(new FixedTarget(game.getControllerId(sourceObject.getId())));
return true;
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class KaervekTheMercilessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cost = spell.getManaValue();
Player target = game.getPlayer(source.getFirstTarget());
if (target != null) {
target.damage(cost, source.getSourceId(), source, game);
return true;
}
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
if (targetCreature != null) {
targetCreature.damage(cost, source.getSourceId(), source, game, false, true);
return true;
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
morMap.values().removeIf(Set::isEmpty);
return;
}
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null) {
return;
}
morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
use of mage.game.stack.Spell in project mage by magefree.
the class KozilekDiscardCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
if (targetSpell == null) {
return false;
}
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
}
FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
TargetCardInHand target = new TargetCardInHand(filter);
this.getTargets().clear();
this.getTargets().add(target);
if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
for (UUID targetId : targets.get(0).getTargets()) {
Card card = player.getHand().get(targetId, game);
if (card == null) {
return false;
}
player.discard(card, true, source, game);
paid = true;
}
}
return paid;
}
use of mage.game.stack.Spell in project mage by magefree.
the class KumanoFacesKakkazanCounterEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (this.isControlledBy(event.getPlayerId())) {
Spell spell = game.getSpell(event.getTargetId());
if (spell != null && spell.isCreature(game)) {
this.getEffects().clear();
this.getEffects().add(new KumanoFacesKakkazanCounterEffect(spell.getSourceId()));
return true;
}
}
return false;
}
Aggregations