Fixes alert category being the same but alert type changing to one without severity

Also adds alert type to the exceptions in AlertPrototype
This commit is contained in:
Vera Aguilera Puerto
2021-01-02 20:51:02 +01:00
parent 85add420b0
commit 74fed841a3
2 changed files with 8 additions and 5 deletions

View File

@@ -123,7 +123,7 @@ namespace Content.Shared.Alert
{
if (!SupportsSeverity && severity != null)
{
throw new InvalidOperationException("This alert does not support severity");
throw new InvalidOperationException($"This alert ({AlertKey}) does not support severity");
}
if (!SupportsSeverity)
@@ -131,24 +131,24 @@ namespace Content.Shared.Alert
if (severity == null)
{
throw new ArgumentException("No severity specified but this alert has severity.", nameof(severity));
throw new ArgumentException($"No severity specified but this alert ({AlertKey}) has severity.", nameof(severity));
}
if (severity < MinSeverity)
{
throw new ArgumentOutOfRangeException(nameof(severity), "Severity below minimum severity.");
throw new ArgumentOutOfRangeException(nameof(severity), $"Severity below minimum severity in {AlertKey}.");
}
if (severity > MaxSeverity)
{
throw new ArgumentOutOfRangeException(nameof(severity), "Severity above maximum severity.");
throw new ArgumentOutOfRangeException(nameof(severity), $"Severity above maximum severity in {AlertKey}.");
}
var severityText = severity.Value.ToString(CultureInfo.InvariantCulture);
switch (Icon)
{
case SpriteSpecifier.EntityPrototype entityPrototype:
throw new InvalidOperationException("Severity not supported for EntityPrototype icon");
throw new InvalidOperationException($"Severity not supported for EntityPrototype icon in {AlertKey}");
case SpriteSpecifier.Rsi rsi:
return new SpriteSpecifier.Rsi(rsi.RsiPath, rsi.RsiState + severityText);
case SpriteSpecifier.Texture texture:

View File

@@ -93,6 +93,9 @@ namespace Content.Shared.GameObjects.Components.Mobs
return;
}
// In the case we're changing the alert type but not the category, we need to remove it first.
_alerts.Remove(alert.AlertKey);
_alerts[alert.AlertKey] = new AlertState
{Cooldown = cooldown, Severity = severity};