use of WayofTime.alchemicalWizardry.common.omega.ReagentRegenConfiguration in project BloodMagic by WayofTime.
the class AlchemicalWizardryEventHooks method omegaUpdateReagentAndHpEvent.
@SubscribeEvent
public void omegaUpdateReagentAndHpEvent(LivingUpdateEvent event) {
if (event.entityLiving instanceof EntityPlayer && !event.entityLiving.worldObj.isRemote) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
float reagentAmount = APISpellHelper.getPlayerCurrentReagentAmount(player);
boolean hasReagentChanged = false;
if (reagentAmount > 0 && OmegaRegistry.hasParadigm(reagent)) {
int cooldown = APISpellHelper.getPlayerReagentRegenCooldownTag(player);
boolean canHealHPBar = true;
if (cooldown > 0) {
float extra = 0;
if (player.isPotionActive(AlchemicalWizardry.customPotionSoulHarden)) {
extra += 0.25f * (1 + player.getActivePotionEffect(AlchemicalWizardry.customPotionSoulHarden).getAmplifier());
}
if (player.isPotionActive(AlchemicalWizardry.customPotionSoulFray)) {
extra -= 0.25f * (1 + player.getActivePotionEffect(AlchemicalWizardry.customPotionSoulFray).getAmplifier());
}
int deduction = -1 - (extra >= 0 ? (rand.nextFloat() < extra ? 1 : 0) : (rand.nextFloat() < -extra / 2 ? -1 : 0));
APISpellHelper.setPlayerReagentRegenCooldownTag(player, Math.max(cooldown + deduction, 0));
canHealHPBar = false;
}
OmegaParadigm parad = OmegaRegistry.getParadigmForReagent(reagent);
ReagentRegenConfiguration config = parad.getRegenConfig(player);
if (parad.isPlayerWearingFullSet(player)) {
if (canHealHPBar) {
int tickRate = config.tickRate;
if (player.isPotionActive(Potion.regeneration)) {
int i = player.getActivePotionEffect(Potion.regeneration).getAmplifier();
double factor = Math.pow(1.5, i + 1);
tickRate = Math.max((int) (tickRate / factor), 1);
}
if (event.entityLiving.worldObj.getWorldTime() % tickRate == 0) {
boolean hasHealthChanged = false;
int maxHealth = parad.getMaxAdditionalHealth();
float health = APISpellHelper.getCurrentAdditionalHP(player);
if (health > maxHealth) {
health = maxHealth;
hasHealthChanged = true;
} else if (health < maxHealth) {
float addedAmount = Math.min(Math.min((reagentAmount / config.costPerPoint), config.healPerTick), maxHealth - health);
float drain = addedAmount * config.costPerPoint;
reagentAmount -= drain;
hasReagentChanged = true;
health += addedAmount;
hasHealthChanged = true;
}
if (player instanceof EntityPlayerMP) {
if (hasHealthChanged) {
APISpellHelper.setCurrentAdditionalHP(player, health);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(health, maxHealth), (EntityPlayerMP) player);
}
}
}
}
} else {
reagentAmount = 0;
APISpellHelper.setPlayerMaxReagentAmount(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getReagentBarPacket(null, 0, 0), (EntityPlayerMP) player);
APISpellHelper.setCurrentAdditionalHP(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(0, 0), (EntityPlayerMP) player);
}
// Consumes the amount
float costPerTick = parad.getCostPerTickOfUse(player);
if (parad.doDrainReagent(player)) {
if (reagentAmount > costPerTick) {
hasReagentChanged = true;
reagentAmount = Math.max(0, reagentAmount - costPerTick);
} else {
hasReagentChanged = true;
reagentAmount = 0;
}
}
hasReagentChanged = true;
}
if (reagentAmount <= 0) {
boolean hasRevertedArmour = false;
ItemStack[] armourInventory = player.inventory.armorInventory;
for (ItemStack stack : armourInventory) {
if (stack != null && stack.getItem() instanceof OmegaArmour) {
((OmegaArmour) stack.getItem()).revertArmour(player, stack);
hasRevertedArmour = true;
}
}
if (hasRevertedArmour) {
APISpellHelper.setCurrentAdditionalHP(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(0, 0), (EntityPlayerMP) player);
}
}
if (player instanceof EntityPlayerMP) {
if (hasReagentChanged) {
APISpellHelper.setPlayerCurrentReagentAmount(player, reagentAmount);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getReagentBarPacket(reagent, reagentAmount, APISpellHelper.getPlayerMaxReagentAmount(player)), (EntityPlayerMP) player);
}
}
}
}
Aggregations