Take world size into account when finding rtp

This commit is contained in:
zontreck 2025-03-10 11:18:45 -07:00
parent 5f99672a9b
commit c69e1de64b
2 changed files with 30 additions and 19 deletions

View file

@ -99,7 +99,7 @@ public class RTPFactory
/// <param name="maxDistance">Max distance +/- the current position.</param>
public static void TryRTP(IServerPlayer isp, int maxDistance)
{
var data = new RTPData(isp, maxDistance, 100, PlayerPosition.from(isp.Entity));
var data = new RTPData(isp, maxDistance, 10, PlayerPosition.from(isp.Entity));
RTPCache.Add(data);
}
@ -124,13 +124,24 @@ public class RTPFactory
int num = ChunkChecks.Select(x => x.rtp.player.PlayerUID == rtp.player.PlayerUID).Count();
if (num > 0) continue;
// Generate a new position
var position = rtp.MakeNewPosition();
ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress"));
if (rtp.NumTriesRemaining <= 0)
{
// Send failure message to the player
ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail"));
// This check needs to be removed from the queue
RTPCache.Remove(rtp);
return; // We modified the list, so abort the loop.
}
// Get the world handle, then get chunk size
var worldManager = ServerUtilities.API.WorldManager;
var chunkSize = worldManager.ChunkSize;
var worldSize = new Vec3i(worldManager.MapSizeX, worldManager.MapSizeY, worldManager.MapSizeZ);
// Generate a new position
var position = rtp.MakeNewPosition(worldSize);
//ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress"));
// Generate a chunk load check object.
RTPChunk chunk = new RTPChunk();
@ -145,14 +156,6 @@ public class RTPFactory
// Load the chunk
worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ);
if (rtp.NumTriesRemaining <= 0)
{
// Send failure message to the player
ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail"));
// This check needs to be removed from the queue
RTPCache.Remove(rtp);
return; // We modified the list, so abort the loop.
}
}
}
@ -212,10 +215,10 @@ public class RTPData
StartPosition = playerPosition;
}
public RTPPosition MakeNewPosition()
public RTPPosition MakeNewPosition(Vec3i mapSize)
{
NumTriesRemaining--;
LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension);
LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize);
return LastPosition;
}
@ -229,16 +232,24 @@ public class RTPPosition
public int dimension;
public RTPPosition(int x, int z, int maxDist, int dim)
public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize)
{
int worldx = mapSize.X / 2;
int worldz = mapSize.Z / 2;
if (maxDist > worldx) maxDist = worldx / 2;
int minX = x - maxDist;
int maxX = x + maxDist;
int minZ = z - maxDist;
int maxZ = z + maxDist;
this.x = ServerUtilities.rng.Next(minX, maxX);
this.x = ServerUtilities.rng.Next(worldx - minX, worldx + maxX);
this.y = 1;
this.z = ServerUtilities.rng.Next(minZ, maxZ);
this.z = ServerUtilities.rng.Next(worldz - minZ, worldz + maxZ);
this.dimension = dim;
}

View file

@ -3,8 +3,8 @@
"modid": "ariasserverutils",
"name": "Aria's Server Utilities",
"authors": ["zontreck"],
"description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:04 AM MST",
"version": "1.0.6-dev.15",
"description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:18 AM MST",
"version": "1.0.6-dev.16",
"dependencies": {
"game": ""
}