forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into DisruptorEvents
- Loading branch information
Showing
23 changed files
with
401 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
EXILED/Exiled.API/Features/CustomStats/CustomHumeShieldStat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.