mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 13:57:59 +01:00
Fixed not being able to toggle delegated spells
This commit is contained in:
parent
613b39436f
commit
df2706cfc6
6 changed files with 26 additions and 8 deletions
|
@ -129,6 +129,10 @@ public interface SpellContainer {
|
||||||
public enum Operation {
|
public enum Operation {
|
||||||
SKIP,
|
SKIP,
|
||||||
KEEP,
|
KEEP,
|
||||||
REMOVE
|
REMOVE;
|
||||||
|
|
||||||
|
public static Operation ofBoolean(boolean result) {
|
||||||
|
return result ? KEEP : REMOVE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.ability.magic.spell;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Affinity;
|
import com.minelittlepony.unicopia.Affinity;
|
||||||
|
@ -36,6 +37,11 @@ public abstract class AbstractDelegatingSpell implements ProjectileSpell {
|
||||||
return ProjectileSpell.super.equalsOrContains(id) || getDelegates().stream().anyMatch(s -> s.equalsOrContains(id));
|
return ProjectileSpell.super.equalsOrContains(id) || getDelegates().stream().anyMatch(s -> s.equalsOrContains(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<Spell> findMatches(Predicate<Spell> predicate) {
|
||||||
|
return Stream.concat(ProjectileSpell.super.findMatches(predicate), getDelegates().stream().flatMap(s -> s.findMatches(predicate)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Affinity getAffinity() {
|
public Affinity getAffinity() {
|
||||||
return Affinity.NEUTRAL;
|
return Affinity.NEUTRAL;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.minelittlepony.unicopia.ability.magic.spell;
|
package com.minelittlepony.unicopia.ability.magic.spell;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.spongepowered.include.com.google.common.base.Objects;
|
import org.spongepowered.include.com.google.common.base.Objects;
|
||||||
|
|
||||||
|
@ -32,6 +34,13 @@ public interface Spell extends NbtSerialisable, Affine {
|
||||||
return Objects.equal(getUuid(), id);
|
return Objects.equal(getUuid(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an optional containing the spell that matched the given predicate.
|
||||||
|
*/
|
||||||
|
default Stream<Spell> findMatches(Predicate<Spell> predicate) {
|
||||||
|
return predicate.test(this) ? Stream.of(this) : Stream.empty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this effect as dead.
|
* Sets this effect as dead.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class CastSpellEntity extends Entity implements Caster<LivingEntity> {
|
||||||
return super.getName();
|
return super.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
@ -113,10 +114,7 @@ public class CastSpellEntity extends Entity implements Caster<LivingEntity> {
|
||||||
|
|
||||||
if (!dataTracker.get(SPELL).filter(spellId -> {
|
if (!dataTracker.get(SPELL).filter(spellId -> {
|
||||||
return getSpellSlot().forEach(spell -> {
|
return getSpellSlot().forEach(spell -> {
|
||||||
if (!spell.getUuid().equals(spellId)) {
|
return spell.getUuid().equals(spellId) ? Operation.ofBoolean(spell.tick(this, Situation.GROUND_ENTITY)) : Operation.SKIP;
|
||||||
return Operation.SKIP;
|
|
||||||
}
|
|
||||||
return spell.tick(this, Situation.GROUND_ENTITY) ? Operation.KEEP: Operation.REMOVE;
|
|
||||||
}, true);
|
}, true);
|
||||||
}).isPresent()) {
|
}).isPresent()) {
|
||||||
discard();
|
discard();
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.SpellContainer;
|
import com.minelittlepony.unicopia.ability.magic.SpellContainer;
|
||||||
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.SpellContainer.Operation;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
import com.minelittlepony.unicopia.network.datasync.EffectSync;
|
import com.minelittlepony.unicopia.network.datasync.EffectSync;
|
||||||
|
@ -85,7 +86,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
getSpellSlot().removeIf(effect -> !effect.tick(this, Situation.BODY), true);
|
getSpellSlot().forEach(spell -> Operation.ofBoolean(spell.tick(this, Situation.BODY)), true);
|
||||||
|
|
||||||
if (invinsibilityTicks > 0) {
|
if (invinsibilityTicks > 0) {
|
||||||
invinsibilityTicks--;
|
invinsibilityTicks--;
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class EffectSync implements SpellContainer {
|
||||||
@Override
|
@Override
|
||||||
public boolean removeIf(Predicate<Spell> test, boolean update) {
|
public boolean removeIf(Predicate<Spell> test, boolean update) {
|
||||||
return reduce((initial, effect) -> {
|
return reduce((initial, effect) -> {
|
||||||
if (!test.test(effect)) {
|
if (!effect.findMatches(test).findFirst().isPresent()) {
|
||||||
return initial;
|
return initial;
|
||||||
}
|
}
|
||||||
spells.removeReference(effect);
|
spells.removeReference(effect);
|
||||||
|
@ -107,7 +107,7 @@ public class EffectSync implements SpellContainer {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return spells.getReferences();
|
return spells.getReferences();
|
||||||
}
|
}
|
||||||
return spells.getReferences().filter(type);
|
return spells.getReferences().flatMap(s -> s.findMatches(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reduce(Alteration alteration) {
|
public boolean reduce(Alteration alteration) {
|
||||||
|
|
Loading…
Reference in a new issue