Skip to content

Commit f163006

Browse files
authored
Fixed a bunch of issues (#134)
1 parent bce7f83 commit f163006

File tree

7 files changed

+72
-29
lines changed

7 files changed

+72
-29
lines changed

Common Utilities/Config.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ public class Config : IConfig
1717
[Description("Whether or not debug messages should be shown.")]
1818
public bool Debug { get; set; } = false;
1919

20-
[Description("The SCP Roles able to use V to talk to humans.")]
21-
public List<RoleTypeId> ScpSpeech { get; set; } = new()
22-
{
23-
RoleTypeId.Scp049,
24-
};
25-
2620
[Description("Whether or not MTF/CI can 'escape' while disarmed to switch teams.")]
2721
public bool DisarmSwitchTeams { get; set; } = true;
2822

2923
[Description("Whether or not disarmed people will be prevented from interacting with doors/elevators.")]
3024
public bool RestrictiveDisarming { get; set; } = true;
3125

3226
[Description("The text displayed at the timed interval specified below.")]
33-
public string TimedBroadcast { get; set; } = "<color=lime>This server is running </color><color=red>EXILED Common-Utilities</color><color=lime>, enjoy your stay!</color>";
27+
public string TimedBroadcast { get; set; } = "<color=#bfff00>This server is running </color><color=red>EXILED Common-Utilities</color><color=lime>, enjoy your stay!</color>";
3428

3529
[Description("The time each timed broadcast will be displayed.")]
3630
public ushort TimedBroadcastDuration { get; set; } = 5;
@@ -165,7 +159,7 @@ public class Config : IConfig
165159
},
166160
};
167161

168-
[Description("The list of 914 teleport settings. Note that if you set \"zone\" to anything other than Unspecified, it will always select a random room from that zone, instead of the room type defined.")]
162+
[Description("The list of 914 teleport settings. Note that if you set \"zone\" to anything other than Unspecified, it will always select a random room from that zone that isn't in the ignoredRooms list, instead of the room type defined.")]
169163
public Dictionary<Scp914KnobSetting, List<Scp914TeleportChance>> Scp914TeleportChances { get; set; } = new()
170164
{
171165
{
@@ -176,6 +170,14 @@ public class Config : IConfig
176170
Room = RoomType.LczClassDSpawn,
177171
Chance = 100,
178172
},
173+
new()
174+
{
175+
Zone = ZoneType.LightContainment,
176+
IgnoredRooms = new()
177+
{
178+
RoomType.Lcz173,
179+
},
180+
},
179181
}
180182
},
181183
};

Common Utilities/ConfigObjects/PlayerUpgradeChance.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ public class PlayerUpgradeChance
1212

1313
public bool KeepInventory { get; set; } = true;
1414

15-
public void Deconstruct(out RoleTypeId old, out string newRole, out double i, out bool keepInventory)
15+
public bool KeepHealth { get; set; } = true;
16+
17+
public void Deconstruct(out RoleTypeId old, out string newRole, out double i, out bool keepInventory, out bool keepHealth)
1618
{
1719
old = Original;
1820
newRole = New;
1921
i = Chance;
2022
keepInventory = KeepInventory;
23+
keepHealth = KeepHealth;
2124
}
2225
}
2326
}

