Added a new targetting system
This commit is contained in:
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.82
|
version: 0.84
|
||||||
commands:
|
commands:
|
||||||
marena:
|
marena:
|
||||||
description: Base command for MobArena
|
description: Base command for MobArena
|
||||||
|
|||||||
@@ -76,5 +76,8 @@ public class MAMonsterListener extends EntityListener
|
|||||||
|
|
||||||
if (event.getReason() == TargetReason.FORGOT_TARGET)
|
if (event.getReason() == TargetReason.FORGOT_TARGET)
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (event.getReason() == TargetReason.TARGET_DIED)
|
||||||
|
event.setTarget(MASpawnThread.getClosestPlayer(event.getEntity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.entity.Slime;
|
import org.bukkit.entity.Slime;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Creature;
|
import org.bukkit.entity.Creature;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.CreatureType;
|
import org.bukkit.entity.CreatureType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -29,14 +31,13 @@ public class MASpawnThread implements Runnable
|
|||||||
private int dZombies, dSkeletons, dSpiders, dCreepers;
|
private int dZombies, dSkeletons, dSpiders, dCreepers;
|
||||||
private Random random;
|
private Random random;
|
||||||
private Player target;
|
private Player target;
|
||||||
private Object[] playerArray;
|
|
||||||
private String reward, currentRewards;
|
private String reward, currentRewards;
|
||||||
|
// TO-DO: Move this into MAUtils
|
||||||
|
private static List<Player> playerList;
|
||||||
|
|
||||||
public MASpawnThread()
|
public MASpawnThread()
|
||||||
{
|
{
|
||||||
// Turn the set into an array for lookup with random numbers.
|
noOfPlayers = ArenaManager.playerSet.size();
|
||||||
playerArray = ArenaManager.playerSet.toArray();
|
|
||||||
noOfPlayers = playerArray.length;
|
|
||||||
noOfSpawnPoints = ArenaManager.spawnpoints.size();
|
noOfSpawnPoints = ArenaManager.spawnpoints.size();
|
||||||
wave = 1;
|
wave = 1;
|
||||||
random = new Random();
|
random = new Random();
|
||||||
@@ -50,13 +51,16 @@ public class MASpawnThread implements Runnable
|
|||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
// Make a new ArrayList with all the players for fast lookup
|
||||||
|
playerList = new ArrayList<Player>(ArenaManager.playerSet);
|
||||||
|
|
||||||
// Check if we need to grant more rewards with the recurrent waves.
|
// Check if we need to grant more rewards with the recurrent waves.
|
||||||
for (Integer i : ArenaManager.everyWaveMap.keySet())
|
for (Integer i : ArenaManager.everyWaveMap.keySet())
|
||||||
{
|
{
|
||||||
if (wave % i != 0)
|
if (wave % i != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (Player p : ArenaManager.playerSet)
|
for (Player p : playerList)
|
||||||
{
|
{
|
||||||
currentRewards = ArenaManager.rewardMap.get(p);
|
currentRewards = ArenaManager.rewardMap.get(p);
|
||||||
reward = MAUtils.getRandomReward(ArenaManager.everyWaveMap.get(i));
|
reward = MAUtils.getRandomReward(ArenaManager.everyWaveMap.get(i));
|
||||||
@@ -69,7 +73,7 @@ public class MASpawnThread implements Runnable
|
|||||||
// Same deal, this time with the one-time waves.
|
// Same deal, this time with the one-time waves.
|
||||||
if (ArenaManager.afterWaveMap.containsKey(wave))
|
if (ArenaManager.afterWaveMap.containsKey(wave))
|
||||||
{
|
{
|
||||||
for (Player p : ArenaManager.playerSet)
|
for (Player p : playerList)
|
||||||
{
|
{
|
||||||
currentRewards = ArenaManager.rewardMap.get(p);
|
currentRewards = ArenaManager.rewardMap.get(p);
|
||||||
reward = MAUtils.getRandomReward(ArenaManager.afterWaveMap.get(wave));
|
reward = MAUtils.getRandomReward(ArenaManager.afterWaveMap.get(wave));
|
||||||
@@ -124,11 +128,8 @@ public class MASpawnThread implements Runnable
|
|||||||
ArenaManager.monsterSet.add(e);
|
ArenaManager.monsterSet.add(e);
|
||||||
|
|
||||||
// Grab a random target.
|
// Grab a random target.
|
||||||
// TO-DO: Find a different solution to this.
|
Creature c = (Creature) e;
|
||||||
//ran = random.nextInt(noOfPlayers);
|
c.setTarget(getClosestPlayer(e));
|
||||||
//Creature c = (Creature) e;
|
|
||||||
//c.setTarget(MAUtils.getRandomPlayer());
|
|
||||||
//c.setTarget((Player)playerArray[ran]); // This is faster, but unstable
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +180,7 @@ public class MASpawnThread implements Runnable
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spawn the hippie monsters.
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
loc = ArenaManager.spawnpoints.get(i % noOfSpawnPoints);
|
loc = ArenaManager.spawnpoints.get(i % noOfSpawnPoints);
|
||||||
@@ -190,20 +192,63 @@ public class MASpawnThread implements Runnable
|
|||||||
if (wolf) ((Wolf)e).setAngry(true);
|
if (wolf) ((Wolf)e).setAngry(true);
|
||||||
|
|
||||||
// Slimes can't have targets, apparently.
|
// Slimes can't have targets, apparently.
|
||||||
//if (!(e instanceof Creature))
|
if (!(e instanceof Creature))
|
||||||
// continue;
|
continue;
|
||||||
|
|
||||||
// Grab a random target.
|
// Grab a random target.
|
||||||
//ran = random.nextInt(noOfPlayers);
|
Creature c = (Creature) e;
|
||||||
//Creature c = (Creature) e;
|
c.setTarget(getClosestPlayer(e));
|
||||||
//c.setTarget(MAUtils.getRandomPlayer());
|
|
||||||
//c.setTarget((Player)playerArray[ran]); // This is faster, but unstable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lightning, just for effect ;)
|
// Lightning, just for effect ;)
|
||||||
for (Location l : ArenaManager.spawnpoints)
|
for (Location spawn : ArenaManager.spawnpoints)
|
||||||
{
|
{
|
||||||
ArenaManager.world.strikeLightningEffect(l);
|
ArenaManager.world.strikeLightningEffect(spawn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player closest to the input entity. ArrayList implementation
|
||||||
|
* means a complexity of O(n).
|
||||||
|
*/
|
||||||
|
// TO-DO: Move this into MAUtils
|
||||||
|
public static Player getClosestPlayer(Entity e)
|
||||||
|
{
|
||||||
|
// Grab the coordinates.
|
||||||
|
double ex = e.getLocation().getX();
|
||||||
|
double ey = e.getLocation().getY();
|
||||||
|
double ez = e.getLocation().getZ();
|
||||||
|
|
||||||
|
// Set up the comparison variable and the result.
|
||||||
|
double current = Double.POSITIVE_INFINITY;
|
||||||
|
Player result = null;
|
||||||
|
|
||||||
|
/* Iterate through the ArrayList, and update current and result every
|
||||||
|
* time a squared distance smaller than current is found. */
|
||||||
|
for (int i = 0; i < playerList.size(); i++)
|
||||||
|
{
|
||||||
|
Player p = playerList.get(i);
|
||||||
|
double dist = distance(p.getLocation(), ex, ey, ez);
|
||||||
|
|
||||||
|
if (dist < current || current == -1.0D)
|
||||||
|
{
|
||||||
|
current = dist;
|
||||||
|
result = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the squared distance between locations.
|
||||||
|
*/
|
||||||
|
// TO-DO: Move this into MAUtils
|
||||||
|
private static double distance(Location loc, double d1, double d2, double d3)
|
||||||
|
{
|
||||||
|
double d4 = loc.getX() - d1;
|
||||||
|
double d5 = loc.getY() - d2;
|
||||||
|
double d6 = loc.getZ() - d3;
|
||||||
|
|
||||||
|
return d4*d4 + d5*d5 + d6*d6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user