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