Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
- Updated to a new version of the game (14.0.0)
- Updated the lobby system, now more rooms are available to a custom location
- Added commands to simplify the control of custom locations
  • Loading branch information
MrAfitol committed Dec 28, 2024
1 parent c5f9620 commit a1484ac
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 81 deletions.
42 changes: 27 additions & 15 deletions Lobby/API/LobbyLocationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace Lobby.API
{
using MapGeneration;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using MapGeneration;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Lobby.API
{
public static class LobbyLocationHandler
{
public static GameObject Point;
Expand All @@ -16,9 +17,9 @@ public static class LobbyLocationHandler
{ LobbyLocationType.Tower_3, new CustomLocationData() { PositionX = 39.262f, PositionY = 1014.112f, PositionZ = -31.844f, RotationX = 0, RotationY = 0, RotationZ = 0 } },
{ LobbyLocationType.Tower_4, new CustomLocationData() { PositionX = -15.854f, PositionY = 1014.461f, PositionZ = -31.543f, RotationX = 0, RotationY = 0, RotationZ = 0 } },
{ LobbyLocationType.Tower_5, new CustomLocationData() { PositionX = 130.483f, PositionY = 993.366f, PositionZ = 20.601f, RotationX = 0, RotationY = 0, RotationZ = 0 } },
{ LobbyLocationType.Intercom, new CustomRoomLocationData() { RoomNameType = RoomName.EzIntercom, OffsetX = -4.16f, OffsetY = -3.860f, OffsetZ = -2.113f, RotationX = 0, RotationY = 180, RotationZ = 0 } },
{ LobbyLocationType.GR18, new CustomRoomLocationData() { RoomNameType = RoomName.LczGlassroom, OffsetX = 4.8f, OffsetY = 1f, OffsetZ = 2.3f, RotationX = 0, RotationY = 180, RotationZ = 0 } },
{ LobbyLocationType.SCP173, new CustomRoomLocationData() { RoomNameType = RoomName.Lcz173, OffsetX = 17f, OffsetY = 13f, OffsetZ = 8f, RotationX = 0, RotationY = -90, RotationZ = 0 } },
{ LobbyLocationType.Intercom, new CustomRoomLocationData() { RoomNameType = RoomName.EzIntercom.ToString(), OffsetX = -4.16f, OffsetY = -3.860f, OffsetZ = -2.113f, RotationX = 0, RotationY = 180, RotationZ = 0 } },
{ LobbyLocationType.GR18, new CustomRoomLocationData() { RoomNameType = RoomName.LczGlassroom.ToString(), OffsetX = 4.8f, OffsetY = 1f, OffsetZ = 2.3f, RotationX = 0, RotationY = 180, RotationZ = 0 } },
{ LobbyLocationType.SCP173, new CustomRoomLocationData() { RoomNameType = RoomName.Lcz173.ToString(), OffsetX = 17f, OffsetY = 13f, OffsetZ = 8f, RotationX = 0, RotationY = -90, RotationZ = 0 } },
};

public static void SetLocation(LocationData locationData)
Expand All @@ -27,15 +28,21 @@ public static void SetLocation(LocationData locationData)
{
RoomIdentifier Room;

Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == customRoomLocation.RoomNameType);

if (customRoomLocation.RoomNameType == RoomName.EzIntercom)
EventHandlers.IsIntercom = true;
if (Enum.TryParse<RoomName>(customRoomLocation.RoomNameType, out RoomName roomName))
{
Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == roomName);

if (Room == null)
if (customRoomLocation.RoomNameType == RoomName.EzIntercom.ToString())
EventHandlers.IsIntercom = true;
}
else if (RoomIdentifier.AllRoomIdentifiers.Count(x => x.name.Contains(customRoomLocation.RoomNameType)) > 0)
{
Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.name.Contains(customRoomLocation.RoomNameType));
}
else
{
customRoomLocation = (CustomRoomLocationData)LocationDatas[LobbyLocationType.GR18];
Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == customRoomLocation.RoomNameType);
Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == ParseEnum<RoomName>(customRoomLocation.RoomNameType));
}

