Skip to content

Commit

Permalink
Merge pull request #298 from madsboddum/296
Browse files Browse the repository at this point in the history
Dynamic spawn eggs spawn way less frequently above or below ground #296
  • Loading branch information
Josh-Larson committed Jan 3, 2021
2 parents 94a44b6 + 1b81420 commit a7c58e0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ application {

repositories {
jcenter()
maven("https://jitpack.io") // Automatically creates a JVM library based on a git repository
}

sourceSets {
Expand All @@ -34,6 +35,7 @@ sourceSets {
implementation(group="me.joshlarson", name="fast-json", version="3.0.0")
implementation(group="me.joshlarson", name="jlcommon-network", version="1.0.0")
implementation(group="commons-cli", name="commons-cli", version="1.4")
implementation(group="com.github.madsboddum", name="swgterrain", version="1.1.2")
}
}
test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject;
import com.projectswg.holocore.resources.support.objects.swg.custom.AIBehavior;
import com.projectswg.holocore.resources.support.objects.swg.custom.AIObject;
import com.projectswg.holocore.utilities.TerrainUtils;
import dk.madsboddum.swgterrain.api.TerrainEngine;
import me.joshlarson.jlcommon.control.IntentHandler;
import me.joshlarson.jlcommon.control.Service;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -170,10 +172,13 @@ private void spawnNewNpcs(CreatureObject player, Location location) {
double randomOffsetZ = random.nextDouble(-MAX_SPAWN_DISTANCE_TO_PLAYER, MAX_SPAWN_DISTANCE_TO_PLAYER);
double eggX = location.getX() + randomOffsetX;
double eggZ = location.getZ() + randomOffsetZ;
double eggY = getEggY(terrain, eggX, eggZ);

Location eggLocation = Location.builder(location)
.setX(eggX)
.setZ(eggZ)
.build(); // TODO y parameter should be set and calculated based on X and Z in relevant terrain. Currently they'll spawn in the air or below ground.
.setY(eggY)
.build();
int randomSpawnInfoIndex = random.nextInt(0, spawnInfos.size());
DynamicSpawnLoader.DynamicSpawnInfo spawnInfo = new ArrayList<>(spawnInfos).get(randomSpawnInfoIndex);

Expand Down Expand Up @@ -218,4 +223,10 @@ private String randomNpc(String npcString) {
return npcIds[randomIdx];
}

private double getEggY(Terrain terrain, double eggX, double eggZ) {
TerrainEngine terrainEngine = TerrainUtils.getEngine(terrain);

return terrainEngine.getHeight(eggX, eggZ);
}

}
44 changes: 44 additions & 0 deletions src/main/java/com/projectswg/holocore/utilities/TerrainUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***********************************************************************************
* Copyright (c) 2020 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.utilities;

import com.projectswg.common.data.location.Terrain;
import dk.madsboddum.swgterrain.api.TerrainEngine;
import dk.madsboddum.swgterrain.api.TerrainEngineFactory;

import java.io.File;

public class TerrainUtils {

public static TerrainEngine getEngine(Terrain terrain) {
TerrainEngineFactory factory = new TerrainEngineFactory();
File trnFile = new File("clientdata/" + terrain.getFile());

return factory.create(trnFile);
}

}
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
requires commons.cli;
requires kotlin.stdlib;
requires kotlinx.coroutines.core;

requires swgterrain;
}

0 comments on commit a7c58e0

Please sign in to comment.