2016-01-01 18:59:56 +00:00
|
|
|
package WayofTime.bloodmagic.ritual;
|
|
|
|
|
2016-04-11 19:36:27 +00:00
|
|
|
import java.util.ArrayList;
|
2016-11-07 02:49:48 +00:00
|
|
|
import java.util.Collections;
|
2016-04-11 19:36:27 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-01-01 18:59:56 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-24 18:11:05 +00:00
|
|
|
import net.minecraft.init.MobEffects;
|
2016-01-01 18:59:56 +00:00
|
|
|
import net.minecraft.potion.PotionEffect;
|
2016-03-17 20:00:44 +00:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-01-01 18:59:56 +00:00
|
|
|
import net.minecraft.world.World;
|
2016-11-07 02:49:48 +00:00
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
2016-04-11 19:36:27 +00:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
2016-09-07 23:44:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.saving.SoulNetwork;
|
2016-11-07 02:49:48 +00:00
|
|
|
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
|
2016-04-11 19:36:27 +00:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-11-07 02:49:48 +00:00
|
|
|
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
|
|
|
|
import WayofTime.bloodmagic.util.Utils;
|
2016-01-01 18:59:56 +00:00
|
|
|
|
|
|
|
public class RitualRegeneration extends Ritual
|
|
|
|
{
|
|
|
|
public static final String HEAL_RANGE = "heal";
|
2016-11-07 02:49:48 +00:00
|
|
|
public static final String VAMPIRE_RANGE = "vampire";
|
2016-01-01 18:59:56 +00:00
|
|
|
|
|
|
|
public static final int SACRIFICE_AMOUNT = 100;
|
|
|
|
|
2016-11-07 02:49:48 +00:00
|
|
|
public static final double corrosiveWillDrain = 0.04;
|
|
|
|
|
2016-01-01 18:59:56 +00:00
|
|
|
public RitualRegeneration()
|
|
|
|
{
|
|
|
|
super("ritualRegeneration", 0, 25000, "ritual." + Constants.Mod.MODID + ".regenerationRitual");
|
|
|
|
addBlockRange(HEAL_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-15, -15, -15), 31));
|
2016-11-07 02:49:48 +00:00
|
|
|
addBlockRange(VAMPIRE_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-15, -15, -15), 31));
|
|
|
|
|
2016-04-11 19:36:27 +00:00
|
|
|
setMaximumVolumeAndDistanceOfRange(HEAL_RANGE, 0, 20, 20);
|
2016-11-07 02:49:48 +00:00
|
|
|
setMaximumVolumeAndDistanceOfRange(VAMPIRE_RANGE, 0, 20, 20);
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void performRitual(IMasterRitualStone masterRitualStone)
|
|
|
|
{
|
2016-01-03 13:30:59 +00:00
|
|
|
World world = masterRitualStone.getWorldObj();
|
2016-01-01 18:59:56 +00:00
|
|
|
SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner());
|
|
|
|
int currentEssence = network.getCurrentEssence();
|
|
|
|
|
|
|
|
if (currentEssence < getRefreshCost())
|
|
|
|
{
|
2016-06-12 20:41:02 +00:00
|
|
|
network.causeNausea();
|
2016-01-01 18:59:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-03 13:30:59 +00:00
|
|
|
BlockPos pos = masterRitualStone.getBlockPos();
|
2016-01-01 18:59:56 +00:00
|
|
|
|
|
|
|
int maxEffects = currentEssence / getRefreshCost();
|
|
|
|
int totalEffects = 0;
|
|
|
|
|
2016-09-07 23:44:28 +00:00
|
|
|
int totalCost = 0;
|
|
|
|
|
2016-11-07 02:49:48 +00:00
|
|
|
List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
|
|
|
|
|
|
|
|
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<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, healRange);
|
|
|
|
List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, healRange);
|
|
|
|
List<EntityLivingBase> damagedEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, damageRange);
|
2016-01-01 18:59:56 +00:00
|
|
|
|
2016-11-07 02:49:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-01 18:59:56 +00:00
|
|
|
|
2016-09-07 23:40:12 +00:00
|
|
|
for (EntityLivingBase entity : entities)
|
2016-01-01 18:59:56 +00:00
|
|
|
{
|
2016-09-07 23:40:12 +00:00
|
|
|
float health = entity.getHealth();
|
|
|
|
if (health <= entity.getMaxHealth() - 1)
|
2016-01-01 18:59:56 +00:00
|
|
|
{
|
2016-09-07 23:44:28 +00:00
|
|
|
if (entity.isPotionApplicable(new PotionEffect(MobEffects.REGENERATION)))
|
2016-01-01 18:59:56 +00:00
|
|
|
{
|
2016-09-07 23:44:28 +00:00
|
|
|
if (entity instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
totalCost += getRefreshCost();
|
2016-11-07 02:49:48 +00:00
|
|
|
currentEssence -= getRefreshCost();
|
2016-09-07 23:44:28 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
totalCost += getRefreshCost() / 10;
|
2016-11-07 02:49:48 +00:00
|
|
|
currentEssence -= getRefreshCost() / 10;
|
2016-09-07 23:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entity.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 50, 0, false, false));
|
|
|
|
|
|
|
|
totalEffects++;
|
|
|
|
|
|
|
|
if (totalEffects >= maxEffects)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-07 02:49:48 +00:00
|
|
|
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);
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 23:44:28 +00:00
|
|
|
network.syphon(totalCost);
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshTime()
|
|
|
|
{
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshCost()
|
|
|
|
{
|
2016-01-02 22:15:33 +00:00
|
|
|
return 200;
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<RitualComponent> getComponents()
|
|
|
|
{
|
|
|
|
ArrayList<RitualComponent> components = new ArrayList<RitualComponent>();
|
|
|
|
|
|
|
|
components.add(new RitualComponent(new BlockPos(4, 0, 0), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(5, 0, -1), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(5, 0, 1), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(-4, 0, 0), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(-5, 0, -1), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(-5, 0, 1), EnumRuneType.AIR));
|
|
|
|
components.add(new RitualComponent(new BlockPos(0, 0, 4), EnumRuneType.FIRE));
|
|
|
|
components.add(new RitualComponent(new BlockPos(1, 0, 5), EnumRuneType.FIRE));
|
|
|
|
components.add(new RitualComponent(new BlockPos(-1, 0, 5), EnumRuneType.FIRE));
|
|
|
|
components.add(new RitualComponent(new BlockPos(0, 0, -4), EnumRuneType.FIRE));
|
|
|
|
components.add(new RitualComponent(new BlockPos(1, 0, -5), EnumRuneType.FIRE));
|
|
|
|
components.add(new RitualComponent(new BlockPos(-1, 0, -5), EnumRuneType.FIRE));
|
|
|
|
this.addOffsetRunes(components, 3, 5, 0, EnumRuneType.WATER);
|
|
|
|
this.addCornerRunes(components, 3, 0, EnumRuneType.DUSK);
|
|
|
|
this.addOffsetRunes(components, 4, 5, 0, EnumRuneType.EARTH);
|
|
|
|
this.addOffsetRunes(components, 4, 5, -1, EnumRuneType.EARTH);
|
|
|
|
this.addCornerRunes(components, 5, 0, EnumRuneType.EARTH);
|
|
|
|
|
|
|
|
return components;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Ritual getNewCopy()
|
|
|
|
{
|
|
|
|
return new RitualRegeneration();
|
|
|
|
}
|
2016-11-07 02:49:48 +00:00
|
|
|
|
|
|
|
public float getSyphonAmountForWill(double corrosiveWill)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-01 18:59:56 +00:00
|
|
|
}
|