Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
VALERA771 committed Aug 16, 2024
1 parent 500533c commit 1b135b6
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 43 deletions.
15 changes: 5 additions & 10 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,10 @@ private set
/// </summary>
public bool HasHint => CurrentHint != null;

/// <summary>
/// Gets the <see cref="ReferenceHub"/>'s <see cref="VoiceModule"/>, can be null.
/// </summary>
public VoiceModuleBase VoiceModule => RoleManager.CurrentRole is IVoiceRole voiceRole ? voiceRole.VoiceModule : null;

/// <summary>
/// Gets the <see cref="ReferenceHub"/>'s <see cref="PersonalRadioPlayback"/>, can be null.
/// </summary>
public PersonalRadioPlayback RadioPlayback => VoiceModule is IRadioVoiceModule radioVoiceModule ? radioVoiceModule.RadioPlayback : null;
public PersonalRadioPlayback RadioPlayback => Role is Roles.IVoiceRole voiceRole ? voiceRole.VoiceModule is IRadioVoiceModule radioVoiceModule ? radioVoiceModule.RadioPlayback : null : null;

/// <summary>
/// Gets the <see cref="Hints.HintDisplay"/> of the player.
Expand Down Expand Up @@ -793,7 +788,7 @@ public bool IsIntercomMuted
/// <summary>
/// Gets a value indicating whether or not the player is speaking.
/// </summary>
public bool IsSpeaking => VoiceModule != null && VoiceModule.IsSpeaking;
public bool IsSpeaking => Role is Roles.IVoiceRole voiceRole && voiceRole.VoiceModule.IsSpeaking;

/// <summary>
/// Gets the player's voice color.
Expand All @@ -805,13 +800,13 @@ public bool IsIntercomMuted
/// </summary>
public VoiceChatChannel VoiceChannel
{
get => VoiceModule == null ? VoiceChatChannel.None : VoiceModule.CurrentChannel;
get => Role is Roles.IVoiceRole voiceRole ? voiceRole.VoiceModule.CurrentChannel : VoiceChatChannel.None;
set
{
if (VoiceModule == null)
if (Role is not Roles.IVoiceRole voiceRole)
return;

VoiceModule.CurrentChannel = value;
voiceRole.VoiceModule.CurrentChannel = value;
}
}

Expand Down
35 changes: 12 additions & 23 deletions EXILED/Exiled.API/Features/Roles/FpcRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Exiled.API.Features.Roles
using HarmonyLib;
using PlayerRoles;
using PlayerRoles.FirstPersonControl;
using PlayerRoles.Ragdolls;
using PlayerRoles.Spectating;
using PlayerRoles.Visibility;
using PlayerRoles.Voice;
Expand All @@ -24,7 +25,7 @@ namespace Exiled.API.Features.Roles
/// <summary>
/// Defines a role that represents an fpc class.
/// </summary>
public abstract class FpcRole : Role
public abstract class FpcRole : Role, IVoiceRole
{
private static FieldInfo enableFallDamageField;
private bool isUsingStamina = true;
Expand Down Expand Up @@ -244,40 +245,28 @@ public bool IsNoclipEnabled
}

/// <summary>
/// Gets or sets <see cref="API.Features.Ragdoll"/> for this role.
/// Gets or sets a prefab ragdoll for this role.
/// </summary>
public Ragdoll Ragdoll
public BasicRagdoll Ragdoll
{
get => Ragdoll.Get(FirstPersonController.Ragdoll);
set => FirstPersonController.Ragdoll = value.Base;
get => FirstPersonController.Ragdoll;
set => FirstPersonController.Ragdoll = value;
}

/// <summary>
/// Gets or sets voice module for this role.
/// Gets a voice module for this role.
/// </summary>
public VoiceModuleBase VoiceModule
{
get => FirstPersonController.VoiceModule;
set => FirstPersonController.VoiceModule = value;
}
public VoiceModuleBase VoiceModule => FirstPersonController.VoiceModule;

/// <summary>
/// Gets or sets <see cref="VisibilityController"/> for this role.
/// Gets a <see cref="VisibilityController"/> for this role.
/// </summary>
public VisibilityController VisibilityController
{
get => FirstPersonController.VisibilityController;
set => FirstPersonController.VisibilityController = value;
}
public VisibilityController VisibilityController => FirstPersonController.VisibilityController;

/// <summary>
/// Gets or sets <see cref="SpectatableModuleBase"/> for this role.
/// Gets a <see cref="SpectatableModuleBase"/> for this role.
/// </summary>
public SpectatableModuleBase SpectatableModuleBase
{
get => FirstPersonController.SpectatorModule;
set => FirstPersonController.SpectatorModule = value;
}
public SpectatableModuleBase SpectatableModuleBase => FirstPersonController.SpectatorModule;

