Compare commits

..

1 Commits

Author SHA1 Message Date
byronhb 221ae0a58b Fixes for /mob, /npc, and /equipset commands. 2025-11-10 21:14:28 -06:00
7 changed files with 29 additions and 62 deletions
-5
View File
@@ -24,8 +24,3 @@
hs_err_pid*
replay_pid*
*.idea/
Server.iml
*.gitignore
prestonbane.iml
qodana.yaml
+6 -2
View File
@@ -243,8 +243,12 @@ public class dbNPCHandler extends dbHandlerBase {
public boolean UPDATE_EQUIPSET(NPC npc, int equipSetID) {
// Column name must match what NPC/Mob loaders read ("equipmentSet").
// Using the wrong column here causes the update to fail silently and
// dev command to report "Unable to find Equipset" despite a valid ID.
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `equipsetID`=? WHERE `UID`=?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `equipmentSet`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, equipSetID);
preparedStatement.setLong(2, npc.getObjectUUID());
@@ -467,4 +471,4 @@ public class dbNPCHandler extends dbHandlerBase {
return false;
}
}
}
}
+1 -11
View File
@@ -88,7 +88,7 @@ public enum MovementManager {
// if (msg.getEndLat() < 0)
// msg.setEndLat(0);
//
//
// if (msg.getEndLon() > 0)
// msg.setEndLon(0);
@@ -216,16 +216,6 @@ public enum MovementManager {
}
if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) {
Vector3fImmutable playerCollidePoint = Bounds.PlayerCollisionPoint((PlayerCharacter) toMove, toMove.getLoc(), endLocation);
if (playerCollidePoint != null) {
msg.setEndCoord(playerCollidePoint);
endLocation = playerCollidePoint;
collide = true;
}
}
if (toMove.getObjectType() == GameObjectType.PlayerCharacter && ((PlayerCharacter) toMove).isTeleportMode()) {
toMove.teleport(endLocation);
return;
+1 -40
View File
@@ -81,7 +81,7 @@ public class Bounds {
Bounds identityBounds = Bounds.borrow();
identityBounds.setBounds(location);
collisionState = collide(targetBounds, identityBounds, 0.1f);
collisionState = collide(targetBounds, identityBounds, 0.0f);
identityBounds.release();
return collisionState;
}
@@ -267,45 +267,6 @@ public class Bounds {
return collidePoint;
}
public static Vector3fImmutable PlayerCollisionPoint(PlayerCharacter player, Vector3fImmutable start, Vector3fImmutable end) {
Vector3fImmutable collidePoint = null;
float distance = player.getLoc().distance2D(end);
// Check for building collisions first
collidePoint = PlayerBuildingCollisionPoint(player, start, end);
if (collidePoint != null) {
return collidePoint;
}
// Now check for player collisions
HashSet<AbstractWorldObject> nearbyPlayers = WorldGrid.getObjectsInRangePartial(player, distance + 2, MBServerStatics.MASK_PLAYER);
float minDistance = 5.0f; // Minimum distance between players
for (AbstractWorldObject awo : nearbyPlayers) {
PlayerCharacter otherPlayer = (PlayerCharacter) awo;
if (otherPlayer == player) continue;
Vector3fImmutable otherLoc = otherPlayer.getLoc();
Vector3fImmutable closestPoint = getClosestPointOnLine(start, end, otherLoc);
if (closestPoint.distance2D(otherLoc) < minDistance) {
// Collision detected, adjust end point
Vector3fImmutable pushVector = closestPoint.subtract(otherLoc).normalize();
collidePoint = closestPoint.add(pushVector.scaleAdd(minDistance, Vector3fImmutable.ZERO));
break;
}
}
return collidePoint != null ? collidePoint : end;
}
private static Vector3fImmutable getClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd, Vector3fImmutable point) {
Vector3fImmutable line = lineEnd.subtract(lineStart);
float t = point.subtract(lineStart).dot(line) / line.dot(line);
t = Math.max(0, Math.min(1, t));
return lineStart.add(line.scaleAdd(t, Vector3fImmutable.ZERO));
}
public static boolean linesTouching(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float denominator = ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3));
float numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3));
+11 -1
View File
@@ -541,8 +541,18 @@ public class Mob extends AbstractIntelligenceAgent {
mobWithoutID.parentZone = parent;
mobWithoutID.parentZoneID = parent.getObjectUUID();
// NPC in a Building derives position from slot
// Ensure spawn coordinates are persisted for DB insert
// statLat/statAlt/statLon represent local (zone-relative) spawn
// coordinates used by the DB handler when creating the mob row.
if (spawn != null && parent != null) {
// Convert world coordinates to zone-local spawn coordinates
Vector3fImmutable localSpawn = spawn.subtract(parent.getLoc());
mobWithoutID.statLat = localSpawn.x;
mobWithoutID.statAlt = localSpawn.y;
mobWithoutID.statLon = localSpawn.z;
}
// NPC in a Building derives position from slot
if (mobWithoutID.building != null)
mobWithoutID.bindLoc = Vector3fImmutable.ZERO;
+3 -2
View File
@@ -470,7 +470,8 @@ public class NPC extends AbstractCharacter {
newNPC.bindLoc = Vector3fImmutable.ZERO;
newNPC.parentZoneUUID = parent.getObjectUUID();
newNPC.guildUUID = guild.getObjectUUID();
// guild may be null when spawning via ./npc; default to 0
newNPC.guildUUID = (guild != null) ? guild.getObjectUUID() : 0;
if (building == null)
newNPC.buildingUUID = 0;
@@ -1347,4 +1348,4 @@ public class NPC extends AbstractCharacter {
}
}
}
}
+7 -1
View File
@@ -26,6 +26,7 @@ import engine.job.JobScheduler;
import engine.jobs.DeferredPowerJob;
import engine.jobs.FinishSpireEffectJob;
import engine.jobs.NoTimeJob;
import engine.math.Bounds;
import engine.math.FastMath;
import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter;
@@ -268,6 +269,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.hash = rs.getString("hash");
// For debugging skills
// CharacterSkill.printSkills(this);
}
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
@@ -4561,6 +4565,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.charItemManager = new CharacterItemManager(this);
Bounds playerBounds = Bounds.borrow();
playerBounds.setBounds(this.getLoc());
this.setBounds(playerBounds);
}
@Override
@@ -5356,7 +5363,6 @@ public class PlayerCharacter extends AbstractCharacter {
moveToMsg.setSourceType(GameObjectType.PlayerCharacter.ordinal());
moveToMsg.setSourceID(this.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(this, moveToMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);