Point.transform.SetParent(Room.transform);
Expand All @@ -48,5 +55,10 @@ public static void SetLocation(LocationData locationData)
Point.transform.localRotation = Quaternion.Euler(customLocation.RotationX, customLocation.RotationY, customLocation.RotationZ);
}
}

public static T ParseEnum<T>(string value)
{
return (T)Enum.Parse(typeof(T), value, true);
}
}
}
69 changes: 69 additions & 0 deletions Lobby/Command/ControlCommands/AddLocationCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using CommandSystem;
using Lobby.Extensions;
using PluginAPI.Core;
using System;
using UnityEngine;

namespace Lobby.Command.ControlCommands
{
public class AddLocationCommand : ICommand
{
public string Command => "addloc";

public string[] Aliases { get; } = { "add", "ad" };

public string Description => "Add a new lobby location.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player playerSender = Player.Get(sender);

if (!playerSender.IsAllowCommand())
{
response = $"You don't have permission to use this command!";
return false;
}

if (arguments.Count != 1)
{
response = "Incorrect command, use: \nlobby addloc room\nlobby addloc static";
return false;
}

var handler = PluginHandler.Get(Lobby.Instance);

switch (arguments.At(0))
{
case "room":
GameObject Point = new GameObject("Point");
Point.transform.position = playerSender.Position;
Point.transform.eulerAngles = playerSender.Rotation;
Point.transform.SetParent(playerSender.Room.transform);

CustomRoomLocationData roomLocationData = new CustomRoomLocationData();
roomLocationData.RoomNameType = playerSender.Room.name;
roomLocationData.OffsetX = Point.transform.localPosition.x; roomLocationData.OffsetY = Point.transform.localPosition.y + 0.05f; roomLocationData.OffsetZ = Point.transform.localPosition.z;
roomLocationData.RotationX = Point.transform.localEulerAngles.x; roomLocationData.RotationY = Point.transform.localEulerAngles.y; roomLocationData.RotationZ = Point.transform.localEulerAngles.z;

Lobby.Config.CustomRoomLocations.Add(roomLocationData);
handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config));
response = "New custom location added to the config.";
return true;
case "static":
CustomLocationData locationData = new CustomLocationData();
locationData.PositionX = playerSender.Position.x; locationData.PositionY = playerSender.Position.y + 0.05f; locationData.PositionZ = playerSender.Position.z;
locationData.RotationX = playerSender.Rotation.x; locationData.RotationY = playerSender.Rotation.y; locationData.RotationZ = playerSender.Rotation.z;

Lobby.Config.CustomLocations.Add(locationData);
handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config));
response = "New custom location added to the config.";
return true;
default:
response = "Incorrect command, use: \nlobby addloc room\nlobby addloc static";
return false;
}
}


}
}
72 changes: 72 additions & 0 deletions Lobby/Command/ControlCommands/RemoveLocationCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using CommandSystem;
using Lobby.Extensions;
using PluginAPI.Core;
using System;

namespace Lobby.Command.ControlCommands
{
public class RemoveLocationCommand : ICommand
{
public string Command => "removeloc";

public string[] Aliases { get; } = { "remloc", "rloc", "rl" };

public string Description => "Remove a new lobby location.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player playerSender = Player.Get(sender);

if (!playerSender.IsAllowCommand())
{
response = $"You don't have permission to use this command!";
return false;
}

if (arguments.Count != 2)
{
response = "Incorrect command, use: \nlobby removeloc room (index)\nlobby removeloc static (index)";
return false;
}

if (!Int32.TryParse(arguments.At(1), out int index))
{
response = "The index must be a number!";
return false;
}

var handler = PluginHandler.Get(Lobby.Instance);

switch (arguments.At(0))
{
case "room":
if (Lobby.Config.CustomRoomLocations == null || Lobby.Config.CustomRoomLocations?.Count - 1 < index)
{
response = $"Custom location at index {index} was not found.";
return false;
}

Lobby.Config.CustomRoomLocations.RemoveAt(index);

handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config));
response = $"Custom location at index {index} has been removed.";
return true;
case "static":
if (Lobby.Config.CustomLocations == null || Lobby.Config.CustomLocations?.Count - 1 < index)
{
response = $"Custom location at index {index} was not found.";
return false;
}

Lobby.Config.CustomLocations.RemoveAt(index);

handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config));
response = $"Custom location at index {index} has been removed.";
return true;
default:
response = "Incorrect command, use: \nlobby removeloc room (index)\nlobby removeloc static (index)";
return false;
}
}
}
}
48 changes: 48 additions & 0 deletions Lobby/Command/DebugCommands/GetLocalDataCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using CommandSystem;
using Lobby.Extensions;
using PluginAPI.Core;
using System;
using UnityEngine;

