Skip to content

Commit

Permalink
Merge branch 'refs/heads/apis-rework' into scp244event-transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
BoltonDev committed May 25, 2024
2 parents 3027893 + 528e6c1 commit a026d44
Show file tree
Hide file tree
Showing 70 changed files with 2,582 additions and 505 deletions.
2 changes: 1 addition & 1 deletion EXILED.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<PropertyGroup>
<!-- This is the global version and is used for all projects that don't have a version -->
<Version Condition="$(Version) == ''">8.8.2</Version>
<Version Condition="$(Version) == ''">8.9.2</Version>
<!-- Enables public beta warning via the PUBLIC_BETA constant -->
<PublicBeta>false</PublicBeta>

Expand Down
1 change: 0 additions & 1 deletion Exiled.API/Enums/DoorLockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Exiled.API.Enums
/// <summary>
/// All possible door locks.
/// </summary>
/// <seealso cref="Door.LockAll(float, DoorLockType)"/>
/// <seealso cref="Door.ChangeLock(DoorLockType)"/>
[Flags]
public enum DoorLockType
Expand Down
6 changes: 6 additions & 0 deletions Exiled.API/Enums/EffectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ public enum EffectType
/// Makes the player nearly invisible, and allows them to pass through doors.
/// </summary>
Ghostly,

/// <summary>
/// Manipulate wish Fog player will have.
/// <remarks>You can choose fog with <see cref="CustomRendering.FogType"/> and putting it on intensity.</remarks>
/// </summary>
FogControl,
}
}
9 changes: 9 additions & 0 deletions Exiled.API/Extensions/EffectTypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Exiled.API.Extensions
using System.Linq;

using CustomPlayerEffects;
using CustomRendering;
using Enums;
using InventorySystem.Items.MarshmallowMan;
using InventorySystem.Items.Usables.Scp244.Hypothermia;
Expand Down Expand Up @@ -71,6 +72,7 @@ public static class EffectTypeExtension
#pragma warning restore CS0618
{ EffectType.Strangled, typeof(Strangled) },
{ EffectType.Ghostly, typeof(Ghostly) },
{ EffectType.FogControl, typeof(FogControl) },
});

/// <summary>
Expand Down Expand Up @@ -120,6 +122,13 @@ public static bool TryGetEffectType(this StatusEffectBase statusEffectBase, out
return true;
}

/// <summary>
/// Sets the <see cref="FogType"/> of the specified <see cref="FogControl"/>.
/// </summary>
/// <param name="fogControl">The <see cref="FogControl"/> effect.</param>
/// <param name="fogType">The <see cref="FogType"/> applied.</param>
public static void SetFogType(this FogControl fogControl, FogType fogType) => fogControl.Intensity = (byte)(fogType + 1);

/// <summary>
/// Returns whether or not the provided <paramref name="effect"/> drains health over time.
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions Exiled.API/Features/Attributes/Validators/GreaterThanAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="GreaterThanAttribute.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.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is greater than a specified number.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class GreaterThanAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="GreaterThanAttribute"/> class.
/// </summary>
/// <param name="number">The number the marked property should be greater than.</param>
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param>
public GreaterThanAttribute(object number, bool isIncluded = false)
{
Number = (IComparable)number;
IsIncluded = isIncluded;
}

/// <summary>
/// Gets the number that the value of the marked property should be greater than.
/// </summary>
public IComparable Number { get; }

/// <summary>
/// Gets a value indicating whether or not the comparison is inclusive.
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks>
/// </summary>
public bool IsIncluded { get; }

/// <inheritdoc/>
public bool Validate(object value) => Number.CompareTo(value) is -1 || (IsIncluded && Number.CompareTo(value) is 0);
}
}
45 changes: 45 additions & 0 deletions Exiled.API/Features/Attributes/Validators/LessThanAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="LessThanAttribute.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.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is less than a specified number.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class LessThanAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="LessThanAttribute"/> class.
/// </summary>
/// <param name="number">The number the marked property should be less than.</param>
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param>
public LessThanAttribute(object number, bool isIncluded = false)
{
Number = (IComparable)number;
IsIncluded = isIncluded;
}

