BloodMagic/src/main/java/WayofTime/bloodmagic/ritual/RitualRegeneration.java
Nicholas Ignoffo f99b21cffc Rewrite LP network data saving system
Instead of creating a new file for each player with their UUID as the name, we create a single file and store it all in a List. That List gets converted to a UUID -> SoulNetwork map when read from the file.

MigrateNetworkDataHandler is used to migrate players from the old system to the new one. It reads both data files and sets the LP of the new network to the LP of the old network (if the old network is larger). Once conversion is done, we delete the old file so that it doesn't happen again and overwrite player progress.

This is an API breaking change due to an import change.
2016-06-12 13:41:02 -07:00

120 lines
4.3 KiB
Java

package WayofTime.bloodmagic.ritual;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
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.Constants;
import WayofTime.bloodmagic.api.saving.SoulNetwork;
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;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
public class RitualRegeneration extends Ritual
{
public static final String HEAL_RANGE = "heal";
public static final int SACRIFICE_AMOUNT = 100;
public RitualRegeneration()
{
super("ritualRegeneration", 0, 25000, "ritual." + Constants.Mod.MODID + ".regenerationRitual");
addBlockRange(HEAL_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-15, -15, -15), 31));
setMaximumVolumeAndDistanceOfRange(HEAL_RANGE, 0, 20, 20);
}
@Override
public void performRitual(IMasterRitualStone masterRitualStone)
{
World world = masterRitualStone.getWorldObj();
SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner());
int currentEssence = network.getCurrentEssence();
if (currentEssence < getRefreshCost())
{
network.causeNausea();
return;
}
BlockPos pos = masterRitualStone.getBlockPos();
int maxEffects = currentEssence / getRefreshCost();
int totalEffects = 0;
AreaDescriptor damageRange = getBlockRange(HEAL_RANGE);
AxisAlignedBB range = damageRange.getAABB(pos);
List<EntityPlayer> entities = world.getEntitiesWithinAABB(EntityPlayer.class, range);
for (EntityLivingBase player : entities)
{
float health = player.getHealth();
if (health <= player.getMaxHealth() - 1)
{
player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 50, 0, false, false));
totalEffects++;
if (totalEffects >= maxEffects)
{
break;
}
}
}
network.syphon(getRefreshCost() * totalEffects);
}
@Override
public int getRefreshTime()
{
return 50;
}
@Override
public int getRefreshCost()
{
return 200;
}
@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();
}
}