From 0ea59c10970aef05390971e395e3b99f771b08ac Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 27 Feb 2019 17:35:56 +0200 Subject: [PATCH] Added the gem of siphoning --- .../unicopia/spell/SpellRegistry.java | 1 + .../unicopia/spell/SpellSiphon.java | 133 ++++++++++++++++++ .../unicopia/enchanting/ingredients/life.json | 1 + .../unicopia/enchanting/recipes/pilon.json | 14 ++ .../unicopia/enchanting/recipes/siphon.json | 15 ++ .../resources/assets/unicopia/lang/en_US.lang | 8 +- 6 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/spell/SpellSiphon.java create mode 100644 src/main/resources/assets/unicopia/enchanting/recipes/pilon.json create mode 100644 src/main/resources/assets/unicopia/enchanting/recipes/siphon.json diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java index eb04c883..42eb2a9b 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java @@ -45,6 +45,7 @@ public class SpellRegistry { registerSpell(SpellReveal::new); registerSpell(SpellDarkness::new); registerSpell(SpellFlame::new); + registerSpell(SpellSiphon::new); registerSpell(GenericSpell.factory("light", 0xF7FACB, SpellAffinity.GOOD)); } diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellSiphon.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellSiphon.java new file mode 100644 index 00000000..d3b707e0 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellSiphon.java @@ -0,0 +1,133 @@ +package com.minelittlepony.unicopia.spell; + +import java.util.List; +import java.util.stream.Collectors; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; +import com.minelittlepony.util.MagicalDamageSource; +import com.minelittlepony.util.shape.Sphere; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public class SpellSiphon extends AbstractSpell.RangedAreaSpell { + + @Override + public String getName() { + return "siphon"; + } + + @Override + public int getTint() { + return 0xe308ab; + } + + @Override + public boolean update(ICaster source) { + + int radius = 4 + source.getCurrentLevel(); + + EntityLivingBase owner = source.getOwner(); + + List target = source.findAllEntitiesInRange(radius) + .filter(e -> e instanceof EntityLivingBase) + .map(e -> (EntityLivingBase)e) + .collect(Collectors.toList()); + + DamageSource damage = damageSource(owner); + + if (source.getAffinity() == SpellAffinity.BAD) { + if (owner != null) { + float healthGain = 0; + float maxHealthGain = owner.getMaxHealth() - owner.getHealth(); + + if (maxHealthGain > 0) { + float attackAmount = Math.max(maxHealthGain / target.size(), 0.5F); + + for (EntityLivingBase e : target) { + if (!e.equals(owner)) { + float dealt = Math.min(e.getHealth(), attackAmount); + + if (e instanceof EntityPlayer) { + IPlayer player = PlayerSpeciesList.instance().getPlayer((EntityPlayer)e); + + Race race = player.getPlayerSpecies(); + + if (race.canCast()) { + dealt /= 2; + } + if (race.canUseEarth()) { + dealt *= 2; + } + } + + e.attackEntityFrom(damage, dealt); + + healthGain += dealt; + } + } + } + + owner.heal(healthGain); + } + + } else { + target.forEach(e -> { + float maxHealthGain = e.getMaxHealth() - e.getHealth(); + + if (maxHealthGain <= 0) { + if (source.getWorld().rand.nextInt(30) == 0) { + setDead(); + } else { + e.attackEntityFrom(damage, e.getHealth() / 4); + } + } else { + e.heal((float)Math.min(0.5F * (1 + source.getCurrentLevel()), maxHealthGain * 0.6)); + } + }); + } + + return false; + } + + protected DamageSource damageSource(EntityLivingBase actor) { + if (actor == null) { + return MagicalDamageSource.create("drain"); + } + + return MagicalDamageSource.causeMobDamage("drain", actor); + } + + @Override + public void render(ICaster source) { + int radius = 4 + source.getCurrentLevel(); + + Vec3d origin = source.getOriginVector(); + int direction = source.getAffinity() == SpellAffinity.GOOD ? 1 : -1; + + source.spawnParticles(new Sphere(true, radius, 1, 0, 1), 1, pos -> { + if (!source.getWorld().isAirBlock(new BlockPos(pos).down())) { + + double dist = pos.distanceTo(origin); + Vec3d velocity = pos.subtract(origin).normalize().scale(direction * dist); + + + source.getWorld().spawnParticle( + direction == 1 ? EnumParticleTypes.HEART : EnumParticleTypes.VILLAGER_ANGRY, + pos.x, pos.y, pos.z, velocity.x, velocity.y, velocity.z); + } + }); + } + + @Override + public SpellAffinity getAffinity() { + return SpellAffinity.NEUTRAL; + } + +} diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/life.json b/src/main/resources/assets/unicopia/enchanting/ingredients/life.json index b185e544..af7b9d89 100644 --- a/src/main/resources/assets/unicopia/enchanting/ingredients/life.json +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/life.json @@ -4,6 +4,7 @@ { "item": "unicopia:rotten_apple" }, { "item": "minecraft:golden_carrot" }, { "item": "minecraft:wheat" }, + { "item": "minecraft:wheat_seeds" }, { "item": "minecraft:grain" }, { "item": "minecraft:alfalfa_leaves" }, { "item": "unicopia:moss" } diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/pilon.json b/src/main/resources/assets/unicopia/enchanting/recipes/pilon.json new file mode 100644 index 00000000..4e95c658 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/recipes/pilon.json @@ -0,0 +1,14 @@ +{ + "type": "unicopia:crafting_spell", + "ingredients": [ + { "id": "unicopia:energy" }, + { "id": "unicopia:life" }, + { "item": "unicopia:gem", "spell": "charge" } + ], + "result": { + "item": [ + { "item": "unicopia:gem" } + ], + "spell": "siphon" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/siphon.json b/src/main/resources/assets/unicopia/enchanting/recipes/siphon.json new file mode 100644 index 00000000..22949607 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/recipes/siphon.json @@ -0,0 +1,15 @@ +{ + "type": "unicopia:crafting_spell", + "ingredients": [ + { "id": "unicopia:energy" }, + { "id": "unicopia:life" }, + { "id": "unicopia:dark" }, + { "item": "unicopia:gem", "spell": "siphon" } + ], + "result": { + "item": [ + { "item": "unicopia:corrupted_gem" } + ], + "spell": "siphon" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/lang/en_US.lang b/src/main/resources/assets/unicopia/lang/en_US.lang index 84ab48d6..741f326b 100644 --- a/src/main/resources/assets/unicopia/lang/en_US.lang +++ b/src/main/resources/assets/unicopia/lang/en_US.lang @@ -69,9 +69,12 @@ spell.fire.tagline=Fire II spell.vortex.name=Retention spell.vortex.tagline=Containment I -spell.charge.name=Chanelling +spell.charge.name=Channeling spell.charge.tagline=Energy I +spell.siphon.name=Pilon +spell.siphon.tagline=Energy II + spell.ice.name=Frost spell.ice.tagline=Ice I @@ -99,6 +102,9 @@ curse.necromancy.tagline=Resurrection I curse.inferno.name=Inferno curse.inferno.tagline=Fire III +curse.siphon.name=Siphoning +curse.siphon.tagline=Energy III + item.spellbook.name=Spellbook item.bag_of_holding.name=Bag of Holding