use of mage.game.stack.StackObject in project mage by magefree.
the class GoblinArtisansTarget method canTarget.
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
if (!super.canTarget(controllerId, id, source, game)) {
return false;
}
MageObjectReference sourceRef = new MageObjectReference(source.getSourceObject(game), game);
Spell spell = game.getSpell(id);
if (spell == null) {
return false;
}
for (StackObject stackObject : game.getStack()) {
if (!(stackObject instanceof StackAbility)) {
continue;
}
Permanent permanent = ((StackAbility) stackObject).getSourcePermanentOrLKI(game);
if (permanent != null && !sourceRef.refersTo(permanent, game) && permanent.isCreature(game) && "Goblin Artisans".equals(permanent.getName()) && stackObject.getStackAbility().getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).anyMatch(id::equals)) {
return false;
}
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class GrimoireThiefCounterspellEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Cards cards = new CardsImpl();
MageObject sourceObject = game.getObject(source.getSourceId());
Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(GrimoireThief.VALUE_PREFIX + source.getSourceId().toString());
if (exileZones != null && sourceObject != null) {
for (ExileZone exileZone : game.getExile().getExileZones()) {
if (!exileZone.isEmpty()) {
cards.addAll(exileZone.getCards(game));
}
}
// set face up first
for (Card card : cards.getCards(game)) {
card.setFaceDown(false, game);
}
// then counter any with the same name as the card exiled with Grimoire Thief
for (Card card : cards.getCards(game)) {
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
MageObject mageObject = game.getObject(card.getId());
String name1;
String name2;
if (mageObject instanceof SplitCard) {
name1 = ((SplitCard) mageObject).getLeftHalfCard().getName();
name2 = ((SplitCard) mageObject).getRightHalfCard().getName();
} else {
// modal double faces cards, adventure cards -- all have one name in non stack/battlefield zone
name1 = mageObject.getName();
name2 = name1;
}
if (CardUtil.haveSameNames(stackObject, name1, game) || CardUtil.haveSameNames(stackObject, name2, game)) {
Spell spell = (Spell) stackObject;
game.getStack().counter(stackObject.getId(), source, game);
game.informPlayers(sourceObject.getLogName() + ": spell " + spell.getIdName() + " was countered.");
}
}
}
return true;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class JelevaNephaliasWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
// Watcher saves all casts becaus of possible Clone cards that copy Jeleva
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
if (!game.getStack().isEmpty()) {
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell) {
Spell spell = (Spell) stackObject;
manaSpendToCast.putIfAbsent(spell.getSourceId().toString() + spell.getCard().getZoneChangeCounter(game), spell.getSpellAbility().getManaCostsToPay().manaValue());
}
}
}
}
}
use of mage.game.stack.StackObject in project mage by magefree.
the class JadedResponseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
boolean matches = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game).stream().map(permanent -> permanent.getColor(game)).anyMatch(stackObject.getColor(game)::shares);
return matches && game.getStack().counter(stackObject.getId(), source, game);
}
use of mage.game.stack.StackObject in project mage by magefree.
the class KozilekDiscardCost method canPay.
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
if (game.getStack().isEmpty()) {
return false;
}
Set<Integer> stackCMC = new HashSet<>();
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell) {
stackCMC.add(stackObject.getManaValue());
}
}
Player controller = game.getPlayer(ability.getControllerId());
if (controller != null) {
for (Card card : controller.getHand().getCards(game)) {
if (stackCMC.contains(card.getManaValue())) {
return true;
}
}
}
return false;
}
Aggregations