diff --git a/Nuclei/Events/PlayerEvents.cs b/Nuclei/Events/PlayerEvents.cs index dae0291..b86cbf0 100644 --- a/Nuclei/Events/PlayerEvents.cs +++ b/Nuclei/Events/PlayerEvents.cs @@ -1,5 +1,6 @@ using System; using NuclearOption.Networking; +using Nuclei.Features; namespace Nuclei.Events; @@ -16,6 +17,7 @@ public static class PlayerEvents internal static void OnPlayerJoined(Player e) { PlayerJoined?.Invoke(e); + if (NucleiConfig.RankCatchUp!.Value) RankCatchUpService.CatchUpPlayer(e); } /// diff --git a/Nuclei/Features/Commands/DefaultCommands/HelpCommand.cs b/Nuclei/Features/Commands/DefaultCommands/HelpCommand.cs index 120a54b..a263ef9 100644 --- a/Nuclei/Features/Commands/DefaultCommands/HelpCommand.cs +++ b/Nuclei/Features/Commands/DefaultCommands/HelpCommand.cs @@ -25,8 +25,13 @@ public override bool Execute(Player player, string[] args) if (args.Length == 0) { var accessibleCommands = CommandService.GetCommands().Where(c => c.PermissionLevel <= CommandService.GetPlayerPermissionLevel(player)).ToList(); - var commandNames = accessibleCommands.Select(c => c.Name).ToList(); - ChatService.SendPrivateChatMessage($"You have access to the following commands: {string.Join(", ", commandNames)}", player); + var commands = accessibleCommands.ToList(); + ChatService.SendPrivateChatMessage($"You have access to the following commands:", player); + ChatService.SendPrivateChatMessage($"(For more help, type {NucleiConfig.CommandPrefixChar}{Usage})", player); + foreach (var cmd in commands) + { + ChatService.SendPrivateChatMessage($"{cmd.Name} - {cmd.Description}", player); + } return true; } @@ -38,6 +43,7 @@ public override bool Execute(Player player, string[] args) } ChatService.SendPrivateChatMessage($"Command '{command.Name}': {command.Description}", player); + ChatService.SendPrivateChatMessage($"Usage: {command.Usage}", player); return true; } diff --git a/Nuclei/Features/NucleiConfig.cs b/Nuclei/Features/NucleiConfig.cs index 2860158..0c0938c 100644 --- a/Nuclei/Features/NucleiConfig.cs +++ b/Nuclei/Features/NucleiConfig.cs @@ -92,6 +92,8 @@ public static class NucleiConfig internal static ConfigEntry? ServerBroadcastName; internal const string DefaultServerBroadcastName = "[Nuclei]"; + internal static ConfigEntry? RankCatchUp; + internal const bool DefaultRankCatchUp = true; internal static List ModeratorsList => Moderators!.Value.Split(';').Where(m => !string.IsNullOrWhiteSpace(m)).ToList(); @@ -185,6 +187,9 @@ internal static void InitSettings(ConfigFile config) ServerBroadcastName = config.Bind(GeneralSection, "ServerBroadcastName", DefaultServerBroadcastName, "The name that appears in the chat when the server broadcasts a message."); Nuclei.Logger?.LogDebug($"ServerBroadcastName: {ServerBroadcastName}"); + + RankCatchUp = config.Bind(GeneralSection, "RankCatchUp", DefaultRankCatchUp, "Whether to enable the rank catch-up system, which gives players a rank and allocation boost based on how far into the mission they join."); + Nuclei.Logger?.LogDebug($"RankCatchUp: {RankCatchUp.Value}"); Nuclei.Logger?.LogDebug("Loaded settings!"); } diff --git a/Nuclei/Features/RankCatchUpService.cs b/Nuclei/Features/RankCatchUpService.cs new file mode 100644 index 0000000..b908387 --- /dev/null +++ b/Nuclei/Features/RankCatchUpService.cs @@ -0,0 +1,51 @@ +using NuclearOption.Networking; +using Nuclei.Helpers; +using UnityEngine; +namespace Nuclei.Features; + +public class RankCatchUpService +{ + public static void CatchUpPlayer(Player player) + { + if (player.GetAuthData().SaveData.Faction != null) + { + return; // Means that they already joined the server. No double-dipping! + } + var currentMissionTime = Time.timeSinceLevelLoad; + var maxMissionTime = Globals.DedicatedServerManagerInstance.CurrentMissionOption.MaxTime; + var percentComplete = (currentMissionTime / maxMissionTime) * 2; + + var rank = 0; + var allocation = 0f; + + if (percentComplete < .20) return; + else if (percentComplete >= .80) + { + rank = 5; + allocation = 400f; + } + else if (percentComplete >= .60) + { + rank = 4; + allocation = 350f; + } + else if (percentComplete >= .40) + { + rank = 3; + allocation = 300f; + } + else if (percentComplete >= .40) + { + rank = 2; + allocation = 250f; + } + else if (percentComplete >= .20) + { + rank = 1; + allocation = 200f; + } + player.SetRank(rank, false); + player.SetAllocation(player.Allocation + allocation); + ChatService.SendPrivateChatMessage($"Late join - You have been promoted to Rank {rank} with +${allocation}m", player); + } +} \ No newline at end of file