Add max distance argument to rtp

This commit is contained in:
zontreck 2025-03-07 01:12:36 -07:00
parent 54e8d8a4d5
commit a9150cf322
5 changed files with 20 additions and 7 deletions

View file

@ -210,7 +210,7 @@ namespace AriasServerUtils
api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack);
api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.Int("maxDist")).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP);
} }
private void OnCheckPlayerCooldowns() private void OnCheckPlayerCooldowns()

View file

@ -54,6 +54,15 @@ namespace AriasServerUtils
{ {
if (args.Caller.Player is IServerPlayer isp) if (args.Caller.Player is IServerPlayer isp)
{ {
int maxDistance = ServerUtilities.config.MaxRTPBlockDistance;
if (args[0] is int ix)
{
if (ix > maxDistance)
{
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance));
}
else maxDistance = ix;
}
PlayerStorage ps = ServerUtilities.GetPlayerData(isp); PlayerStorage ps = ServerUtilities.GetPlayerData(isp);
if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP)) if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP))
@ -67,7 +76,7 @@ namespace AriasServerUtils
ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp());
ServerUtilities.MarkDirty(); ServerUtilities.MarkDirty();
PlayerPosition pPos = RTPFactory.GetRandomPosition(isp); PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance);
if (pPos == null) if (pPos == null)
{ {
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail"));

View file

@ -16,7 +16,7 @@ public class RTPFactory
/// </summary> /// </summary>
/// <param name="isp">The player to be teleported</param> /// <param name="isp">The player to be teleported</param>
/// <returns>A random position +/- max distance from current position.</returns> /// <returns>A random position +/- max distance from current position.</returns>
public static PlayerPosition GetRandomPosition(IServerPlayer isp) public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance)
{ {
Random rng = new Random(); Random rng = new Random();
EntityPos vPos = isp.Entity.Pos; EntityPos vPos = isp.Entity.Pos;
@ -29,10 +29,13 @@ public class RTPFactory
while (tries-- > 0) while (tries-- > 0)
{ {
// Generate random X and Z within max RTP distance // Generate random X and Z within max RTP distance
bPos.X = (int)vPos.X + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); bPos.X = (int)vPos.X + rng.Next(0, maxDistance);
bPos.Z = (int)vPos.Z + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance);
bPos.Y = 255; bPos.Y = 255;
if (rng.Next(0, 1) == 1) bPos.X = -bPos.X;
if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z;
Block lastAboveLast = null; Block lastAboveLast = null;
Block lastBlock = null; Block lastBlock = null;
Block curBlock; Block curBlock;

View file

@ -36,6 +36,7 @@
"rtp-search": "Searching for a random position...", "rtp-search": "Searching for a random position...",
"rtp": "You have been teleported [{0}] blocks away!", "rtp": "You have been teleported [{0}] blocks away!",
"rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later",
"rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]",
"cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]"
} }

View file

@ -3,8 +3,8 @@
"modid": "ariasserverutils", "modid": "ariasserverutils",
"name": "Aria's Server Utilities", "name": "Aria's Server Utilities",
"authors": ["zontreck"], "authors": ["zontreck"],
"description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:37 PM MST", "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 00:52 AM MST",
"version": "1.0.4", "version": "1.0.5-dev.1",
"dependencies": { "dependencies": {
"game": "" "game": ""
} }