Common Utilities/ConfigObjects/Scp914TeleportChance.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Collections.Generic;
2+
13
namespace Common_Utilities.ConfigObjects
24
{
35
using Exiled.API.Enums;
@@ -6,6 +8,8 @@ namespace Common_Utilities.ConfigObjects
68
public class Scp914TeleportChance
79
{
810
public ZoneType Zone { get; set; } = ZoneType.Unspecified;
11+
12+
public List<RoomType> IgnoredRooms { get; set; }
913

1014
public RoomType Room { get; set; }
1115

@@ -15,9 +19,10 @@ public class Scp914TeleportChance
1519

1620
public float Damage { get; set; } = 0f;
1721

18-
public void Deconstruct(out RoomType room, out Vector3 offset, out double chance, out float damage, out ZoneType zone)
22+
public void Deconstruct(out RoomType room, out List<RoomType> ignoredRooms, out Vector3 offset, out double chance, out float damage, out ZoneType zone)
1923
{
2024
room = Room;
25+
ignoredRooms = IgnoredRooms;
2126
offset = Offset;
2227
chance = Chance;
2328
damage = Damage;

Common Utilities/EventHandlers/MapHandlers.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Exiled.API.Extensions;
2+
using Exiled.API.Features.Items;
3+
14
namespace Common_Utilities.EventHandlers
25
{
36
using System;
@@ -86,11 +89,11 @@ public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev)
8689

8790
public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
8891
{
89-
if (plugin.Config.Scp914ClassChanges != null && plugin.Config.Scp914ClassChanges.ContainsKey(ev.KnobSetting))
92+
if (plugin.Config.Scp914ClassChanges != null && plugin.Config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change))
9093
{
91-
IEnumerable<PlayerUpgradeChance> playerUpgradeChance = plugin.Config.Scp914ClassChanges[ev.KnobSetting].Where(x => x.Original == ev.Player.Role);
94+
IEnumerable<PlayerUpgradeChance> playerUpgradeChance = change.Where(x => x.Original == ev.Player.Role);
9295

93-
foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory) in playerUpgradeChance)
96+
foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance)
9497
{
9598
double r;
9699
if (plugin.Config.AdditiveProbabilities)
@@ -101,6 +104,10 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
101104
Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role})is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {r <= chance} ({r})");
102105
if (r <= chance)
103106
{
107+
float originalHealth = ev.Player.Health;
108+
var originalItems = ev.Player.Items;
109+
var originalAmmo = ev.Player.Ammo;
110+
104111
if (Enum.TryParse(destinationRole, true, out RoleTypeId roleType))
105112
{
106113
ev.Player.Role.Set(roleType, SpawnReason.Respawn, RoleSpawnFlags.None);
@@ -114,6 +121,24 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
114121
}
115122
}
116123

