Changed loiter and turning modes to use thread local random

This commit is contained in:
Obique
2018-08-29 18:02:57 -05:00
parent ab95f4355a
commit d4e75b83be
2 changed files with 16 additions and 8 deletions
@@ -31,6 +31,9 @@ import com.projectswg.common.data.location.Location.LocationBuilder;
import com.projectswg.holocore.resources.support.objects.swg.custom.AIObject;
import com.projectswg.holocore.resources.support.objects.swg.custom.NpcMode;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* AI object that loiters the area
*/
@@ -47,28 +50,29 @@ public class NpcLoiterMode extends NpcMode {
@Override
public void act() {
Random random = ThreadLocalRandom.current();
if (isRooted()) {
queueNextLoop(10000+getRandom().nextInt(5));
queueNextLoop(10000 + random.nextInt(5));
return;
}
Location currentLocation = getAI().getLocation();
if (mainLocation == null)
mainLocation = currentLocation;
if (getRandom().nextDouble() > 0.25) // Only a 25% movement chance
if (random.nextDouble() > 0.25) // Only a 25% movement chance
return;
double dist = Math.sqrt(radius);
double theta;
LocationBuilder l = Location.builder(currentLocation);
do {
theta = getRandom().nextDouble() * Math.PI * 2;
theta = random.nextDouble() * Math.PI * 2;
l.setX(currentLocation.getX() + Math.cos(theta) * dist);
l.setZ(currentLocation.getZ() + Math.sin(theta) * dist);
} while (!l.isWithinFlatDistance(mainLocation, radius));
l.setHeading(l.getYaw() - Math.toDegrees(theta));
walkTo(l.build());
queueNextLoop(30 + getRandom().nextInt(10));
queueNextLoop(30 + random.nextInt(10));
}
}
@@ -30,6 +30,9 @@ import com.projectswg.common.data.location.Location;
import com.projectswg.holocore.resources.support.objects.swg.custom.AIObject;
import com.projectswg.holocore.resources.support.objects.swg.custom.NpcMode;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* AI object that loiters the area
*/
@@ -41,17 +44,18 @@ public class NpcTurningMode extends NpcMode {
@Override
public void act() {
Random random = ThreadLocalRandom.current();
if (isRooted()) {
queueNextLoop(10000+getRandom().nextInt(5));
queueNextLoop(10000+ random.nextInt(5));
return;
}
if (getRandom().nextDouble() > 0.25) // Only a 25% movement chance
if (random.nextDouble() > 0.25) // Only a 25% movement chance
return;
double theta = getRandom().nextDouble() * 360;
double theta = random.nextDouble() * 360;
walkTo(Location.builder(getAI().getLocation()).setHeading(theta).build());
queueNextLoop(30 + getRandom().nextInt(10));
queueNextLoop(30 + random.nextInt(10));
}
}