Skip to content

Commit

Permalink
Fixed a bunch of issues (Exiled-Team#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikihero authored May 30, 2024
1 parent bce7f83 commit f163006
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 29 deletions.
18 changes: 10 additions & 8 deletions Common Utilities/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ public class Config : IConfig
[Description("Whether or not debug messages should be shown.")]
public bool Debug { get; set; } = false;

[Description("The SCP Roles able to use V to talk to humans.")]
public List<RoleTypeId> ScpSpeech { get; set; } = new()
{
RoleTypeId.Scp049,
};

[Description("Whether or not MTF/CI can 'escape' while disarmed to switch teams.")]
public bool DisarmSwitchTeams { get; set; } = true;

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

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

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

[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.")]
[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.")]
public Dictionary<Scp914KnobSetting, List<Scp914TeleportChance>> Scp914TeleportChances { get; set; } = new()
{
{
Expand All @@ -176,6 +170,14 @@ public class Config : IConfig
Room = RoomType.LczClassDSpawn,
Chance = 100,
},
new()
{
Zone = ZoneType.LightContainment,
IgnoredRooms = new()
{
RoomType.Lcz173,
},
},
}
},
};
Expand Down
5 changes: 4 additions & 1 deletion Common Utilities/ConfigObjects/PlayerUpgradeChance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public class PlayerUpgradeChance

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

public void Deconstruct(out RoleTypeId old, out string newRole, out double i, out bool keepInventory)
public bool KeepHealth { get; set; } = true;

public void Deconstruct(out RoleTypeId old, out string newRole, out double i, out bool keepInventory, out bool keepHealth)
{
old = Original;
newRole = New;
i = Chance;
keepInventory = KeepInventory;
keepHealth = KeepHealth;
}
}
}
7 changes: 6 additions & 1 deletion Common Utilities/ConfigObjects/Scp914TeleportChance.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace Common_Utilities.ConfigObjects
{
using Exiled.API.Enums;
Expand All @@ -6,6 +8,8 @@ namespace Common_Utilities.ConfigObjects
public class Scp914TeleportChance
{
public ZoneType Zone { get; set; } = ZoneType.Unspecified;

public List<RoomType> IgnoredRooms { get; set; }

public RoomType Room { get; set; }

Expand All @@ -15,9 +19,10 @@ public class Scp914TeleportChance

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

public void Deconstruct(out RoomType room, out Vector3 offset, out double chance, out float damage, out ZoneType zone)
public void Deconstruct(out RoomType room, out List<RoomType> ignoredRooms, out Vector3 offset, out double chance, out float damage, out ZoneType zone)
{
room = Room;
ignoredRooms = IgnoredRooms;
offset = Offset;
chance = Chance;
damage = Damage;
Expand Down
35 changes: 30 additions & 5 deletions Common Utilities/EventHandlers/MapHandlers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Exiled.API.Extensions;
using Exiled.API.Features.Items;

namespace Common_Utilities.EventHandlers
{
using System;
Expand Down Expand Up @@ -86,11 +89,11 @@ public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev)

public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
{
if (plugin.Config.Scp914ClassChanges != null && plugin.Config.Scp914ClassChanges.ContainsKey(ev.KnobSetting))
if (plugin.Config.Scp914ClassChanges != null && plugin.Config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change))
{
IEnumerable<PlayerUpgradeChance> playerUpgradeChance = plugin.Config.Scp914ClassChanges[ev.KnobSetting].Where(x => x.Original == ev.Player.Role);
IEnumerable<PlayerUpgradeChance> playerUpgradeChance = change.Where(x => x.Original == ev.Player.Role);

foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory) in playerUpgradeChance)
foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance)
{
double r;
if (plugin.Config.AdditiveProbabilities)
Expand All @@ -101,6 +104,10 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
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})");
if (r <= chance)
{
float originalHealth = ev.Player.Health;
var originalItems = ev.Player.Items;
var originalAmmo = ev.Player.Ammo;

if (Enum.TryParse(destinationRole, true, out RoleTypeId roleType))
{
ev.Player.Role.Set(roleType, SpawnReason.Respawn, RoleSpawnFlags.None);
Expand All @@ -114,6 +121,24 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
}
}

if (keepHealth)
{
ev.Player.Health = originalHealth;
}

if (keepInventory)
{
foreach (var item in originalItems)
{
ev.Player.AddItem(item);
}

foreach (var kvp in originalAmmo)
{
ev.Player.SetAmmo(kvp.Key.GetAmmoType(), kvp.Value);
}
}

