@Override public boolean apply(Game game, Ability source) { conditionState = condition.apply(game, source); if (conditionState) { effect.setTargetPointer(this.targetPointer); return effect.apply(game, source); } else if (otherwiseEffect != null) { otherwiseEffect.setTargetPointer(this.targetPointer); return otherwiseEffect.apply(game, source); } if (!conditionState && effect.getDuration() == Duration.OneUse) { used = true; } if (!conditionState && effect.getDuration() == Duration.Custom) { this.discard(); } return false; }
@Override public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { conditionState = condition.apply(game, source); if (conditionState) { effect.setTargetPointer(this.targetPointer); return effect.applies(sourceId, source, affectedControllerId, game); } else if (otherwiseEffect != null) { otherwiseEffect.setTargetPointer(this.targetPointer); return otherwiseEffect.applies(sourceId, source, affectedControllerId, game); } return false; }
public ConditionalAsThoughEffect(final ConditionalAsThoughEffect effect) { super(effect); this.effect = effect.effect.copy(); if (effect.otherwiseEffect != null) { this.otherwiseEffect = effect.otherwiseEffect.copy(); } this.condition = effect.condition; this.conditionState = effect.conditionState; }
public ConditionalAsThoughEffect(AsThoughEffect effect, Condition condition, AsThoughEffect otherwiseEffect) { super(effect.getAsThoughEffectType(), effect.getDuration(), effect.getOutcome()); this.effect = effect; this.condition = condition; this.otherwiseEffect = otherwiseEffect; }
/** * Filters out asThough effects that are not active. * * @param type type * @param game * @return */ public List<AsThoughEffect> getApplicableAsThoughEffects(AsThoughEffectType type, Game game) { List<AsThoughEffect> asThoughEffectsList = new ArrayList<>(); if (asThoughEffectsMap.containsKey(type)) { for (AsThoughEffect effect : asThoughEffectsMap.get(type)) { Set<Ability> abilities = asThoughEffectsMap.get(type).getAbility(effect.getId()); for (Ability ability : abilities) { if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, null)) { if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) { asThoughEffectsList.add(effect); break; } } } } } return asThoughEffectsList; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (controller != null && sourcePermanent != null) { if (controller.getHand().isEmpty()) { return true; } TargetCard target = new TargetCard(Zone.HAND, filter); target.setNotTarget(true); Card chosenCard = null; if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) { chosenCard = controller.getHand().get(target.getFirstTarget(), game); } if (chosenCard != null) { controller.moveCardToExileWithInfo(chosenCard, source.getSourceId(), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.HAND, true); AsThoughEffect effect = new IceCauldronCastFromExileEffect(); effect.setTargetPointer(new FixedTarget(chosenCard.getId())); game.addEffect(effect, source); game.getState().setValue("IceCauldronCard" + source.getSourceId().toString(), new MageObjectReference(chosenCard.getId(), game)); //store the exiled card return true; } } return false; } }
public ManaType asThoughMana(ManaType manaType, ManaPoolItem mana, UUID objectId, Ability affectedAbility, UUID controllerId, Game game) { // First check existing only effects List<AsThoughEffect> asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_ONLY_MANA, game); for (AsThoughEffect effect : asThoughEffectsList) { Set<Ability> abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_ONLY_MANA).getAbility(effect.getId()); for (Ability ability : abilities) { if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game)) || effect.applies(objectId, affectedAbility, ability, game, controllerId)) { if (((AsThoughManaEffect) effect).getAsThoughManaType(manaType, mana, controllerId, ability, game) == null) { return null; } } } } // then check effects that allow to use other mana types to pay the current mana type to pay asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_OTHER_MANA, game); for (AsThoughEffect effect : asThoughEffectsList) { Set<Ability> abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_OTHER_MANA).getAbility(effect.getId()); for (Ability ability : abilities) { if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game)) || effect.applies(objectId, affectedAbility, ability, game, controllerId)) { ManaType usableManaType = ((AsThoughManaEffect) effect).getAsThoughManaType(manaType, mana, controllerId, ability, game); if (usableManaType != null) { return usableManaType; } } } } return manaType; }
case ASTHOUGH: AsThoughEffect newAsThoughEffect = (AsThoughEffect) entry.getKey(); if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) { break; asThoughEffectsMap.get(newAsThoughEffect.getAsThoughEffectType()).removeEffects(entry.getKey().getId(), entry.getValue()); break; case COSTMODIFICATION:
@Override public boolean isDiscarded() { return effect.isDiscarded() || (otherwiseEffect != null && otherwiseEffect.isDiscarded()); }
private boolean checkPlayability(Card card, Player targetPlayer, Game game, Ability source) { // check for card playability boolean canPlay = false; if (card.isLand()) { // we can't use getPlayableInHand(game) in here because it disallows playing lands outside the main step if (targetPlayer.canPlayLand() && game.getActivePlayerId().equals(targetPlayer.getId())) { canPlay = true; for (Ability ability : card.getAbilities(game)) { if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), targetPlayer.getId()), ability, game, true)) { canPlay &= true; } } } } else { // Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect(); game.addEffect(effect2, source); if (targetPlayer.getPlayableInHand(game).contains(card.getId())) { canPlay = true; } for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) { if (eff instanceof WordOfCommandTestFlashEffect) { eff.discard(); break; } } } return canPlay; } }
@Override public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(source.getFirstTarget()); if (opponent != null && opponent.getHand().size() > 0) { Card revealedCard = opponent.getHand().getRandom(game); if (revealedCard == null) { return false; } Cards cards = new CardsImpl(); cards.add(revealedCard); opponent.revealCards("Planeswalker's Mischief Reveal", cards, game); if (revealedCard.isInstant() || revealedCard.isSorcery()) { opponent.moveCardToExileWithInfo(revealedCard, source.getSourceId(), "Planeswalker's Mischief", source.getSourceId(), game, Zone.HAND, true); AsThoughEffect effect = new PlaneswalkersMischiefCastFromExileEffect(); effect.setTargetPointer(new FixedTarget(revealedCard.getId())); game.addEffect(effect, source); OneShotEffect effect2 = new ReturnFromExileEffect(source.getSourceId(), Zone.HAND); Condition condition = new PlaneswalkersMischiefCondition(source.getSourceId(), revealedCard.getId()); ConditionalOneShotEffect effect3 = new ConditionalOneShotEffect(effect2, condition, "if you haven't cast it, return it to its owner's hand."); DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect3); game.addDelayedTriggeredAbility(delayedAbility, source); return true; } } return false; } }
Set<Ability> abilities = asThoughEffectsMap.get(type).getAbility(effect.getId()); for (Ability ability : abilities) { if (affectedAbility == null) { if (effect.applies(idToCheck, ability, controllerId, game)) { return new MageObjectReference(ability.getSourceObject(game), game); } else if (effect.applies(idToCheck, affectedAbility, ability, game, controllerId)) { return new MageObjectReference(ability.getSourceObject(game), game);
case ASTHOUGH: AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect; if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) { ContinuousEffectsList<AsThoughEffect> list = new ContinuousEffectsList<>(); allEffectsLists.add(list); asThoughEffectsMap.put(newAsThoughEffect.getAsThoughEffectType(), list); asThoughEffectsMap.get(newAsThoughEffect.getAsThoughEffectType()).addEffect(newAsThoughEffect, source); break; case COSTMODIFICATION:
effect.setTargetPointer(new FixedTarget(chosenCard.getId())); game.addEffect(effect, source);