Search in sources :

Example 1 with StaticAbility

use of mage.abilities.StaticAbility in project mage by magefree.

the class ContinuousEffects method getApplicableRestrictionEffects.

public Map<RestrictionEffect, Set<Ability>> getApplicableRestrictionEffects(Permanent permanent, Game game) {
    Map<RestrictionEffect, Set<Ability>> effects = new HashMap<>();
    for (RestrictionEffect effect : restrictionEffects) {
        Set<Ability> abilities = restrictionEffects.getAbility(effect.getId());
        Set<Ability> applicableAbilities = new HashSet<>();
        for (Ability ability : abilities) {
            if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, ability instanceof MageSingleton ? permanent : null, null)) {
                if (effect.applies(permanent, ability, game)) {
                    applicableAbilities.add(ability);
                }
            }
        }
        if (!applicableAbilities.isEmpty()) {
            effects.put(effect, abilities);
        }
    }
    return effects;
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) StaticAbility(mage.abilities.StaticAbility) MageSingleton(mage.abilities.MageSingleton)

Example 2 with StaticAbility

use of mage.abilities.StaticAbility in project mage by magefree.

the class ContinuousEffects method preventedByRuleModification.

/**
 * Checks if an event won't happen because of an rule modifying effect
 *
 * @param event
 * @param targetAbility ability the event is attached to. can be null.
 * @param game
 * @param silentMode    true if the event does not really happen but it's
 *                      checked if the event would be replaced
 * @return
 */