namespace Lobby.Command.DebugCommands
{
public class GetLocalDataCommand : ICommand
{
public string Command => "getlocaldata";

public string[] Aliases { get; } = { "getlocdat", "getld", "gld" };

public string Description => "Shows the exact position and rotation in the room where the player is located.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player playerSender = Player.Get(sender);

if (!playerSender.IsAllowCommand())
{
response = $"You don't have permission to use this command!";
return false;
}

if (arguments.Count > 0)
{
response = "Incorrect command, use: \nlobby getlocalpos";
return false;
}

if (playerSender.Room == null)
{
response = "An error occurred when getting the room you are in.";
return false;
}

GameObject Point = new GameObject("Point");
Point.transform.position = playerSender.Position;
Point.transform.eulerAngles = playerSender.Rotation;
Point.transform.SetParent(playerSender.Room.transform);

response = $"Room name {playerSender.Room.name}; Local position: {Point.transform.localPosition.ToString()}; Local Rotation: {Point.transform.localEulerAngles.ToString()}.";
return true;
}
}
}
85 changes: 85 additions & 0 deletions Lobby/Command/DebugCommands/LocationListCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using CommandSystem;
using Lobby.Extensions;
using PluginAPI.Core;
using System;

namespace Lobby.Command.DebugCommands
{
public class LocationListCommand : ICommand
{
public string Command => "loclist";

public string[] Aliases { get; } = { "llist", "ll" };

public string Description => "Display a list of custom locations in the console.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player playerSender = Player.Get(sender);

if (!playerSender.IsAllowCommand())
{
response = $"You don't have permission to use this command!";
return false;
}

if (arguments.Count != 1)
{
response = "Incorrect command, use: \nlobby loclist all\nlobby loclist room\nlobby loclist static";
return false;
}

string resString = string.Empty;

switch (arguments.At(0))
{
case "all":
resString += "Room locations:\n";
if (Lobby.Config.CustomRoomLocations?.Count > 0)
{
foreach (var item in Lobby.Config.CustomRoomLocations)
resString += item.RoomNameType + " " + $"({item.OffsetX}, {item.OffsetY}, {item.OffsetZ})\n";
}

resString += "\nStatic locations:\n";
if (Lobby.Config.CustomLocations?.Count > 0)
{
foreach (var item in Lobby.Config.CustomLocations)
resString += $"({item.PositionX}, {item.PositionY}, {item.PositionZ})\n";
}

response = resString;
return true;
case "room":
resString += "Room locations:\n";
if (Lobby.Config.CustomRoomLocations?.Count > 0)
{
for (int i = 0; i < Lobby.Config.CustomRoomLocations.Count; i++)
{
CustomRoomLocationData data = Lobby.Config.CustomRoomLocations[i];
resString += $"({i}) " + data.RoomNameType + " " + $"({data.OffsetX}, {data.OffsetY}, {data.OffsetZ})\n";
}
}

response = resString;
return true;
case "static":
resString += "Static locations:\n";
if (Lobby.Config.CustomLocations?.Count > 0)
{
for (int i = 0; i < Lobby.Config.CustomLocations.Count; i++)
{
CustomLocationData data = Lobby.Config.CustomLocations[i];
resString += $"({i}) " + $"({data.PositionX}, {data.PositionY}, {data.PositionZ})\n";
}
}

response = resString;
return true;
default:
response = "Incorrect command, use: \nlobby loclist all\nlobby loclist room\nlobby loclist static";
return false;
}
}
}
}
Loading

0 comments on commit a1484ac

Please sign in to comment.