BloodMagic/src/main/java/WayofTime/bloodmagic/livingArmour/tracker/StatTrackerMeleeDamage.java
Nicholas Ignoffo ddaadfbe52 Swap the API packages
The new one is now built for the api jar and the old one is now internal.
It will slowly be moved around to sane places within the internal code. Most
of the features provided in the old "api" are addon specific features which
will generally rely on the main jar anyways. The new API will be specific
to compatibility features, such as blacklists, recipes, and value modification.
2018-02-05 17:04:46 -08:00

104 lines
3.4 KiB
Java

package WayofTime.bloodmagic.livingArmour.tracker;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.apibutnotreally.livingArmour.StatTracker;
import WayofTime.bloodmagic.livingArmour.LivingArmour;
import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeMeleeDamage;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class StatTrackerMeleeDamage extends StatTracker {
public static HashMap<LivingArmour, Double> changeMap = new HashMap<LivingArmour, Double>();
public static int[] damageRequired = new int[]{200, 800, 1300, 2500, 3800, 5000, 7000, 9200, 11500, 140000};
public double totalDamageDealt = 0;
@Override
public String getUniqueIdentifier() {
return BloodMagic.MODID + ".tracker.meleeDamage";
}
@Override
public void resetTracker() {
this.totalDamageDealt = 0;
}
@Override
public void readFromNBT(NBTTagCompound tag) {
totalDamageDealt = tag.getDouble(BloodMagic.MODID + ".tracker.meleeDamage");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
tag.setDouble(BloodMagic.MODID + ".tracker.meleeDamage", totalDamageDealt);
}
@Override
public boolean onTick(World world, EntityPlayer player, LivingArmour livingArmour) {
if (changeMap.containsKey(livingArmour)) {
double change = Math.abs(changeMap.get(livingArmour));
if (change > 0) {
totalDamageDealt += Math.abs(changeMap.get(livingArmour));
changeMap.put(livingArmour, 0d);
this.markDirty();
return true;
}
}
return false;
}
@Override
public void onDeactivatedTick(World world, EntityPlayer player, LivingArmour livingArmour) {
if (changeMap.containsKey(livingArmour)) {
changeMap.remove(livingArmour);
}
}
@Override
public List<LivingArmourUpgrade> getUpgrades() {
List<LivingArmourUpgrade> upgradeList = new ArrayList<LivingArmourUpgrade>();
for (int i = 0; i < 10; i++) {
if (totalDamageDealt >= damageRequired[i]) {
upgradeList.add(new LivingArmourUpgradeMeleeDamage(i));
}
}
return upgradeList;
}
@Override
public double getProgress(LivingArmour livingArmour, int currentLevel) {
return Utils.calculateStandardProgress(totalDamageDealt, damageRequired, currentLevel);
}
@Override
public boolean providesUpgrade(String key) {
return key.equals(BloodMagic.MODID + ".upgrade.meleeDamage");
}
@Override
public void onArmourUpgradeAdded(LivingArmourUpgrade upgrade) {
if (upgrade instanceof LivingArmourUpgradeMeleeDamage) {
int level = upgrade.getUpgradeLevel();
if (level < damageRequired.length) {
totalDamageDealt = Math.max(totalDamageDealt, damageRequired[level]);
this.markDirty();
}
}
}
public static void incrementCounter(LivingArmour armour, double damage) {
changeMap.put(armour, changeMap.containsKey(armour) ? changeMap.get(armour) + damage : damage);
}
}