Skip to content

Commit 3e20426

Browse files
committed
Fixed UCR
1 parent f36c775 commit 3e20426

3 files changed

Lines changed: 44 additions & 21 deletions

File tree

UncomplicatedCustomEscapeZones/Events/EventHandler.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UncomplicatedEscapeZones.Interfaces;
1010
using UncomplicatedEscapeZones.Intergrations;
1111
using UncomplicatedEscapeZones.Managers;
12+
using UnityEngine;
1213

1314
namespace UncomplicatedEscapeZones.Events;
1415

@@ -58,16 +59,29 @@ public override void OnPlayerEscaping(PlayerEscapingEventArgs ev)
5859
if (role is not RoleTypeId.None)
5960
{
6061
ev.NewRole = role;
61-
ev.IsAllowed = true;
6262
if (ev.EscapeScenario == Escape.EscapeScenarioType.None)
6363
ev.EscapeScenario = Escape.EscapeScenarioType.Custom;
64+
65+
if (UCR.TryGetSummonedCustomRole(ev.Player, out _))
66+
{
67+
ev.IsAllowed = false;
68+
ev.Player.ConnectionToClient.Send(new Escape.EscapeMessage
69+
{
70+
ScenarioId = (byte) ev.EscapeScenario,
71+
EscapeTime = (ushort) Mathf.CeilToInt(ev.Player.RoleBase.ActiveTime)
72+
});
73+
ev.Player.SetRole(ev.NewRole, RoleChangeReason.Escaped);
74+
return;
75+
}
76+
77+
ev.IsAllowed = true;
6478
LogManager.Debug($"Player {ev.Player.Nickname} will respawn as {role}!");
6579
}
6680
}
6781
else
6882
{
69-
LogManager.Debug($"Trying to find CustomRole with Id {newRoleValue.Key}");
70-
if (int.TryParse(newRoleValue.Key.ToString(), out int id) && UCR.TryGetCustomRole(id, out object _))
83+
LogManager.Debug($"Trying to find CustomRole with Id {newRoleValue.Value}");
84+
if (int.TryParse(newRoleValue.Value.ToString(), out int id) && UCR.TryGetCustomRole(id, out object _))
7185
{
7286
LogManager.Debug("Role found!");
7387
ev.IsAllowed = false;
@@ -79,12 +93,10 @@ public override void OnPlayerEscaping(PlayerEscapingEventArgs ev)
7993
UCR.GiveCustomRole(id, ev.Player);
8094
LogManager.Debug(
8195
$"Successfully called method SpawnManager::SummonCustomSubclass(<...>) for player {ev.Player.Nickname}!");
96+
return;
8297
}
83-
else
84-
{
85-
LogManager.Debug(
86-
"Canceled call to method SpawnManager::SummonCustomSubclass(<...>) due to the presence of the player inside the Escape::Bucket! - Event already fired!");
87-
}
98+
LogManager.Debug(
99+
"Canceled call to method SpawnManager::SummonCustomSubclass(<...>) due to the presence of the player inside the Escape::Bucket! - Event already fired!");
88100
}
89101
}
90102
}

UncomplicatedCustomEscapeZones/Managers/EscapeManager.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace UncomplicatedEscapeZones.Managers;
1212

13-
public class EscapeManager
13+
public static class EscapeManager
1414
{
1515
public static KeyValuePair<bool, object?>? ParseEscapeRole(
1616
Dictionary<string, List<Dictionary<string, string>>> roleAfterEscape, Player player)
@@ -103,22 +103,33 @@ public class EscapeManager
103103

104104
LogManager.Debug($"Parsing escape condition: {kvp.Key} -> {kvp.Value}");
105105

106-
switch (elements[2])
106+
switch (elements[2].ToLowerInvariant())
107107
{
108-
case "InternalFaction" or "IF" when Enum.TryParse(elements[3], out Faction faction):
109-
asCuffedByInternalFaction.TryAdd(faction, data);
108+
case "internalfaction" or "if":
109+
if (Enum.TryParse(elements[3], true, out Faction faction))
110+
asCuffedByInternalFaction.TryAdd(faction, data);
111+
else
112+
LogManager.Warn($"Failed to parse faction '{elements[3]}' for escape condition '{kvp.Key}'.");
110113
break;
111-
case "InternalTeam" or "IT" when Enum.TryParse(elements[3], out Team team):
112-
asCuffedByInternalTeam.TryAdd(team, data);
114+
case "internalteam" or "it":
115+
if (Enum.TryParse(elements[3], true, out Team team))
116+
asCuffedByInternalTeam.TryAdd(team, data);
117+
else
118+
LogManager.Warn($"Failed to parse team '{elements[3]}' for escape condition '{kvp.Key}'.");
113119
break;
114-
case "InternalRole" or "IR" when Enum.TryParse(elements[3], out RoleTypeId id):
115-
asCuffedByInternalRole.TryAdd(id, data);
120+
case "internalrole" or "ir":
121+
if (Enum.TryParse(elements[3], true, out RoleTypeId id))
122+
asCuffedByInternalRole.TryAdd(id, data);
123+
else
124+
LogManager.Warn($"Failed to parse role '{elements[3]}' for escape condition '{kvp.Key}'.");
116125
break;
117-
case "CustomRole" or "CR"
118-
when int.TryParse(elements[3], out int id) && UCR.TryGetCustomRole(id, out _):
119-
asCuffedByCustomRole.TryAdd(id, data);
126+
case "customrole" or "cr":
127+
if (int.TryParse(elements[3], out int cid) && UCR.TryGetCustomRole(cid, out _))
128+
asCuffedByCustomRole.TryAdd(cid, data);
129+
else
130+
LogManager.Warn($"Failed to parse custom role id '{elements[3]}' for escape condition '{kvp.Key}'.");
120131
break;
121-
case "all" or "ALL":
132+
case "all":
122133
defaultCuffedValue = data;
123134
break;
124135
default:

UncomplicatedCustomEscapeZones/Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class Plugin : Plugin<Config>
2323
public override string Name => "UncomplicatedCustomEscapeZones";
2424
public override string Description => "Customize your SCP:SL server with Custom Escape Zones!";
2525
public override string Author => "MedveMarci & FoxWorn3365";
26-
public override Version Version => new(1, 1, 0, 0);
26+
public override Version Version => new(1, 2, 0, 0);
2727
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
2828
public override LoadPriority Priority => LoadPriority.Highest;
2929

0 commit comments

Comments
 (0)