Improved resource spawning per planet

This commit is contained in:
Obique PSWG
2017-06-02 15:39:59 -05:00
parent 4c30fa6379
commit 47eec5f9ac
5 changed files with 924 additions and 863 deletions

View File

@@ -4,8 +4,15 @@ import services.galaxy.GalacticManager
import com.projectswg.common.debug.Log
import services.crafting.resource.galactic.storage.GalacticResourceContainer
import intents.crafting.survey.StartSurveyingIntent
import intents.chat.ChatBroadcastIntent
static def execute(GalacticManager galacticManager, Player player, SWGObject target, String args) {
def resource = GalacticResourceContainer.getContainer().getGalacticResourceByName(args)
if (player.getCreatureObject().hasAbility("admin")) {
def spawns = GalacticResourceContainer.getContainer().getTerrainResourceSpawns(resource, player.getCreatureObject().getTerrain());
for (int i = 0; i < spawns.size(); i++) {
new ChatBroadcastIntent(player, "Spawn: " + spawns.get(i)).broadcast()
}
}
new StartSurveyingIntent(player.getCreatureObject(), resource).broadcast()
}

File diff suppressed because it is too large Load Diff

View File

@@ -381,12 +381,6 @@ public enum RadialItem {
return text;
}
public boolean isCase(RadialItem item) {
if (item == null)
return false;
return item == this;
}
/**
* Gets the RadialItem from the selection id. If the item is undefined,
* then NULL is returned

View File

@@ -40,7 +40,12 @@ import resources.server_info.DataManager;
public class GalacticResourceSpawn implements Persistable {
private static final int MAP_SIZE = 16384;
private static final int MAP_SIZE = 16384;
private static final int MUST_MAP_SIZE = 8000;
private static final int KASH_MAP_SIZE = 8192;
private static final double POSITION_GAUSSIAN_FACTOR = MAP_SIZE / 2 * Math.sqrt(2);
private static final double POSITION_MUST_GAUSSIAN_FACTOR = MUST_MAP_SIZE / 2 * Math.sqrt(2);
private static final double POSITION_KASH_GAUSSIAN_FACTOR = KASH_MAP_SIZE / 2 * Math.sqrt(2);
// Resource-based
private long resourceId;
@@ -66,13 +71,12 @@ public class GalacticResourceSpawn implements Persistable {
public void setRandomValues(Terrain terrain) {
Random random = new Random();
this.minConcentration = random.nextInt(100);
this.maxConcentration = random.nextInt(100 - minConcentration) + minConcentration;
this.minConcentration = random.nextInt(50);
this.maxConcentration = calculateRandomMaxConcentration(random, minConcentration);
this.terrain = terrain;
this.x = random.nextInt(MAP_SIZE) - MAP_SIZE/2;
this.z = random.nextInt(MAP_SIZE) - MAP_SIZE/2;
this.radius = (int) (random.nextDouble() * (getMaxRadius() - getMinRadius()) + getMinRadius());
setPosition(random, terrain);
this.radius = calculateRandomRadius(random);
int minSpawnTime = getMinSpawnTime();
int maxSpawnTime = getMaxSpawnTime();
@@ -120,7 +124,9 @@ public class GalacticResourceSpawn implements Persistable {
double distance = getDistance(terrain, x, z);
if (distance > radius)
return 0;
return (int) ((1 - distance / radius) * (maxConcentration - minConcentration) + minConcentration);
double factor = (1 - distance / radius);
factor = factor * factor; // creates a more serious dropoff of concentration
return (int) (factor * (maxConcentration - minConcentration) + minConcentration);
}
public boolean isExpired() {
@@ -143,6 +149,42 @@ public class GalacticResourceSpawn implements Persistable {
return DataManager.getConfig(ConfigFile.FEATURES).getInt("RESOURCES-MAX-SPAWN-RADIUS", 500);
}
private int calculateRandomMaxConcentration(Random random, int min) {
double x;
do {
x = random.nextDouble();
x = x * x * 100;
} while (x <= min);
return (int) x;
}
private void setPosition(Random random, Terrain terrain) {
double angle = random.nextDouble() * 6.283185307;
double distance = Math.max(-1, Math.min(1, random.nextGaussian() / 6 + 0.5));
if (terrain == Terrain.MUSTAFAR)
distance *= POSITION_MUST_GAUSSIAN_FACTOR;
else if (terrain == Terrain.KASHYYYK_MAIN)
distance *= POSITION_KASH_GAUSSIAN_FACTOR;
else
distance *= POSITION_GAUSSIAN_FACTOR;
this.x = capPosition((int) (Math.cos(angle) * distance));
this.z = capPosition((int) (Math.sin(angle) * distance));
if (terrain == Terrain.MUSTAFAR) {
x += -2880;
z += 2976;
}
}
private int calculateRandomRadius(Random random) {
double x = random.nextDouble();
x = Math.sqrt(x);
return (int) (x * (getMaxRadius() - getMinRadius()) + getMinRadius());
}
private int capPosition(int x) {
return Math.max(-MAP_SIZE/2, Math.min(MAP_SIZE/2, x));
}
@Override
public void save(NetBufferStream stream) {
stream.addByte(0);

View File

@@ -34,10 +34,14 @@ import java.util.stream.Collectors;
import com.projectswg.common.data.location.Terrain;
import com.projectswg.common.debug.Log;
import com.projectswg.common.debug.Log.LogLevel;
import com.projectswg.common.debug.log_wrapper.ConsoleLogWrapper;
import resources.server_info.DataManager;
import resources.server_info.StandardLog;
import services.crafting.resource.galactic.storage.GalacticResourceContainer;
import services.crafting.resource.raw.RawResource;
import services.crafting.resource.raw.RawResourceContainer;
public class GalacticResourceSpawner {
@@ -50,9 +54,9 @@ public class GalacticResourceSpawner {
private static final Terrain [] BASE_PLANETS = new Terrain[] {
Terrain.CORELLIA, Terrain.DANTOOINE, Terrain.DATHOMIR,
Terrain.ENDOR, Terrain.KASHYYYK_MAIN, Terrain.LOK,
Terrain.NABOO, Terrain.RORI, Terrain.TALUS,
Terrain.TATOOINE, Terrain.YAVIN4
Terrain.ENDOR, Terrain.LOK, Terrain.NABOO,
Terrain.RORI, Terrain.TALUS, Terrain.TATOOINE,
Terrain.YAVIN4
};
private final Random random;
@@ -63,6 +67,20 @@ public class GalacticResourceSpawner {
this.resourceIdMax = new AtomicLong(0);
}
public static void main(String [] args) {
Log.addWrapper(new ConsoleLogWrapper(LogLevel.VERBOSE));
DataManager.initialize();
RawResourceContainer container = new RawResourceContainer();
container.loadResources();
for (RawResource rawResource : container.getResources()) {
GalacticResourceContainer.getContainer().addRawResource(rawResource);
}
GalacticResourceSpawner spawner = new GalacticResourceSpawner();
spawner.initialize();
spawner.terminate();
DataManager.terminate();
}
public void initialize() {
loadOldResources();
updateAllResources();