Skip to content

Commit

Permalink
Merge branch 'apis-rework' into devscp244
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Apr 10, 2024
2 parents 10192da + 516596d commit 8c0c583
Show file tree
Hide file tree
Showing 34 changed files with 693 additions and 195 deletions.
5 changes: 0 additions & 5 deletions Exiled.API/Enums/DoorBeepType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public enum DoorBeepType
/// </summary>
LockBypassDenied,

/// <summary>
/// Interaction denied.
/// </summary>
InteractionDenied,

/// <summary>
/// Interaction allowed.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Exiled.API/Features/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ public void PlaySound(DoorBeepType beep)
{
switch (Base)
{
case Interactables.Interobjects.BasicDoor basic:
basic.RpcPlayBeepSound(beep is not DoorBeepType.InteractionAllowed);
case Interactables.Interobjects.BasicDoor basic when beep is DoorBeepType.PermissionDenied or DoorBeepType.LockBypassDenied:
basic.RpcPlayBeepSound(beep is DoorBeepType.PermissionDenied);
break;
case Interactables.Interobjects.CheckpointDoor chkPt:
chkPt.RpcPlayBeepSound((byte)Mathf.Min((int)beep, 3));
chkPt.RpcPlayBeepSound((byte)Mathf.Min((int)beep, 2));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/Lift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal Lift(ElevatorChamber elevator)
Base = elevator;
ElevatorChamberToLift.Add(elevator, this);

internalDoorsList.AddRange(Interactables.Interobjects.ElevatorDoor.AllElevatorDoors[Group]);
internalDoorsList.AddRange(Elevator.AllElevatorDoors[Group]);
}

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Exiled.API.Features
using Exiled.API.Extensions;
using Exiled.API.Features.Hazards;
using Exiled.API.Features.Pickups;
using Exiled.API.Features.Scp914Processors;
using Exiled.API.Features.Toys;
using global::Hazards;
using InventorySystem;
Expand Down Expand Up @@ -346,12 +347,20 @@ public static void CleanAllRagdolls(IEnumerable<Ragdoll> ragDolls)
ragDoll.Destroy();
}

/// <summary>
/// Places a decal.
/// </summary>
/// <param name="position">The position of the blood decal.</param>
/// <param name="direction">The direction of the blood decal.</param>
/// <param name="type">The type of decal to place.</param>
public static void PlaceDecal(Vector3 position, Vector3 direction, DecalPoolType type) => new GunDecalMessage(position, direction, type).SendToAuthenticated(0);

/// <summary>
/// Places a blood decal.
/// </summary>
/// <param name="position">The position of the blood decal.</param>
/// <param name="direction">The direction of the blood decal.</param>
public static void PlaceBlood(Vector3 position, Vector3 direction) => new GunDecalMessage(position, direction, DecalPoolType.Blood).SendToAuthenticated(0);
public static void PlaceBlood(Vector3 position, Vector3 direction) => PlaceDecal(position, direction, DecalPoolType.Blood);

/// <summary>
/// Gets all the near cameras.
Expand Down Expand Up @@ -413,6 +422,7 @@ internal static void ClearCache()
Firearm.BaseCodesValue.Clear();
Firearm.AvailableAttachmentsValue.Clear();

