Added speed upgrades to Living Armour

This commit is contained in:
WayofTime 2016-01-03 14:12:55 -05:00
parent 81edc58769
commit f0331b4d4d
4 changed files with 144 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.livingArmour;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.entity.ai.attributes.AttributeModifier;
@ -21,6 +22,9 @@ public class LivingArmour
public HashMap<String, StatTracker> trackerMap = new HashMap<String, StatTracker>();
public HashMap<String, LivingArmourUpgrade> upgradeMap = new HashMap<String, LivingArmourUpgrade>();
public int maxUpgradePoints = 100;
public int totalUpgradePoints = 0;
public Multimap<String, AttributeModifier> getAttributeModifiers()
{
HashMultimap<String, AttributeModifier> modifierMap = HashMultimap.<String, AttributeModifier>create();
@ -28,12 +32,54 @@ public class LivingArmour
for (Entry<String, LivingArmourUpgrade> entry : upgradeMap.entrySet())
{
LivingArmourUpgrade upgrade = entry.getValue();
if (upgrade == null)
{
continue;
}
modifierMap.putAll(upgrade.getAttributeModifiers());
}
return modifierMap;
}
public boolean upgradeArmour(EntityPlayer user, LivingArmourUpgrade upgrade)
{
String key = upgrade.getUniqueIdentifier();
if (upgradeMap.containsKey(key))
{
//Check if this is a higher level than the previous upgrade
int nextLevel = upgrade.getUpgradeLevel();
int currentLevel = upgradeMap.get(key).getUpgradeLevel();
if (nextLevel > currentLevel)
{
int upgradePointDifference = upgrade.getCostOfUpgrade() - upgradeMap.get(key).getCostOfUpgrade();
if (upgradePointDifference >= 0 && totalUpgradePoints + upgradePointDifference <= maxUpgradePoints)
{
upgradeMap.put(key, upgrade);
notifyPlayerOfUpgrade(user, upgrade);
return true;
}
}
} else
{
int upgradePoints = upgrade.getCostOfUpgrade();
if (totalUpgradePoints + upgradePoints <= maxUpgradePoints)
{
upgradeMap.put(key, upgrade);
notifyPlayerOfUpgrade(user, upgrade);
return true;
}
}
return false;
}
public void notifyPlayerOfUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade)
{
System.out.println("Upgraded!");
}
/**
* Ticks the upgrades and stat trackers, passing in the world and player as
* well as the LivingArmour
@ -64,8 +110,15 @@ public class LivingArmour
continue;
}
tracker.onTick(world, player, this); // TODO: Check if the upgrades
// need to be updated.
if (tracker.onTick(world, player, this))
{
List<LivingArmourUpgrade> upgradeList = tracker.getUpgrades();
for (LivingArmourUpgrade upgrade : upgradeList) //TODO: make a getNextUpgrade?
{
upgradeArmour(player, upgrade);
}
}
}
}
@ -80,7 +133,12 @@ public class LivingArmour
String key = upgradeTag.getString("key");
int level = upgradeTag.getInteger("level");
NBTTagCompound nbtTag = upgradeTag.getCompoundTag("upgrade");
LivingArmourHandler.generateUpgradeFromKey(key, level, nbtTag);
LivingArmourUpgrade upgrade = LivingArmourHandler.generateUpgradeFromKey(key, level, nbtTag);
if (upgrade != null)
{
upgradeMap.put(key, upgrade);
totalUpgradePoints += upgrade.getCostOfUpgrade();
}
}
}

View file

@ -0,0 +1,61 @@
package WayofTime.bloodmagic.livingArmour;
import java.util.UUID;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.nbt.NBTTagCompound;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
public class LivingArmourUpgradeSpeed extends LivingArmourUpgrade
{
public LivingArmourUpgradeSpeed(int level)
{
super(level);
}
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers()
{
Multimap<String, AttributeModifier> modifierMap = HashMultimap.<String, AttributeModifier>create();
// Adds 10% per level
modifierMap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(new UUID(895132, 1), "Speed modifier" + 1, (this.level + 1) * 0.1, 1));
return modifierMap;
}
@Override
public String getUniqueIdentifier()
{
return Constants.Mod.MODID + ".upgrade.movement";
}
@Override
public int getMaxTier()
{
return 5;
}
@Override
public int getCostOfUpgrade()
{
return this.level + 1;
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
// EMPTY
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
// EMPTY
}
}

View file

@ -61,7 +61,7 @@ public class StatTrackerMovement extends StatTracker
double distanceTravelled = Math.sqrt(Math.pow(lastPosX.get(player) - player.posX, 2) + Math.pow(lastPosZ.get(player) - player.posZ, 2));
if (distanceTravelled > 0.0001)
if (distanceTravelled > 0.0001 && distanceTravelled < 2)
{
totalMovement += distanceTravelled;
@ -69,9 +69,15 @@ public class StatTrackerMovement extends StatTracker
lastPosZ.put(player, player.posZ);
markDirty();
if (world.getWorldTime() % 20 == 0)
{
System.out.println("Total movement since activated: " + totalMovement);
}
return true;
}
// System.out.println("Total movement since activated: " + totalMovement);
return false;
}
@ -79,6 +85,16 @@ public class StatTrackerMovement extends StatTracker
public List<LivingArmourUpgrade> getUpgrades()
{
// TODO Auto-generated method stub
return new ArrayList<LivingArmourUpgrade>();
List<LivingArmourUpgrade> upgradeList = new ArrayList<LivingArmourUpgrade>();
for (int i = 0; i < 5; i++)
{
if (totalMovement > (i + 1) * (i + 1) * (i + 1) * 100)
{
upgradeList.add(new LivingArmourUpgradeSpeed(i));
}
}
return upgradeList;
}
}

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler;
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgradeSpeed;
import WayofTime.bloodmagic.livingArmour.StatTrackerMovement;
public class ModArmourTrackers
@ -8,5 +9,7 @@ public class ModArmourTrackers
public static void init()
{
LivingArmourHandler.registerStatTracker(StatTrackerMovement.class);
LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeSpeed(1));
}
}