/// <summary>
/// Resets the <see cref="Player"/>'s stamina.
Expand Down
22 changes: 22 additions & 0 deletions EXILED/Exiled.API/Features/Roles/IVoiceRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -----------------------------------------------------------------------
// <copyright file="IVoiceRole.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Roles
{
using PlayerRoles.Voice;

/// <summary>
/// Interface for all roles with <see cref="VoiceModuleBase"/>.
/// </summary>
public interface IVoiceRole
{
/// <summary>
/// Gets the <see cref="VoiceModuleBase"/> of the role.
/// </summary>
public VoiceModuleBase VoiceModule { get; }
}
}
6 changes: 5 additions & 1 deletion EXILED/Exiled.API/Features/Roles/NoneRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
namespace Exiled.API.Features.Roles
{
using PlayerRoles;
using PlayerRoles.Voice;

using NoneGameRole = PlayerRoles.NoneRole;

/// <summary>
/// Defines a role that represents players with no role.
/// </summary>
public class NoneRole : Role
public class NoneRole : Role, IVoiceRole
{
/// <summary>
/// Initializes a new instance of the <see cref="NoneRole"/> class.
Expand All @@ -27,5 +28,8 @@ internal NoneRole(PlayerRoleBase baseRole)

/// <inheritdoc/>
public override RoleTypeId Type { get; } = RoleTypeId.None;

/// <inheritdoc/>
public VoiceModuleBase VoiceModule => (Base as NoneGameRole) !.VoiceModule;
}
}
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Roles/Scp0492Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public float SimulatedStare
/// <summary>
/// Gets the <see cref="Ragdoll"/> that SCP-049-2 is currently consuming. Will be <see langword="null"/> if <see cref="IsConsuming"/> is <see langword="false"/>.
/// </summary>
public Ragdoll RagdollConsuming => Ragdoll.Get(ConsumeAbility.CurRagdoll);
public Ragdoll RagdollConsuming => Features.Ragdoll.Get(ConsumeAbility.CurRagdoll);

/// <summary>
/// Gets the amount of time in between SCP-049-2 attacks.
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Roles/Scp049Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal Scp049Role(Scp049GameRole baseRole)
/// <summary>
/// Gets the ragdoll that is currently being revived by SCP-049. Will be <see langword="null"/> if <see cref="IsRecalling"/> is <see langword="false"/>.
/// </summary>
public Ragdoll RecallingRagdoll => Ragdoll.Get(ResurrectAbility.CurRagdoll);
public Ragdoll RecallingRagdoll => Features.Ragdoll.Get(ResurrectAbility.CurRagdoll);

/// <summary>
/// Gets all the dead zombies.
Expand Down Expand Up @@ -255,7 +255,7 @@ public bool Resurrect(Player player)
HumeShieldModuleBase humeShield = ResurrectAbility.CastRole.HumeShieldModule;
humeShield.HsCurrent = Mathf.Min(humeShield.HsCurrent + 100f, humeShield.HsMax);

return Resurrect(Ragdoll.GetLast(player));
return Resurrect(Features.Ragdoll.GetLast(player));
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion EXILED/Exiled.API/Features/Roles/Scp079Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Exiled.API.Features.Roles
using PlayerRoles.PlayableScps.Scp079.Pinging;
using PlayerRoles.PlayableScps.Scp079.Rewards;
using PlayerRoles.Subroutines;
using PlayerRoles.Voice;
using RelativePositioning;
using Utils.NonAllocLINQ;

Expand All @@ -32,7 +33,7 @@ namespace Exiled.API.Features.Roles
/// <summary>
/// Defines a role that represents SCP-079.
/// </summary>
public class Scp079Role : Role, ISubroutinedScpRole, ISpawnableScp
public class Scp079Role : Role, ISubroutinedScpRole, ISpawnableScp, IVoiceRole
{
/// <summary>
/// Initializes a new instance of the <see cref="Scp079Role"/> class.
Expand Down Expand Up @@ -374,6 +375,9 @@ public float Scp2176LostTime
/// </summary>
public float EnergyRegenerationSpeed => AuxManager.RegenSpeed;

/// <inheritdoc/>
public VoiceModuleBase VoiceModule => Base.VoiceModule;

/// <summary>
/// Gets the game <see cref="Scp079GameRole"/>.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions EXILED/Exiled.API/Features/Roles/SpectatorRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace Exiled.API.Features.Roles
using System;

using PlayerRoles;

using PlayerRoles.Voice;
using UnityEngine;

using SpectatorGameRole = PlayerRoles.Spectating.SpectatorRole;

/// <summary>
/// Defines a role that represents a spectator.
/// </summary>
public class SpectatorRole : Role
public class SpectatorRole : Role, IVoiceRole
{
/// <summary>
/// Initializes a new instance of the <see cref="SpectatorRole"/> class.
Expand Down Expand Up @@ -70,5 +70,8 @@ public Player SpectatedPlayer
/// Gets the game <see cref="SpectatorGameRole"/>.
/// </summary>
public new SpectatorGameRole Base { get; }

/// <inheritdoc/>
public VoiceModuleBase VoiceModule => Base.VoiceModule;
}
}
5 changes: 2 additions & 3 deletions EXILED/Exiled.Events/Patches/Events/Player/VoiceChatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// voiceModule.
new(OpCodes.Ldloc_S, player.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Player), nameof(API.Features.Player.Role))),
new(OpCodes.Callvirt, PropertyGetter(typeof(Role), nameof(Role.Base))),
new(OpCodes.Isinst, typeof(IVoiceRole)),
new(OpCodes.Callvirt, PropertyGetter(typeof(IVoiceRole), nameof(IVoiceRole.VoiceModule))),
new(OpCodes.Isinst, typeof(API.Features.Roles.IVoiceRole)),
new(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Roles.IVoiceRole), nameof(API.Features.Roles.IVoiceRole.VoiceModule))),
new(OpCodes.Dup),
new(OpCodes.Stloc_S, voiceModule.LocalIndex),

Expand Down

0 comments on commit 1b135b6

Please sign in to comment.