mirror of
https://github.com/correl/mage.git
synced 2024-11-25 11:09:53 +00:00
small nonfunctional cleanup to continuous effects handling
This commit is contained in:
parent
e532cfddcd
commit
9c8943384a
2 changed files with 18 additions and 32 deletions
|
@ -1288,45 +1288,36 @@ public class ContinuousEffects implements Serializable {
|
||||||
switch (effect.getEffectType()) {
|
switch (effect.getEffectType()) {
|
||||||
case REPLACEMENT:
|
case REPLACEMENT:
|
||||||
case REDIRECTION:
|
case REDIRECTION:
|
||||||
ReplacementEffect newReplacementEffect = (ReplacementEffect) effect;
|
replacementEffects.addEffect((ReplacementEffect) effect, source);
|
||||||
replacementEffects.addEffect(newReplacementEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case PREVENTION:
|
case PREVENTION:
|
||||||
PreventionEffect newPreventionEffect = (PreventionEffect) effect;
|
preventionEffects.addEffect((PreventionEffect) effect, source);
|
||||||
preventionEffects.addEffect(newPreventionEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case RESTRICTION:
|
case RESTRICTION:
|
||||||
RestrictionEffect newRestrictionEffect = (RestrictionEffect) effect;
|
restrictionEffects.addEffect((RestrictionEffect) effect, source);
|
||||||
restrictionEffects.addEffect(newRestrictionEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case RESTRICTION_UNTAP_NOT_MORE_THAN:
|
case RESTRICTION_UNTAP_NOT_MORE_THAN:
|
||||||
RestrictionUntapNotMoreThanEffect newRestrictionUntapNotMoreThanEffect = (RestrictionUntapNotMoreThanEffect) effect;
|
restrictionUntapNotMoreThanEffects.addEffect((RestrictionUntapNotMoreThanEffect) effect, source);
|
||||||
restrictionUntapNotMoreThanEffects.addEffect(newRestrictionUntapNotMoreThanEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case REQUIREMENT:
|
case REQUIREMENT:
|
||||||
RequirementEffect newRequirementEffect = (RequirementEffect) effect;
|
requirementEffects.addEffect((RequirementEffect) effect, source);
|
||||||
requirementEffects.addEffect(newRequirementEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case ASTHOUGH:
|
case ASTHOUGH:
|
||||||
AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect;
|
AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect;
|
||||||
if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) {
|
asThoughEffectsMap.computeIfAbsent(newAsThoughEffect.getAsThoughEffectType(), x -> {
|
||||||
ContinuousEffectsList<AsThoughEffect> list = new ContinuousEffectsList<>();
|
ContinuousEffectsList<AsThoughEffect> list = new ContinuousEffectsList<>();
|
||||||
allEffectsLists.add(list);
|
allEffectsLists.add(list);
|
||||||
asThoughEffectsMap.put(newAsThoughEffect.getAsThoughEffectType(), list);
|
return list;
|
||||||
}
|
}).addEffect(newAsThoughEffect, source);
|
||||||
asThoughEffectsMap.get(newAsThoughEffect.getAsThoughEffectType()).addEffect(newAsThoughEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case COSTMODIFICATION:
|
case COSTMODIFICATION:
|
||||||
CostModificationEffect newCostModificationEffect = (CostModificationEffect) effect;
|
costModificationEffects.addEffect((CostModificationEffect) effect, source);
|
||||||
costModificationEffects.addEffect(newCostModificationEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case SPLICE:
|
case SPLICE:
|
||||||
SpliceCardEffect newSpliceCardEffect = (SpliceCardEffect) effect;
|
spliceCardEffects.addEffect((SpliceCardEffect) effect, source);
|
||||||
spliceCardEffects.addEffect(newSpliceCardEffect, source);
|
|
||||||
break;
|
break;
|
||||||
case CONTINUOUS_RULE_MODIFICATION:
|
case CONTINUOUS_RULE_MODIFICATION:
|
||||||
ContinuousRuleModifyingEffect newContinuousRuleModifiyingEffect = (ContinuousRuleModifyingEffect) effect;
|
continuousRuleModifyingEffects.addEffect((ContinuousRuleModifyingEffect) effect, source);
|
||||||
continuousRuleModifyingEffects.addEffect(newContinuousRuleModifiyingEffect, source);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
layeredEffects.addEffect(effect, source);
|
layeredEffects.addEffect(effect, source);
|
||||||
|
|
|
@ -192,24 +192,19 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
|
||||||
* @param source - connected ability
|
* @param source - connected ability
|
||||||
*/
|
*/
|
||||||
public void addEffect(T effect, Ability source) {
|
public void addEffect(T effect, Ability source) {
|
||||||
if (effectAbilityMap.containsKey(effect.getId())) {
|
Set<Ability> set = effectAbilityMap.computeIfAbsent(effect.getId(), x -> new HashSet<>());
|
||||||
Set<Ability> set = effectAbilityMap.get(effect.getId());
|
if (set.stream()
|
||||||
for (Ability ability : set) {
|
.filter(ability -> ability.getId().equals(source.getId()))
|
||||||
if (ability.getId().equals(source.getId()) && ability.getSourceId().equals(source.getSourceId())) {
|
.map(Ability::getId)
|
||||||
return;
|
.anyMatch(source.getId()::equals)) {
|
||||||
}
|
|
||||||
}
|
|
||||||
set.add(source);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<Ability> set = new HashSet<>();
|
|
||||||
set.add(source);
|
set.add(source);
|
||||||
this.effectAbilityMap.put(effect.getId(), set);
|
|
||||||
this.add(effect);
|
this.add(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Ability> getAbility(UUID effectId) {
|
public Set<Ability> getAbility(UUID effectId) {
|
||||||
return effectAbilityMap.getOrDefault(effectId, new HashSet<>());
|
return effectAbilityMap.computeIfAbsent(effectId, x -> new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTemporaryEffects() {
|
public void removeTemporaryEffects() {
|
||||||
|
@ -230,7 +225,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object object) {
|
public boolean contains(Object object) {
|
||||||
if (object == null || !(object instanceof ContinuousEffect)) {
|
if (!(object instanceof ContinuousEffect)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue