Introduced health-multiplier and amount-multiplier

This commit is contained in:
Garbage Mule 2011-09-13 23:31:55 +02:00
parent 3147bdfda0
commit 35647bd14c
9 changed files with 95 additions and 15 deletions

Binary file not shown.

View File

@ -1028,14 +1028,32 @@ public class MAUtils
return false;
}
public static int getInt(Configuration config, String path)
public static double getDouble(Configuration config, String path)
{
return getDouble(config, path, 0D);
}
public static double getDouble(Configuration config, String path, double def)
{
Object o = config.getProperty(path);
if (o instanceof Double)
return (Double) o;
else if (o instanceof Number)
return (Integer) o;
return def;
}
public static int getInt(Configuration config, String path)
{
return getInt(config, path, 0);
}
public static int getInt(Configuration config, String path, int def)
{
Object o = config.getProperty(path);
if (o instanceof Integer)
return (Integer) o;
return 0;
return def;
}

View File

@ -137,14 +137,12 @@ public class WaveUtils
if (type == null || !isWaveWellDefined(config, path, branch, type))
return null;
//
Wave result = null;
if (branch == WaveBranch.RECURRENT)
{
int frequency = config.getInt(path + "frequency", 0);
int priority = config.getInt(path + "priority", 0);
int wave = MAUtils.getInt(config, path + "wave");
//int wave = config.getInt(path + "wave", frequency);
if (type == WaveType.DEFAULT)
result = new DefaultWave(arena, name, wave, frequency, priority, config, path);
@ -158,7 +156,6 @@ public class WaveUtils
else
{
int wave = MAUtils.getInt(config, path + "wave");
//int wave = config.getInt(path + "wave", 0);
if (type == WaveType.DEFAULT)
result = new DefaultWave(arena, name, wave, config, path);
@ -199,6 +196,23 @@ public class WaveUtils
// This boolean is used in the "leaf methods"
boolean wellDefined = true;
// OPTIONAL: Health multiplier
int hMulti = MAUtils.getInt(config, path + "health-multiplier");
if (hMulti < 0)
{
MobArena.warning("Invalid health multiplier '" + hMulti + "' in " + path);
wellDefined = false;
}
// OPTIONAL: Amount multiplier
int aMulti = MAUtils.getInt(config, path + "amount-multiplier");
if (aMulti < 0)
{
MobArena.warning("Invalid amount multiplier '" + aMulti + "' in " + path);
wellDefined = false;
}
// Branch-specific nodes.
if (branch == WaveBranch.RECURRENT)
{
// REQUIRED: Priority and frequency
@ -214,9 +228,9 @@ public class WaveUtils
MobArena.warning("Missing 'frequency'-node in " + path);
wellDefined = false;
}
// OPTIONAL: Wave
int wave = MAUtils.getInt(config, path + "wave");
//int wave = config.getInt(path + "wave", frequency);
if (wave < 0)
{
MobArena.warning("'wave' must be greater than 0 in " + path);
@ -227,7 +241,6 @@ public class WaveUtils
{
// REQUIRED: Wave number
int wave = MAUtils.getInt(config, path + "wave");
//int wave = config.getInt(path + "wave", 0);
if (wave == 0)
{
MobArena.warning("Missing 'wave'-node in " + path);

View File

@ -18,6 +18,7 @@ public abstract class AbstractWave implements Wave
private World world;
private String waveName;
private int wave, frequency, priority;
private double healthMultiplier, amountMultiplier;
private WaveBranch branch;
private WaveType type;
private WaveGrowth growth;
@ -86,6 +87,10 @@ public abstract class AbstractWave implements Wave
// Spawn and add to collection
LivingEntity e = creature.spawn(getArena(), getWorld(), loc);
getArena().addMonster(e);
// Boost health
if (getHealthMultiplier() > 1)
e.setHealth((int) Math.min(150D, e.getHealth() * getHealthMultiplier()));
// Grab a random target.
if (e instanceof Creature)
@ -114,7 +119,8 @@ public abstract class AbstractWave implements Wave
{
for (int i = 0; i < entry.getValue(); i++)
{
spawnMonster(entry.getKey(), spawnpoints.get(index % spawnpointCount));
LivingEntity e = spawnMonster(entry.getKey(), spawnpoints.get(index % spawnpointCount));
e.setHealth((int) Math.min(150D, e.getHealth() * healthMultiplier));
index++;
}
}
@ -161,6 +167,16 @@ public abstract class AbstractWave implements Wave
return priority;
}
public double getHealthMultiplier()
{
return healthMultiplier;
}
public double getAmountMultiplier()
{
return amountMultiplier;
}
public String getName()
{
return waveName;
@ -182,6 +198,16 @@ public abstract class AbstractWave implements Wave
this.growth = growth;
}
public void setHealthMultiplier(double value)
{
healthMultiplier = Math.max(0.1D, value);
}
public void setAmountMultiplier(double value)
{
amountMultiplier = Math.max(0.1D, value);
}
// MISC
public String toString()
{

View File

@ -43,19 +43,20 @@ public class DefaultWave extends NormalWave
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena(), getArena().getLivingPlayers());
// Initialize the total amount of mobs to spawn
int totalToSpawn = getGrowth().getAmount(wave, getArena().getPlayerCount());
int totalToSpawn = (int) (getGrowth().getAmount(wave, getArena().getPlayerCount()) * getAmountMultiplier());
// Spawn all the monsters
spawnAll(getMonstersToSpawn(totalToSpawn), validSpawnpoints);
}
private Map<MACreature,Integer> getMonstersToSpawn(int totalToSpawn)
{
{
Map<MACreature,Integer> result = new HashMap<MACreature,Integer>();
Random random = new Random();
int randomNumber;
MACreature creature;
if (totalToSpawn < 1) totalToSpawn = 1;
for (int i = 0; i < totalToSpawn; i++)
{
randomNumber = random.nextInt(getTotalProbability());

View File

@ -7,6 +7,7 @@ import java.util.TreeMap;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.util.WaveUtils;
public abstract class NormalWave extends AbstractWave
@ -75,6 +76,10 @@ public abstract class NormalWave extends AbstractWave
totalProbability = 50;
}
}
// Load multipliers
setHealthMultiplier(MAUtils.getDouble(config, path + "health-multiplier", 1D));
setAmountMultiplier(MAUtils.getDouble(config, path + "amount-multiplier", 1D));
}
public int getTotalProbability()

View File

@ -68,7 +68,7 @@ public class SpecialWave extends NormalWave
default: amount = playerCount + 1; break;
}
result.put(entry.getValue(), amount);
result.put(entry.getValue(), (int) (amount * getAmountMultiplier()));
break;
}

View File

@ -40,6 +40,10 @@ public class SwarmWave extends AbstractWave
// And the amount
amount = WaveUtils.getEnumFromString(SwarmAmount.class, config.getString(path + "amount"), SwarmAmount.LOW);
// Load multipliers
setHealthMultiplier(MAUtils.getDouble(config, path + "health-multiplier", 1D));
setAmountMultiplier(MAUtils.getDouble(config, path + "amount-multiplier", 1D));
}
public void spawn(int wave)
@ -51,7 +55,8 @@ public class SwarmWave extends AbstractWave
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena(), getArena().getLivingPlayers());
// Spawn the hellians!
spawnAll(monster, amount.getAmount(getArena().getPlayerCount()), validSpawnpoints);
int toSpawn = (int) (amount.getAmount(getArena().getPlayerCount()) * getAmountMultiplier());
spawnAll(monster, toSpawn, validSpawnpoints);
}
public void spawnAll(MACreature monster, int amount, List<Location> spawnpoints)

View File

@ -133,6 +133,18 @@ public interface Wave
*/
public int getPriority();
/**
* Get the wave's health multiplier.
* @return The health multiplier
*/
public double getHealthMultiplier();
/**
* Get the wave's amount multiplier.
* @return The amount multiplier
*/
public double getAmountMultiplier();
/**
* Get the wave's name.
* @return The name