use of WayofTime.alchemicalWizardry.common.omega.OmegaParadigm 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);
}
}
}
}
use of WayofTime.alchemicalWizardry.common.omega.OmegaParadigm in project BloodMagic by WayofTime.
the class RitualEffectOmegaStalling method performEffect.
@Override
public void performEffect(IMasterRitualStone ritualStone) {
String owner = ritualStone.getOwner();
int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
World world = ritualStone.getWorld();
int x = ritualStone.getXCoord();
int y = ritualStone.getYCoord();
int z = ritualStone.getZCoord();
if (world.getWorldTime() % 20 != 0) {
return;
}
TileEntity tile = world.getTileEntity(x, y + 5, z);
if (tile instanceof TileEntityBeacon) {
int levels = ((TileEntityBeacon) tile).getLevels();
if (levels >= 4) {
int horizontalRadius = 100;
int verticalRadius = 100;
List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, horizontalRadius, verticalRadius);
for (EntityPlayer player : playerList) {
if (SoulNetworkHandler.canSyphonFromOnlyNetwork(owner, getCostPerRefresh())) {
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
OmegaParadigm parad = OmegaRegistry.getParadigmForReagent(reagent);
if (parad != null) {
float costOffset = parad.getCostPerTickOfUse(player);
parad.setOmegaStalling(player, 100);
SoulNetworkHandler.syphonFromNetwork(owner, (int) (getCostPerRefresh() * Math.min(costOffset, 1)));
}
}
}
}
}
}
use of WayofTime.alchemicalWizardry.common.omega.OmegaParadigm in project BloodMagic by WayofTime.
the class RitualEffectOmegaTest method performEffect.
@Override
public void performEffect(IMasterRitualStone ritualStone) {
String owner = ritualStone.getOwner();
int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
World world = ritualStone.getWorld();
int x = ritualStone.getXCoord();
int y = ritualStone.getYCoord();
int z = ritualStone.getZCoord();
if (world.getWorldTime() % 200 != 0) {
return;
}
OmegaStructureParameters param = OmegaStructureHandler.getStructureStabilityFactor(world, x, y, z, 5, new Int3(0, 1, 0));
int stab = param.stability;
int enchantability = param.enchantability;
int enchantmentLevel = param.enchantmentLevel;
if (stab <= 0) {
return;
}
// System.out.println("Stability: " + stab + ", Enchantability: " + enchantability + ", Enchantment Level: " + enchantmentLevel);
double range = 0.5;
List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 1.5, z + 0.5, range, range);
Reagent reagent = null;
Map<Reagent, Integer> reagentMap = new HashMap();
for (int i = 0; i < 4; i++) {
Int3 jarLoc = this.getJarLocation(i);
TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
if (tile instanceof IReagentHandler) {
IReagentHandler container = (IReagentHandler) tile;
ReagentContainerInfo[] containerInfoArray = container.getContainerInfo(ForgeDirection.UP);
if (containerInfoArray == null) {
continue;
}
for (ReagentContainerInfo containerInfo : containerInfoArray) {
ReagentStack containedReagent = containerInfo.reagent;
if (containedReagent == null) {
continue;
}
Reagent rea = containedReagent.reagent;
int amt = containedReagent.amount;
if (reagentMap.containsKey(rea)) {
reagentMap.put(rea, reagentMap.get(rea) + amt);
} else {
reagentMap.put(rea, amt);
}
}
}
}
for (Entry<Reagent, Integer> entry : reagentMap.entrySet()) {
if (entry.getValue() >= drainTotal) {
reagent = entry.getKey();
break;
}
}
if (reagent == null) {
return;
}
int tickDuration = isTesting ? 20 * 30 : 15 * 20 * 60 + (int) ((15 * 20 * 60) * Math.sqrt(stab / 700));
int affinity = 0;
for (EntityPlayer player : playerList) {
OmegaParadigm waterParadigm = OmegaRegistry.getParadigmForReagent(reagent);
if (waterParadigm != null && waterParadigm.convertPlayerArmour(player, x, y, z, stab, affinity, enchantability, enchantmentLevel)) {
APISpellHelper.setPlayerCurrentReagentAmount(player, tickDuration);
APISpellHelper.setPlayerMaxReagentAmount(player, tickDuration);
APISpellHelper.setPlayerReagentType(player, reagent);
APISpellHelper.setCurrentAdditionalMaxHP(player, waterParadigm.getMaxAdditionalHealth());
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getReagentBarPacket(reagent, APISpellHelper.getPlayerCurrentReagentAmount(player), APISpellHelper.getPlayerMaxReagentAmount(player)), (EntityPlayerMP) player);
if (!isTesting) {
int drainLeft = this.drainTotal;
for (int i = 0; i < 4; i++) {
if (drainLeft <= 0) {
break;
}
Int3 jarLoc = this.getJarLocation(i);
TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
if (tile instanceof IReagentHandler) {
IReagentHandler container = (IReagentHandler) tile;
ReagentStack drained = container.drain(ForgeDirection.UP, new ReagentStack(reagent, drainLeft), true);
if (drained != null) {
drainLeft -= drained.amount;
world.markBlockForUpdate(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
world.addWeatherEffect(new EntityLightningBolt(world, x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord));
}
}
}
ritualStone.setActive(false);
}
break;
}
}
}
use of WayofTime.alchemicalWizardry.common.omega.OmegaParadigm in project BloodMagic by WayofTime.
the class AlchemicalWizardryEventHooks method onLivingHurtEvent.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onLivingHurtEvent(LivingHurtEvent event) {
if (!event.isCanceled() && event.entityLiving instanceof EntityPlayer && !event.entityLiving.worldObj.isRemote) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
if (APISpellHelper.getCurrentAdditionalMaxHP(player) > 0) {
APISpellHelper.setPlayerReagentRegenCooldownTag(player, 20 * 20);
}
float prevHp = APISpellHelper.getCurrentAdditionalHP((EntityPlayer) event.entityLiving);
if (prevHp > 0) {
float recalculatedAmount = ArmorProperties.ApplyArmor(player, player.inventory.armorInventory, event.source, event.ammount);
if (recalculatedAmount <= 0)
return;
// Recalculated damage
recalculatedAmount = SpellHelper.applyPotionDamageCalculations(player, event.source, recalculatedAmount);
float ratio = recalculatedAmount / event.ammount;
float f1 = recalculatedAmount;
recalculatedAmount = Math.max(recalculatedAmount - player.getAbsorptionAmount(), 0.0F);
player.setAbsorptionAmount(player.getAbsorptionAmount() - (f1 - recalculatedAmount));
if (prevHp > recalculatedAmount) {
// New HP - this is obviously > 0...
float hp = (prevHp - recalculatedAmount);
// event.setCanceled(true);
event.ammount = 0;
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
OmegaParadigm paradigm = OmegaRegistry.getParadigmForReagent(reagent);
if (paradigm != null) {
ItemStack chestStack = player.inventory.armorInventory[2];
if (chestStack != null && chestStack.getItem() instanceof OmegaArmour) {
if (((OmegaArmour) chestStack.getItem()).paradigm == paradigm) {
paradigm.onHPBarDepleted(player, chestStack);
}
}
}
APISpellHelper.setCurrentAdditionalHP(player, hp);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(hp, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP) player);
// if(event.ammount <= 0.3)
// {
// event.ammount++;
// }
} else {
APISpellHelper.setCurrentAdditionalHP(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(0, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP) player);
event.ammount -= prevHp / ratio;
if (event.ammount < 0) {
event.ammount = 0;
}
}
}
}
}
use of WayofTime.alchemicalWizardry.common.omega.OmegaParadigm in project BloodMagic by WayofTime.
the class AlchemicalWizardryEventHooks method onEntityInteractEvent.
@SubscribeEvent
public void onEntityInteractEvent(EntityInteractEvent event) {
EntityPlayer player = event.entityPlayer;
OmegaParadigm parad = OmegaRegistry.getOmegaParadigmOfWeilder(player);
if (parad == null) {
return;
}
ItemStack heldItem = player.getHeldItem();
if (heldItem == null) {
parad.onEmptyHandEntityInteract(player, event.target);
} else {
if (heldItem.getItem() instanceof EnergySword) {
parad.onBoundSwordInteractWithEntity(player, event.target);
}
}
}
Aggregations