Added the gem of siphoning

This commit is contained in:
Sollace 2019-02-27 17:35:56 +02:00
parent d69d1fcfb7
commit 0ea59c1097
6 changed files with 171 additions and 1 deletions

View file

@ -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));
}

View file

@ -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<EntityLivingBase> 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;
}
}

View file

@ -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" }

View file

@ -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"
}
}

View file

@ -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"
}
}

View file

@ -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