/// <summary>
/// Gets the number that the value of the marked property should be less than.
/// </summary>
public IComparable Number { get; }

/// <summary>
/// Gets a value indicating whether or not the comparison is inclusive.
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks>
/// </summary>
public bool IsIncluded { get; }

/// <inheritdoc/>
public bool Validate(object value) => Number.CompareTo(value) is 1 || (IsIncluded && Number.CompareTo(value) is 0);
}
}
23 changes: 23 additions & 0 deletions Exiled.API/Features/Attributes/Validators/NonNegativeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="NonNegativeAttribute.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.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is non-negative.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class NonNegativeAttribute : Attribute, IValidator
{
/// <inheritdoc/>
public bool Validate(object value) => value is >= 0;
}
}
23 changes: 23 additions & 0 deletions Exiled.API/Features/Attributes/Validators/NonPositiveAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="NonPositiveAttribute.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.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is non-positive.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class NonPositiveAttribute : Attribute, IValidator
{
/// <inheritdoc/>
public bool Validate(object value) => value is <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="PossibleValuesAttribute.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.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property included in the specified values.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class PossibleValuesAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="PossibleValuesAttribute"/> class.
/// </summary>
/// <param name="values">The values the marked property can have that should be considered valid.</param>
public PossibleValuesAttribute(params object[] values)
{
Values = values;
}

/// <summary>
/// Gets the values the marked property can have that should be considered valid.
/// </summary>
public object[] Values { get; }

/// <inheritdoc/>
public bool Validate(object value) => Values.Contains(value);
}
}
75 changes: 35 additions & 40 deletions Exiled.API/Features/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public bool IsOpen
set => Base.NetworkTargetState = value;
}

/// <summary>
/// Gets or sets a value indicating whether the door is close.
/// </summary>
public bool IsClosed
{
get => !IsOpen;
set => IsOpen = !value;
}

/// <summary>
/// Gets a value indicating whether or not this door is a gate.
/// </summary>
Expand Down Expand Up @@ -202,12 +211,12 @@ public bool AllowsScp106
/// <summary>
/// Gets a value indicating whether or not the door is locked.
/// </summary>
public bool IsLocked => DoorLockType > 0;
public bool IsLocked => LockType > 0;

/// <summary>
/// Gets or sets the door lock type.
/// </summary>
public DoorLockType DoorLockType
public DoorLockType LockType
{
get => (DoorLockType)Base.NetworkActiveLocks;
set
Expand Down Expand Up @@ -428,12 +437,10 @@ public static Door GetClosest(Vector3 position, out float distance)
/// <returns><see cref="Door"/> object.</returns>
public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false)
{
List<Door> doors = onlyUnbroken || type is not ZoneType.Unspecified ? Get(x =>
(x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)).
ToList() :
DoorVariantToDoor.Values.ToList();
if (onlyUnbroken || type != ZoneType.Unspecified)
return Get(x => (x.Room == null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (!onlyUnbroken || !(x is Breakable { IsDestroyed: true }))).Random();

return doors[UnityEngine.Random.Range(0, doors.Count)];
return DoorVariantToDoor.Values.Random();
}

/// <summary>
Expand Down Expand Up @@ -498,7 +505,7 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke
/// <param name="type">The <see cref="ZoneType"/> to affect.</param>
/// <param name="duration">The duration of the lockdown.</param>
/// <param name="lockType">The specified <see cref="Enums.DoorLockType"/>.</param>
public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true));
public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(duration, lockType, true));

