small nonfunctional cleanup to continuous effects handling

This commit is contained in:
Evan Kranzler 2022-02-17 08:19:52 -05:00
parent e532cfddcd
commit 9c8943384a
2 changed files with 18 additions and 32 deletions

View file

@ -1288,45 +1288,36 @@ public class ContinuousEffects implements Serializable {
switch (effect.getEffectType()) {
case REPLACEMENT:
case REDIRECTION:
ReplacementEffect newReplacementEffect = (ReplacementEffect) effect;
replacementEffects.addEffect(newReplacementEffect, source);
replacementEffects.addEffect((ReplacementEffect) effect, source);
break;
case PREVENTION:
PreventionEffect newPreventionEffect = (PreventionEffect) effect;
preventionEffects.addEffect(newPreventionEffect, source);
preventionEffects.addEffect((PreventionEffect) effect, source);
break;
case RESTRICTION:
RestrictionEffect newRestrictionEffect = (RestrictionEffect) effect;
restrictionEffects.addEffect(newRestrictionEffect, source);
restrictionEffects.addEffect((RestrictionEffect) effect, source);
break;
case RESTRICTION_UNTAP_NOT_MORE_THAN:
RestrictionUntapNotMoreThanEffect newRestrictionUntapNotMoreThanEffect = (RestrictionUntapNotMoreThanEffect) effect;
restrictionUntapNotMoreThanEffects.addEffect(newRestrictionUntapNotMoreThanEffect, source);
restrictionUntapNotMoreThanEffects.addEffect((RestrictionUntapNotMoreThanEffect) effect, source);
break;
case REQUIREMENT:
RequirementEffect newRequirementEffect = (RequirementEffect) effect;
requirementEffects.addEffect(newRequirementEffect, source);
requirementEffects.addEffect((RequirementEffect) effect, source);
break;
case ASTHOUGH:
AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect;
if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) {
asThoughEffectsMap.computeIfAbsent(newAsThoughEffect.getAsThoughEffectType(), x -> {
ContinuousEffectsList<AsThoughEffect> list = new ContinuousEffectsList<>();
allEffectsLists.add(list);
asThoughEffectsMap.put(newAsThoughEffect.getAsThoughEffectType(), list);
}
asThoughEffectsMap.get(newAsThoughEffect.getAsThoughEffectType()).addEffect(newAsThoughEffect, source);
return list;
}).addEffect(newAsThoughEffect, source);
break;
case COSTMODIFICATION:
CostModificationEffect newCostModificationEffect = (CostModificationEffect) effect;
costModificationEffects.addEffect(newCostModificationEffect, source);
costModificationEffects.addEffect((CostModificationEffect) effect, source);
break;
case SPLICE:
SpliceCardEffect newSpliceCardEffect = (SpliceCardEffect) effect;
spliceCardEffects.addEffect(newSpliceCardEffect, source);
spliceCardEffects.addEffect((SpliceCardEffect) effect, source);
break;
case CONTINUOUS_RULE_MODIFICATION:
ContinuousRuleModifyingEffect newContinuousRuleModifiyingEffect = (ContinuousRuleModifyingEffect) effect;
continuousRuleModifyingEffects.addEffect(newContinuousRuleModifiyingEffect, source);
continuousRuleModifyingEffects.addEffect((ContinuousRuleModifyingEffect) effect, source);
break;
default:
layeredEffects.addEffect(effect, source);

View file

@ -192,24 +192,19 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
* @param source - connected ability
*/
public void addEffect(T effect, Ability source) {
if (effectAbilityMap.containsKey(effect.getId())) {
Set<Ability> set = effectAbilityMap.get(effect.getId());
for (Ability ability : set) {
if (ability.getId().equals(source.getId()) && ability.getSourceId().equals(source.getSourceId())) {
Set<Ability> set = effectAbilityMap.computeIfAbsent(effect.getId(), x -> new HashSet<>());
if (set.stream()
.filter(ability -> ability.getId().equals(source.getId()))
.map(Ability::getId)
.anyMatch(source.getId()::equals)) {
return;
}
}
set.add(source);
return;
}
Set<Ability> set = new HashSet<>();
set.add(source);
this.effectAbilityMap.put(effect.getId(), set);
this.add(effect);
}
public Set<Ability> getAbility(UUID effectId) {
return effectAbilityMap.getOrDefault(effectId, new HashSet<>());
return effectAbilityMap.computeIfAbsent(effectId, x -> new HashSet<>());
}
public void removeTemporaryEffects() {
@ -230,7 +225,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
@Override
public boolean contains(Object object) {
if (object == null || !(object instanceof ContinuousEffect)) {
if (!(object instanceof ContinuousEffect)) {
return false;
}