Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// -----------------------------------------------------------------------
// <copyright file="SettingMimicPointEventArgs.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Scp939
{
using API.Features;
using Exiled.API.Features.Roles;
using Interfaces;

/// <summary>
/// Contains all information before SCP-939 plays a stolen player's voice.
/// </summary>
public class SettingMimicPointEventArgs : IScp939Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="SettingMimicPointEventArgs" /> class.
/// </summary>
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// /// <param name="isAllowed">
/// Indicates whether the mimic point can be placed or not.
/// </param>
public SettingMimicPointEventArgs(Player player, bool isAllowed = true)
{
Player = player;
Scp939 = Player.Role.As<Scp939Role>();
IsAllowed = isAllowed;
}

/// <summary>
/// Gets or sets a value indicating whether SCP-939 can play the stolen voice.
/// </summary>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets the player who's controlling SCP-939.
/// </summary>
public Player Player { get; }

/// <inheritdoc/>
public Scp939Role Scp939 { get; }
}
}
11 changes: 11 additions & 0 deletions EXILED/Exiled.Events/Handlers/Scp939.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public static class Scp939
/// </summary>
public static Event<ValidatingVisibilityEventArgs> ValidatingVisibility { get; set; } = new();

/// <summary>
/// Invoked before SCP-939 places a mimic point.
/// </summary>
public static Event<SettingMimicPointEventArgs> SettingMimicPoint { get; set; } = new();

/// <summary>
/// Called before SCP-939 changes its target focus.
/// </summary>
Expand Down Expand Up @@ -139,5 +144,11 @@ public static class Scp939
/// </summary>
/// <param name="ev">The <see cref="ValidatingVisibilityEventArgs"/> instance.</param>
public static void OnValidatingVisibility(ValidatingVisibilityEventArgs ev) => ValidatingVisibility.InvokeSafely(ev);

/// <summary>
/// Invoked before SCP-939 places a mimic point.
/// </summary>
/// <param name="ev">The <see cref="SettingMimicPointEventArgs"/> instance.</param>
public static void OnSettingMimicPoint(SettingMimicPointEventArgs ev) => SettingMimicPoint.InvokeSafely(ev);
}
}
56 changes: 56 additions & 0 deletions EXILED/Exiled.Events/Patches/Events/Scp939/SettingMimicPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// -----------------------------------------------------------------------
// <copyright file="SettingMimicPoint.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

#pragma warning disable SA1313 // Parameter names should begin with lower-case letter

namespace Exiled.Events.Patches.Events.Scp939
{
using Attributes;
using Exiled.Events.EventArgs.Scp939;
using HarmonyLib;
using Mirror;
using PlayerRoles.PlayableScps.Scp939.Mimicry;
using RelativePositioning;

/// <summary>
/// Patches <see cref="MimicPointController.ServerProcessCmd"/>.
/// Adds the <see cref="Handlers.Scp939.SettingMimicPoint" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Scp939), nameof(Handlers.Scp939.SettingMimicPoint))]
[HarmonyPatch(typeof(MimicPointController), nameof(MimicPointController.ServerProcessCmd))]
internal static class SettingMimicPoint
{
private static bool Prefix(MimicPointController __instance, ref NetworkReader reader)
{
if (!__instance.Active)
{
SettingMimicPointEventArgs ev = new SettingMimicPointEventArgs(API.Features.Player.Get(__instance.Owner));
Handlers.Scp939.OnSettingMimicPoint(ev);

if (!ev.IsAllowed)
{
return false;
}
}

if (__instance.Active)
{
__instance._syncMessage = MimicPointController.RpcStateMsg.RemovedByUser;
__instance.Active = false;
}
else
{
__instance._syncMessage = MimicPointController.RpcStateMsg.PlacedByUser;
__instance._syncPos = new RelativePosition(__instance.CastRole.FpcModule.Position);
__instance.Active = true;
}

__instance.ServerSendRpc(true);
return true;
}
}
}