Skip to content

Commit

Permalink
Fix scp079
Browse files Browse the repository at this point in the history
Signed-off-by: FakeMan2332 <[email protected]>
  • Loading branch information
fakeman2332 committed Nov 22, 2023
1 parent 96e0575 commit 941403e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 118 deletions.
32 changes: 29 additions & 3 deletions MERRoomReplacement/Api/RoomReplacer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Exiled.API.Enums;
using Exiled.API.Features;
using MapEditorReborn.API;
Expand Down Expand Up @@ -48,11 +49,36 @@ public static SchematicObject ReplaceRoom(RoomType roomType, RoomSchematic roomS

return cachedRoomData.Schematic;
}

foreach (var component in room.gameObject.GetComponentsInChildren<Component>())
{
try
{
if (component.name.Contains("SCP-079") || component.name.Contains("CCTV"))
{
Log.Debug($"Prevent from destroying: {component.name} {component.tag} {component.GetType().FullName}");
continue;
}

Object.Destroy(room.gameObject);

if (component.GetComponentsInParent<Component>()
.Any(c => c.name.Contains("SCP-079") || c.name.Contains("CCTV")))
{
Log.Debug($"Prevent from destroying: {component.name} {component.tag} {component.GetType().FullName}");
continue;
}

Log.Debug($"Destroying component: {component.name} {component.tag} {component.GetType().FullName}");

Object.Destroy(component);
}
catch
{
// ignored
}
}

var schematic = ObjectSpawner.SpawnSchematic(roomSchematic.SchematicName, schematicPosition + room.Position,
Quaternion.Euler(schematicRotation + room.Rotation.eulerAngles));
Quaternion.Euler(schematicRotation + room.transform.localRotation.eulerAngles));
API.SpawnedObjects.Add(schematic);

var roomDetails = new CachedRoom(room.Position, room.Rotation.eulerAngles, schematic);
Expand Down
50 changes: 3 additions & 47 deletions MERRoomReplacement/Events/Handlers/ReplacementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exiled.API.Extensions;
using Exiled.Events.EventArgs.Player;
using System.Collections.Generic;
using Exiled.Events.Handlers;
using MERRoomReplacement.Api;
using MERRoomReplacement.Api.Structures;
using MERRoomReplacement.Events.Interfaces;
using PlayerRoles;
using Random = UnityEngine.Random;
using UnityEngine;

namespace MERRoomReplacement.Events.Handlers;

public class ReplacementHandler : IEventHandler
{
private readonly IEnumerable<RoomSchematic> _replacementOptions;

private readonly bool _scp079ShouldReplaced;

private static readonly IEnumerable<RoleTypeId> ScpsRoleTypes;

static ReplacementHandler()
{
ScpsRoleTypes = Enum.GetValues(typeof(RoleTypeId))
.ToArray<RoleTypeId>()
.Where(roleType => RoleExtensions.GetTeam(roleType) == Team.SCPs &&
roleType is not RoleTypeId.Scp079 and not RoleTypeId.Scp0492);
}

public ReplacementHandler(IEnumerable<RoomSchematic> replacementOptions, bool scp079ShouldReplaced)
public ReplacementHandler(IEnumerable<RoomSchematic> replacementOptions)
{
_replacementOptions = replacementOptions;
_scp079ShouldReplaced = scp079ShouldReplaced;
}

public void SubscribeEvents()
{
Server.WaitingForPlayers += OnWaitingForPlayers;
Player.ChangingRole += OnPlayerChangingRole;
}

private void OnPlayerChangingRole(ChangingRoleEventArgs ev)
{
if (ev.NewRole != RoleTypeId.Scp079)
return;

if (!_scp079ShouldReplaced)
return;

ev.NewRole = GetFreeScp();
}


private void OnWaitingForPlayers()
{
Expand All @@ -63,19 +32,6 @@ private void OnWaitingForPlayers()

public void UnsubscribeEvents()
{
Player.ChangingRole -= OnPlayerChangingRole;
Server.WaitingForPlayers -= OnWaitingForPlayers;
}

private static RoleTypeId GetFreeScp()
{
var scpPlayers = Exiled.API.Features.Player.Get(Team.SCPs);
var possibleScps = ScpsRoleTypes
.Where(scpRoleType => scpPlayers.All(s => s.Role.Type != scpRoleType))
.ToList();

return possibleScps.Count == 0 ?
RoleTypeId.ClassD :
possibleScps[Random.Range(0, possibleScps.Count)];
}
}
6 changes: 0 additions & 6 deletions MERRoomReplacement/Features/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ public class Config : IConfig
[Description("Indicates debug mode enabled or not")]
public bool Debug { get; set; } = false;

[Description("Should SCP-079 be removed from spawn queue")]
public bool RemoveScp079FromSpawnQueue { get; set; } = false;

[Description("Should SCP-079 be replaced with another free SCP")]
public bool PreventScp079OnRoleChange { get; set; } = false;

[Description("Options for replacement")]
public List<RoomSchematic> ReplacementOptions { get; set; } = new()
{
Expand Down
13 changes: 1 addition & 12 deletions MERRoomReplacement/MERRoomReplacement.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using Exiled.API.Features;
using HarmonyLib;
using MERRoomReplacement.Events.Handlers;
using MERRoomReplacement.Events.Interfaces;
using MERRoomReplacement.Features.Configuration;
Expand All @@ -12,7 +11,6 @@ public class MERRoomReplacement : Plugin<Config>
{
private IEventHandler _replacementHandler;

private Harmony _harmony;

public override string Name => "MERRoomReplacement";

Expand All @@ -27,25 +25,16 @@ public override void OnEnabled()
base.OnEnabled();

_replacementHandler = new ReplacementHandler(
Config.ReplacementOptions.Where(x => x.IsEnabled),
Config.PreventScp079OnRoleChange);
Config.ReplacementOptions.Where(x => x.IsEnabled));

_replacementHandler.SubscribeEvents();

if (Config.RemoveScp079FromSpawnQueue)
return;

_harmony = new Harmony("fakeman.merroomreplacement.patcher");

// RemoveScp079FromSpawnQueue.PatchSpawnQueue(_harmony);
}

public override void OnDisabled()
{
base.OnDisabled();

_replacementHandler?.UnsubscribeEvents();
_harmony?.UnpatchAll(_harmony.Id);
}
}
}
50 changes: 0 additions & 50 deletions MERRoomReplacement/Patches/RemoveScp079FromSpawnQueue.cs

This file was deleted.

0 comments on commit 941403e

Please sign in to comment.