mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-08-03 04:16:19 -04:00
Merge pull request #1055 from Obique/master
Fixed Resource and Survey Services; Changed ObjectService
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -67,7 +67,9 @@ public class ResourceListForSurveyMessage extends SWGMessage {
|
||||
if (toolName.equals("survey_tool_liquid"))
|
||||
generalType = (byte) 7;
|
||||
|
||||
Vector<GalacticResource> planetVector = core.resourceService.getSpawnedResourcesByPlanetAndType(surveyor.getPlanetId(),generalType);
|
||||
if (core.resourceService == null)
|
||||
System.out.println("heyyyy guess who's confused?!");
|
||||
List<GalacticResource> planetVector = core.resourceService.getSpawnedResourcesByPlanetAndType(surveyor.getPlanetId(),generalType);
|
||||
|
||||
resourceList = new ArrayList<GalacticResource>(planetVector);
|
||||
|
||||
|
||||
@@ -137,13 +137,21 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
private transient double minDist = 99999.0;
|
||||
|
||||
|
||||
public GalacticResource(){
|
||||
public GalacticResource() {
|
||||
super();
|
||||
createResourceName();
|
||||
}
|
||||
|
||||
public GalacticResource(long objectID, Planet planet, Point3D position, Quaternion orientation, String template){
|
||||
super(objectID, planet, position, orientation, template);
|
||||
this.id = objectID;
|
||||
createResourceName();
|
||||
}
|
||||
|
||||
private void createResourceName() {
|
||||
this.name = NAME_SYLLABLE_1[(int) new Random().nextInt(NAME_SYLLABLE_1.length-1)]
|
||||
+ NAME_SYLLABLE_2[(int) new Random().nextInt(NAME_SYLLABLE_2.length-1)]
|
||||
+ NAME_SYLLABLE_3[(int) new Random().nextInt(NAME_SYLLABLE_3.length-1)];
|
||||
}
|
||||
|
||||
public GalacticResource(long id){
|
||||
@@ -155,8 +163,8 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
init();
|
||||
}
|
||||
|
||||
public GalacticResource(String name, String fileName, String category){
|
||||
this.name = name;
|
||||
public GalacticResource(String fileName, String category){
|
||||
createResourceName();
|
||||
this.fileName = fileName;
|
||||
this.category = category;
|
||||
//this.type = type;
|
||||
@@ -177,10 +185,6 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFileName(){
|
||||
return fileName;
|
||||
}
|
||||
@@ -211,10 +215,9 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initializeNewGalaxyResource(Vector<String> completeResourceNameHistory){
|
||||
public void initializeNewGalaxyResource(){
|
||||
galacticDepositList.clear();
|
||||
|
||||
constructResourceName(completeResourceNameHistory);
|
||||
generateResourceType();
|
||||
generateResourceStats();
|
||||
generatePlanetarySpawns();
|
||||
@@ -274,17 +277,18 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
}
|
||||
|
||||
public int[] generateRandomPlanetArray(){
|
||||
int planets = 6 + new Random().nextInt(2);
|
||||
int[] outpool = new int[planets];
|
||||
int[] pool = new int[10]; // 10 Number of SWG planets
|
||||
for (int i = 0; i < 10; i++) pool[i] = i+1;
|
||||
for (int i = 0; i < planets; i++) outpool[i] = i+1;
|
||||
shuffleArray(pool);
|
||||
for (int i = 0; i < outpool.length; i++)
|
||||
{
|
||||
outpool[i]=pool[i];
|
||||
}
|
||||
return outpool;
|
||||
// int planets = 6 + new Random().nextInt(2);
|
||||
// int[] outpool = new int[planets];
|
||||
// int[] pool = new int[10]; // 10 Number of SWG planets
|
||||
// for (int i = 0; i < 10; i++) pool[i] = i+1;
|
||||
// for (int i = 0; i < planets; i++) outpool[i] = i+1;
|
||||
// shuffleArray(pool);
|
||||
// for (int i = 0; i < outpool.length; i++)
|
||||
// {
|
||||
// outpool[i]=pool[i];
|
||||
// }
|
||||
// return outpool;
|
||||
return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
}
|
||||
|
||||
public void shuffleArray(int[] ar)
|
||||
@@ -325,20 +329,36 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
|
||||
// Calculate deposit positions
|
||||
Random generator = new Random();
|
||||
int depositQuantity = 8 + generator.nextInt(24);
|
||||
int depositQuantity = 20;
|
||||
// int depositQuantity = 100;
|
||||
|
||||
// datatables/clientregion -> cities
|
||||
|
||||
for (int i = 0; i < depositQuantity; i++) {
|
||||
ResourceDeposit deposit = new ResourceDeposit();
|
||||
generator = new Random(); // Exclude mountains at the edge of the maps
|
||||
int spawnCoordsX = generator.nextInt(15000) - 7500;
|
||||
int spawnCoordsZ = generator.nextInt(15000) - 7500;
|
||||
int spawnCoordsX = 0;
|
||||
int spawnCoordsZ = 0;
|
||||
for (int k = 0; k < 10; k++) {
|
||||
spawnCoordsX = generator.nextInt(15000) - 7500;
|
||||
spawnCoordsZ = generator.nextInt(15000) - 7500;
|
||||
boolean works = true;
|
||||
for (ResourceDeposit r : depositList) {
|
||||
double dist = Math.pow(r.getSpawnCoordinatesX()-spawnCoordsX, 2);
|
||||
dist += Math.pow(r.getSpawnCoordinatesZ()-spawnCoordsZ, 2);
|
||||
dist = Math.sqrt(dist);
|
||||
if (dist < 1500) {
|
||||
works = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (works)
|
||||
break;
|
||||
}
|
||||
// check maybe for: if (!core.terrainService.isWater(player.getPlanetId(), spawnCoordsX, spawnCoordsZ)) ?
|
||||
generator = new Random();
|
||||
int spawnConcentration = 30 + generator.nextInt(70);
|
||||
generator = new Random();
|
||||
int spawnRadius = 360 + generator.nextInt(1200-360);
|
||||
// int spawnRadius = 360 + generator.nextInt(1200-360);
|
||||
int spawnRadius = 1500 + generator.nextInt(1000);
|
||||
deposit.setSpawnRadius(spawnRadius);
|
||||
deposit.setSpawnConcentration(spawnConcentration);
|
||||
//System.out.println("spawnConcentration " + spawnConcentration);
|
||||
@@ -348,7 +368,7 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
}
|
||||
return depositList;
|
||||
}
|
||||
|
||||
|
||||
public float deliverConcentrationForSurvey(int planetId, float coordsX, float coordsY) {
|
||||
float measuredOutput = 0;
|
||||
for (int i = 0; i < galacticDepositList.size(); i++) {
|
||||
@@ -359,7 +379,7 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
ResourceDeposit resourceDeposit = depositList.get(j);
|
||||
int spawnCoordsX = (int)resourceDeposit.getSpawnCoordinatesX();
|
||||
int spawnCoordsZ = (int)resourceDeposit.getSpawnCoordinatesZ();
|
||||
int spawnRadius = (int)resourceDeposit.getSpawnRadius();
|
||||
float spawnRadius = resourceDeposit.getSpawnRadius();
|
||||
float deltaX = coordsX-spawnCoordsX;
|
||||
float deltaY = coordsY-spawnCoordsZ;
|
||||
float localConcentration=0;
|
||||
@@ -368,7 +388,8 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
minDist = hypothen;
|
||||
if (hypothen<spawnRadius) {
|
||||
double depositConcentrationFactor = 1.0f -(hypothen/spawnRadius);
|
||||
localConcentration = (float)(depositConcentrationFactor*resourceDeposit.getSpawnConcentration());
|
||||
localConcentration = (float)(depositConcentrationFactor*resourceDeposit.getSpawnConcentration()/100);
|
||||
localConcentration *= 100;
|
||||
if (localConcentration>measuredOutput) {
|
||||
measuredOutput=localConcentration;
|
||||
}
|
||||
@@ -460,18 +481,6 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
return minDist;
|
||||
}
|
||||
|
||||
public void constructResourceName(Vector<String> completeResourceNameHistory){
|
||||
// ToDo: This is where the database check for past names must be added
|
||||
boolean check=true;
|
||||
while(check)
|
||||
{
|
||||
this.name = NAME_SYLLABLE_1[(int) new Random().nextInt(NAME_SYLLABLE_1.length-1)]
|
||||
+ NAME_SYLLABLE_2[(int) new Random().nextInt(NAME_SYLLABLE_2.length-1)]
|
||||
+ NAME_SYLLABLE_3[(int) new Random().nextInt(NAME_SYLLABLE_3.length-1)];
|
||||
check = completeResourceNameHistory.contains(this.name);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector<PlanetDeposits> getGalacticDepositList(){
|
||||
return galacticDepositList;
|
||||
}
|
||||
@@ -668,19 +677,6 @@ public class GalacticResource extends SWGObject implements Serializable {
|
||||
this.getresourceType = getresourceType;
|
||||
}
|
||||
|
||||
public GalacticResource convertToHistoricResource(){
|
||||
GalacticResource historicResource = new GalacticResource();
|
||||
historicResource.setName(this.getName());
|
||||
historicResource.setResourceClass(this.getResourceClass());
|
||||
historicResource.setResourceStats(this.getResourceStats());
|
||||
historicResource.setResourceType(this.getResourceType());
|
||||
historicResource.setGeneralType(this.getGeneralType());
|
||||
historicResource.setId(this.getId());
|
||||
historicResource.setIffFileName(this.getIffFileName());
|
||||
|
||||
return historicResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@@ -219,7 +219,7 @@ public class ResourceRoot implements Serializable {
|
||||
return generalType;
|
||||
}
|
||||
|
||||
public void setgeneralType(byte generalType){
|
||||
public void setGeneralType(byte generalType){
|
||||
this.generalType = generalType;
|
||||
}
|
||||
|
||||
@@ -231,10 +231,6 @@ public class ResourceRoot implements Serializable {
|
||||
this.containerType = containerType;
|
||||
}
|
||||
|
||||
public void setGeneralType(byte generalType) {
|
||||
this.generalType = generalType;
|
||||
}
|
||||
|
||||
public int getResourceRootID() {
|
||||
return resourceRootID;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import resources.harvest.SurveyTool;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.player.PlayerObject;
|
||||
import resources.objects.resource.GalacticResource;
|
||||
import resources.objects.resource.ResourceConcentration;
|
||||
import resources.objects.resource.ResourceContainerObject;
|
||||
import resources.objects.resource.ResourceRoot;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
@@ -323,7 +324,35 @@ public class SurveyService implements INetworkDispatch {
|
||||
PlayClientEffectLocMessage cEffMsg = new PlayClientEffectLocMessage(effectFile,crafter.getPlanet().getName(),crafter.getPosition());
|
||||
crafter.getClient().getSession().write(cEffMsg.serialize());
|
||||
crafter.sendSystemMessage("You begin to survey for " + commandArgs, (byte) 0);
|
||||
|
||||
|
||||
float surveyRadius = 64.0f;
|
||||
int surveyToolRangeSetting = surveyTool.getSurveyRangeSetting();
|
||||
//surveyToolRangeSetting = 4;
|
||||
int divisor = 0;
|
||||
if (surveyToolRangeSetting==0) {
|
||||
divisor = 2;
|
||||
surveyRadius = 64.0f;
|
||||
} else if (surveyToolRangeSetting==1) {
|
||||
divisor = 3;
|
||||
surveyRadius = 128.0f;
|
||||
} else if (surveyToolRangeSetting==2) {
|
||||
divisor = 3;
|
||||
surveyRadius = 192.0f;
|
||||
} else if (surveyToolRangeSetting==3) {
|
||||
divisor = 4;
|
||||
surveyRadius = 256.0f;
|
||||
} else if (surveyToolRangeSetting==4) {
|
||||
divisor = 4;
|
||||
surveyRadius = 320.0f;
|
||||
} else {
|
||||
divisor = 5;
|
||||
surveyRadius = 3072.0f;
|
||||
}
|
||||
|
||||
float differential = surveyRadius / (float) divisor;
|
||||
GalacticResource resourceToSurvey = resource;
|
||||
Vector<ResourceConcentration> concentrationMap = resourceToSurvey.buildConcentrationsCollection(crafter.getPosition(),resourceToSurvey, surveyRadius, differential, crafter.getPlanetId());
|
||||
resourceToSurvey.constructSurveyMapMessage(crafter, concentrationMap, surveyRadius);
|
||||
}
|
||||
|
||||
public void requestSampling(CreatureObject crafter, SWGObject target, String commandArgs){
|
||||
|
||||
@@ -251,10 +251,15 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
if(objectID == 0)
|
||||
objectID = generateObjectID();
|
||||
else
|
||||
isSnapshot = !overrideSnapshot;
|
||||
synchronized(objectMutex) {
|
||||
if(objectID == 0)
|
||||
objectID = generateObjectID();
|
||||
else
|
||||
isSnapshot = !overrideSnapshot;
|
||||
|
||||
if(!core.getObjectIdODB().contains(objectID))
|
||||
core.getObjectIdODB().put(objectID, new ObjectId(objectID));
|
||||
}
|
||||
|
||||
if (planet == null) {
|
||||
System.err.println("Planet is null in createObject for some reason.");
|
||||
@@ -383,10 +388,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
object.setAttachment("customServerTemplate", customServerTemplate);
|
||||
|
||||
object.setisInSnapshot(isSnapshot);
|
||||
synchronized(objectMutex) {
|
||||
if(!core.getObjectIdODB().contains(objectID))
|
||||
core.getObjectIdODB().put(objectID, new ObjectId(objectID));
|
||||
}
|
||||
|
||||
// Set Options - easier to set them across the board here
|
||||
// because we'll be spawning them despite most of them being unscripted.
|
||||
// Any such settings can be completely reset with setOptionsBitmask
|
||||
@@ -691,30 +693,27 @@ public class ObjectService implements INetworkDispatch {
|
||||
return generateObjectID();
|
||||
|
||||
return objectID;*/
|
||||
|
||||
long newId = 0;
|
||||
boolean found = false;
|
||||
|
||||
// stack overflow when using recursion
|
||||
synchronized(objectMutex) {
|
||||
while(!found) {
|
||||
newId = highestId.incrementAndGet();
|
||||
PreparedStatement ps2;
|
||||
try {
|
||||
ps2 = databaseConnection.preparedStatement("UPDATE highestid SET id=" + newId + " WHERE id=(SELECT MAX(id) FROM highestid)");
|
||||
ps2.executeUpdate();
|
||||
ps2.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
long newId = 0;
|
||||
try {
|
||||
synchronized(objectMutex) {
|
||||
newId = highestId.get();
|
||||
ObjectDatabase objectIdODB = core.getObjectIdODB();
|
||||
while (objectList.containsKey(newId) || objectIdODB.contains(newId)) {
|
||||
newId = highestId.incrementAndGet();
|
||||
}
|
||||
if(objectList.containsKey(newId) || core.getObjectIdODB().contains(newId))
|
||||
found = false;
|
||||
else
|
||||
found = true;
|
||||
}
|
||||
final String sql = "UPDATE highestid SET id=? WHERE id=(SELECT MAX(id) FROM highestid)";
|
||||
final PreparedStatement ps2 = databaseConnection.preparedStatement(sql);
|
||||
ps2.setLong(1, newId);
|
||||
ps2.executeUpdate();
|
||||
ps2.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newId;
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
public long getDOId(String planet, String template, int type, long containerId, int cellNumber, float x1, float y, float z1) {
|
||||
|
||||
+419
-11196
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user