use of mage.abilities.SpellAbility in project mage by magefree.
the class InvasionOfTheGiantsWatcher method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
InvasionOfTheGiantsWatcher watcher = game.getState().getWatcher(InvasionOfTheGiantsWatcher.class);
if (watcher == null) {
return false;
}
if (watcher.getCount(source.getControllerId()) > spellsCast) {
// only one use
discard();
return false;
}
if (!(abilityToModify instanceof SpellAbility) || !abilityToModify.isControlledBy(source.getControllerId())) {
return false;
}
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
return spellCard != null && spellCard.hasSubtype(SubType.GIANT, game);
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class RetetherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<Card, Permanent> auraMap = new HashMap<>();
auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
if (aura != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
filter.add(new CanBeEnchantedByPredicate(aura));
Target target = null;
auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
if (permanent != null) {
for (Ability ability : aura.getAbilities()) {
if (ability instanceof SpellAbility) {
for (Target abilityTarget : ability.getTargets()) {
if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
target = abilityTarget.copy();
break auraLegalitySearch;
}
}
}
}
}
}
}
if (target != null) {
target.getFilter().add(CardType.CREATURE.getPredicate());
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
auraMap.put(aura, permanent);
game.getState().setValue("attachTo:" + aura.getId(), permanent);
continue auraCardsInGraveyard;
}
}
}
}
game.informPlayers("No valid creature targets for " + aura.getLogName());
}
}
controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
Card aura = entry.getKey();
Permanent permanent = entry.getValue();
if (aura != null && permanent != null) {
permanent.addAttachment(aura.getId(), source, game);
}
}
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SenatorLottDodSpellsTargetingYouCostModificationEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (!(abilityToModify instanceof SpellAbility)) {
return false;
}
if (!game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
Set<UUID> allTargets;
if (spell != null) {
// real cast
allTargets = CardUtil.getAllSelectedTargets(abilityToModify, game);
} else {
// playable
allTargets = CardUtil.getAllPossibleTargets(abilityToModify, game);
// can target without cost increase
if (allTargets.stream().anyMatch(target -> !isTargetCompatible(target, source, game))) {
return false;
}
;
}
return allTargets.stream().anyMatch(target -> isTargetCompatible(target, source, game));
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class TitheTakerCostReductionEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (abilityToModify.getAbilityType() == AbilityType.SPELL) {
SpellAbility spellAbility = (SpellAbility) abilityToModify;
CardUtil.adjustCost(spellAbility, -1);
}
if (abilityToModify.getAbilityType() == AbilityType.ACTIVATED) {
CardUtil.increaseCost(abilityToModify, 1);
}
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class TizerusChargerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (!(spellAbility instanceof EscapeAbility) || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
return false;
}
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
CounterType counterType = player.chooseUse(outcome, "Choose +1/+1 or flying", null, "+1/+1", "Flying", source, game) ? CounterType.P1P1 : CounterType.FLYING;
permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game, appliedEffects);
return true;
}
Aggregations