public boolean preventedByRuleModification(GameEvent event, Ability targetAbility, Game game, boolean silentMode) {
    for (ContinuousRuleModifyingEffect effect : continuousRuleModifyingEffects) {
        if (!effect.checksEventType(event, game)) {
            continue;
        }
        for (Ability sourceAbility : continuousRuleModifyingEffects.getAbility(effect.getId())) {
            if (!(sourceAbility instanceof StaticAbility) || sourceAbility.isInUseableZone(game, null, event)) {
                if (checkAbilityStillExists(sourceAbility, effect, event, game)) {
                    if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
                        effect.setValue("targetAbility", targetAbility);
                        if (effect.applies(event, sourceAbility, game)) {
                            if (!game.inCheckPlayableState() && !silentMode) {
                                MageObject sourceObject = sourceAbility.getSourceObject(game);
                                String message = effect.getInfoMessage(sourceAbility, event, game);
                                if (sourceObject != null) {
                                    message = sourceObject.getIdName() + ": " + message;
                                }
                                if (message != null && !message.isEmpty()) {
                                    if (effect.sendMessageToUser()) {
                                        Player player = game.getPlayer(event.getPlayerId());
                                        if (player != null && !game.isSimulation()) {
                                            game.informPlayer(player, message);
                                        }
                                    }
                                    if (effect.sendMessageToGameLog() && !game.isSimulation()) {
                                        game.informPlayers(message);
                                    }
                                }
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) StaticAbility(mage.abilities.StaticAbility) MageObject(mage.MageObject)

Example 3 with StaticAbility

use of mage.abilities.StaticAbility in project mage by magefree.

the class ContinuousEffects method getApplicableRequirementEffects.

public Map<RequirementEffect, Set<Ability>> getApplicableRequirementEffects(Permanent permanent, boolean playerRealted, Game game) {
    Map<RequirementEffect, Set<Ability>> effects = new HashMap<>();
    for (RequirementEffect effect : requirementEffects) {
        if (playerRealted == effect.isPlayerRelated()) {
            Set<Ability> abilities = requirementEffects.getAbility(effect.getId());
            Set<Ability> applicableAbilities = new HashSet<>();
            for (Ability ability : abilities) {
                if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, ability instanceof MageSingleton ? permanent : null, null)) {
                    if (effect.applies(permanent, ability, game)) {
                        applicableAbilities.add(ability);
                    }
                }
            }
            if (!applicableAbilities.isEmpty()) {
                effects.put(effect, abilities);
            }
        }
    }
    return effects;
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) StaticAbility(mage.abilities.StaticAbility) MageSingleton(mage.abilities.MageSingleton)

Example 4 with StaticAbility

use of mage.abilities.StaticAbility in project mage by magefree.

the class SkullbriarEffect method updateZoneChangeCounter.

@Override
public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
    boolean skullBriarEffectApplied = false;
    if (event.getToZone() != Zone.HAND && event.getToZone() != Zone.LIBRARY) {
        for (StaticAbility ability : getAbilities(game).getStaticAbilities(event.getFromZone())) {
            for (Effect effect : ability.getEffects(game, EffectType.REPLACEMENT)) {
                if (effect instanceof SkullbriarEffect && event.getAppliedEffects().contains(effect.getId())) {
                    skullBriarEffectApplied = true;
                }
            }
        }
    }
    Counters copyFrom = null;
    if (skullBriarEffectApplied) {
        if (event.getTarget() != null && event.getFromZone() == Zone.BATTLEFIELD) {
            copyFrom = new Counters(event.getTarget().getCounters(game));
        } else {
            copyFrom = new Counters(this.getCounters(game));
        }
    }
    super.updateZoneChangeCounter(game, event);
    Counters copyTo = null;
    if (event.getTarget() != null && event.getToZone() == Zone.BATTLEFIELD) {
        if (event.getFromZone() != Zone.BATTLEFIELD) {
            copyTo = event.getTarget().getCounters(game);
        }
    } else {
        copyTo = this.getCounters(game);
    }
    if (copyTo != null && copyFrom != null) {
        for (Counter counter : copyFrom.values()) {
            copyTo.addCounter(counter);
        }
    }
}
Also used : Counter(mage.counters.Counter) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) StaticAbility(mage.abilities.StaticAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Effect(mage.abilities.effects.Effect) Counters(mage.counters.Counters)

Example 5 with StaticAbility

use of mage.abilities.StaticAbility in project mage by magefree.

the class ContinuousEffects method getLayeredEffects.

/**
 * Return effects list ordered by timestamps (timestamps are automaticity
 * generates from new/old lists on same layer)
 *
 * @param game
 * @param timestampGroupName workaround to fix broken timestamps on effect's
 *                           add/remove between different layers
 * @return effects list ordered by timestamp
 */
public synchronized List<ContinuousEffect> getLayeredEffects(Game game, String timestampGroupName) {
    List<ContinuousEffect> layerEffects = new ArrayList<>();
    for (ContinuousEffect effect : layeredEffects) {
        switch(effect.getDuration()) {
            case WhileOnBattlefield:
            case WhileControlled:
            case WhileOnStack:
            case WhileInGraveyard:
                Set<Ability> abilities = layeredEffects.getAbility(effect.getId());
                if (!abilities.isEmpty()) {
                    for (Ability ability : abilities) {
                        // If e.g. triggerd abilities (non static) created the effect, the ability must not be in usable zone (e.g. Unearth giving Haste effect)
                        if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, null)) {
                            layerEffects.add(effect);
                            break;
                        }
                    }
                } else {
                    logger.error("No abilities for continuous effect: " + effect);
                }
                break;
            default:
                layerEffects.add(effect);
        }
    }
    updateTimestamps(timestampGroupName, layerEffects);
    layerEffects.sort(Comparator.comparingLong(ContinuousEffect::getOrder));
    return layerEffects;
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) StaticAbility(mage.abilities.StaticAbility)

Aggregations

StaticAbility (mage.abilities.StaticAbility)8 Ability (mage.abilities.Ability)7 MageObject (mage.MageObject)3 MageSingleton (mage.abilities.MageSingleton)2 Effect (mage.abilities.effects.Effect)2 File (java.io.File)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 ActivatedAbility (mage.abilities.ActivatedAbility)1 SpellAbility (mage.abilities.SpellAbility)1 TriggeredAbility (mage.abilities.TriggeredAbility)1 PassAbility (mage.abilities.common.PassAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 SearchEffect (mage.abilities.effects.SearchEffect)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 mage.abilities.keyword (mage.abilities.keyword)1 CantBeBlockedSourceAbility (mage.abilities.keyword.CantBeBlockedSourceAbility)1