Unicopia/src/main/java/com/minelittlepony/unicopia/ability/AbstractSpellCastingAbility.java
Sollace 4202723731 Make first/second/gem spell selection less confusing
- cast and shoot now both use the slot that's visually selected in the hud
- swapping between first/second slot is done only by sneaking
- there are now messages in the hud indicating the spell being cast
- gems now have a cooldown after being used
- holding a gem now changes the selector icon and title to make it clear that spells can be swapped
- activating an ability whilst holding a gem changes the message to indicate you're casting the spell from the gem rather than your spell slot
- ability titles now reflect what they do when sneaking
- equipping a spell from a gem whilst in creative mode no longer consumes the gem's spell
2023-05-29 14:13:52 +01:00

70 lines
2.6 KiB
Java

package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.TypedActionResult;
abstract class AbstractSpellCastingAbility implements Ability<Hit> {
@Override
public int getCooldownTime(Pony player) {
return 0;
}
@Override
public boolean canUse(Race race) {
return race.canCast();
}
@Override
public Text getName(Pony player) {
CustomisedSpellType<?> spell = player.getCharms().getEquippedSpell(player.getCharms().getHand());
TypedActionResult<CustomisedSpellType<?>> gemSpell = player.getCharms().getSpellInHand(false);
var active = !player.getAbilities().getStat(AbilitySlot.PRIMARY).getActiveAbility().isEmpty();
if (!spell.isEmpty()) {
if (active) {
if (gemSpell.getResult().isAccepted()) {
return Text.translatable(getTranslationKey() + ".with_spell.hand",
gemSpell.getValue().type().getName().copy().formatted(gemSpell.getValue().type().getAffinity().getColor())
);
}
return Text.translatable(getTranslationKey() + ".with_spell.active",
spell.type().getName().copy().formatted(spell.type().getAffinity().getColor())
);
}
return Text.translatable(getTranslationKey() + ".with_spell" + (gemSpell.getResult().isAccepted() ? ".replacing" : ""),
spell.type().getName().copy().formatted(spell.type().getAffinity().getColor()),
gemSpell.getValue().type().getName().copy().formatted(gemSpell.getValue().type().getAffinity().getColor())
);
}
return getName();
}
@Override
public int getColor(Pony player) {
TypedActionResult<CustomisedSpellType<?>> newSpell = player.getCharms().getSpellInHand(false);
if (newSpell.getResult() != ActionResult.FAIL) {
return newSpell.getValue().type().getColor();
}
return -1;
}
@Override
public Hit.Serializer<Hit> getSerializer() {
return Hit.SERIALIZER;
}
@Override
public void postApply(Pony player, AbilitySlot slot) {
player.spawnParticles(MagicParticleEffect.UNICORN, 5);
}
}