Added speed upgrades to Living Armour
This commit is contained in:
parent
81edc58769
commit
f0331b4d4d
|
@ -2,6 +2,7 @@ package WayofTime.bloodmagic.livingArmour;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
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, StatTracker> trackerMap = new HashMap<String, StatTracker>();
|
||||||
public HashMap<String, LivingArmourUpgrade> upgradeMap = new HashMap<String, LivingArmourUpgrade>();
|
public HashMap<String, LivingArmourUpgrade> upgradeMap = new HashMap<String, LivingArmourUpgrade>();
|
||||||
|
|
||||||
|
public int maxUpgradePoints = 100;
|
||||||
|
public int totalUpgradePoints = 0;
|
||||||
|
|
||||||
public Multimap<String, AttributeModifier> getAttributeModifiers()
|
public Multimap<String, AttributeModifier> getAttributeModifiers()
|
||||||
{
|
{
|
||||||
HashMultimap<String, AttributeModifier> modifierMap = HashMultimap.<String, AttributeModifier>create();
|
HashMultimap<String, AttributeModifier> modifierMap = HashMultimap.<String, AttributeModifier>create();
|
||||||
|
@ -28,12 +32,54 @@ public class LivingArmour
|
||||||
for (Entry<String, LivingArmourUpgrade> entry : upgradeMap.entrySet())
|
for (Entry<String, LivingArmourUpgrade> entry : upgradeMap.entrySet())
|
||||||
{
|
{
|
||||||
LivingArmourUpgrade upgrade = entry.getValue();
|
LivingArmourUpgrade upgrade = entry.getValue();
|
||||||
|
if (upgrade == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
modifierMap.putAll(upgrade.getAttributeModifiers());
|
modifierMap.putAll(upgrade.getAttributeModifiers());
|
||||||
}
|
}
|
||||||
|
|
||||||
return modifierMap;
|
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
|
* Ticks the upgrades and stat trackers, passing in the world and player as
|
||||||
* well as the LivingArmour
|
* well as the LivingArmour
|
||||||
|
@ -64,8 +110,15 @@ public class LivingArmour
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tracker.onTick(world, player, this); // TODO: Check if the upgrades
|
if (tracker.onTick(world, player, this))
|
||||||
// need to be updated.
|
{
|
||||||
|
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");
|
String key = upgradeTag.getString("key");
|
||||||
int level = upgradeTag.getInteger("level");
|
int level = upgradeTag.getInteger("level");
|
||||||
NBTTagCompound nbtTag = upgradeTag.getCompoundTag("upgrade");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
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;
|
totalMovement += distanceTravelled;
|
||||||
|
|
||||||
|
@ -69,9 +69,15 @@ public class StatTrackerMovement extends StatTracker
|
||||||
lastPosZ.put(player, player.posZ);
|
lastPosZ.put(player, player.posZ);
|
||||||
|
|
||||||
markDirty();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +85,16 @@ public class StatTrackerMovement extends StatTracker
|
||||||
public List<LivingArmourUpgrade> getUpgrades()
|
public List<LivingArmourUpgrade> getUpgrades()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package WayofTime.bloodmagic.registry;
|
package WayofTime.bloodmagic.registry;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler;
|
import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler;
|
||||||
|
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgradeSpeed;
|
||||||
import WayofTime.bloodmagic.livingArmour.StatTrackerMovement;
|
import WayofTime.bloodmagic.livingArmour.StatTrackerMovement;
|
||||||
|
|
||||||
public class ModArmourTrackers
|
public class ModArmourTrackers
|
||||||
|
@ -8,5 +9,7 @@ public class ModArmourTrackers
|
||||||
public static void init()
|
public static void init()
|
||||||
{
|
{
|
||||||
LivingArmourHandler.registerStatTracker(StatTrackerMovement.class);
|
LivingArmourHandler.registerStatTracker(StatTrackerMovement.class);
|
||||||
|
|
||||||
|
LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeSpeed(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue