Skip to content

Commit

Permalink
Merge branch 'dev' into elevators
Browse files Browse the repository at this point in the history
  • Loading branch information
LumiFae authored Jan 10, 2025
2 parents e035551 + 659a6a8 commit 0e67613
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 26 deletions.
1 change: 1 addition & 0 deletions EXILED/Exiled.API/Features/CustomHealthStat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Exiled.API.Features

/// <summary>
/// A custom version of <see cref="HealthStat"/> which allows the player's max amount of health to be changed.
/// TODO: Move to Features.CustomStats.
/// </summary>
public class CustomHealthStat : HealthStat
{
Expand Down
79 changes: 79 additions & 0 deletions EXILED/Exiled.API/Features/CustomStats/CustomHumeShieldStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// -----------------------------------------------------------------------
// <copyright file="CustomHumeShieldStat.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.CustomStats
{
using Mirror;
using PlayerRoles.PlayableScps.HumeShield;
using PlayerStatsSystem;
using UnityEngine;
using Utils.Networking;

/// <summary>
/// A custom version of <see cref="HumeShieldStat"/> which allows the player's max amount of HumeShield to be changed.
/// </summary>
public class CustomHumeShieldStat : HumeShieldStat
{
/// <inheritdoc />
public override float MaxValue => CustomMaxValue == -1 ? base.MaxValue : CustomMaxValue;

/// <summary>
/// Gets or sets the multiplier for gaining HumeShield.
/// </summary>
public float ShieldRegenerationMultiplier { get; set; } = 1;

/// <summary>
/// Gets or sets the maximum amount of HumeShield the player can have.
/// </summary>
public float CustomMaxValue { get; set; } = -1;

private float ShieldRegeneration => TryGetHsModule(out HumeShieldModuleBase controller) ? controller.HsRegeneration * ShieldRegenerationMultiplier : 0;

/// <inheritdoc/>
public override void Update()
{
if (MaxValue == -1 && ShieldRegenerationMultiplier is 1)
{
base.Update();
return;
}

if (!NetworkServer.active)
return;

if (_valueDirty)
{
new SyncedStatMessages.StatMessage()
{
Stat = this,
SyncedValue = CurValue,
}.SendToHubsConditionally(CanReceive);
_lastSent = CurValue;
_valueDirty = false;
}

if (ShieldRegeneration == 0)
return;

float delta = ShieldRegeneration * Time.deltaTime;

if (delta > 0)
{
if (CurValue >= MaxValue)
return;

CurValue = Mathf.MoveTowards(CurValue, MaxValue, delta);
return;
}

if (CurValue <= 0)
return;

CurValue += delta;
}
}
}
8 changes: 7 additions & 1 deletion EXILED/Exiled.API/Features/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,13 @@ private DoorType GetDoorType()
// Doors contains the DoorNameTagExtension component
"CHECKPOINT_LCZ_A" => DoorType.CheckpointLczA,
"CHECKPOINT_LCZ_B" => DoorType.CheckpointLczB,
"CHECKPOINT_EZ_HCZ_A" => DoorType.CheckpointEzHczA,

// TODO: Remove when it's fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/782
"CHECKPOINT_EZ_HCZ_A" => Room?.Type switch
{
RoomType.HczEzCheckpointA => DoorType.CheckpointEzHczA,
_ => DoorType.CheckpointEzHczB,
},
"CHECKPOINT_EZ_HCZ_B" => DoorType.CheckpointEzHczB,
"106_PRIMARY" => DoorType.Scp106Primary,
"106_SECONDARY" => DoorType.Scp106Secondary,
Expand Down
24 changes: 23 additions & 1 deletion EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Exiled.API.Features
using DamageHandlers;
using Enums;
using Exiled.API.Features.Core.Interfaces;
using Exiled.API.Features.CustomStats;
using Exiled.API.Features.Doors;
using Exiled.API.Features.Hazards;
using Exiled.API.Features.Items;
Expand Down Expand Up @@ -96,6 +97,7 @@ public class Player : TypeCastObject<Player>, IEntity, IWorldSpace

private ReferenceHub referenceHub;
private CustomHealthStat healthStat;
private CustomHumeShieldStat humeShieldStat;
private Role role;

/// <summary>
Expand Down Expand Up @@ -177,6 +179,7 @@ private set
CameraTransform = value.PlayerCameraReference;

value.playerStats._dictionarizedTypes[typeof(HealthStat)] = value.playerStats.StatModules[Array.IndexOf(PlayerStats.DefinedModules, typeof(HealthStat))] = healthStat = new CustomHealthStat { Hub = value };
value.playerStats._dictionarizedTypes[typeof(HumeShieldStat)] = value.playerStats.StatModules[Array.IndexOf(PlayerStats.DefinedModules, typeof(HumeShieldStat))] = humeShieldStat = new CustomHumeShieldStat { Hub = value };
}
}