ev.Player.Position = ev.OutputPosition;
break;
}
Expand Down Expand Up @@ -150,7 +175,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
{
IEnumerable<Scp914TeleportChance> scp914TeleportChances = plugin.Config.Scp914TeleportChances[ev.KnobSetting];

foreach ((RoomType roomType, Vector3 offset, double chance, float damage, ZoneType zone) in plugin.Config.Scp914TeleportChances[ev.KnobSetting])
foreach ((RoomType roomType, List<RoomType> ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in plugin.Config.Scp914TeleportChances[ev.KnobSetting])
{
double r;
if (plugin.Config.AdditiveProbabilities)
Expand All @@ -163,7 +188,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev)
{
if (zone != ZoneType.Unspecified)
{
ev.OutputPosition = Room.Random(zone).Position + ((Vector3.up * 1.5f) + offset);
ev.OutputPosition = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset);
if (damage > 0f)
{
float amount = ev.Player.MaxHealth * damage;
Expand Down
7 changes: 2 additions & 5 deletions Common Utilities/EventHandlers/PlayerHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ public void OnSpawned(SpawnedEventArgs ev)

public void OnPlayerDied(DiedEventArgs ev)
{
if (ev.Player != null && plugin.Config.HealthOnKill.ContainsKey(ev.Player.Role))
if (ev.Attacker != null && plugin.Config.HealthOnKill.ContainsKey(ev.Attacker.Role))
{
if (ev.Player.Health + plugin.Config.HealthOnKill[ev.Player.Role] <= ev.Player.MaxHealth)
ev.Player.Health += plugin.Config.HealthOnKill[ev.Player.Role];
else
ev.Player.Health = ev.Player.MaxHealth;
ev.Attacker.Heal(plugin.Config.HealthOnKill[ev.Attacker.Role]);
}
}

Expand Down
7 changes: 5 additions & 2 deletions Common Utilities/EventHandlers/ServerHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public IEnumerator<float> AfkCheck()

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))
{
#pragma warning disable SA1013 // Closing braces should be spaced correctly
#pragma warning disable SA1013
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)}");
#pragma warning restore SA1013 // Closing braces should be spaced correctly
continue;
#pragma warning restore SA1013
}

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

public void OnWarheadStopping(StoppingEventArgs _)
{
if (Warhead.IsLocked)
return;

foreach (Room room in Room.List)
room.ResetColor();
}
Expand Down
22 changes: 15 additions & 7 deletions Common Utilities/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,17 @@ public void DebugConfig()
if (Config.Scp914ClassChanges != null)
{
Log.Debug($"{Config.Scp914ClassChanges.Count}");
foreach (KeyValuePair<Scp914KnobSetting, List<PlayerUpgradeChance>> upgrade in Config
.Scp914ClassChanges)
foreach (KeyValuePair<Scp914KnobSetting, List<PlayerUpgradeChance>> upgrade in Config.Scp914ClassChanges)
{
foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory) in upgrade.Value)
Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory}");
foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value)
Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory} keepHealth: {keepHealth}");
}
}

if (Config.Scp914EffectChances != null)
{
Log.Debug($"{Config.Scp914EffectChances.Count}");
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914EffectChance>> upgrade in Config
.Scp914EffectChances)
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914EffectChance>> upgrade in Config.Scp914EffectChances)
{
foreach ((EffectType effect, double chance, float duration) in upgrade.Value)
Log.Debug($"914 Effect Config: {upgrade.Key}: {effect} + {duration} - {chance}");
Expand All @@ -202,8 +200,18 @@ public void DebugConfig()
Log.Debug($"{Config.Scp914TeleportChances.Count}");
foreach (KeyValuePair<Scp914KnobSetting, List<Scp914TeleportChance>> upgrade in Config.Scp914TeleportChances)
{
foreach ((RoomType room, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value)
foreach ((RoomType room, List<RoomType> ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value)
{
Log.Debug($"914 Teleport Config: {upgrade.Key}: {room}/{zone} + {offset} - {chance} [{damage}]");
Log.Debug("Ignored rooms:");
if (ignoredRooms != null)
{
foreach (RoomType roomType in ignoredRooms)
{
Log.Debug(roomType);
}
}
}
}
}
}
Expand Down

0 comments on commit f163006

Please sign in to comment.