use of mage.game.stack.Spell in project mage by magefree.
the class InvokePrejudiceEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null && spell.isCreature(game)) {
boolean creatureSharesAColor = false;
ObjectColor spellColor = spell.getColor(game);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
if (spellColor.shares(permanent.getColor(game))) {
creatureSharesAColor = true;
break;
}
}
if (!creatureSharesAColor) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class MaelstromNexusGainCascadeFirstSpellEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (StackObject stackObject : game.getStack()) {
// only spells cast, so no copies of spells
if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) stackObject;
FirstSpellCastThisTurnWatcher watcher = game.getState().getWatcher(FirstSpellCastThisTurnWatcher.class);
if (watcher != null && spell.getId().equals(watcher.getIdOfFirstCastSpell(source.getControllerId()))) {
game.getState().addOtherAbility(spell.getCard(), cascadeAbility);
}
}
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class MuldrothaTheGravetideWatcher method addPermanentTypes.
private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
UUID playerId = null;
if (mageObject instanceof Spell) {
playerId = ((Spell) mageObject).getControllerId();
} else if (mageObject instanceof Permanent) {
playerId = ((Permanent) mageObject).getControllerId();
}
if (playerId != null) {
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
if (permanentTypes == null) {
permanentTypes = EnumSet.noneOf(CardType.class);
sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
}
Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
for (CardType cardType : mageObject.getCardType(game)) {
if (cardType.isPermanentType()) {
if (!permanentTypes.contains(cardType)) {
typesNotCast.add(cardType);
}
}
}
if (typesNotCast.size() <= 1) {
permanentTypes.addAll(typesNotCast);
} else {
Player player = game.getPlayer(playerId);
if (player != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
for (CardType cardType : typesNotCast) {
typeChoice.getChoices().add(cardType.toString());
}
if (player.choose(Outcome.Detriment, typeChoice, game)) {
String typeName = typeChoice.getChoice();
CardType chosenType = null;
for (CardType cardType : CardType.values()) {
if (cardType.toString().equals(typeName)) {
chosenType = cardType;
break;
}
}
if (chosenType != null) {
permanentTypes.add(chosenType);
}
}
}
}
}
}
}
use of mage.game.stack.Spell in project mage by magefree.
the class MultanisPresenceWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (GameEvent.EventType.SPELL_CAST == event.getType()) {
Spell spell = game.getSpellOrLKIStack(event.getTargetId());
if (spell != null) {
List<UUID> spellIds;
if (!spellsCast.containsKey(spell.getControllerId())) {
spellIds = new ArrayList<>();
} else {
spellIds = spellsCast.get(spell.getControllerId());
}
spellIds.add(spell.getId());
spellsCast.put(spell.getControllerId(), spellIds);
}
}
}
use of mage.game.stack.Spell in project mage by magefree.
the class ParadisePlumeSpellCastTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ObjectColor color = (ObjectColor) game.getState().getValue(getSourceId() + "_color");
if (color != null) {
FilterSpell filter = new FilterSpell();
filter.add(new ColorPredicate(color));
Spell spell = game.getStack().getSpell(event.getTargetId());
return (spell != null && filter.match(spell, getSourceId(), getControllerId(), game));
}
return false;
}
Aggregations