Scp914Processor.ProcessorToWrapper.Clear();
Workstation.BaseToWrapper.Clear();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ public bool UnloadWeapon()
/// <returns><see langword="true"/> if the weapon flashlight toggle request is received. Returns <see langword="false"/> otherwise, or if the player is not an <see cref="IFpcRole"/> or is not holding a <see cref="Firearm"/>.</returns>
public bool ToggleWeaponFlashlight()
{
if (RoleManager.CurrentRole is not IFpcRole fpc || CurrentItem is not Firearm firearm)
if (RoleManager.CurrentRole is not IFpcRole || CurrentItem is not Firearm firearm)
return false;

bool oldCheck = firearm.FlashlightEnabled; // Temporary Solution
Expand Down
12 changes: 6 additions & 6 deletions Exiled.API/Features/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class Room : GameEntity, IWorldSpace
/// </summary>
internal static readonly Dictionary<RoomIdentifier, Room> RoomIdentifierToRoom = new(250, new ComponentsEqualityComparer());

private GameObject gameObject;
private readonly GameObject gameObject;

/// <summary>
/// Initializes a new instance of the <see cref="Room"/> class.
/// </summary>
/// <param name="go">The room's <see cref="UnityEngine.GameObject"/>.</param>
internal Room(GameObject go)
/// <param name="roomIdentifier">The room's <see cref="RoomIdentifier"/>.</param>
internal Room(RoomIdentifier roomIdentifier)
{
gameObject = go;
gameObject = roomIdentifier.gameObject;

Identifier = gameObject.GetComponent<RoomIdentifier>();
RoomIdentifierToRoom.Add(Identifier, this);
Expand Down Expand Up @@ -252,7 +252,7 @@ public bool AreLightsOff
/// <param name="roomIdentifier">The <see cref="Identifier"/> to search with.</param>
/// <returns>The <see cref="Room"/> of the given identified, if any. Can be <see langword="null"/>.</returns>
public static Room Get(RoomIdentifier roomIdentifier) => roomIdentifier == null ? null :
RoomIdentifierToRoom.TryGetValue(roomIdentifier, out Room room) ? room : null;
RoomIdentifierToRoom.TryGetValue(roomIdentifier, out Room room) ? room : new Room(roomIdentifier);

/// <summary>
/// Gets a <see cref="Room"/> from a given <see cref="RoomIdentifier"/>.
Expand Down Expand Up @@ -307,7 +307,7 @@ public static Room FindParentRoom(GameObject objectInRoom)
// First try to find the room owner quickly.
if (!objectInRoom.CompareTag(playerTag))
{
room = objectInRoom.GetComponentInParent<Room>();
room = Get(objectInRoom.GetComponentInParent<RoomIdentifier>());
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions Exiled.API/Features/Scp914.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace Exiled.API.Features
using Exiled.API.Features.Core.Generic.Pools;
using Exiled.API.Features.Doors;
using Exiled.API.Features.Pickups;
using Exiled.API.Features.Scp914Processors;
using global::Scp914;
using global::Scp914.Processors;
using UnityEngine;

/// <summary>
Expand Down Expand Up @@ -141,5 +143,12 @@ public static IEnumerable<GameObject> Scp914InputObject(out IEnumerable<Player>
/// <param name="player"><see cref="Player"/> who interacts with Scp914.</param>
/// <param name="code"><see cref="Scp914InteractCode"/> Interact code.</param>
public static void Start(Player player = null, Scp914InteractCode code = Scp914InteractCode.Activate) => Scp914Controller.ServerInteract((player ?? Server.Host).ReferenceHub, (byte)code);

/// <summary>
/// Gets the <see cref="Scp914Processor"/> for <paramref name="itemType"/>.
/// </summary>
/// <param name="itemType">Item for which processor should be returned.</param>
/// <returns>The <see cref="Scp914Processor"/> if item has it. Otherwise, <see langword="null"/>.</returns>
public static Scp914Processor GetProcessor(ItemType itemType) => Scp914Upgrader.TryGetProcessor(itemType, out Scp914ItemProcessor scp914ItemProcessor) ? Scp914Processor.Get(scp914ItemProcessor) : null;
}
}
67 changes: 67 additions & 0 deletions Exiled.API/Features/Scp914Processors/AmmoProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// -----------------------------------------------------------------------
// <copyright file="AmmoProcessor.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.Scp914Processors
{
using Exiled.API.Interfaces;
using global::Scp914;
using global::Scp914.Processors;

/// <summary>
/// A processor for <see cref="ItemCategory.Ammo"/>.
/// </summary>
public class AmmoProcessor : Scp914Processor, IWrapper<AmmoItemProcessor>
{
/// <summary>
/// Initializes a new instance of the <see cref="AmmoProcessor"/> class.
/// </summary>
/// <param name="scp914ItemProcessor">The <see cref="AmmoItemProcessor"/> instance.</param>
public AmmoProcessor(AmmoItemProcessor scp914ItemProcessor)
: base(scp914ItemProcessor)
{
Base = scp914ItemProcessor;
}

/// <inheritdoc/>
public new AmmoItemProcessor Base { get; }

/// <summary>
/// Gets or sets a new <see cref="ItemType"/> to which item will be upgraded on <see cref="Scp914KnobSetting.Coarse"/> or <see cref="Scp914KnobSetting.Rough"/>.
/// </summary>
public ItemType PreviousAmmo
{
get => Base._previousAmmo;
set => Base._previousAmmo = value;
}

/// <summary>
/// Gets or sets a new <see cref="ItemType"/> to which item will be upgraded on <see cref="Scp914KnobSetting.Fine"/>.
/// </summary>
public ItemType OneToOneAmmo
{
get => Base._oneToOne;
set => Base._oneToOne = value;
}

/// <summary>
/// Gets or sets a new <see cref="ItemType"/> to which item will be upgraded on <see cref="Scp914KnobSetting.Fine"/> or <see cref="Scp914KnobSetting.VeryFine"/>.
/// </summary>
public ItemType NextAmmo
{
get => Base._nextAmmo;
set => Base._nextAmmo = value;
}

/// <inheritdoc/>
public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => knobSetting switch
{
Scp914KnobSetting.Rough or Scp914KnobSetting.Coarse => PreviousAmmo,
Scp914KnobSetting.OneToOne => OneToOneAmmo,
_ => NextAmmo
};
}
}
93 changes: 93 additions & 0 deletions Exiled.API/Features/Scp914Processors/FirearmProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// -----------------------------------------------------------------------
// <copyright file="FirearmProcessor.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.Scp914Processors
{
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Extensions;
using Exiled.API.Interfaces;
using global::Scp914;
using global::Scp914.Processors;

/// <summary>
/// A processor for <see cref="ItemCategory.Firearm"/>.
/// </summary>
public class FirearmProcessor : Scp914Processor, IWrapper<FirearmItemProcessor>
{
/// <summary>
/// Initializes a new instance of the <see cref="FirearmProcessor"/> class.
/// </summary>
/// <param name="scp914ItemProcessor">The <see cref="FirearmItemProcessor"/> instance.</param>
public FirearmProcessor(FirearmItemProcessor scp914ItemProcessor)
: base(scp914ItemProcessor)
{
Base = scp914ItemProcessor;
}

/// <inheritdoc/>
public new FirearmItemProcessor Base { get; }

/// <summary>
/// Gets or sets a value indicating whether or not magazine should be refilled.
/// </summary>
public bool RefillAmmo
{
get => Base._refillAmmo;
set => Base._refillAmmo = value;
}

/// <summary>
/// Gets or sets a list of items that replace upgrading item when <see cref="Scp914KnobSetting"/> is <see cref="Scp914KnobSetting.Rough"/>.
/// </summary>
public IEnumerable<FirearmItemProcessor.FirearmOutput> RoughOutputs
{
get => Base._roughOutputs;
set => Base._roughOutputs = value.ToArray();
}

/// <summary>
/// Gets or sets a list of items that replace upgrading item when <see cref="Scp914KnobSetting"/> is <see cref="Scp914KnobSetting.Coarse"/>.
/// </summary>
public IEnumerable<FirearmItemProcessor.FirearmOutput> CoarseOutputs
{
get => Base._coarseOutputs;
set => Base._coarseOutputs = value.ToArray();
}

/// <summary>
/// Gets or sets a list of items that replace upgrading item when <see cref="Scp914KnobSetting"/> is <see cref="Scp914KnobSetting.OneToOne"/>.
/// </summary>
public IEnumerable<FirearmItemProcessor.FirearmOutput> OneToOneOutputs
{
get => Base._oneToOneOutputs;
set => Base._oneToOneOutputs = value.ToArray();
}

/// <summary>
/// Gets or sets a list of items that replace upgrading item when <see cref="Scp914KnobSetting"/> is <see cref="Scp914KnobSetting.Fine"/>.
/// </summary>
public IEnumerable<FirearmItemProcessor.FirearmOutput> FineOutputs
{
get => Base._fineOutputs;
set => Base._fineOutputs = value.ToArray();
}

/// <summary>
/// Gets or sets a list of items that replace upgrading item when <see cref="Scp914KnobSetting"/> is <see cref="Scp914KnobSetting.VeryFine"/>.
/// </summary>
public IEnumerable<FirearmItemProcessor.FirearmOutput> VeryFineOutputs
{
get => Base._veryFineOutputs;
set => Base._veryFineOutputs = value.ToArray();
}

/// <inheritdoc/>
public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => Base.GetItems(knobSetting, previousItem).Random();
}
}
35 changes: 35 additions & 0 deletions Exiled.API/Features/Scp914Processors/MicroHidProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// -----------------------------------------------------------------------
// <copyright file="MicroHidProcessor.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.Scp914Processors
{
using Exiled.API.Interfaces;
using global::Scp914;
using global::Scp914.Processors;

/// <summary>
/// A processor for <see cref="ItemType.MicroHID"/>.
/// </summary>
public class MicroHidProcessor : Scp914Processor, IWrapper<MicroHidItemProcessor>
{
/// <summary>
/// Initializes a new instance of the <see cref="MicroHidProcessor"/> class.
/// </summary>
/// <param name="scp914ItemProcessor">The <see cref="MicroHidItemProcessor"/> instance.</param>
public MicroHidProcessor(MicroHidItemProcessor scp914ItemProcessor)
: base(scp914ItemProcessor)
{
Base = scp914ItemProcessor;
}

/// <inheritdoc/>
public new MicroHidItemProcessor Base { get; }

/// <inheritdoc/>
public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => Base.GetOutput(knobSetting);
}
}
Loading

0 comments on commit 8c0c583

Please sign in to comment.