mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-08-03 04:21:12 -04:00
Changed GalacticResourceType to RawResourceType and added functionality to it
This commit is contained in:
Binary file not shown.
@@ -30,6 +30,8 @@ package services.crafting.resource.galactic;
|
||||
import com.projectswg.common.network.NetBufferStream;
|
||||
import com.projectswg.common.persistable.Persistable;
|
||||
|
||||
import services.crafting.resource.raw.RawResource;
|
||||
|
||||
public class GalacticResource implements Persistable {
|
||||
|
||||
private final GalacticResourceStats stats;
|
||||
@@ -37,6 +39,7 @@ public class GalacticResource implements Persistable {
|
||||
private long id;
|
||||
private String name;
|
||||
private long rawId;
|
||||
private RawResource rawResource;
|
||||
|
||||
public GalacticResource() {
|
||||
this(0, "", 0);
|
||||
@@ -46,6 +49,7 @@ public class GalacticResource implements Persistable {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.rawId = rawResourceId;
|
||||
this.rawResource = null;
|
||||
this.stats = new GalacticResourceStats();
|
||||
}
|
||||
|
||||
@@ -65,10 +69,18 @@ public class GalacticResource implements Persistable {
|
||||
return rawId;
|
||||
}
|
||||
|
||||
public RawResource getRawResource() {
|
||||
return rawResource;
|
||||
}
|
||||
|
||||
public GalacticResourceStats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
public void setRawResource(RawResource rawResource) {
|
||||
this.rawResource = rawResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
stream.addByte(0);
|
||||
|
||||
@@ -105,6 +105,7 @@ public class GalacticResourceSpawner {
|
||||
long startTime = StandardLog.onStartLoad("galactic resources");
|
||||
List<GalacticResource> resources = loader.loadResources();
|
||||
for (GalacticResource resource : resources) {
|
||||
resource.setRawResource(GalacticResourceContainer.getContainer().getRawResource(resource.getRawResourceId()));
|
||||
GalacticResourceContainer.getContainer().addGalacticResource(resource);
|
||||
if (resource.getId() > resourceIdMax.get())
|
||||
resourceIdMax.set(resource.getId());
|
||||
|
||||
+18
-5
@@ -30,11 +30,12 @@ package services.crafting.resource.galactic;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.projectswg.common.data.EnumLookup;
|
||||
import com.projectswg.common.data.location.Terrain;
|
||||
|
||||
import services.crafting.resource.raw.RawResource;
|
||||
|
||||
public enum GalacticResourceType {
|
||||
public enum RawResourceType {
|
||||
RESOURCE ("resource", null),
|
||||
ORGANIC ("organic", RESOURCE),
|
||||
CREATURE_RESOURCES ("creature_resources", ORGANIC),
|
||||
@@ -143,10 +144,12 @@ public enum GalacticResourceType {
|
||||
ENERGY_RENEWABLE_SITE_LIMITED_HYDRON3 ("energy_renewable_site_limited_hydron3", ENERGY_RENEWABLE_SITE_LIMITED),
|
||||
ENERGY_RENEWABLE_SITE_LIMITED_GEOTHERMAL ("energy_renewable_site_limited_geothermal", ENERGY_RENEWABLE_SITE_LIMITED);
|
||||
|
||||
private final String resourceName;
|
||||
private final List<GalacticResourceType> children;
|
||||
private static final EnumLookup<String, RawResourceType> NAME_LOOKUP = new EnumLookup<>(RawResourceType.class, rrt -> rrt.getResourceName());
|
||||
|
||||
GalacticResourceType(String resourceName, GalacticResourceType parent) {
|
||||
private final String resourceName;
|
||||
private final List<RawResourceType> children;
|
||||
|
||||
RawResourceType(String resourceName, RawResourceType parent) {
|
||||
this.resourceName = resourceName;
|
||||
this.children = new ArrayList<>();
|
||||
if (parent != null)
|
||||
@@ -169,7 +172,17 @@ public enum GalacticResourceType {
|
||||
return isSpecificResourceType(this, customExtension, resource);
|
||||
}
|
||||
|
||||
private static boolean isSpecificResourceType(GalacticResourceType type, String extension, RawResource resource) {
|
||||
public static RawResourceType getRawResourceType(RawResource resource) {
|
||||
while (resource != null) {
|
||||
RawResourceType type = NAME_LOOKUP.getEnum(resource.getName().getKey(), null);
|
||||
if (type != null)
|
||||
return type;
|
||||
resource = resource.getParent();
|
||||
}
|
||||
return RawResourceType.RESOURCE;
|
||||
}
|
||||
|
||||
private static boolean isSpecificResourceType(RawResourceType type, String extension, RawResource resource) {
|
||||
if (!isResourceNameMatch(resource.getName().getKey(), extension)) {
|
||||
return false;
|
||||
}
|
||||
@@ -104,6 +104,7 @@ public class GalacticResourceContainer {
|
||||
public void addGalacticResource(GalacticResource resource) {
|
||||
RawResource raw = getRawResource(resource.getRawResourceId());
|
||||
Assert.notNull(raw, "Invalid raw resource ID in GalacticResource!");
|
||||
Assert.test(raw == resource.getRawResource(), "RawResource invalid with galactic resource");
|
||||
Assert.isNull(galacticResources.put(resource.getId(), resource), "Duplicate galactic resource!");
|
||||
synchronized (rawToGalactic) {
|
||||
List<GalacticResource> list = rawToGalactic.get(raw);
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import resources.encodables.StringId;
|
||||
import services.crafting.resource.galactic.RawResourceType;
|
||||
|
||||
public class RawResource {
|
||||
|
||||
@@ -40,6 +41,7 @@ public class RawResource {
|
||||
private final List<RawResource> children;
|
||||
|
||||
private RawResource parent;
|
||||
private RawResourceType type;
|
||||
private String crateTemplate;
|
||||
private int minTypes;
|
||||
private int maxTypes;
|
||||
@@ -50,6 +52,7 @@ public class RawResource {
|
||||
public RawResource(long id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
this.type = RawResourceType.RESOURCE;
|
||||
this.children = new ArrayList<>();
|
||||
this.crateTemplate = "";
|
||||
this.name = new StringId("resource/resource_names", "");
|
||||
@@ -71,6 +74,10 @@ public class RawResource {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public RawResourceType getResourceType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public List<RawResource> getChildren() {
|
||||
return Collections.unmodifiableList(children);
|
||||
}
|
||||
@@ -152,6 +159,7 @@ public class RawResource {
|
||||
}
|
||||
|
||||
public RawResource build() {
|
||||
resource.type = RawResourceType.getRawResourceType(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,13 @@ import com.projectswg.common.debug.Log;
|
||||
import intents.crafting.survey.SampleResourceIntent;
|
||||
import intents.crafting.survey.StartSurveyToolIntent;
|
||||
import intents.crafting.survey.StartSurveyingIntent;
|
||||
import network.packets.swg.zone.PlayMusicMessage;
|
||||
import network.packets.swg.zone.crafting.resources.ResourceListForSurveyMessage;
|
||||
import network.packets.swg.zone.crafting.resources.ResourceListForSurveyMessage.ResourceItem;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import services.crafting.resource.galactic.GalacticResource;
|
||||
import services.crafting.resource.galactic.GalacticResourceType;
|
||||
import services.crafting.resource.galactic.RawResourceType;
|
||||
import services.crafting.resource.galactic.storage.GalacticResourceContainer;
|
||||
import services.crafting.resource.raw.RawResource;
|
||||
|
||||
@@ -64,13 +65,14 @@ public class SurveyService extends Service {
|
||||
SWGObject surveyTool = ssti.getSurveyTool();
|
||||
String resourceType = surveyTool.getTemplate().substring(47, surveyTool.getTemplate().length()-4);
|
||||
ResourceListForSurveyMessage survey = new ResourceListForSurveyMessage(creature.getObjectId(), surveyTool.getTemplate());
|
||||
GalacticResourceType surveyToolType = getTypeFromSurveyTool(resourceType);
|
||||
RawResourceType surveyToolType = getTypeFromSurveyTool(resourceType);
|
||||
for (GalacticResource resource : GalacticResourceContainer.getContainer().getSpawnedResources(creature.getTerrain())) {
|
||||
RawResource rawResource = GalacticResourceContainer.getContainer().getRawResource(resource.getRawResourceId());
|
||||
if (!surveyToolType.isResourceType(rawResource))
|
||||
continue;
|
||||
survey.addResource(new ResourceItem(resource.getName(), rawResource.getName().getKey(), resource.getId()));
|
||||
}
|
||||
creature.getOwner().sendPacket(new PlayMusicMessage(0, "sound/item_surveypad_lp.snd", 1, false));
|
||||
creature.getOwner().sendPacket(survey);
|
||||
}
|
||||
|
||||
@@ -82,30 +84,31 @@ public class SurveyService extends Service {
|
||||
inProgressSampleManager.startSession(sri.getCreature(), sri.getResource());
|
||||
}
|
||||
|
||||
private GalacticResourceType getTypeFromSurveyTool(String surveyTool) {
|
||||
private RawResourceType getTypeFromSurveyTool(String surveyTool) {
|
||||
switch (surveyTool) {
|
||||
case "mineral":
|
||||
return GalacticResourceType.MINERAL;
|
||||
return RawResourceType.MINERAL;
|
||||
case "lumber":
|
||||
return GalacticResourceType.FLORA_STRUCTURAL;
|
||||
return RawResourceType.FLORA_STRUCTURAL;
|
||||
case "liquid":
|
||||
return RawResourceType.CHEMICAL;
|
||||
case "moisture":
|
||||
return GalacticResourceType.WATER;
|
||||
return RawResourceType.WATER;
|
||||
case "gas":
|
||||
case "gas_thermal":
|
||||
return GalacticResourceType.GAS;
|
||||
return RawResourceType.GAS;
|
||||
case "wind":
|
||||
return GalacticResourceType.ENERGY_RENEWABLE_UNLIMITED_WIND;
|
||||
return RawResourceType.ENERGY_RENEWABLE_UNLIMITED_WIND;
|
||||
case "solar":
|
||||
return GalacticResourceType.ENERGY_RENEWABLE_UNLIMITED_SOLAR;
|
||||
return RawResourceType.ENERGY_RENEWABLE_UNLIMITED_SOLAR;
|
||||
case "inorganic":
|
||||
return GalacticResourceType.INORGANIC;
|
||||
return RawResourceType.INORGANIC;
|
||||
case "organic":
|
||||
return GalacticResourceType.ORGANIC;
|
||||
return RawResourceType.ORGANIC;
|
||||
default:
|
||||
Log.w("Unknokwn survey tool type: %s", surveyTool);
|
||||
case "all":
|
||||
return GalacticResourceType.RESOURCE;
|
||||
return RawResourceType.RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user