fixed issue with dependecies of continuous effects

This commit is contained in:
Evan Kranzler 2020-04-23 17:37:31 -04:00
parent 63b46c081c
commit 9978b9bec9

View file

@ -953,21 +953,45 @@ public class ContinuousEffects implements Serializable {
// debug // debug
/* /*
System.out.println(game.getTurn() + ", " + game.getPhase() + ": " + "need apply " + layer.stream() System.out.println(
.map((eff) -> {return eff.getClass().getName().replaceAll(".+\\.(.+)", "$1");}) game.getTurn()
.collect(Collectors.joining(", "))); + ", " + game.getPhase()
+ ": need to apply "
+ layer.stream()
.map(Object::getClass)
.map(Class::getName)
.map(s -> s.replaceAll(".+\\.(.+)", "$1"))
.collect(Collectors.joining(", "))
);
*/ */
for (ContinuousEffect effect : layer) { for (ContinuousEffect effect : layer) {
if (activeLayerEffects.contains(effect) && !appliedEffects.contains(effect.getId())) { // Effect does still exist and was not applied yet if (!activeLayerEffects.contains(effect) || appliedEffects.contains(effect.getId())) {
continue;
} // Effect does still exist and was not applied yet
Set<UUID> dependentTo = effect.isDependentTo(layer); Set<UUID> dependentTo = effect.isDependentTo(layer);
if (!appliedEffects.containsAll(dependentTo)) { if (!appliedEffects.containsAll(dependentTo)) {
waitingEffects
.entrySet()
.stream()
.filter(entry -> dependentTo.contains(entry.getKey().getId())
&& entry.getValue().contains(effect.getId()))
.forEach(entry -> {
entry.getValue().remove(effect.getId());
dependentTo.remove(entry.getKey().getId());
});
waitingEffects.entrySet().removeIf(x -> x.getValue() == null || x.getValue().isEmpty());
if (!dependentTo.isEmpty() && !waitingEffects.containsKey(effect)) {
// make sure circular dependencies weren't the only dependencies
waitingEffects.put(effect, dependentTo); waitingEffects.put(effect, dependentTo);
continue; continue;
} }
}
List<Ability> appliedAbilities = appliedEffectAbilities.get(effect); List<Ability> appliedAbilities = appliedEffectAbilities.get(effect);
Set<Ability> abilities = layeredEffects.getAbility(effect.getId()); Set<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) { for (Ability ability : abilities) {
if (appliedAbilities == null || !appliedAbilities.contains(ability)) { if (appliedAbilities != null && appliedAbilities.contains(ability)) {
continue;
}
if (appliedAbilities == null) { if (appliedAbilities == null) {
appliedAbilities = new ArrayList<>(); appliedAbilities = new ArrayList<>();
appliedEffectAbilities.put(effect, appliedAbilities); appliedEffectAbilities.put(effect, appliedAbilities);
@ -978,18 +1002,23 @@ public class ContinuousEffects implements Serializable {
// list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities) // list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities)
activeLayerEffects = getLayeredEffects(game); activeLayerEffects = getLayeredEffects(game);
} }
}
appliedEffects.add(effect.getId()); appliedEffects.add(effect.getId());
if (!waitingEffects.isEmpty()) { if (waitingEffects.isEmpty()) {
continue;
}
// check if waiting effects can be applied now // check if waiting effects can be applied now
for (Iterator<Map.Entry<ContinuousEffect, Set<UUID>>> iterator = waitingEffects.entrySet().iterator(); iterator.hasNext(); ) { for (Iterator<Map.Entry<ContinuousEffect, Set<UUID>>> iterator = waitingEffects.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<ContinuousEffect, Set<UUID>> entry = iterator.next(); Map.Entry<ContinuousEffect, Set<UUID>> entry = iterator.next();
if (appliedEffects.containsAll(entry.getValue())) { // all dependent to effects are applied now so apply the effect itself if (!appliedEffects.containsAll(entry.getValue())) { // all dependent to effects are applied now so apply the effect itself
continue;
}
appliedAbilities = appliedEffectAbilities.get(entry.getKey()); appliedAbilities = appliedEffectAbilities.get(entry.getKey());
abilities = layeredEffects.getAbility(entry.getKey().getId()); abilities = layeredEffects.getAbility(entry.getKey().getId());
for (Ability ability : abilities) { for (Ability ability : abilities) {
if (appliedAbilities == null || !appliedAbilities.contains(ability)) { if (appliedAbilities != null && appliedAbilities.contains(ability)) {
continue;
}
if (appliedAbilities == null) { if (appliedAbilities == null) {
appliedAbilities = new ArrayList<>(); appliedAbilities = new ArrayList<>();
appliedEffectAbilities.put(entry.getKey(), appliedAbilities); appliedEffectAbilities.put(entry.getKey(), appliedAbilities);
@ -1000,15 +1029,11 @@ public class ContinuousEffects implements Serializable {
// list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities) // list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities)
activeLayerEffects = getLayeredEffects(game); activeLayerEffects = getLayeredEffects(game);
} }
}
appliedEffects.add(entry.getKey().getId()); appliedEffects.add(entry.getKey().getId());
iterator.remove(); iterator.remove();
} }
} }
} }
}
}
}
layer = filterLayeredEffects(activeLayerEffects, Layer.PTChangingEffects_7); layer = filterLayeredEffects(activeLayerEffects, Layer.PTChangingEffects_7);
for (ContinuousEffect effect : layer) { for (ContinuousEffect effect : layer) {