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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations