Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features
namespace Exiled.API.Features.CustomStats
{
using PlayerStatsSystem;

Expand Down
74 changes: 74 additions & 0 deletions EXILED/Exiled.API/Features/CustomStats/CustomHumeShieldStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// -----------------------------------------------------------------------
// <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
{
private const float DefaultCustomValue = -1;

/// <inheritdoc/>
public override float MaxValue => CustomMaxValue == DefaultCustomValue ? 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; }

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

/// <inheritdoc/>
public override void Update()
{
if (MaxValue == DefaultCustomValue)
{
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);
}
}
}
}
37 changes: 30 additions & 7 deletions 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 @@ -95,6 +96,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 @@ -176,6 +178,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 @@ -914,6 +917,16 @@ public float MaxArtificialHealth
}
}

/// <summary>
/// Gets the <see cref="AhpStat"/> of the Player.
/// </summary>
public AhpStat AhpStat => ReferenceHub.playerStats.GetModule<AhpStat>();

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

/// <summary>
/// Gets or sets the player's Hume Shield.
/// </summary>
Expand All @@ -925,14 +938,27 @@ public float HumeShield
}

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of all active Artificial Health processes on the player.
/// Gets or sets the players maximum Hume Shield.
/// </summary>
public IEnumerable<AhpStat.AhpProcess> ActiveArtificialHealthProcesses => ReferenceHub.playerStats.GetModule<AhpStat>()._activeProcesses;
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 the player's <see cref="PlayerStatsSystem.HumeShieldStat"/>.
/// </summary>
public HumeShieldStat HumeShieldStat => ReferenceHub.playerStats.GetModule<HumeShieldStat>();
public CustomHumeShieldStat 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 Expand Up @@ -3441,10 +3467,7 @@ public void ChangeEffectIntensity(string effectName, byte intensity, float durat
/// <param name="sustain">The number of seconds to delay the start of the decay.</param>
/// <param name="persistant">Whether the process is removed when the value hits 0.</param>
public void AddAhp(float amount, float limit = 75f, float decay = 1.2f, float efficacy = 0.7f, float sustain = 0f, bool persistant = false)
{
ReferenceHub.playerStats.GetModule<AhpStat>()
.ServerAddProcess(amount, limit, decay, efficacy, sustain, persistant);
}
=> AhpStat.ServerAddProcess(amount, limit, decay, efficacy, sustain, persistant);

/// <summary>
/// Reconnects the player to the server. Can be used to redirect them to another server on a different port but same IP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private static void UpdatePlayerRole(RoleTypeId newRole, API.Features.Player pla
if (newRole is RoleTypeId.Scp173)
Scp173Role.TurnedPlayers.Remove(player);

player.MaxHumeShield = -1;
player.MaxHealth = default;
}

Expand All @@ -192,10 +193,9 @@ private static void ChangeInventory(ChangingRoleEventArgs ev)
}

Inventory inventory = ev.Player.Inventory;
bool flag = InventoryItemProvider.KeepItemsAfterEscaping && ev.Reason == API.Enums.SpawnReason.Escaped;
if (flag)
if (InventoryItemProvider.KeepItemsAfterEscaping && ev.Reason == API.Enums.SpawnReason.Escaped)
{
List<ItemPickupBase> list = new List<ItemPickupBase>();
List<ItemPickupBase> list = new();
if (inventory.TryGetBodyArmor(out BodyArmor bodyArmor))
{
bodyArmor.DontRemoveExcessOnDrop = true;
Expand All @@ -222,8 +222,7 @@ private static void ChangeInventory(ChangingRoleEventArgs ev)
HashSetPool<ushort>.Pool.Return(hashSet);
InventoryItemProvider.PreviousInventoryPickups[ev.Player.ReferenceHub] = list;
}

if (!flag)
else
{
while (inventory.UserInventory.Items.Count > 0)
{
Expand Down
Loading