124+
if (keepHealth)
125+
{
126+
ev.Player.Health = originalHealth;
127+
}
128+
129+
if (keepInventory)
130+
{
131+
foreach (var item in originalItems)
132+
{
133+
ev.Player.AddItem(item);
134+
}
135+
136+
foreach (var kvp in originalAmmo)
137+
{
138+
ev.Player.SetAmmo(kvp.Key.GetAmmoType(), kvp.Value);
139+
}
140+
}
141+
117142
ev.Player.Position = ev.OutputPosition;
118143
break;
119144
}
@@ -150,7 +175,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
150175
{
151176
IEnumerable<Scp914TeleportChance> scp914TeleportChances = plugin.Config.Scp914TeleportChances[ev.KnobSetting];
152177

153-
foreach ((RoomType roomType, Vector3 offset, double chance, float damage, ZoneType zone) in plugin.Config.Scp914TeleportChances[ev.KnobSetting])
178+
foreach ((RoomType roomType, List<RoomType> ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in plugin.Config.Scp914TeleportChances[ev.KnobSetting])
154179
{
155180
double r;
156181
if (plugin.Config.AdditiveProbabilities)
@@ -163,7 +188,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
163188
{
164189
if (zone != ZoneType.Unspecified)
165190
{
166-
ev.OutputPosition = Room.Random(zone).Position + ((Vector3.up * 1.5f) + offset);
191+
ev.OutputPosition = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset);
167192
if (damage > 0f)
168193
{
169194
float amount = ev.Player.MaxHealth * damage;

Common Utilities/EventHandlers/PlayerHandlers.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ public void OnSpawned(SpawnedEventArgs ev)
9292

9393
public void OnPlayerDied(DiedEventArgs ev)
9494
{
95-
if (ev.Player != null && plugin.Config.HealthOnKill.ContainsKey(ev.Player.Role))
95+
if (ev.Attacker != null && plugin.Config.HealthOnKill.ContainsKey(ev.Attacker.Role))
9696
{
97-
if (ev.Player.Health + plugin.Config.HealthOnKill[ev.Player.Role] <= ev.Player.MaxHealth)
98-
ev.Player.Health += plugin.Config.HealthOnKill[ev.Player.Role];
99-
else
100-
ev.Player.Health = ev.Player.MaxHealth;
97+
ev.Attacker.Heal(plugin.Config.HealthOnKill[ev.Attacker.Role]);
10198
}
10299
}
103100

Common Utilities/EventHandlers/ServerHandlers.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ public IEnumerator<float> AfkCheck()
150150

151151
if (player.Role.IsDead || player.IsGodModeEnabled || player.IsNoclipPermitted || player.Role is FpcRole { IsGrounded: false } || player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity) || plugin.Config.AfkIgnoredRoles.Contains(player.Role.Type))
152152
{
153-
#pragma warning disable SA1013 // Closing braces should be spaced correctly
153+
#pragma warning disable SA1013
154154
Log.Debug($"Player {player.Nickname} ({player.Role.Type}) is not a checkable player. NoClip: {player.IsNoclipPermitted} GodMode: {player.IsGodModeEnabled} IsNotGrounded: {player.Role is FpcRole { IsGrounded: false }} AFKImunity: {player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity)}");
155-
#pragma warning restore SA1013 // Closing braces should be spaced correctly
156155
continue;
156+
#pragma warning restore SA1013
157157
}
158158

159159
if ((plugin.AfkDict[player].Item2 - player.Position).sqrMagnitude > 2)
@@ -193,6 +193,9 @@ public void OnWarheadStarting(StartingEventArgs _)
193193

194194
public void OnWarheadStopping(StoppingEventArgs _)
195195
{
196+
if (Warhead.IsLocked)
197+
return;
198+
196199
foreach (Room room in Room.List)
197200
room.ResetColor();
198201
}

Common Utilities/Main.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,17 @@ public void DebugConfig()
178178
if (Config.Scp914ClassChanges != null)
179179
{
180180
Log.Debug($"{Config.Scp914ClassChanges.Count}");
181-
foreach (KeyValuePair<Scp914KnobSetting, List<PlayerUpgradeChance>> upgrade in Config
182-
.Scp914ClassChanges)
181+
foreach (KeyValuePair<Scp914KnobSetting, List<PlayerUpgradeChance>> upgrade in Config.Scp914ClassChanges)
183182
{
184-
foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory) in upgrade.Value)
185-
Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory}");
183+
foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value)
184+
Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory} keepHealth: {keepHealth}");
186185
}
187186
}
188187

189188
if (Config.Scp914EffectChances != null)
190189
{
191190
Log.Debug($"{Config.Scp914EffectChances.Count}");
192-
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914EffectChance>> upgrade in Config
193-
.Scp914EffectChances)
191+
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914EffectChance>> upgrade in Config.Scp914EffectChances)
194192
{
195193
foreach ((EffectType effect, double chance, float duration) in upgrade.Value)
196194
Log.Debug($"914 Effect Config: {upgrade.Key}: {effect} + {duration} - {chance}");
@@ -202,8 +200,18 @@ public void DebugConfig()
202200
Log.Debug($"{Config.Scp914TeleportChances.Count}");
203201
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914TeleportChance>> upgrade in Config.Scp914TeleportChances)
204202
{
205-
foreach ((RoomType room, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value)
203+
foreach ((RoomType room, List<RoomType> ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value)
204+
{
206205
Log.Debug($"914 Teleport Config: {upgrade.Key}: {room}/{zone} + {offset} - {chance} [{damage}]");
206+
Log.Debug("Ignored rooms:");
207+
if (ignoredRooms != null)
208+
{
209+
foreach (RoomType roomType in ignoredRooms)
210+
{
211+
Log.Debug(roomType);
212+
}
213+
}
214+
}
207215
}
208216
}
209217
}

0 commit comments

Comments
 (0)