Compare commits

...

12 Commits

13 changed files with 163 additions and 82 deletions
+1 -1
View File
@@ -469,7 +469,7 @@ public class Enum {
// 14001 does not have a banestone to bind at
if (ruinZone.template == 14001)
if (ruinZone.templateID == 14001)
spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc(), 30);
else
spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc()
+9 -9
View File
@@ -32,12 +32,12 @@ public class Terrain {
public Terrain(Zone zone) {
this.zone = zone;
this.heightmap = this.zone.terrain_image;
this.heightmap = this.zone.template.terrain_image;
// Configure PLANAR zones to use the same 16x16 pixel image
// that all similar terrains share. (See JSON)
if (this.zone.terrain_type.equals("PLANAR"))
if (this.zone.template.terrain_type.equals("PLANAR"))
this.heightmap = 1006300; // all 0
// Load pixel data for this terrain from cache
@@ -62,11 +62,11 @@ public class Terrain {
// the blending area between child and parent terrains when
// they are stitched together.
Vector2f major_blend = new Vector2f(this.zone.max_blend / this.zone.major_radius,
this.zone.min_blend / this.zone.major_radius);
Vector2f major_blend = new Vector2f(this.zone.template.max_blend / this.zone.major_radius,
this.zone.template.min_blend / this.zone.major_radius);
Vector2f minor_blend = new Vector2f(this.zone.max_blend / this.zone.minor_radius,
this.zone.min_blend / this.zone.minor_radius);
Vector2f minor_blend = new Vector2f(this.zone.template.max_blend / this.zone.minor_radius,
this.zone.template.min_blend / this.zone.minor_radius);
if (major_blend.y > 0.4f)
blend_ratio.x = major_blend.y;
@@ -80,7 +80,7 @@ public class Terrain {
// Scale coefficient for this terrain
this.terrain_scale = this.zone.terrain_max_y / 255f;
this.terrain_scale = this.zone.template.terrain_max_y / 255f;
}
public static Zone getNextZoneWithTerrain(Zone zone) {
@@ -205,8 +205,8 @@ public class Terrain {
// Normalize terrain offset
Vector2f normalizedOffset = new Vector2f(Math.abs(zone_offset.x) / this.zone.major_radius,
Math.abs(zone_offset.y) / this.zone.minor_radius);
Vector2f normalizedOffset = new Vector2f(Math.abs(zone_offset.x) / this.zone.template.major_radius,
Math.abs(zone_offset.y) / this.zone.template.minor_radius);
float blendCoefficient;
+36
View File
@@ -11,7 +11,9 @@ package engine.db.handlers;
import engine.Enum;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.objects.Zone;
import engine.objects.ZoneTemplate;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
@@ -66,6 +68,40 @@ public class dbZoneHandler extends dbHandlerBase {
return zone;
}
public void LOAD_ALL_ZONE_TEMPLATES() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_zone_templates")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
ZoneTemplate zoneTemplate = new ZoneTemplate(rs);
ZoneManager._zone_templates.put(zoneTemplate.templateID, zoneTemplate);
}
// Add player city
ZoneTemplate zoneTemplate = new ZoneTemplate();
zoneTemplate.templateID = 0;
zoneTemplate.sea_level_type = "PARENT";
zoneTemplate.sea_level = 0;
zoneTemplate.max_blend = 128;
zoneTemplate.min_blend = 128;
zoneTemplate.terrain_max_y = 5;
zoneTemplate.major_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
zoneTemplate.minor_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
zoneTemplate.terrain_type = "PLANAR";
ZoneManager._zone_templates.put(zoneTemplate.templateID, zoneTemplate);
} catch (SQLException e) {
Logger.error(e);
}
}
public boolean DELETE_ZONE(final Zone zone) {
try (Connection connection = DbManager.getConnection();
+2 -2
View File
@@ -37,8 +37,8 @@ public class GetHeightCmd extends AbstractDevCmd {
Vector2f childZoneLoc = ZoneManager.worldToTerrainSpace(playerCharacter.getLoc(), heightmapZone);
Vector2f childZoneOffset = ZoneManager.worldToZoneOffset(playerCharacter.getLoc(), heightmapZone);
Vector2f normalizedOffset = new Vector2f(Math.abs(childZoneOffset.x) / heightmapZone.major_radius,
Math.abs(childZoneOffset.y) / heightmapZone.minor_radius);
Vector2f normalizedOffset = new Vector2f(Math.abs(childZoneOffset.x) / heightmapZone.template.major_radius,
Math.abs(childZoneOffset.y) / heightmapZone.template.minor_radius);
Vector2f parentZoneLoc = ZoneManager.worldToTerrainSpace(playerCharacter.getLoc(), parentZone);
float childHeight = heightmapZone.terrain.getInterpolatedTerrainHeight(childZoneLoc);
+1 -1
View File
@@ -51,7 +51,7 @@ public class GetZoneCmd extends AbstractDevCmd {
}
for (Zone zone : allIn)
throwbackInfo(pcSender, zone.zoneName + "; UUID: " + zone.getObjectUUID() + ", loadNum: " + zone.template);
throwbackInfo(pcSender, zone.zoneName + "; UUID: " + zone.getObjectUUID() + ", loadNum: " + zone.templateID);
}
@Override
+2 -2
View File
@@ -387,7 +387,7 @@ public class InfoCmd extends AbstractDevCmd {
output += newline;
output += "EquipSet: " + targetNPC.getEquipmentSetID();
output += newline;
output += "Parent Zone LoadNum : " + targetNPC.getParentZone().template;
output += "Parent Zone LoadNum : " + targetNPC.getParentZone().templateID;
}
@@ -473,7 +473,7 @@ public class InfoCmd extends AbstractDevCmd {
output += "EquipSet: " + targetMob.equipmentSetID;
output += newline;
try {
output += "Parent Zone LoadNum : " + targetMob.getParentZone().template;
output += "Parent Zone LoadNum : " + targetMob.getParentZone().templateID;
} catch (Exception ex) {
//who cares
}
+4 -4
View File
@@ -75,7 +75,7 @@ public class ZoneInfoCmd extends AbstractDevCmd {
output += newline;
output += "name: " + zone.zoneName;
output += newline;
output += "loadNum: " + zone.template;
output += "loadNum: " + zone.templateID;
if (zone.parent != null) {
output += StringUtils.addWS(", parent: " + zone.parent.getObjectUUID(), 30);
output += "Parentabs: x: " + zone.parent.absX + ", y: " + zone.parent.absY + ", z: " + zone.parent.absZ;
@@ -91,7 +91,7 @@ public class ZoneInfoCmd extends AbstractDevCmd {
output += newline;
if (zone.terrain != null) {
output += "Terrain image: " + zone.terrain_image;
output += "Terrain image: " + zone.template.terrain_image;
output += newline;
}
@@ -99,7 +99,7 @@ public class ZoneInfoCmd extends AbstractDevCmd {
output += newline;
// output += "minLvl = " + zone.getMinLvl() + " | maxLvl = " + zone.getMaxLvl();
output += newline;
output += "Sea Level = " + zone.seaLevel;
output += "Sea Level = " + zone.sea_level;
output += newline;
output += "World Altitude = " + zone.global_height;
throwbackInfo(player, output);
@@ -127,7 +127,7 @@ public class ZoneInfoCmd extends AbstractDevCmd {
for (Zone child : nodes) {
output += newline;
output += child.zoneName + " (" + child.template + ')';
output += child.zoneName + " (" + child.templateID + ')';
}
}
throwbackInfo(player, output);
+1 -1
View File
@@ -40,7 +40,7 @@ public class ZoneSetCmd extends AbstractDevCmd {
zone = ZoneManager.findSmallestZone(playerCharacter.getLoc());
throwbackInfo(playerCharacter, zone.zoneName + " (" + zone.template + ") " + zone.getObjectUUID());
throwbackInfo(playerCharacter, zone.zoneName + " (" + zone.templateID + ") " + zone.getObjectUUID());
// NPC
+6 -6
View File
@@ -17,16 +17,14 @@ import engine.math.Vector3fImmutable;
import engine.objects.Building;
import engine.objects.City;
import engine.objects.Zone;
import engine.objects.ZoneTemplate;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
@@ -38,6 +36,8 @@ public enum ZoneManager {
ZONEMANAGER;
public static HashMap<Integer, ZoneTemplate> _zone_templates = new HashMap<>();
public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
@@ -169,7 +169,7 @@ public enum ZoneManager {
// collections for quick access
// based upon their type.
ZoneManager.zonesByID.put(zone.template, zone);
ZoneManager.zonesByID.put(zone.templateID, zone);
ZoneManager.zonesByUUID.put(zone.getObjectUUID(), zone);
@@ -431,6 +431,6 @@ public enum ZoneManager {
float localAltitude = Terrain.getWorldHeight(currentLoc);
Zone zone = findSmallestZone(currentLoc);
return localAltitude < zone.seaLevel;
return localAltitude < zone.sea_level;
}
}
+11 -11
View File
@@ -1507,16 +1507,16 @@ public class PlayerCharacter extends AbstractCharacter {
return true;
Zone zone = ZoneManager.findSmallestZone(breather.getLoc());
if (zone.seaLevel != 0) {
if (zone.sea_level != 0) {
float localAltitude = breather.getLoc().y;
if (localAltitude + breather.characterHeight < zone.seaLevel - 2)
if (localAltitude + breather.characterHeight < zone.sea_level - 2)
return false;
if (breather.isMoving()) {
if (localAltitude + breather.characterHeight < zone.seaLevel)
if (localAltitude + breather.characterHeight < zone.sea_level)
return false;
}
} else {
@@ -1547,12 +1547,12 @@ public class PlayerCharacter extends AbstractCharacter {
Zone zone = ZoneManager.findSmallestZone(enterer.getLoc());
if (zone.seaLevel != 0) {
if (zone.sea_level != 0) {
float localAltitude = enterer.getLoc().y + enterer.characterHeight;
if (localAltitude < zone.seaLevel)
if (localAltitude < zone.sea_level)
return true;
} else {
if (enterer.getLoc().y + enterer.characterHeight < 0)
@@ -1579,12 +1579,12 @@ public class PlayerCharacter extends AbstractCharacter {
leaveWater = 1f;
if (zone.seaLevel != 0) {
if (zone.sea_level != 0) {
float localAltitude = leaver.getLoc().y;
if (localAltitude + leaveWater < zone.seaLevel)
if (localAltitude + leaveWater < zone.sea_level)
return false;
} else {
if (leaver.getLoc().y + leaveWater < 0)
@@ -4739,10 +4739,10 @@ public class PlayerCharacter extends AbstractCharacter {
Zone zone = ZoneManager.findSmallestZone(this.getLoc());
if (zone.seaLevel != 0) {
if (zone.sea_level != 0) {
float localAltitude = this.getLoc().y + this.centerHeight;
if (localAltitude < zone.seaLevel)
if (localAltitude < zone.sea_level)
return true;
} else {
if (this.getLoc().y + this.centerHeight < 0)
@@ -4764,9 +4764,9 @@ public class PlayerCharacter extends AbstractCharacter {
Zone zone = ZoneManager.findSmallestZone(currentLoc);
if (zone.seaLevel != 0) {
if (zone.sea_level != 0) {
if (localAltitude < zone.seaLevel)
if (localAltitude < zone.sea_level)
return true;
} else {
if (localAltitude < 0)
+27 -44
View File
@@ -34,12 +34,17 @@ public class Zone extends AbstractWorldObject {
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public ZoneTemplate template;
public final int playerCityUUID;
public final String zoneName;
public final float major_radius;
public final float minor_radius;
public final float xOffset;
public final float zOffset;
public final float yOffset;
public final int template;
public final int templateID;
public final byte peace_zone;
public final String icon1;
public final String icon2;
@@ -58,17 +63,7 @@ public class Zone extends AbstractWorldObject {
public boolean guild_zone;
public String hash;
public float global_height = 0;
public float seaLevel = 0f;
public float sea_level_offset = 0;
public float major_radius;
public float minor_radius;
public float min_blend;
public float max_blend;
public String sea_level_type;
public float sea_level;
public String terrain_type;
public float terrain_max_y;
public int terrain_image;
public Terrain terrain = null;
@@ -80,39 +75,25 @@ public class Zone extends AbstractWorldObject {
super(rs);
this.parentZoneID = rs.getInt("parent");
this.playerCityUUID = rs.getInt("playerCityUUID");
this.guild_zone = this.playerCityUUID != 0;
this.templateID = rs.getInt("template");
this.zoneName = rs.getString("zone_name");
this.peace_zone = rs.getByte("peace_zone");
this.major_radius = rs.getFloat("major_radius");
this.minor_radius = rs.getFloat("minor_radius");
this.xOffset = rs.getFloat("xOffset");
this.zOffset = rs.getFloat("zOffset");
this.yOffset = rs.getFloat("yOffset");
this.template = rs.getInt("template");
this.peace_zone = rs.getByte("peace_zone");
this.playerCityUUID = rs.getInt("playerCityUUID");
this.guild_zone = this.playerCityUUID != 0;
this.icon1 = rs.getString("icon1");
this.icon2 = rs.getString("icon2");
this.icon3 = rs.getString("icon3");
this.min_level = rs.getInt("min_level");
this.max_level = rs.getInt("max_level");
this.major_radius = rs.getFloat("major_radius");
this.minor_radius = rs.getFloat("minor_radius");
this.min_blend = rs.getFloat("min_blend");
this.max_blend = rs.getFloat("max_blend");
this.sea_level_type = rs.getString("sea_level_type");
this.sea_level_offset = rs.getFloat("sea_level");
this.terrain_type = rs.getString("terrain_type");
this.terrain_max_y = rs.getFloat("terrain_max_y");
this.terrain_image = rs.getInt("terrain_image");
// Configuration for player cities
if (this.guild_zone) {
this.max_blend = 128;
this.min_blend = 128;
this.terrain_max_y = 5;
this.major_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
this.minor_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
this.terrain_type = "PLANAR";
}
// If zone doesn't yet hava a hash then write it back to the zone table
@@ -123,7 +104,7 @@ public class Zone extends AbstractWorldObject {
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
if (zone.template == 0 && zone.playerCityUUID == 0)
if (zone.templateID == 0 && zone.playerCityUUID == 0)
Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
@@ -141,7 +122,7 @@ public class Zone extends AbstractWorldObject {
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.template);
writer.putInt(zone.templateID);
if (zone.playerCityUUID > 0) {
City k = City.getCity(zone.playerCityUUID);
@@ -177,12 +158,14 @@ public class Zone extends AbstractWorldObject {
@Override
public void runAfterLoad() {
this.template = ZoneManager._zone_templates.get(this.templateID);
// First zone is always the seafloor
if (ZoneManager.seaFloor == null)
ZoneManager.seaFloor = this;
if (this.terrain_type.equals("NONE"))
if (this.template.terrain_type.equals("NONE"))
this.terrain = null;
else
this.terrain = new Terrain(this);
@@ -207,7 +190,7 @@ public class Zone extends AbstractWorldObject {
// Set initial bounds object
this.bounds = Bounds.borrow();
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(this.major_radius, this.minor_radius), 0.0f);
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(this.template.major_radius, this.template.minor_radius), 0.0f);
}
@@ -225,7 +208,7 @@ public class Zone extends AbstractWorldObject {
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.global_height = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zOffset;
this.seaLevel = 0;
this.sea_level = 0;
this.setBounds();
return;
}
@@ -253,15 +236,15 @@ public class Zone extends AbstractWorldObject {
return;
}
switch (this.sea_level_type) {
switch (this.template.sea_level_type) {
case "WORLD":
this.sea_level = world_sea_level + this.sea_level_offset;
this.sea_level = world_sea_level + this.template.sea_level;
break;
case "PARENT":
this.sea_level = this.parent.sea_level + this.sea_level_offset;
this.sea_level = this.parent.sea_level + this.template.sea_level;
break;
case "SELF":
this.sea_level = this.global_height + this.sea_level_offset;
this.sea_level = this.global_height + this.template.sea_level;
break;
}
}
+59
View File
@@ -0,0 +1,59 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ZoneTemplate {
public int templateID;
public String zone_type;
public String zone_name;
public String peace_zone;
public float major_radius;
public float minor_radius;
public float min_blend;
public float max_blend;
public String has_water;
public String sea_level_type;
public float sea_level;
public String has_terrain;
public String terrain_type;
public float terrain_max_y;
public int terrain_image;
/**
* ResultSet Constructor
*/
public ZoneTemplate() {
}
public ZoneTemplate(ResultSet rs) throws SQLException {
this.templateID = rs.getInt("template");
this.zone_type = rs.getString("zone_type");
this.zone_name = rs.getString("zone_name");
this.major_radius = rs.getFloat("zone_major_radius");
this.minor_radius = rs.getFloat("zone_minor_radius");
this.min_blend = rs.getFloat("zone_min_blend");
this.max_blend = rs.getFloat("zone_max_blend");
this.has_water = rs.getString("zone_has_water");
this.sea_level_type = rs.getString("zone_sea_level_type");
this.sea_level = rs.getFloat("zone_sea_level");
this.has_terrain = rs.getString("zone_has_terrain_gen");
this.terrain_type = rs.getString("terrain_type");
this.terrain_max_y = rs.getFloat("terrain_max_y");
this.terrain_image = rs.getInt("terrain_image");
}
}
+4 -1
View File
@@ -309,6 +309,9 @@ public class WorldServer {
Logger.info("Initializing Errant Guild");
Guild.getErrantGuild();
Logger.info("Loading zone template data");
DbManager.ZoneQueries.LOAD_ALL_ZONE_TEMPLATES();
Logger.info("Initializing PowersManager.");
PowersManager.initPowersManager(true);
@@ -390,7 +393,7 @@ public class WorldServer {
Blueprint.loadAllDoorNumbers();
Blueprint.loadAllBlueprints();
Logger.info("Initializing Heightmap data");
Logger.info("Loading Heightmap Pixel data");
MapLoader.loadAlHeightMaps();
Logger.info("Loading Race data");