## Summary Phase 3.1 of the message-interpolation optimization series. Fixes 9 of the 28 sites flagged in the Phase 2 audit (PR #2435): | File | Fix | |---|---| | `Commands/StaffAccess.cs:88,99` | Drop redundant `.ToString()` on enum holes | | `Commands/Handlers.cs:102` | `builder.ToString()` -> `builder.AsSpan()` | | `World Saves/SaveCommands.cs:71-75` | Merge 3 concatenated `$"..."` into one literal | | `Server/Items/Item.cs:4213` | Hoist nested ternary `$"..."` to if/else | | `Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs:140-150` | Convert switch expression to switch statement | | `Mobiles/Monsters/LBR/Jukas/JukaLord.cs:85` | Restructure `string.Format(toSay.RandomElement(), ...)` into switch | | `Misc/AttackMessage.cs:30-41` | Inline `AggressorFormat`/`AggressedFormat` constants | No functional changes. Each site emits identical text; the only difference is that the message string is now built into a pooled char buffer instead of being allocated as a `string` first.
72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace Server.Misc
|
|
{
|
|
public static class AttackMessage
|
|
{
|
|
private const int Hue = 0x22;
|
|
|
|
private static readonly TimeSpan Delay = TimeSpan.FromMinutes(1.0);
|
|
|
|
public static void Initialize()
|
|
{
|
|
EventSink.AggressiveAction += EventSink_AggressiveAction;
|
|
}
|
|
|
|
public static void EventSink_AggressiveAction(AggressiveActionEventArgs e)
|
|
{
|
|
var aggressor = e.Aggressor;
|
|
var aggressed = e.Aggressed;
|
|
|
|
if (!aggressor.Player || !aggressed.Player)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!CheckAggressions(aggressor, aggressed))
|
|
{
|
|
aggressor.LocalOverheadMessage(
|
|
MessageType.Regular,
|
|
Hue,
|
|
true,
|
|
$"You are attacking {aggressed.Name}!"
|
|
);
|
|
aggressed.LocalOverheadMessage(
|
|
MessageType.Regular,
|
|
Hue,
|
|
true,
|
|
$"{aggressor.Name} is attacking you!"
|
|
);
|
|
}
|
|
}
|
|
|
|
public static bool CheckAggressions(Mobile m1, Mobile m2)
|
|
{
|
|
var list = m1.Aggressors;
|
|
|
|
for (var i = 0; i < list.Count; ++i)
|
|
{
|
|
var info = list[i];
|
|
|
|
if (info.Attacker == m2 && Core.Now < info.LastCombatTime + Delay)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
list = m2.Aggressors;
|
|
|
|
for (var i = 0; i < list.Count; ++i)
|
|
{
|
|
var info = list[i];
|
|
|
|
if (info.Attacker == m1 && Core.Now < info.LastCombatTime + Delay)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|