コード例 #1
0
 public void addEffect(ContinuousEffect effect, Ability source) {
   if (effect == null) {
     logger.error("Effect is null: " + source.toString());
     return;
   } else if (source == null) {
     logger.warn("Adding effect without ability : " + effect.toString());
   }
   switch (effect.getEffectType()) {
     case REPLACEMENT:
     case REDIRECTION:
       ReplacementEffect newReplacementEffect = (ReplacementEffect) effect;
       replacementEffects.addEffect(newReplacementEffect, source);
       break;
     case PREVENTION:
       PreventionEffect newPreventionEffect = (PreventionEffect) effect;
       preventionEffects.addEffect(newPreventionEffect, source);
       break;
     case RESTRICTION:
       RestrictionEffect newRestrictionEffect = (RestrictionEffect) effect;
       restrictionEffects.addEffect(newRestrictionEffect, source);
       break;
     case RESTRICTION_UNTAP_NOT_MORE_THAN:
       RestrictionUntapNotMoreThanEffect newRestrictionUntapNotMoreThanEffect =
           (RestrictionUntapNotMoreThanEffect) effect;
       restrictionUntapNotMoreThanEffects.addEffect(newRestrictionUntapNotMoreThanEffect, source);
       break;
     case REQUIREMENT:
       RequirementEffect newRequirementEffect = (RequirementEffect) effect;
       requirementEffects.addEffect(newRequirementEffect, source);
       break;
     case ASTHOUGH:
       AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect;
       if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) {
         ContinuousEffectsList<AsThoughEffect> list = new ContinuousEffectsList<>();
         allEffectsLists.add(list);
         asThoughEffectsMap.put(newAsThoughEffect.getAsThoughEffectType(), list);
       }
       asThoughEffectsMap
           .get(newAsThoughEffect.getAsThoughEffectType())
           .addEffect(newAsThoughEffect, source);
       break;
     case COSTMODIFICATION:
       CostModificationEffect newCostModificationEffect = (CostModificationEffect) effect;
       costModificationEffects.addEffect(newCostModificationEffect, source);
       break;
     case SPLICE:
       SpliceCardEffect newSpliceCardEffect = (SpliceCardEffect) effect;
       spliceCardEffects.addEffect(newSpliceCardEffect, source);
       break;
     case CONTINUOUS_RULE_MODIFICATION:
       ContinuousRuleModifyingEffect newContinuousRuleModifiyingEffect =
           (ContinuousRuleModifyingEffect) effect;
       continuousRuleModifyingEffects.addEffect(newContinuousRuleModifiyingEffect, source);
       break;
     default:
       layeredEffects.addEffect(effect, source);
       break;
   }
 }
コード例 #2
0
 /**
  * Filters out asThough effects that are not active.
  *
  * @param AsThoughEffectType type
  * @param game
  * @return
  */
 private List<AsThoughEffect> getApplicableAsThoughEffects(AsThoughEffectType type, Game game) {
   List<AsThoughEffect> asThoughEffectsList = new ArrayList<>();
   if (asThoughEffectsMap.containsKey(type)) {
     for (AsThoughEffect effect : asThoughEffectsMap.get(type)) {
       HashSet<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;
 }
コード例 #3
0
 public void removeAllTemporaryEffects() {
   for (Map.Entry<ContinuousEffect, Set<Ability>> entry : temporaryEffects.entrySet()) {
     switch (entry.getKey().getEffectType()) {
       case REPLACEMENT:
       case REDIRECTION:
         replacementEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case PREVENTION:
         preventionEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case RESTRICTION:
         restrictionEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case RESTRICTION_UNTAP_NOT_MORE_THAN:
         restrictionUntapNotMoreThanEffects.removeEffects(
             entry.getKey().getId(), entry.getValue());
         break;
       case REQUIREMENT:
         requirementEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case ASTHOUGH:
         AsThoughEffect newAsThoughEffect = (AsThoughEffect) entry.getKey();
         if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) {
           break;
         }
         asThoughEffectsMap
             .get(newAsThoughEffect.getAsThoughEffectType())
             .removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case COSTMODIFICATION:
         costModificationEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case SPLICE:
         spliceCardEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       case CONTINUOUS_RULE_MODIFICATION:
         continuousRuleModifyingEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
       default:
         layeredEffects.removeEffects(entry.getKey().getId(), entry.getValue());
         break;
     }
   }
   temporaryEffects.clear();
 }
コード例 #4
0
 public boolean asThough(
     UUID objectId,
     AsThoughEffectType type,
     Ability affectedAbility,
     UUID controllerId,
     Game game) {
   List<AsThoughEffect> asThoughEffectsList = getApplicableAsThoughEffects(type, game);
   for (AsThoughEffect effect : asThoughEffectsList) {
     HashSet<Ability> abilities = asThoughEffectsMap.get(type).getAbility(effect.getId());
     for (Ability ability : abilities) {
       if (affectedAbility == null) {
         if (effect.applies(objectId, ability, controllerId, game)) {
           return true;
         }
       } else {
         if (effect.applies(objectId, affectedAbility, ability, game)) {
           return true;
         }
       }
     }
   }
   return false;
 }