From 6dedb234fb41ef9d124d29037ad8aba6171470f8 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Wed, 6 Jan 2016 19:34:10 -0500 Subject: [PATCH] Added Physical Protection upgrade. Reorganized some of the upgrades. --- changelog.txt | 6 ++ .../item/armour/ItemLivingArmour.java | 13 ++- .../LivingArmourUpgradePhysicalProtect.java | 63 ++++++++++++++ .../LivingArmourUpgradeSelfSacrifice.java | 7 +- .../StatTrackerPhysicalProtect.java | 87 +++++++++++++++++++ .../StatTrackerSelfSacrifice.java | 7 +- .../bloodmagic/util/handler/EventHandler.java | 16 +++- .../assets/bloodmagic/lang/en_US.lang | 1 + 8 files changed, 187 insertions(+), 13 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradePhysicalProtect.java create mode 100644 src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerPhysicalProtect.java diff --git a/changelog.txt b/changelog.txt index 8fad296e..af2ffa43 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +------------------------------------------------------ +Version 2.0.0-4 +------------------------------------------------------ +- Added Physical resistance upgrade. + + ------------------------------------------------------ Version 2.0.0-3 ------------------------------------------------------ diff --git a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java index 007d8743..10e58657 100644 --- a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java @@ -49,13 +49,13 @@ public class ItemLivingArmour extends ItemArmor implements ISpecialArmor if (this == ModItems.livingArmourBoots || this == ModItems.livingArmourHelmet) { - damageAmount = 3f / 25f; + damageAmount = 3d / 20d * 0.6; } else if (this == ModItems.livingArmourLegs) { - damageAmount = 6f / 25f; + damageAmount = 6d / 20d * 0.6; } else if (this == ModItems.livingArmourChest) { - damageAmount = 0.52; + damageAmount = 0.64; } double armourPenetrationReduction = 0; @@ -74,7 +74,7 @@ public class ItemLivingArmour extends ItemArmor implements ISpecialArmor if (this == ModItems.livingArmourChest) { - armourReduction = 0.32 / 0.52; // This values puts it at about iron level + armourReduction = 0.24 / 0.64; // This values puts it at iron level ItemStack helmet = player.getEquipmentInSlot(4); ItemStack leggings = player.getEquipmentInSlot(2); @@ -100,6 +100,11 @@ public class ItemLivingArmour extends ItemArmor implements ISpecialArmor { LivingArmourUpgrade upgrade = entry.getValue(); remainder *= (1 - upgrade.getArmourProtection(source)); + /* + * Just as a side note, if one upgrade provides + * upgrade.getArmourProtection(source) = 0.5, the + * armour would have a diamond level protection + */ } } } diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradePhysicalProtect.java b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradePhysicalProtect.java new file mode 100644 index 00000000..fb9a4abc --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradePhysicalProtect.java @@ -0,0 +1,63 @@ +package WayofTime.bloodmagic.livingArmour; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; + +public class LivingArmourUpgradePhysicalProtect extends LivingArmourUpgrade +{ + public static final int[] costs = new int[] { 5, 10, 18, 35, 65, 100, 160, 220, 280, 350 }; + public static final double[] protectionLevel = new double[] { 0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.75, 0.8, 0.85, 0.9 }; + + public LivingArmourUpgradePhysicalProtect(int level) + { + super(level); + } + + public double getArmourProtection(DamageSource source) + { + if (source.getEntity() != null) + { + return protectionLevel[this.level]; + } + + return 0; + } + + @Override + public String getUniqueIdentifier() + { + return Constants.Mod.MODID + ".upgrade.physicalProtect"; + } + + @Override + public int getMaxTier() + { + return 10; // Set to here until I can add more upgrades to it. + } + + @Override + public int getCostOfUpgrade() + { + return costs[this.level]; + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + // EMPTY + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + // EMPTY + } + + @Override + public String getUnlocalizedName() + { + return tooltipBase + "physicalProtect"; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradeSelfSacrifice.java b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradeSelfSacrifice.java index 137632d8..9436eb8a 100644 --- a/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradeSelfSacrifice.java +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmourUpgradeSelfSacrifice.java @@ -6,8 +6,9 @@ import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; public class LivingArmourUpgradeSelfSacrifice extends LivingArmourUpgrade { - public static final int[] costs = new int[] { 10, 25, 50, 80, 120 }; - public static final double[] sacrificeModifier = new double[] { 0.2, 0.4, 0.6, 0.8, 1.0 }; + //TODO: Add extra effects for higher levels + public static final int[] costs = new int[] { 7, 13, 22, 40, 65, 90, 130, 180, 250, 350 }; + public static final double[] sacrificeModifier = new double[] { 0.15, 0.3, 0.45, 0.6, 0.75, 0.9, 1.05, 1.2, 1.35, 1.5 }; public LivingArmourUpgradeSelfSacrifice(int level) { @@ -28,7 +29,7 @@ public class LivingArmourUpgradeSelfSacrifice extends LivingArmourUpgrade @Override public int getMaxTier() { - return 5; // Set to here until I can add more upgrades to it. + return 10; // Set to here until I can add more upgrades to it. } @Override diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerPhysicalProtect.java b/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerPhysicalProtect.java new file mode 100644 index 00000000..20ff18ec --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerPhysicalProtect.java @@ -0,0 +1,87 @@ +package WayofTime.bloodmagic.livingArmour; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; +import WayofTime.bloodmagic.api.livingArmour.StatTracker; + +public class StatTrackerPhysicalProtect extends StatTracker +{ + public int totalDamage = 0; + + public static HashMap changeMap = new HashMap(); + public static int[] damageRequired = new int[] { 30, 200, 400, 800, 1500, 2500, 3500, 5000, 6000 }; + + public static void incrementCounter(LivingArmour armour, double damage) + { + changeMap.put(armour, changeMap.containsKey(armour) ? changeMap.get(armour) + damage : damage); + } + + @Override + public String getUniqueIdentifier() + { + return Constants.Mod.MODID + ".tracker.physicalProtect"; + } + + @Override + public void resetTracker() + { + this.totalDamage = 0; + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + totalDamage = tag.getInteger(Constants.Mod.MODID + ".tracker.physicalProtect"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + tag.setInteger(Constants.Mod.MODID + ".tracker.physicalProtect", totalDamage); + } + + @Override + public boolean onTick(World world, EntityPlayer player, LivingArmour livingArmour) + { + if (changeMap.containsKey(livingArmour)) + { + double change = Math.abs(changeMap.get(livingArmour)); + if (change > 0) + { + totalDamage += Math.abs(changeMap.get(livingArmour)); + + changeMap.put(livingArmour, 0d); + + this.markDirty(); + + return true; + } + } + + return false; + } + + @Override + public List getUpgrades() + { + // TODO Auto-generated method stub + List upgradeList = new ArrayList(); + + for (int i = 0; i < 1; i++) + { + if (totalDamage >= damageRequired[i]) + { + upgradeList.add(new LivingArmourUpgradePhysicalProtect(i)); + } + } + + return upgradeList; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerSelfSacrifice.java b/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerSelfSacrifice.java index f17aadd0..d60f8e57 100644 --- a/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerSelfSacrifice.java +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/StatTrackerSelfSacrifice.java @@ -14,7 +14,7 @@ import WayofTime.bloodmagic.api.livingArmour.StatTracker; public class StatTrackerSelfSacrifice extends StatTracker { public static HashMap changeMap = new HashMap(); - public static int[] sacrificesRequired = new int[] { 50, 200, 400, 600, 800 }; //testing + public static int[] sacrificesRequired = new int[] { 30, 200, 400, 700, 1100, 1500, 2000, 2800, 3600, 5000 }; //testing public int totalSacrifices = 0; @@ -72,12 +72,11 @@ public class StatTrackerSelfSacrifice extends StatTracker @Override public List getUpgrades() { - // TODO Auto-generated method stub List upgradeList = new ArrayList(); - for (int i = 0; i < 5; i++) + for (int i = 0; i < 10; i++) { - if (totalSacrifices > sacrificesRequired[i]) + if (totalSacrifices >= sacrificesRequired[i]) { upgradeList.add(new LivingArmourUpgradeSelfSacrifice(i)); } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java index b87c4526..48d2cc96 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.FillBucketEvent; @@ -30,6 +31,7 @@ import WayofTime.bloodmagic.livingArmour.LivingArmour; import WayofTime.bloodmagic.livingArmour.LivingArmourUpgradeDigging; import WayofTime.bloodmagic.livingArmour.LivingArmourUpgradeSelfSacrifice; import WayofTime.bloodmagic.livingArmour.StatTrackerDigging; +import WayofTime.bloodmagic.livingArmour.StatTrackerPhysicalProtect; import WayofTime.bloodmagic.livingArmour.StatTrackerSelfSacrifice; import WayofTime.bloodmagic.registry.ModBlocks; import WayofTime.bloodmagic.registry.ModItems; @@ -174,6 +176,7 @@ public class EventHandler @SubscribeEvent public void onEntityAttacked(LivingAttackEvent event) { + DamageSource source = event.source; Entity sourceEntity = event.source.getEntity(); EntityLivingBase attackedEntity = event.entityLiving; @@ -182,7 +185,7 @@ public class EventHandler return; } - if (sourceEntity != null && attackedEntity instanceof EntityPlayer) + if (attackedEntity instanceof EntityPlayer) { EntityPlayer attackedPlayer = (EntityPlayer) attackedEntity; @@ -202,7 +205,16 @@ public class EventHandler if (hasFullSet) { System.out.println(amount); - + ItemStack chestStack = attackedPlayer.getCurrentArmor(2); + LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack); + if (armour != null) + { + if (sourceEntity != null && !source.isMagicDamage()) + { + // Add resistance to the upgrade that protects against non-magic damage + StatTrackerPhysicalProtect.incrementCounter(armour, amount); + } + } } } } diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index 6ca5761e..33c7d51f 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -223,6 +223,7 @@ tooltip.BloodMagic.livingArmour.upgrade.digging=Dwarven Might tooltip.BloodMagic.livingArmour.upgrade.poisonResist=Poison Resistance tooltip.BloodMagic.livingArmour.upgrade.selfSacrifice=Tough Palms tooltip.BloodMagic.livingArmour.upgrade.knockback=Body Builder +tooltip.BloodMagic.livingArmour.upgrade.physicalProtect=Tough Skin tooltip.BloodMagic.livingArmour.upgrade.level=(Level %d) # Ritual