Phase 1: Extract Constants.cs and CommandRouter.cs
- Extract magic numbers (timer intervals, message type IDs, property keys) into Constants.cs - Replace ~600-line HandleMmCommand switch with dictionary-based CommandRouter - All /mm commands preserved with same behavior, now registered via lambdas - PluginCore.cs and CharacterStats.cs updated to use named constants Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9e9a94f159
commit
4845a67c1f
5 changed files with 585 additions and 516 deletions
|
|
@ -134,9 +134,9 @@ namespace MosswartMassacre
|
|||
long key = tmpStruct.Value<Int64>("key");
|
||||
long value = tmpStruct.Value<Int64>("value");
|
||||
|
||||
if (key == 6) // AvailableLuminance
|
||||
if (key == Constants.AvailableLuminanceKey)
|
||||
luminanceEarned = value;
|
||||
else if (key == 7) // MaximumLuminance
|
||||
else if (key == Constants.MaximumLuminanceKey)
|
||||
luminanceTotal = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -162,9 +162,9 @@ namespace MosswartMassacre
|
|||
int key = BitConverter.ToInt32(raw, 5);
|
||||
long value = BitConverter.ToInt64(raw, 9);
|
||||
|
||||
if (key == 6) // AvailableLuminance
|
||||
if (key == Constants.AvailableLuminanceKey)
|
||||
luminanceEarned = value;
|
||||
else if (key == 7) // MaximumLuminance
|
||||
else if (key == Constants.MaximumLuminanceKey)
|
||||
luminanceTotal = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
67
MosswartMassacre/CommandRouter.cs
Normal file
67
MosswartMassacre/CommandRouter.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MosswartMassacre
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary-based /mm command dispatcher. Commands are registered with descriptions
|
||||
/// and routed by name lookup instead of a giant switch statement.
|
||||
/// </summary>
|
||||
internal class CommandRouter
|
||||
{
|
||||
private readonly Dictionary<string, (Action<string[]> handler, string description)> _commands
|
||||
= new Dictionary<string, (Action<string[]>, string)>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Register a command with its handler and help description.
|
||||
/// </summary>
|
||||
internal void Register(string name, Action<string[]> handler, string description)
|
||||
{
|
||||
_commands[name] = (handler, description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatch a raw /mm command string. Returns false if the command was not found.
|
||||
/// </summary>
|
||||
internal bool Dispatch(string rawText)
|
||||
{
|
||||
string[] args = rawText.Substring(3).Trim().Split(' ');
|
||||
|
||||
if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
|
||||
{
|
||||
PluginCore.WriteToChat("Usage: /mm <command>. Try /mm help");
|
||||
return true;
|
||||
}
|
||||
|
||||
string subCommand = args[0].ToLower();
|
||||
|
||||
if (subCommand == "help")
|
||||
{
|
||||
PrintHelp();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_commands.TryGetValue(subCommand, out var entry))
|
||||
{
|
||||
entry.handler(args);
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginCore.WriteToChat($"Unknown /mm command: {subCommand}. Try /mm help");
|
||||
return false;
|
||||
}
|
||||
|
||||
private void PrintHelp()
|
||||
{
|
||||
PluginCore.WriteToChat("Mosswart Massacre Commands:");
|
||||
foreach (var kvp in _commands)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(kvp.Value.description))
|
||||
{
|
||||
PluginCore.WriteToChat($"/mm {kvp.Key,-18} - {kvp.Value.description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
MosswartMassacre/Constants.cs
Normal file
30
MosswartMassacre/Constants.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
namespace MosswartMassacre
|
||||
{
|
||||
/// <summary>
|
||||
/// Centralized constants for timer intervals, message type IDs, and property keys.
|
||||
/// </summary>
|
||||
internal static class Constants
|
||||
{
|
||||
// Timer intervals (milliseconds)
|
||||
internal const int StatsUpdateIntervalMs = 1000;
|
||||
internal const int VitalsUpdateIntervalMs = 5000;
|
||||
internal const int CommandProcessIntervalMs = 10;
|
||||
internal const int QuestStreamingIntervalMs = 30000;
|
||||
internal const int CharacterStatsIntervalMs = 600000; // 10 minutes
|
||||
internal const int LoginDelayMs = 5000;
|
||||
|
||||
// Network message types
|
||||
internal const int GameEventMessageType = 0xF7B0;
|
||||
internal const int PrivateUpdatePropertyInt64 = 0x02CF;
|
||||
|
||||
// Game event IDs (sub-events within 0xF7B0)
|
||||
internal const int AllegianceInfoEvent = 0x0020;
|
||||
internal const int LoginCharacterEvent = 0x0013;
|
||||
internal const int TitlesListEvent = 0x0029;
|
||||
internal const int SetTitleEvent = 0x002b;
|
||||
|
||||
// Int64 property keys
|
||||
internal const int AvailableLuminanceKey = 6;
|
||||
internal const int MaximumLuminanceKey = 7;
|
||||
}
|
||||
}
|
||||
|
|
@ -304,6 +304,8 @@
|
|||
<Compile Include="..\Shared\VCS_Connector.cs">
|
||||
<Link>Shared\VCS_Connector.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CommandRouter.cs" />
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="ClientTelemetry.cs" />
|
||||
<Compile Include="DecalHarmonyClean.cs" />
|
||||
<Compile Include="FlagTrackerData.cs" />
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue