use of mage.game.stack.Spell in project mage by magefree.
the class ChefsKissApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpell(source.getFirstTarget());
if (spell == null) {
return false;
}
spell.setControllerId(source.getControllerId());
List<UUID> possibleTargets = new ArrayList<>(game.getState().getPlayersInRange(source.getControllerId(), game));
possibleTargets.remove(source.getControllerId());
game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(p -> !p.isControlledBy(source.getControllerId())).map(MageItem::getId).forEach(possibleTargets::add);
possibleTargets.removeIf(uuid -> !spell.canTarget(game, uuid));
StackObjectCopyApplier applier;
MageObjectReferencePredicate predicate;
if (possibleTargets.isEmpty()) {
applier = null;
predicate = null;
} else {
applier = new ChefsKissApplier(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game);
predicate = new MageObjectReferencePredicate(new MageObjectReference(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game));
}
spell.createCopyOnStack(game, source, source.getControllerId(), false, 1, applier);
if (predicate != null) {
spell.chooseNewTargets(game, source.getControllerId(), true, true, predicate);
}
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class CounterbalanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Card topcard = controller.getLibrary().getFromTop(game);
if (topcard != null) {
CardsImpl cards = new CardsImpl();
cards.add(topcard);
controller.revealCards(sourcePermanent.getName(), cards, game);
if (topcard.getManaValue() == spell.getManaValue()) {
return game.getStack().counter(spell.getId(), source, game);
}
}
return true;
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class DeflectingPalmEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
// only one use
this.discard();
if (preventionData.getPreventedDamage() > 0) {
MageObject damageDealingObject = game.getObject(target.getFirstTarget());
UUID objectControllerId = null;
if (damageDealingObject instanceof Permanent) {
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Ability) {
objectControllerId = ((Ability) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Spell) {
objectControllerId = ((Spell) damageDealingObject).getControllerId();
}
if (objectControllerId != null) {
Player objectController = game.getPlayer(objectControllerId);
if (objectController != null) {
objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class IncreasingSavageryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int amount = 5;
Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
if (spell != null) {
if (spell.getFromZone() == Zone.GRAVEYARD) {
amount = 10;
}
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class IncreasingDevotionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int amount = 5;
Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
if (spell != null) {
if (spell.getFromZone() == Zone.GRAVEYARD) {
amount = 10;
}
token.putOntoBattlefield(amount, game, source, source.getControllerId());
return true;
}
return false;
}
Aggregations