Expand Down Expand Up @@ -930,15 +933,34 @@ public float HumeShield
set => HumeShieldStat.CurValue = value;
}

/// <summary>
/// Gets or sets the players maximum Hume Shield.
/// </summary>
public float MaxHumeShield
{
get => humeShieldStat.MaxValue;
set => humeShieldStat.CustomMaxValue = value;
}

/// <summary>
/// Gets or sets the players multiplier for gaining HumeShield.
/// </summary>
public float HumeShieldRegenerationMultiplier
{
get => humeShieldStat.ShieldRegenerationMultiplier;
set => humeShieldStat.ShieldRegenerationMultiplier = value;
}

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of all active Artificial Health processes on the player.
/// </summary>
public IEnumerable<AhpStat.AhpProcess> ActiveArtificialHealthProcesses => ReferenceHub.playerStats.GetModule<AhpStat>()._activeProcesses;

/// <summary>
/// Gets the player's <see cref="PlayerStatsSystem.HumeShieldStat"/>.
/// TODO: Change to <see cref="CustomHumeShieldStat"/>.
/// </summary>
public HumeShieldStat HumeShieldStat => ReferenceHub.playerStats.GetModule<HumeShieldStat>();
public HumeShieldStat HumeShieldStat => humeShieldStat;

/// <summary>
/// Gets or sets the item in the player's hand. Value will be <see langword="null"/> if the player is not holding anything.
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ private static RoomType FindType(GameObject gameObject)
"EZ_Shelter" => RoomType.EzShelter,
"EZ_HCZ_Checkpoint Part" => gameObject.transform.position.z switch
{
> 80 => RoomType.EzCheckpointHallwayA,
> 95 => RoomType.EzCheckpointHallwayA,
_ => RoomType.EzCheckpointHallwayB,
},
"HCZ_EZ_Checkpoint Part" => gameObject.transform.position.z switch
{
> 80 => RoomType.HczEzCheckpointA,
> 95 => RoomType.HczEzCheckpointA,
_ => RoomType.HczEzCheckpointB
},
_ => RoomType.Unknown,
Expand Down
9 changes: 9 additions & 0 deletions EXILED/Exiled.API/Features/Toys/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ public LightType LightType
set => Base.NetworkLightType = value;
}

/// <summary>
/// Gets or sets the type of shadows the light casts.
/// </summary>
public LightShadows ShadowType
{
get => Base.NetworkShadowType;
set => Base.NetworkShadowType = value;
}

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
Expand Down
38 changes: 35 additions & 3 deletions EXILED/Exiled.CustomItems/API/Features/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ internal bool TryUnregister()
protected virtual void SubscribeEvents()
{
Exiled.Events.Handlers.Player.Dying += OnInternalOwnerDying;
Exiled.Events.Handlers.Player.DroppingItem += OnInternalDropping;
Exiled.Events.Handlers.Player.DroppingItem += OnInternalDroppingItem;
Exiled.Events.Handlers.Player.DroppingAmmo += OnInternalDroppingAmmo;
Exiled.Events.Handlers.Player.ChangingItem += OnInternalChanging;
Exiled.Events.Handlers.Player.Escaping += OnInternalOwnerEscaping;
Exiled.Events.Handlers.Player.PickingUpItem += OnInternalPickingUp;
Expand All @@ -852,7 +853,8 @@ protected virtual void SubscribeEvents()
protected virtual void UnsubscribeEvents()
{
Exiled.Events.Handlers.Player.Dying -= OnInternalOwnerDying;
Exiled.Events.Handlers.Player.DroppingItem -= OnInternalDropping;
Exiled.Events.Handlers.Player.DroppingItem -= OnInternalDroppingItem;
Exiled.Events.Handlers.Player.DroppingAmmo -= OnInternalDroppingAmmo;
Exiled.Events.Handlers.Player.ChangingItem -= OnInternalChanging;
Exiled.Events.Handlers.Player.Escaping -= OnInternalOwnerEscaping;
Exiled.Events.Handlers.Player.PickingUpItem -= OnInternalPickingUp;
Expand Down Expand Up @@ -900,10 +902,27 @@ protected virtual void OnOwnerHandcuffing(OwnerHandcuffingEventArgs ev)
/// Handles tracking items when they are dropped by a player.
/// </summary>
/// <param name="ev"><see cref="DroppingItemEventArgs"/>.</param>
protected virtual void OnDroppingItem(DroppingItemEventArgs ev)
{
}

/// <summary>
/// Handles tracking items when they are dropped by a player.
/// </summary>
/// <param name="ev"><see cref="DroppingItemEventArgs"/>.</param>
[Obsolete("Use OnDroppingItem instead.", false)]
protected virtual void OnDropping(DroppingItemEventArgs ev)
{
}

/// <summary>
/// Handles tracking when player requests drop of item which <see cref="ItemType"/> equals to the <see cref="ItemType"/> specified by <see cref="CustomItem"/>.
/// </summary>
/// <param name="ev"><see cref="DroppingAmmoEventArgs"/>.</param>
protected virtual void OnDroppingAmmo(DroppingAmmoEventArgs ev)
{
}

/// <summary>
/// Handles tracking items when they are picked up by a player.
/// </summary>
Expand Down Expand Up @@ -1061,12 +1080,25 @@ private void OnInternalOwnerHandcuffing(HandcuffingEventArgs ev)
}
}

