Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it a flashlight? #2225

Merged
merged 11 commits into from
Nov 12, 2023
Merged
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
56 changes: 38 additions & 18 deletions Exiled.API/Features/Items/Flashlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@

namespace Exiled.API.Features.Items
{
using System;

using Exiled.API.Interfaces;
using InventorySystem.Items.ToggleableLights;
using InventorySystem.Items.ToggleableLights.Flashlight;
using InventorySystem.Items.ToggleableLights.Lantern;
using Utils.Networking;

/// <summary>
/// A wrapped class for <see cref="FlashlightItem"/>.
/// A wrapped class for <see cref="ToggleableLightItemBase"/>.
/// </summary>
public class Flashlight : Item, IWrapper<FlashlightItem>
public class Flashlight : Item, IWrapper<ToggleableLightItemBase>
{
/// <summary>
/// Initializes a new instance of the <see cref="Flashlight"/> class.
/// </summary>
/// <param name="itemBase">The base <see cref="FlashlightItem"/> class.</param>
public Flashlight(FlashlightItem itemBase)
/// <param name="itemBase">The base <see cref="ToggleableLightItemBase"/> class.</param>
public Flashlight(ToggleableLightItemBase itemBase)
: base(itemBase)
{
Base = itemBase;
Expand All @@ -30,20 +33,30 @@ public Flashlight(FlashlightItem itemBase)
/// <summary>
/// Initializes a new instance of the <see cref="Flashlight"/> class, as well as a new Flashlight item.
/// </summary>
internal Flashlight()
: this((FlashlightItem)Server.Host.Inventory.CreateItemInstance(new(ItemType.Flashlight, 0), false))
/// <param name="type"><see cref="ItemType.Flashlight"/> or <see cref="ItemType.Lantern"/>.</param>
internal Flashlight(ItemType type)
: this((ToggleableLightItemBase)Server.Host.Inventory.CreateItemInstance(new(type, 0), false))
{
}

/// <summary>
/// Gets the <see cref="FlashlightItem"/> that this class is encapsulating.
/// Gets the <see cref="ToggleableLightItemBase"/> that this class is encapsulating.
/// </summary>
public new FlashlightItem Base { get; }
/// <remarks>Can be <see cref="FlashlightItem"/> or <see cref="LanternItem"/>.</remarks>
public new ToggleableLightItemBase Base { get; }

/// <inheritdoc cref="IsEmittingLight"/>
[Obsolete("Use IsEmittingLight instead.")]
public bool Active
{
get => IsEmittingLight;
set => IsEmittingLight = value;
}

/// <summary>
/// Gets or sets a value indicating whether the flashlight is turned on.
/// Gets or sets a value indicating whether the item is emitting light.
/// </summary>
public bool Active
VALERA771 marked this conversation as resolved.
Show resolved Hide resolved
public bool IsEmittingLight
{
get => Base.IsEmittingLight;
set
Expand All @@ -54,18 +67,25 @@ public bool Active
}

/// <summary>
/// Clones current <see cref="Flashlight"/> object.
/// Gets or sets time since level loaded when player will be able to change <see cref="IsEmittingLight"/> again.
/// </summary>
/// <returns> New <see cref="Flashlight"/> object. </returns>
public override Item Clone() => new Flashlight()
public float NextAllowedTime
{
get => Base.NextAllowedTime;
set => Base.NextAllowedTime = value;
}

/// <inheritdoc/>
public override Item Clone() => new Flashlight(Type)
{
Active = Active,
IsEmittingLight = IsEmittingLight,
NextAllowedTime = NextAllowedTime,
};

/// <summary>
/// Returns the Flashlight in a human readable format.
/// Returns the item in a human readable format.
/// </summary>
/// <returns>A string containing Flashlight-related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Active}|";
/// <returns>A string containing item-related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{IsEmittingLight}| /{NextAllowedTime}/";
}
}
}
5 changes: 3 additions & 2 deletions Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Exiled.API.Features.Items
using InventorySystem.Items.Pickups;
using InventorySystem.Items.Radio;
using InventorySystem.Items.ThrowableProjectiles;
using InventorySystem.Items.ToggleableLights;
using InventorySystem.Items.ToggleableLights.Flashlight;
using InventorySystem.Items.Usables;
using InventorySystem.Items.Usables.Scp1576;
Expand Down Expand Up @@ -202,7 +203,7 @@ public static Item Get(ItemBase itemBase)
MicroHIDItem micro => new MicroHid(micro),
BodyArmor armor => new Armor(armor),
AmmoItem ammo => new Ammo(ammo),
FlashlightItem flashlight => new Flashlight(flashlight),
ToggleableLightItemBase flashlight => new Flashlight(flashlight),
JailbirdItem jailbird => new Jailbird(jailbird),
ThrowableItem throwable => throwable.Projectile switch
{
Expand Down Expand Up @@ -259,7 +260,7 @@ public static Item Get(ItemBase itemBase)
ItemType.Adrenaline or ItemType.Medkit or ItemType.Painkillers or ItemType.SCP500 or ItemType.SCP207 or ItemType.SCP1853 => new Consumable(type),
ItemType.SCP244a or ItemType.SCP244b => new Scp244(type),
ItemType.Ammo9x19 or ItemType.Ammo12gauge or ItemType.Ammo44cal or ItemType.Ammo556x45 or ItemType.Ammo762x39 => new Ammo(type),
ItemType.Flashlight => new Flashlight(),
ItemType.Flashlight or ItemType.Lantern => new Flashlight(type),
ItemType.Radio => new Radio(),
ItemType.MicroHID => new MicroHid(),
ItemType.GrenadeFlash => new FlashGrenade(owner),
Expand Down
Loading