From 1d156305668b41c24777ad81caf792b54e176d3d Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 18 May 2024 13:14:20 +0100 Subject: [PATCH] Properly replace existing spells when casting one with different traits. #353 --- .../unicopia/ability/UnicornCastingAbility.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index 64a0e4bf..fae2d49c 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -100,12 +100,19 @@ public class UnicornCastingAbility extends AbstractSpellCastingAbility { if (newSpell.getResult() != ActionResult.FAIL && canCast(newSpell.getValue().type())) { CustomisedSpellType spell = newSpell.getValue(); + if (newSpell.getResult() == ActionResult.CONSUME) { + CustomisedSpellType equippedType = player.getCharms().getEquippedSpell(player.getCharms().getHand()); + if (equippedType.type() == spell.type()) { + player.getCharms().equipSpell(player.getCharms().getHand(), spell); + } + } + boolean hasExact = player.getSpellSlot().contains(spell); boolean removed = player.getSpellSlot().removeWhere(s -> { - return s.findMatches(spell).findAny().isPresent() && (spell.isEmpty() || !SpellType.PLACED_SPELL.test(s)); + return s.findMatches(spell.type()).findAny().isPresent() && (spell.isEmpty() || !SpellType.PLACED_SPELL.test(s)); }, true); player.subtractEnergyCost(removed ? 2 : 4); - if (!removed) { + if (!hasExact && !spell.isEmpty()) { Spell s = spell.apply(player, CastingMethod.DIRECT); if (s == null) { player.spawnParticles(ParticleTypes.LARGE_SMOKE, 6);