use of mage.game.stack.StackObject in project mage by magefree.
the class CounterlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (stackObject != null && controller != null) {
game.getStack().counter(source.getFirstTarget(), source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
FilterCard filter = new FilterCard();
List<Predicate<MageObject>> types = new ArrayList<>();
for (CardType type : stackObject.getCardType(game)) {
if (type != CardType.LAND) {
types.add(type.getPredicate());
}
}
filter.add(Predicates.or(types));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class CountermandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean countered = false;
StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (game.getStack().counter(source.getFirstTarget(), source, game)) {
countered = true;
}
if (stackObject != null) {
Player controller = game.getPlayer(stackObject.getControllerId());
if (controller != null) {
controller.millCards(4, source, game);
}
}
return countered;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class FiendslayerPaladinEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Card targetCard = game.getCard(event.getTargetId());
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (targetCard != null && stackObject != null && targetCard.getId().equals(source.getSourceId())) {
if (stackObject.getColor(game).isBlack() || stackObject.getColor(game).isRed()) {
if (!stackObject.isControlledBy(source.getControllerId()) && stackObject.isInstant(game) || stackObject.isSorcery(game)) {
return true;
}
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class FrightfulDelusionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
Cost cost = ManaUtil.createManaCost(1, false);
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
if (player != null) {
cost.clearPaid();
game.getPlayer(spell.getControllerId()).discard(1, false, false, source, game);
if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class PsychicBattleEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject != null) {
if (!stackObject.isTargetChanged() && !stackObject.getName().equals("Psychic Battle")) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
// resets the targetChanged flag
stackObject.setTargetChanged(false);
return true;
}
}
return false;
}
Aggregations