use of mage.game.stack.StackObject in project mage by magefree.
the class BecomesTargetAttachedTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanent(sourceId);
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getTargetId().equals(enchantment.getAttachedTo()) && filter.match(sourceObject, getSourceId(), getControllerId(), game)) {
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class CounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell == null) {
return false;
}
Player player = game.getPlayer(spell.getControllerId());
if (player == null) {
return false;
}
Cost costToPay;
String costValueMessage;
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message = "";
if (costToPay instanceof ManaCost) {
message += "Pay ";
}
message += costValueMessage + '?';
costToPay.clearPaid();
if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
if (exile) {
game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
} else {
return game.getStack().counter(spell.getId(), source, game);
}
}
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class CantBeTargetedTargetEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {
if (targetController == TargetController.OPPONENT && !game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
return false;
}
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
MageObject sourceObject;
if (stackObject instanceof StackAbility) {
sourceObject = ((StackAbility) stackObject).getSourceObject(game);
} else {
sourceObject = stackObject;
}
if (filterSource.match(sourceObject, game)) {
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SameControllerPredicate method apply.
@Override
public boolean apply(ObjectSourcePlayer<MageItem> input, Game game) {
StackObject source = game.getStack().getStackObject(input.getSourceId());
if (source != null) {
if (source.getStackAbility().getTargets().isEmpty() || source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
return true;
}
Permanent firstTarget = game.getPermanent(source.getStackAbility().getTargets().get(0).getTargets().get(0));
Permanent inputPermanent = game.getPermanent(input.getObject().getId());
if (firstTarget != null && inputPermanent != null) {
return firstTarget.isControlledBy(inputPermanent.getControllerId());
}
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class BrowbeatDrawEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
StackObject spell = null;
for (StackObject object : game.getStack()) {
if (object instanceof Spell && object.getSourceId().equals(source.getSourceId())) {
spell = object;
}
}
if (spell != null) {
boolean drawCards = true;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.chooseUse(Outcome.Detriment, "Have " + spell.getLogName() + " deal 5 damage to you?", source, game)) {
drawCards = false;
player.damage(5, source.getSourceId(), source, game);
game.informPlayers(player.getLogName() + " has " + spell.getLogName() + " deal 5 to them");
}
}
if (drawCards) {
UUID targetPlayer = getTargetPointer().getFirst(game, source);
if (targetPlayer != null) {
Player player = game.getPlayer(targetPlayer);
if (player != null) {
player.drawCards(3, source, game);
}
}
}
return drawCards;
}
return false;
}
Aggregations