diff --git a/src/main/java/com/minelittlepony/unicopia/power/PowerEngulf.java b/src/main/java/com/minelittlepony/unicopia/power/PowerEngulf.java new file mode 100644 index 00000000..e2a4f6d7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/power/PowerEngulf.java @@ -0,0 +1,68 @@ +package com.minelittlepony.unicopia.power; + +import javax.annotation.Nullable; + +import org.lwjgl.input.Keyboard; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.power.data.Hit; +import com.minelittlepony.unicopia.spell.ITossedEffect; +import com.minelittlepony.unicopia.spell.SpellChangelingTrap; + +public class PowerEngulf implements IPower { + + @Override + public String getKeyName() { + return "engulf"; + } + + @Override + public int getKeyCode() { + return Keyboard.KEY_L; + } + + @Override + public int getWarmupTime(IPlayer player) { + return 0; + } + + @Override + public int getCooldownTime(IPlayer player) { + return 30; + } + + @Override + public boolean canUse(Race playerSpecies) { + return playerSpecies == Race.CHANGELING; + } + + @Nullable + @Override + public Hit tryActivate(IPlayer player) { + return new Hit(); + } + + @Override + public Class getPackageType() { + return Hit.class; + } + + @Override + public void apply(IPlayer player, Hit data) { + ITossedEffect effect = new SpellChangelingTrap(); + + effect.toss(player); + } + + @Override + public void preApply(IPlayer player) { + + } + + @Override + public void postApply(IPlayer player) { + + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/power/PowersRegistry.java b/src/main/java/com/minelittlepony/unicopia/power/PowersRegistry.java index b63d146b..73bd37f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/power/PowersRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/power/PowersRegistry.java @@ -33,6 +33,7 @@ public class PowersRegistry { registerPower(new PowerCarry()); registerPower(new PowerDisguise()); registerPower(new PowerCloudBase()); + registerPower(new PowerEngulf()); } public boolean hasRegisteredPower(int keyCode) { diff --git a/src/main/java/com/minelittlepony/unicopia/spell/ITossedEffect.java b/src/main/java/com/minelittlepony/unicopia/spell/ITossedEffect.java index 6e5ad0da..8f3dc5e9 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/ITossedEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/ITossedEffect.java @@ -12,6 +12,12 @@ import net.minecraft.world.World; public interface ITossedEffect extends IMagicEffect, ITossable> { + default ItemStack getCastAppearance(ICaster caster) { + Item item = this.getAffinity() == SpellAffinity.BAD ? UItems.curse : UItems.spell; + + return SpellRegistry.instance().enchantStack(new ItemStack(item), getName()); + } + default void toss(ICaster caster) { World world = caster.getWorld(); @@ -22,9 +28,7 @@ public interface ITossedEffect extends IMagicEffect, ITossable> { if (!world.isRemote) { EntityProjectile projectile = new EntityProjectile(world, caster.getOwner()); - Item item = this.getAffinity() == SpellAffinity.BAD ? UItems.curse : UItems.spell; - - projectile.setItem(SpellRegistry.instance().enchantStack(new ItemStack(item), getName())); + projectile.setItem(getCastAppearance(caster)); projectile.setThrowDamage(getThrowDamage(caster)); projectile.setOwner(caster.getOwner()); projectile.setEffect(this); diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellChangelingTrap.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellChangelingTrap.java new file mode 100644 index 00000000..2217522e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellChangelingTrap.java @@ -0,0 +1,78 @@ +package com.minelittlepony.unicopia.spell; + +import com.minelittlepony.unicopia.entity.EntityProjectile; +import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; +import com.minelittlepony.util.vector.VecHelper; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect { + + @Override + public String getName() { + return "changeling_trap"; + } + + @Override + public int getTint() { + return 0x88FF88; + } + + @Override + public boolean isCraftable() { + return false; + } + + @Override + public boolean update(ICaster source) { + Entity entity = source.getEntity(); + + if (!(entity instanceof EntityProjectile)) { + entity.motionX /= 3; + entity.motionY /= 3; + entity.motionZ /= 3; + } + + return true; + } + + @Override + public void render(ICaster source) { + source.spawnParticles(EnumParticleTypes.DRIP_LAVA.getParticleID(), 3); + } + + @Override + public SpellAffinity getAffinity() { + return SpellAffinity.BAD; + } + + public void enforce() { + + setDirty(true); + } + + protected void entrap(IPlayer e) { + + SpellChangelingTrap existing = e.getEffect(SpellChangelingTrap.class, true); + + if (existing == null) { + e.setEffect(copy()); + } else { + existing.enforce(); + } + } + + @Override + public void onImpact(World world, BlockPos pos, IBlockState state) { + VecHelper.findAllEntitiesInRange(null, world, pos, 5) + .filter(e -> e instanceof EntityPlayer) + .map(e -> PlayerSpeciesList.instance().getPlayer((EntityPlayer)e)) + .forEach(this::entrap); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java index 34900f68..3aed186f 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java @@ -47,6 +47,7 @@ public class SpellRegistry { registerSpell(SpellFlame::new); registerSpell(SpellSiphon::new); registerSpell(SpellLight::new); + registerSpell(SpellChangelingTrap::new); } @Nullable