Implement casting via the staff for the mind swap spell

This commit is contained in:
Sollace 2023-08-28 13:58:21 +01:00
parent fbf96005ae
commit 514ce8f984
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
8 changed files with 50 additions and 18 deletions

View file

@ -103,7 +103,7 @@ public class UnicornCastingAbility extends AbstractSpellCastingAbility {
}, true);
player.subtractEnergyCost(removed ? 2 : 4);
if (!removed) {
Spell s = spell.apply(player, CastingMethod.GEM);
Spell s = spell.apply(player, CastingMethod.DIRECT);
if (s == null) {
player.spawnParticles(ParticleTypes.LARGE_SMOKE, 6);
player.playSound(USounds.SPELL_CAST_FAIL, 1, 0.5F);

View file

@ -4,15 +4,15 @@ public enum CastingMethod {
/**
* Casting from a gem or a unicorn's equipped spell.
*/
GEM,
DIRECT,
/**
* Casting a projectile form from a gem or unicorn's equipped spell
*/
GEM_PROJECTILE,
STORED,
/**
* Result of a projectile impact
*/
PROJECTILE,
INDIRECT,
/**
* Casting from a magic staff
*/
@ -20,5 +20,21 @@ public enum CastingMethod {
/**
* Result of an entities innate ability
*/
INNATE
INNATE;
public boolean isIndirectCause() {
return this == STAFF || this == STORED;
}
public boolean isIndirectEffect() {
return this == INDIRECT;
}
public boolean isDirect() {
return this == DIRECT || this == INNATE;
}
public boolean isTool() {
return this == STAFF;
}
}

View file

@ -64,7 +64,7 @@ public final class ThrowableSpell extends AbstractDelegatingSpell {
projectile.setPosition(entity.getX(), entity.getEyeY() - 0.1F, entity.getZ());
projectile.setOwner(entity);
projectile.setItem(UItems.GEMSTONE.getDefaultStack(spell.getType()));
spell.prepareForCast(caster, CastingMethod.PROJECTILE).apply(projectile);
spell.prepareForCast(caster, CastingMethod.STORED).apply(projectile);
projectile.setVelocity(entity, entity.getPitch(), entity.getYaw(), 0, 1.5F, divergance);
projectile.setNoGravity(true);
configureProjectile(projectile, caster);

View file

@ -146,7 +146,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
if (!isDead() && getTraits().get(Trait.CHAOS) > 0) {
setDead();
Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE));
Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT));
}
}

View file

@ -153,7 +153,7 @@ public class BubbleSpell extends AbstractSpell implements TimedSpell,
@Override
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
Caster.of(hit.getEntity()).ifPresent(caster -> {
getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE);
getTypeAndTraits().apply(caster, CastingMethod.INDIRECT);
});
}

View file

@ -86,7 +86,7 @@ public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileD
@Override
public void onImpact(MagicProjectileEntity projectile) {
Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE));
Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT));
}
@Override

View file

@ -5,17 +5,22 @@ import java.util.Optional;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell;
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
import com.minelittlepony.unicopia.ability.magic.spell.Spell;
import com.minelittlepony.unicopia.entity.EntityReference;
import com.minelittlepony.unicopia.entity.behaviour.EntitySwap;
import com.minelittlepony.unicopia.entity.behaviour.Inventory;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.util.hit.EntityHitResult;
public class MindSwapSpell extends MimicSpell {
public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.EntityHitListener {
private final EntityReference<LivingEntity> counterpart = new EntityReference<>();
@ -28,6 +33,10 @@ public class MindSwapSpell extends MimicSpell {
super(type);
}
@Override
public Spell prepareForCast(Caster<?> caster, CastingMethod method) {
return method == CastingMethod.STAFF ? toThrowable() : this;
}
@Override
public void onDestroyed(Caster<?> caster) {
@ -57,6 +66,10 @@ public class MindSwapSpell extends MimicSpell {
@Override
public boolean tick(Caster<?> caster, Situation situation) {
if (situation != Situation.BODY) {
return true;
}
if (!caster.isClient()) {
if (!initialized) {
initialized = true;
@ -66,7 +79,7 @@ public class MindSwapSpell extends MimicSpell {
setDisguise(e);
Caster<?> other = Caster.of(e).get();
SpellType.MIMIC.withTraits().apply(other, CastingMethod.PROJECTILE).setDisguise(master);
SpellType.MIMIC.withTraits().apply(other, CastingMethod.INDIRECT).setDisguise(master);
EntitySwap.ALL.accept(master, e);
Inventory.swapInventories(
@ -100,6 +113,16 @@ public class MindSwapSpell extends MimicSpell {
return super.tick(caster, situation);
}
@Override
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
Caster.of(projectile.getMaster()).ifPresent(master -> {
if (getTypeAndTraits().apply(master, CastingMethod.DIRECT) instanceof HomingSpell homing) {
homing.setTarget(hit.getEntity());
}
});
}
@Override
public boolean setTarget(Entity target) {
if (target instanceof LivingEntity living && Caster.of(target).isPresent()) {

View file

@ -7,9 +7,7 @@ import java.util.function.Supplier;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell;
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
import com.minelittlepony.unicopia.ability.magic.spell.Spell;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.entity.Creature;
import com.minelittlepony.unicopia.entity.EntityReference;
@ -88,11 +86,6 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
super(type);
}
@Override
public Spell prepareForCast(Caster<?> caster, CastingMethod method) {
return method == CastingMethod.GEM ? toPlaceable() : super.prepareForCast(caster, method);
}
@Override
public boolean tick(Caster<?> source, Situation situation) {