/// <summary>
/// Temporary locks all <see cref="Door">doors</see> given the specified zones.
Expand Down Expand Up @@ -582,49 +589,37 @@ public void PlaySound(DoorBeepType beep)
/// <summary>
/// Change the door lock with the given lock type.
/// </summary>
/// <param name="lockType">The <see cref="Enums.DoorLockType"/> to use.</param>
public void ChangeLock(DoorLockType lockType)
{
if (lockType is DoorLockType.None)
{
Base.NetworkActiveLocks = 0;
}
else
{
DoorLockType locks = DoorLockType;
if (locks.HasFlag(lockType))
locks &= ~lockType;
else
locks |= lockType;

Base.NetworkActiveLocks = (ushort)locks;
}

DoorEvents.TriggerAction(Base, IsLocked ? DoorAction.Locked : DoorAction.Unlocked, null);
}
/// <param name="lockType">The <see cref="DoorLockType"/> to use.</param>
public void ChangeLock(DoorLockType lockType) => Base.ServerChangeLock((DoorLockReason)lockType, !LockType.HasFlag(lockType));

/// <summary>
/// Permanently locks all active locks on the door, and then reverts back any changes after a specified length of time.
/// </summary>
/// <param name="lockType">The <see cref="Enums.DoorLockType"/> of the lockdown.</param>
/// <param name="shouldBeClosed">A value indicating whether the door should be closed.</param>
public void Lock(DoorLockType lockType = DoorLockType.Regular079, bool shouldBeClosed = false)
/// <param name="lockType">The <see cref="DoorLockType"/> of the lockdown.</param>
/// <param name="updateTheDoorState">A value indicating whether the door state should be modified.</param>
public void Lock(DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true)
{
if (shouldBeClosed)
IsOpen = false;

ChangeLock(lockType);

if (updateTheDoorState)
return;

DoorLockMode mode = DoorLockUtils.GetMode((DoorLockReason)LockType);
if (mode is DoorLockMode.CanOpen)
IsOpen = true;
else if (mode is DoorLockMode.CanClose)
IsOpen = false;
}

/// <summary>
/// Temporary locks all active locks on the door, and then reverts back any changes after a specified length of time.
/// </summary>
/// <param name="time">The amount of time that must pass before unlocking the door.</param>
/// <param name="lockType">The <see cref="Enums.DoorLockType"/> of the lockdown.</param>
/// <param name="shouldBeClosed">A value indicating whether the door should be closed.</param>
public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bool shouldBeClosed = false)
/// <param name="lockType">The <see cref="DoorLockType"/> of the lockdown.</param>
/// <param name="updateTheDoorState">A value indicating whether the door state should be modified.</param>
public void Lock(float time, DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true)
{
Lock(lockType, shouldBeClosed);
Lock(lockType, updateTheDoorState);
Unlock(time, lockType);
}

Expand All @@ -637,7 +632,7 @@ public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bo
/// Unlocks and clears all active locks on the door after a specified length of time.
/// </summary>
/// <param name="time">The amount of time that must pass before unlocking the door.</param>
/// <param name="flagsToUnlock">The <see cref="Enums.DoorLockType"/> of the lockdown.</param>
/// <param name="flagsToUnlock">The <see cref="DoorLockType"/> of the lockdown.</param>
public void Unlock(float time, DoorLockType flagsToUnlock) => DoorScheduledUnlocker.UnlockLater(Base, time, (DoorLockReason)flagsToUnlock);

/// <summary>
Expand All @@ -651,7 +646,7 @@ public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bo
/// Returns the Door in a human-readable format.
/// </summary>
/// <returns>A string containing Door-related data.</returns>
public override string ToString() => $"{Type} ({Zone}) [{Room}] *{DoorLockType}* ={RequiredPermissions.RequiredPermissions}=";
public override string ToString() => $"{Type} ({Zone}) [{Room}] *{LockType}* ={RequiredPermissions.RequiredPermissions}=";

/// <summary>
/// Creates the door object associated with a specific <see cref="DoorVariant"/>.
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/Items/Armor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal Armor(ItemType type)
/// <summary>
/// Gets or sets the Weight of the armor.
/// </summary>
public new float Weight
public override float Weight
{
get => Base.Weight;
set => Base._weight = value;
Expand Down
Loading

0 comments on commit a026d44

Please sign in to comment.