private void OnInternalDropping(DroppingItemEventArgs ev)
private void OnInternalDroppingItem(DroppingItemEventArgs ev)
{
if (!Check(ev.Item))
return;

OnDroppingItem(ev);

// TODO: Don't forget to remove this with next update
#pragma warning disable CS0618
OnDropping(ev);
#pragma warning restore CS0618
}

private void OnInternalDroppingAmmo(DroppingAmmoEventArgs ev)
{
if (Type != ev.ItemType)
return;

OnDroppingAmmo(ev);
}

private void OnInternalPickingUp(PickingUpItemEventArgs ev)
Expand Down
15 changes: 11 additions & 4 deletions EXILED/Exiled.Events/EventArgs/Player/DroppedAmmoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Exiled.Events.EventArgs.Player

using API.Enums;
using API.Features;
using Exiled.API.Extensions;
using Exiled.API.Features.Pickups;
using Interfaces;

Expand All @@ -27,23 +28,29 @@ public class DroppedAmmoEventArgs : IPlayerEvent
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="ammoType">
/// <inheritdoc cref="AmmoType" />
/// <param name="itemType">
/// <inheritdoc cref="ItemType"/>
/// </param>
/// <param name="amount">
/// <inheritdoc cref="Amount" />
/// </param>
/// <param name="ammoPickups">
/// <inheritdoc cref="AmmoPickups" />
/// </param>
public DroppedAmmoEventArgs(Player player, AmmoType ammoType, ushort amount, List<InventorySystem.Items.Firearms.Ammo.AmmoPickup> ammoPickups)
public DroppedAmmoEventArgs(Player player, ItemType itemType, ushort amount, List<InventorySystem.Items.Firearms.Ammo.AmmoPickup> ammoPickups)
{
Player = player;
AmmoType = ammoType;
ItemType = itemType;
AmmoType = ItemExtensions.GetAmmoType(itemType);
Amount = amount;
AmmoPickups = Pickup.Get<AmmoPickup>(ammoPickups);
}

/// <summary>
/// Gets the type of dropped item instead of <see cref="API.Enums.AmmoType"/>.
/// </summary>
public ItemType ItemType { get; }

/// <summary>
/// Gets the type of dropped ammo.
/// </summary>
Expand Down
17 changes: 12 additions & 5 deletions EXILED/Exiled.Events/EventArgs/Player/DroppingAmmoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Exiled.Events.EventArgs.Player
{
using API.Enums;
using API.Features;

using Exiled.API.Extensions;
using Interfaces;

using PlayerRoles;
Expand All @@ -27,23 +27,30 @@ public class DroppingAmmoEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="ammoType">
/// <inheritdoc cref="AmmoType" />
/// <param name="itemType">
/// <inheritdoc cref="ItemType"/>
/// </param>
/// <param name="amount">
/// <inheritdoc cref="int" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public DroppingAmmoEventArgs(Player player, AmmoType ammoType, ushort amount, bool isAllowed = true)
public DroppingAmmoEventArgs(Player player, ItemType itemType, ushort amount, bool isAllowed = true)
{
Player = player;
AmmoType = ammoType;
ItemType = itemType;
AmmoType = ItemExtensions.GetAmmoType(itemType);
Amount = amount;
IsAllowed = isAllowed;
}

/// <summary>
/// Gets the type of item being dropped instead of <see cref="API.Enums.AmmoType"/>.
/// For example, if the plugin gives the player one of the items instead of ammo.
/// </summary>
public ItemType ItemType { get; }

/// <summary>
/// Gets the type of ammo being dropped.
/// </summary>
Expand Down
Loading

0 comments on commit 0e67613

Please sign in to comment.