From 00a20fbdc7d4344bca1f5341d536dddcbda9d6ea Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 21 Feb 2024 22:46:10 +0000 Subject: [PATCH] Fixed ability spells not cancelling when the player loses access to the granting ability. Fixes #272 --- .../com/minelittlepony/unicopia/ability/magic/Caster.java | 5 +++++ .../ability/magic/spell/DispersableDisguiseSpell.java | 5 +++++ .../unicopia/ability/magic/spell/RageAbilitySpell.java | 3 ++- .../unicopia/ability/magic/spell/RainboomAbilitySpell.java | 3 ++- .../ability/magic/spell/TimeControlAbilitySpell.java | 7 +------ .../java/com/minelittlepony/unicopia/entity/Living.java | 6 ++++++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java index 150b1004..2d662cb1 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -7,6 +7,7 @@ import java.util.stream.Stream; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.*; +import com.minelittlepony.unicopia.ability.Ability; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.entity.*; import com.minelittlepony.unicopia.entity.damage.UDamageSources; @@ -103,6 +104,10 @@ public interface Caster extends return !Ether.get(asWorld()).anyMatch(SpellType.ARCANE_PROTECTION, (spell, caster) -> spell.blocksMagicFor(caster, this, pos)); } + default boolean canUse(Ability ability) { + return false; + } + static Stream> stream(Stream entities) { return entities.map(Caster::of).flatMap(Optional::stream); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java index c3b3bfc1..f52b0e4a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.ability.magic.spell; import java.util.Optional; +import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.IllusionarySpell; import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; @@ -55,6 +56,10 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I } } + if (!source.canUse(Abilities.DISGUISE)) { + setDead(); + } + Entity owner = source.asEntity(); Entity appearance = getDisguise().getAppearance(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RageAbilitySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RageAbilitySpell.java index 17e3acd8..f674edbf 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RageAbilitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RageAbilitySpell.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.ability.magic.spell; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.USounds; +import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.effect.*; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; @@ -45,7 +46,7 @@ public class RageAbilitySpell extends AbstractSpell { @Override public boolean tick(Caster source, Situation situation) { - if (situation != Situation.BODY || source.asEntity().isRemoved()) { + if (situation != Situation.BODY || source.asEntity().isRemoved() || !source.canUse(Abilities.RAGE)) { return false; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java index 6c6d1099..05ce028a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.UTags; +import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.effect.*; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; @@ -43,7 +44,7 @@ public class RainboomAbilitySpell extends AbstractSpell { @Override public boolean tick(Caster source, Situation situation) { - if (situation != Situation.BODY) { + if (situation != Situation.BODY || !source.canUse(Abilities.RAINBOOM)) { return false; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/TimeControlAbilitySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/TimeControlAbilitySpell.java index 6953ff87..8490cbeb 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/TimeControlAbilitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/TimeControlAbilitySpell.java @@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.data.Rot; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.effect.*; -import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.server.world.UGameRules; import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties; @@ -31,11 +30,7 @@ public class TimeControlAbilitySpell extends AbstractSpell { @Override public boolean tick(Caster source, Situation situation) { - if (!source.asWorld().getGameRules().getBoolean(UGameRules.DO_TIME_MAGIC)) { - return false; - } - - if (situation != Situation.BODY || !(source instanceof Pony pony) || !Abilities.TIME.canUse(pony.getCompositeRace())) { + if (!source.asWorld().getGameRules().getBoolean(UGameRules.DO_TIME_MAGIC) || situation != Situation.BODY || !source.canUse(Abilities.TIME)) { return false; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index 463a5136..53384423 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.Abilities; +import com.minelittlepony.unicopia.ability.Ability; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.SpellContainer; import com.minelittlepony.unicopia.ability.magic.SpellPredicate; @@ -614,6 +615,11 @@ public abstract class Living implements Equine, Caste updateVelocity(entity); } + @Override + public boolean canUse(Ability ability) { + return ability.canUse(getCompositeRace()); + } + public static Optional> getOrEmpty(Entity entity) { return Equine.of(entity, a -> a instanceof Living); }