Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Nuclei/Events/PlayerEvents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using NuclearOption.Networking;
using Nuclei.Features;

namespace Nuclei.Events;

Expand All @@ -16,6 +17,7 @@ public static class PlayerEvents
internal static void OnPlayerJoined(Player e)
{
PlayerJoined?.Invoke(e);
if (NucleiConfig.RankCatchUp!.Value) RankCatchUpService.CatchUpPlayer(e);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should never perform functionality in the events. Should instead subscribe to the event somewhere and trigger through that.

The event invocations should be isolated like that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you edit the file to show me? I'm unfamiliar with doing this myself

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd subscribe to the PlayerJoined event and run a method on that, see Nuclei.cs for an example of this.

}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions Nuclei/Features/Commands/DefaultCommands/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions Nuclei/Features/NucleiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static class NucleiConfig

internal static ConfigEntry<string>? ServerBroadcastName;
internal const string DefaultServerBroadcastName = "<color=#99182e>[Nuclei]</color>";
internal static ConfigEntry<bool>? RankCatchUp;
internal const bool DefaultRankCatchUp = true;

internal static List<string> ModeratorsList => Moderators!.Value.Split(';').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();

Expand Down Expand Up @@ -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!");
}
Expand Down
51 changes: 51 additions & 0 deletions Nuclei/Features/RankCatchUpService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}