From 97907367a1531d333d47996785254ac66fe4799a Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sun, 6 Nov 2016 21:49:48 -0500 Subject: [PATCH] Made a ritual augment that makes the Ritual of Regeneration steal health from mobs to heal the player. Also tinkered with having the ritual give absorption hearts (at a slow rate) --- .../bloodmagic/ritual/RitualRegeneration.java | 92 ++++++++++++++++++- .../java/WayofTime/bloodmagic/util/Utils.java | 22 +++++ .../assets/bloodmagic/lang/en_US.lang | 6 ++ 3 files changed, 117 insertions(+), 3 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualRegeneration.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualRegeneration.java index f9c7c769..95f13cfb 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/RitualRegeneration.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualRegeneration.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.ritual; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import net.minecraft.entity.EntityLivingBase; @@ -10,6 +11,7 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.ritual.AreaDescriptor; import WayofTime.bloodmagic.api.ritual.EnumRuneType; @@ -17,19 +19,28 @@ import WayofTime.bloodmagic.api.ritual.IMasterRitualStone; import WayofTime.bloodmagic.api.ritual.Ritual; import WayofTime.bloodmagic.api.ritual.RitualComponent; import WayofTime.bloodmagic.api.saving.SoulNetwork; +import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; +import WayofTime.bloodmagic.util.Utils; public class RitualRegeneration extends Ritual { public static final String HEAL_RANGE = "heal"; + public static final String VAMPIRE_RANGE = "vampire"; public static final int SACRIFICE_AMOUNT = 100; + public static final double corrosiveWillDrain = 0.04; + public RitualRegeneration() { super("ritualRegeneration", 0, 25000, "ritual." + Constants.Mod.MODID + ".regenerationRitual"); addBlockRange(HEAL_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-15, -15, -15), 31)); + addBlockRange(VAMPIRE_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-15, -15, -15), 31)); + setMaximumVolumeAndDistanceOfRange(HEAL_RANGE, 0, 20, 20); + setMaximumVolumeAndDistanceOfRange(VAMPIRE_RANGE, 0, 20, 20); } @Override @@ -52,10 +63,66 @@ public class RitualRegeneration extends Ritual int totalCost = 0; - AreaDescriptor damageRange = getBlockRange(HEAL_RANGE); - AxisAlignedBB range = damageRange.getAABB(pos); + List willConfig = masterRitualStone.getActiveWillConfig(); - List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, range); + double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig); + double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig); + double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig); + double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig); + double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig); + + double vengefulDrain = 0; + double steadfastDrain = 0; + double destructiveDrain = 0; + double corrosiveDrain = 0; + + boolean syphonHealth = corrosiveWill >= corrosiveWillDrain; + boolean applyAbsorption = true; + float absorptionRate = 1; + int maxAbsorption = 20; + + AreaDescriptor healArea = getBlockRange(HEAL_RANGE); + AxisAlignedBB healRange = healArea.getAABB(pos); + + AreaDescriptor damageArea = getBlockRange(VAMPIRE_RANGE); + AxisAlignedBB damageRange = damageArea.getAABB(pos); + + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, healRange); + List players = world.getEntitiesWithinAABB(EntityPlayer.class, healRange); + List damagedEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, damageRange); + + if (syphonHealth) + { + for (EntityPlayer player : players) + { + if (player.getHealth() <= player.getMaxHealth() - 1) + { + float syphonedHealthAmount = getSyphonAmountForWill(corrosiveWill); + Collections.shuffle(damagedEntities); + for (EntityLivingBase damagedEntity : damagedEntities) + { + if (damagedEntity instanceof EntityPlayer) + { + continue; + } + + float currentHealth = damagedEntity.getHealth(); + + damagedEntity.attackEntityFrom(BloodMagicAPI.getDamageSource(), Math.min(player.getMaxHealth() - player.getHealth(), syphonedHealthAmount)); + + float healthDifference = currentHealth - damagedEntity.getHealth(); + if (healthDifference > 0) + { + corrosiveDrain += corrosiveWillDrain; + corrosiveWill -= corrosiveWillDrain; + player.heal(healthDifference); + } + + break; + } + } + } + } for (EntityLivingBase entity : entities) { @@ -67,9 +134,11 @@ public class RitualRegeneration extends Ritual if (entity instanceof EntityPlayer) { totalCost += getRefreshCost(); + currentEssence -= getRefreshCost(); } else { totalCost += getRefreshCost() / 10; + currentEssence -= getRefreshCost() / 10; } entity.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 50, 0, false, false)); @@ -82,6 +151,18 @@ public class RitualRegeneration extends Ritual } } } + if (applyAbsorption && entity instanceof EntityPlayer) + { + if (applyAbsorption) + { + float added = Utils.addAbsorptionToMaximum(entity, absorptionRate, maxAbsorption, 1000); + } + } + } + + if (corrosiveDrain > 0) + { + WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveDrain, true); } network.syphon(totalCost); @@ -130,4 +211,9 @@ public class RitualRegeneration extends Ritual { return new RitualRegeneration(); } + + public float getSyphonAmountForWill(double corrosiveWill) + { + return 1; + } } diff --git a/src/main/java/WayofTime/bloodmagic/util/Utils.java b/src/main/java/WayofTime/bloodmagic/util/Utils.java index 4cf9471b..cfae8ee0 100644 --- a/src/main/java/WayofTime/bloodmagic/util/Utils.java +++ b/src/main/java/WayofTime/bloodmagic/util/Utils.java @@ -29,6 +29,7 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumFacing; @@ -67,6 +68,27 @@ import com.google.common.collect.Iterables; public class Utils { + public static float addAbsorptionToMaximum(EntityLivingBase entity, float added, int maximum, int duration) + { + float currentAmount = entity.getAbsorptionAmount(); + added = Math.min(maximum - currentAmount, added); + + if (added <= 0) + { + return 0; + } + + if (duration > 0) + { + int potionLevel = (int) ((currentAmount + added) / 4); + entity.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, duration, potionLevel, true, false)); + } + + entity.setAbsorptionAmount(currentAmount + added); + + return added; + } + public static Item getItem(ResourceLocation resource) { return Item.REGISTRY.getObject(resource); diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index 500ec54f..5cde52e1 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -620,6 +620,11 @@ ritual.BloodMagic.jumpRitual.info=Causes entities to leap up into the air. ritual.BloodMagic.wellOfSufferingRitual.info=Attacks mobs within its damage zone and puts the LP into a nearby blood altar. ritual.BloodMagic.featheredKnifeRitual.info=Drains health from players in its area and puts the LP into a nearby blood altar. ritual.BloodMagic.regenerationRitual.info=Casts regeneration on entities within its range if they are missing health. +ritual.BloodMagic.regenerationRitual.default.info=(Raw) +ritual.BloodMagic.regenerationRitual.corrosive.info=(Corrosive) Steals health from non-players inside of its Vampirism range and directly heals players. +ritual.BloodMagic.regenerationRitual.destructive.info=(Destructive) +ritual.BloodMagic.regenerationRitual.vengeful.info=(Vengeful) +ritual.BloodMagic.regenerationRitual.steadfast.info=(Steadfast) ritual.BloodMagic.harvestRitual.info=Harvests plants within its range, dropping the results on the ground. ritual.BloodMagic.magneticRitual.info=Pulls up ores from the ground and puts them into its placement range. ritual.BloodMagic.crushingRitual.info=Breaks blocks within its crushing range and places the items into the linked chest. @@ -681,6 +686,7 @@ ritual.BloodMagic.wellOfSufferingRitual.damage.info=(Damage) This defines where ritual.BloodMagic.featheredKnifeRitual.altar.info=(Altar) This range defines the area that the ritual searches for the blood altar. Changing this will either expand or limit the range to a certain region. ritual.BloodMagic.featheredKnifeRitual.damage.info=(Damage) This defines where the ritual will damage a player. Players inside of this range will receive damage over time up to the specified limit. ritual.BloodMagic.regenerationRitual.heal.info=(Healing) Mobs within this range will receive a regeneration buff. +ritual.BloodMagic.regenerationRitual.vampire.info=(Vampirism) Mobs within this range have their health syphoned to heal players in the Healing range. ritual.BloodMagic.harvestRitual.harvestRange.info=(Harvesting) Plants within this range will be harvested. ritual.BloodMagic.magneticRitual.placementRange.info=(Placement) The range that the ritual will place the grabbed ores into. ritual.BloodMagic.crushingRitual.crushingRange.info=(Crushing) The blocks that the ritual will break.