Skip to content

Commit

Permalink
Merge branch 'dev' into xmas-2024-feats
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Dec 26, 2024
2 parents df84098 + d513ff1 commit 48bc649
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 121 deletions.
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="SettingBase.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
Expand Down Expand Up @@ -131,7 +131,7 @@ public string HintDescription
public Action<Player, SettingBase> OnChanged { get; set; }

/// <summary>
/// Tries ti get the setting with the specified id.
/// Tries to get the setting with the specified id.
/// </summary>
/// <param name="player">Player who has received the setting.</param>
/// <param name="id">Id of the setting.</param>
Expand Down
6 changes: 3 additions & 3 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,7 @@ public void AddItem(Firearm item, IEnumerable<AttachmentIdentifier> identifiers)
/// <param name="pickup">The <see cref="Pickup"/> of the item to be added.</param>
/// <param name="addReason">The reason the item was added.</param>
/// <returns>The <see cref="Item"/> that was added.</returns>
public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.Undefined) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));
public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.AdminCommand) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));

/// <summary>
/// Adds an item to the player's inventory.
Expand All @@ -2791,7 +2791,7 @@ public void AddItem(Firearm item, IEnumerable<AttachmentIdentifier> identifiers)
/// <returns>The <see cref="Item"/> that was added.</returns>
public Item AddItem(FirearmPickup pickup, IEnumerable<AttachmentIdentifier> identifiers)
{
Firearm firearm = Item.Get<Firearm>(Inventory.ServerAddItem(pickup.Type, ItemAddReason.Undefined, pickup.Serial, pickup.Base));
Firearm firearm = Item.Get<Firearm>(Inventory.ServerAddItem(pickup.Type, ItemAddReason.AdminCommand, pickup.Serial, pickup.Base));

if (identifiers is not null)
firearm.AddAttachment(identifiers);
Expand Down Expand Up @@ -3714,7 +3714,7 @@ public override bool Equals(object obj)
/// <inheritdoc />
public override int GetHashCode()
{
return ReferenceHub.GetHashCode();
return base.GetHashCode();
}

/// <summary>
Expand Down
34 changes: 33 additions & 1 deletion EXILED/Exiled.API/Features/Toys/Speaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

namespace Exiled.API.Features.Toys
{
using System.Collections.Generic;

using AdminToys;
using Enums;
using Exiled.API.Interfaces;
using UnityEngine;
using VoiceChat.Networking;
using VoiceChat.Playbacks;

/// <summary>
/// A wrapper class for <see cref="SpeakerToy"/>.
Expand Down Expand Up @@ -44,7 +48,7 @@ internal Speaker(SpeakerToy speakerToy)
public float Volume
{
get => Base.NetworkVolume;
set => Base.NetworkVolume = value;
set => Base.NetworkVolume = Mathf.Clamp01(value);
}

/// <summary>
Expand Down Expand Up @@ -86,6 +90,15 @@ public float MinDistance
set => Base.NetworkMinDistance = value;
}

/// <summary>
/// Gets or sets the controller ID of speaker.
/// </summary>
public byte ControllerId
{
get => Base.NetworkControllerId;
set => Base.NetworkControllerId = value;
}

/// <summary>
/// Creates a new <see cref="Speaker"/>.
/// </summary>
Expand All @@ -108,5 +121,24 @@ public static Speaker Create(Vector3? position, Vector3? rotation, Vector3? scal

return speaker;
}

/// <summary>
/// Plays audio through this speaker.
/// </summary>
/// <param name="message">An <see cref="AudioMessage"/> instance.</param>
/// <param name="targets">Targets who will hear the audio. If <c>null</c>, audio will be sent to all players.</param>
public static void Play(AudioMessage message, IEnumerable<Player> targets = null)
{
foreach (Player target in targets ?? Player.List)
target.Connection.Send(message);
}

/// <summary>
/// Plays audio through this speaker.
/// </summary>
/// <param name="samples">Audio samples.</param>
/// <param name="length">The length of the samples array.</param>
/// <param name="targets">Targets who will hear the audio. If <c>null</c>, audio will be sent to all players.</param>
public void Play(byte[] samples, int? length = null, IEnumerable<Player> targets = null) => Play(new AudioMessage(ControllerId, samples, length ?? samples.Length), targets);
}
}
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/EventArgs/Interfaces/IItemEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Exiled.Events.EventArgs.Interfaces
/// <summary>
/// Event args used for all <see cref="API.Features.Items.Item" /> related events.
/// </summary>
public interface IItemEvent : IExiledEvent
public interface IItemEvent : IPlayerEvent
{
/// <summary>
/// Gets the <see cref="API.Features.Items.Item" /> triggering the event.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// -----------------------------------------------------------------------
// <copyright file="ChangingMicroHIDPickupStateEventArgs.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.Item
{
using Exiled.API.Features.Pickups;

using Interfaces;
using InventorySystem.Items.MicroHID.Modules;
using InventorySystem.Items.Pickups;

/// <summary>
/// Contains all information before MicroHID pickup state is changed.
/// </summary>
public class ChangingMicroHIDPickupStateEventArgs : IDeniableEvent, IPickupEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ChangingMicroHIDPickupStateEventArgs" /> class.
/// </summary>
/// <param name="microHID">
/// <inheritdoc cref="MicroHID" />
/// </param>
/// <param name="newPhase">
/// <inheritdoc cref="NewPhase" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public ChangingMicroHIDPickupStateEventArgs(ItemPickupBase microHID, MicroHidPhase newPhase, bool isAllowed = true)
{
MicroHID = Pickup.Get<MicroHIDPickup>(microHID);
NewPhase = newPhase;
IsAllowed = isAllowed;
}

/// <summary>
/// Gets the MicroHID instance.
/// </summary>
public MicroHIDPickup MicroHID { get; }

/// <summary>
/// Gets or sets the new MicroHID state.
/// </summary>
public MicroHidPhase NewPhase { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the MicroHID state can be changed.
/// </summary>
public bool IsAllowed { get; set; }

/// <inheritdoc/>
public Pickup Pickup => MicroHID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Exiled.Events.EventArgs.Item
/// <summary>
/// Contains all information before a player charges a <see cref="Jailbird"/>.
/// </summary>
public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent
public class ChargingJailbirdEventArgs : IItemEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ChargingJailbirdEventArgs"/> class.
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Exiled.Events.EventArgs.Item
/// <summary>
/// Contains all information before a player swings a <see cref="Jailbird"/>.
/// </summary>
public class SwingingEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
public class SwingingEventArgs : IItemEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="SwingingEventArgs"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information after a player's held item changes.
/// </summary>
public class ChangedItemEventArgs : IPlayerEvent, IItemEvent
public class ChangedItemEventArgs : IItemEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ChangedItemEventArgs" /> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="ChangingDisruptorModeEventArgs.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
Expand All @@ -8,6 +8,7 @@
namespace Exiled.Events.EventArgs.Player
{
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.API.Features.Items;
using Exiled.Events.EventArgs.Interfaces;

Expand Down Expand Up @@ -37,5 +38,8 @@ public ChangingDisruptorModeEventArgs(Item firearm, bool mode)
/// Gets a new disruptor's fire mode.
/// </summary>
public DisruptorMode NewMode { get; }

/// <inheritdoc />
public Player Player => Item.Owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Exiled.Events.EventArgs.Player
using API.Features;
using API.Features.Items;
using Interfaces;

using InventorySystem.Items;
using InventorySystem.Items.MicroHID;
using InventorySystem.Items.MicroHID.Modules;

Expand All @@ -32,9 +34,9 @@ public class ChangingMicroHIDStateEventArgs : IDeniableEvent, IItemEvent
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public ChangingMicroHIDStateEventArgs(Item microHID, MicroHidPhase newPhase, bool isAllowed = true)
public ChangingMicroHIDStateEventArgs(ItemBase microHID, MicroHidPhase newPhase, bool isAllowed = true)
{
MicroHID = microHID.As<MicroHid>();
MicroHID = Item.Get<MicroHid>(microHID);
NewPhase = newPhase;
IsAllowed = isAllowed;
}
Expand All @@ -56,5 +58,8 @@ public ChangingMicroHIDStateEventArgs(Item microHID, MicroHidPhase newPhase, boo

/// <inheritdoc/>
public Item Item => MicroHID;

/// <inheritdoc/>
public Player Player => MicroHID.Owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information before radio preset is changed.
/// </summary>
public class ChangingRadioPresetEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
public class ChangingRadioPresetEventArgs : IItemEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ChangingRadioPresetEventArgs" /> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information before a player drops an item.
/// </summary>
public class DroppingItemEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
public class DroppingItemEventArgs : IItemEvent, IDeniableEvent
{
private bool isAllowed = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ public class InteractingElevatorEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="elevator">
/// <inheritdoc cref="Elevator" />
/// </param>
/// <param name="isCalledFromInside">
/// <inheritdoc cref="IsCalledFromInside" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, bool isAllowed = true)
public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, bool isCalledFromInside, bool isAllowed = true)
{
Player = player;
Lift = Lift.Get(elevator);
Elevator = elevator;
IsCalledFromInside = isCalledFromInside;
IsAllowed = isAllowed;
}

Expand All @@ -54,6 +58,11 @@ public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, boo
/// </summary>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets a value indicating whether the player as interact with the elevator from the inside.
/// </summary>
public bool IsCalledFromInside { get; }

/// <summary>
/// Gets the player who's interacting with the elevator.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information after adding an item to a player's inventory.
/// </summary>
public class ItemAddedEventArgs : IPlayerEvent, IItemEvent, IPickupEvent
public class ItemAddedEventArgs : IItemEvent, IPickupEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ItemAddedEventArgs"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information after removing an item from a player's inventory.
/// </summary>
public class ItemRemovedEventArgs : IPlayerEvent, IItemEvent, IPickupEvent
public class ItemRemovedEventArgs : IItemEvent, IPickupEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ItemRemovedEventArgs"/> class.
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public SpawningEventArgs(Player player, Vector3 position, float rotation, Player
/// Gets the player's old <see cref="PlayerRoleBase">role</see>.
/// </summary>
[Obsolete("Removed because the method is no longer provide OldRole since version 14.0. Use Player.Role instead")]
public Role OldRole { get; }
public Role OldRole => Player.Role;

/// <summary>
/// Gets the player's new <see cref="PlayerRoleBase">role</see>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information before receving a throwing request.
/// </summary>
public class ThrowingRequestEventArgs : IPlayerEvent, IItemEvent
public class ThrowingRequestEventArgs : IItemEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ThrowingRequestEventArgs"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Exiled.Events.EventArgs.Player
/// <summary>
/// Contains all information after a player throws a grenade.
/// </summary>
public class ThrownProjectileEventArgs : IPlayerEvent, IItemEvent, IPickupEvent
public class ThrownProjectileEventArgs : IItemEvent, IPickupEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ThrownProjectileEventArgs"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ public UsingMicroHIDEnergyEventArgs(MicroHIDItem microHIDitem, float newEnergy,
/// Gets or sets a value indicating whether the MicroHID energy can be changed.
/// </summary>
public bool IsAllowed { get; set; }

/// <inheritdoc/>
public Player Player => MicroHID.Owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Exiled.Events.EventArgs.Scp914
/// <summary>
/// Contains all information before SCP-914 upgrades an item.
/// </summary>
public class UpgradingInventoryItemEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
public class UpgradingInventoryItemEventArgs : IItemEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="UpgradingInventoryItemEventArgs" /> class.
Expand Down
11 changes: 11 additions & 0 deletions EXILED/Exiled.Events/Handlers/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public static class Item
/// </summary>
public static Event<UsingRadioPickupBatteryEventArgs> UsingRadioPickupBattery { get; set; } = new();

/// <summary>
/// Invoked before a<see cref="API.Features.Pickups.MicroHIDPickup"/> state is changed.
/// </summary>
public static Event<ChangingMicroHIDPickupStateEventArgs> ChangingMicroHIDPickupState { get; set; } = new();

/// <summary>
/// Called before the ammo of an firearm is changed.
/// </summary>
Expand Down Expand Up @@ -94,5 +99,11 @@ public static class Item
/// </summary>
/// <param name="ev">The <see cref="UsingRadioPickupBatteryEventArgs"/> instance.</param>
public static void OnUsingRadioPickupBattery(UsingRadioPickupBatteryEventArgs ev) => UsingRadioPickupBattery.InvokeSafely(ev);

/// <summary>
/// Called before a <see cref="API.Features.Pickups.MicroHIDPickup"/> state is changed.
/// </summary>
/// <param name="ev">The <see cref="ChangingMicroHIDPickupStateEventArgs"/> instance.</param>
public static void OnChangingMicroHIDPickupState(ChangingMicroHIDPickupStateEventArgs ev) => ChangingMicroHIDPickupState.InvokeSafely(ev);
}
}
Loading

0 comments on commit 48bc649

Please sign in to comment.