public void removeEndOfCombatEffects() { for (Iterator<T> i = this.iterator(); i.hasNext();) { T entry = i.next(); if (entry.getDuration() == Duration.EndOfCombat) { i.remove(); effectAbilityMap.remove(entry.getId()); } } }
public void removeEndOfTurnEffects() { for (Iterator<T> i = this.iterator(); i.hasNext();) { T entry = i.next(); if (entry.getDuration() == Duration.EndOfTurn) { i.remove(); effectAbilityMap.remove(entry.getId()); } } }
public synchronized List<ContinuousEffect> getLayeredEffects(Game game) { List<ContinuousEffect> layerEffects = new ArrayList<>(); for (ContinuousEffect effect : layeredEffects) { switch (effect.getDuration()) { case WhileOnBattlefield: 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.toString()); } break; default: layerEffects.add(effect); } } updateTimestamps(layerEffects); Collections.sort(layerEffects, Comparator.comparingLong(ContinuousEffect::getOrder)); return layerEffects; }
@Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { if (!initDone) { // if simpleStaticAbility, init won't be called init(source, game); } boolean conditionState = condition.apply(game, source); if (conditionState) { return effect.apply(layer, sublayer, source, game); } else if (otherwiseEffect != null) { return otherwiseEffect.apply(layer, sublayer, source, game); } if (!conditionState && effect.getDuration() == Duration.OneUse) { used = true; } if (!conditionState && effect.getDuration() == Duration.Custom) { this.discard(); } return false; }
/** * Only use this if both effects have the same layers * * @param effect * @param otherwiseEffect * @param condition * @param text */ public ConditionalContinuousEffect(ContinuousEffect effect, ContinuousEffect otherwiseEffect, Condition condition, String text) { super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome()); this.effect = effect; this.otherwiseEffect = otherwiseEffect; this.baseCondition = condition; this.staticText = text; }
@Override public boolean apply(Game game, Ability source) { if (condition == null && baseCondition != null) { condition = baseCondition; } boolean 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; }
it.remove(); } else { switch (effect.getDuration()) { case WhileOnBattlefield: case WhileInGraveyard:
private boolean checkAbilityStillExists(Ability ability, ContinuousEffect effect, GameEvent event, Game game) { switch (effect.getDuration()) { // effects with fixed duration don't need an object with the source ability (e.g. a silence cast with isochronic Scepter has no more a card object case EndOfCombat: case EndOfGame: