mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed ability spells not cancelling when the player loses access to the granting ability. Fixes #272
This commit is contained in:
parent
53497c70d6
commit
00a20fbdc7
6 changed files with 21 additions and 8 deletions
|
@ -7,6 +7,7 @@ import java.util.stream.Stream;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.*;
|
import com.minelittlepony.unicopia.*;
|
||||||
|
import com.minelittlepony.unicopia.ability.Ability;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
||||||
import com.minelittlepony.unicopia.entity.*;
|
import com.minelittlepony.unicopia.entity.*;
|
||||||
import com.minelittlepony.unicopia.entity.damage.UDamageSources;
|
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));
|
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) {
|
static Stream<Caster<?>> stream(Stream<Entity> entities) {
|
||||||
return entities.map(Caster::of).flatMap(Optional::stream);
|
return entities.map(Caster::of).flatMap(Optional::stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.ability.magic.spell;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.ability.Abilities;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.IllusionarySpell;
|
import com.minelittlepony.unicopia.ability.magic.IllusionarySpell;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
|
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 owner = source.asEntity();
|
||||||
Entity appearance = getDisguise().getAppearance();
|
Entity appearance = getDisguise().getAppearance();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.ability.magic.spell;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
import com.minelittlepony.unicopia.InteractionManager;
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
|
import com.minelittlepony.unicopia.ability.Abilities;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.*;
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.*;
|
||||||
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
||||||
|
@ -45,7 +46,7 @@ public class RageAbilitySpell extends AbstractSpell {
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
import com.minelittlepony.unicopia.InteractionManager;
|
||||||
import com.minelittlepony.unicopia.UTags;
|
import com.minelittlepony.unicopia.UTags;
|
||||||
|
import com.minelittlepony.unicopia.ability.Abilities;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.*;
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.*;
|
||||||
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
||||||
|
@ -43,7 +44,7 @@ public class RainboomAbilitySpell extends AbstractSpell {
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
|
|
||||||
if (situation != Situation.BODY) {
|
if (situation != Situation.BODY || !source.canUse(Abilities.RAINBOOM)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.ability.Abilities;
|
||||||
import com.minelittlepony.unicopia.ability.data.Rot;
|
import com.minelittlepony.unicopia.ability.data.Rot;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.*;
|
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.UGameRules;
|
||||||
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
|
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
|
||||||
|
|
||||||
|
@ -31,11 +30,7 @@ public class TimeControlAbilitySpell extends AbstractSpell {
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
|
|
||||||
if (!source.asWorld().getGameRules().getBoolean(UGameRules.DO_TIME_MAGIC)) {
|
if (!source.asWorld().getGameRules().getBoolean(UGameRules.DO_TIME_MAGIC) || situation != Situation.BODY || !source.canUse(Abilities.TIME)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (situation != Situation.BODY || !(source instanceof Pony pony) || !Abilities.TIME.canUse(pony.getCompositeRace())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.UTags;
|
import com.minelittlepony.unicopia.UTags;
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.ability.Abilities;
|
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.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;
|
||||||
|
@ -614,6 +615,11 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
updateVelocity(entity);
|
updateVelocity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(Ability<?> ability) {
|
||||||
|
return ability.canUse(getCompositeRace());
|
||||||
|
}
|
||||||
|
|
||||||
public static Optional<Living<?>> getOrEmpty(Entity entity) {
|
public static Optional<Living<?>> getOrEmpty(Entity entity) {
|
||||||
return Equine.of(entity, a -> a instanceof Living);
|
return Equine.of(entity, a -> a instanceof Living);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue