use of mage.game.stack.StackObject in project mage by magefree.
the class AegisOfHonorEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId())) {
// Checks to see the damage is to Aegis of Honor's controller
Spell spell = null;
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject == null) {
stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
}
if (stackObject instanceof Spell) {
spell = (Spell) stackObject;
}
// Checks if damage is from a sorcery or instants
if (spell != null && instantOrSorceryfilter.match(spell.getCard(), game)) {
TargetPlayer target = new TargetPlayer();
target.add(spell.getControllerId(), game);
redirectTarget = target;
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class ArcaneAdaptationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (controller == null || subType == null) {
return false;
}
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
// in Exile
for (Card card : game.getState().getExile().getAllCards(game)) {
if (card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
// in Library (e.g. for Mystical Teachings)
for (Card card : controller.getLibrary().getCards(game)) {
if (card.isOwnedBy(controller.getId()) && card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
// commander in command zone
for (CommandObject commandObject : game.getState().getCommand()) {
if (commandObject instanceof Commander) {
Card card = game.getCard(((Commander) commandObject).getId());
if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game) && !stackObject.hasSubtype(subType, game)) {
Card card = ((Spell) stackObject).getCard();
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
}
}
// creatures you control
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
for (Permanent creature : creatures) {
if (creature != null) {
creature.addSubType(game, subType);
}
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SharesTypePredicate 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 firstPermanent = game.getPermanent(source.getStackAbility().getTargets().get(0).getTargets().get(0));
Permanent secondPermanent = game.getPermanent(input.getObject().getId());
if (firstPermanent != null && secondPermanent != null) {
if (firstPermanent.isCreature(game) && secondPermanent.isCreature(game)) {
return true;
}
if (firstPermanent.isArtifact(game) && secondPermanent.isArtifact(game)) {
return true;
}
}
return false;
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class PowerSinkCounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && controller != null && sourceObject != null) {
int amount = source.getManaCostsToPay().getX();
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, true);
if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
if (cost.pay(source, game, source, player.getId(), false)) {
game.informPlayers(sourceObject.getName() + ": additional cost was paid");
return true;
}
}
game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
// Counter target spell unless its controller pays {X}
game.getStack().counter(source.getFirstTarget(), source, game);
// that player taps all lands with mana abilities they control...
List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
for (Permanent land : lands) {
Abilities<Ability> landAbilities = land.getAbilities();
for (Ability ability : landAbilities) {
if (ability instanceof ActivatedManaAbilityImpl) {
land.tap(source, game);
break;
}
}
}
// ...and empties their mana pool
player.getManaPool().emptyPool(game);
}
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class ValkmiraProtectorsShieldTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) {
return false;
}
if (isControlledBy(event.getTargetId())) {
this.getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
return true;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent == null || !permanent.isControlledBy(getControllerId())) {
return false;
}
this.getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
return true;
}
Aggregations