Fixed ability spells not cancelling when the player loses access to the granting ability. Fixes #272

This commit is contained in:
Sollace 2024-02-21 22:46:10 +00:00
parent 53497c70d6
commit 00a20fbdc7
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
6 changed files with 21 additions and 8 deletions

View file

@ -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<E extends Entity> 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<Caster<?>> stream(Stream<Entity> entities) {
return entities.map(Caster::of).flatMap(Optional::stream);
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<T extends LivingEntity> implements Equine<T>, Caste
updateVelocity(entity);
}
@Override
public boolean canUse(Ability<?> ability) {
return ability.canUse(getCompositeRace());
}
public static Optional<Living<?>> getOrEmpty(Entity entity) {
return Equine.of(entity, a -> a instanceof Living);
}