Skip to content

Commit e254141

Browse files
committed
Adjustments to the CustomEffect API
1 parent 53d4bff commit e254141

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

LabExtended/API/Custom/Effects/CustomDurationEffect.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using LabExtended.Attributes;
22

33
using UnityEngine;
4+
using YamlDotNet.Serialization;
45

56
namespace LabExtended.API.Custom.Effects;
67

@@ -11,21 +12,15 @@ namespace LabExtended.API.Custom.Effects;
1112
public abstract class CustomDurationEffect : CustomTickingEffect
1213
{
1314
/// <summary>
14-
/// Gets or sets the remaining duration (in seconds).
15-
/// </summary>
16-
public float RemainingDuration { get; set; } = 0f;
17-
18-
/// <summary>
19-
/// Gets the effect's default duration.
15+
/// Gets or sets the effect's duration.
2016
/// </summary>
21-
/// <returns>The effect's duration.</returns>
22-
public abstract float GetDuration();
17+
public float Duration { get; set; } = 0f;
2318

2419
/// <summary>
25-
/// Called once the remaining duration reaches zero.
20+
/// Gets or sets the remaining duration (in seconds).
2621
/// </summary>
27-
/// <returns>Seconds to add to remaining duration.</returns>
28-
public virtual float CheckDuration() => 0f;
22+
[YamlIgnore]
23+
public float RemainingDuration { get; set; } = 0f;
2924

3025
/// <inheritdoc cref="CustomTickingEffect.Tick"/>
3126
public override void Tick()
@@ -39,14 +34,6 @@ public override void Tick()
3934

4035
if (RemainingDuration <= 0f)
4136
{
42-
var addDuration = CheckDuration();
43-
44-
if (addDuration > 0f)
45-
{
46-
RemainingDuration += addDuration;
47-
return;
48-
}
49-
5037
RemainingDuration = 0f;
5138

5239
IsActive = false;
@@ -57,7 +44,7 @@ public override void Tick()
5744

5845
internal override void OnApplyEffects()
5946
{
60-
RemainingDuration = GetDuration();
47+
RemainingDuration = Duration;
6148
IsActive = RemainingDuration > 0f;
6249

6350
if (IsActive)

LabExtended/API/Custom/Effects/CustomPlayerEffect.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using LabExtended.Utilities;
88

99
using PlayerRoles;
10+
using YamlDotNet.Serialization;
1011

1112
namespace LabExtended.API.Custom.Effects;
1213

@@ -63,11 +64,13 @@ public static bool TryGetEffect(string name, bool onlyFullName, bool ignoreCase,
6364
/// <summary>
6465
/// Gets the player that this effect belongs to.
6566
/// </summary>
67+
[YamlIgnore]
6668
public ExPlayer? Player { get; internal set; }
6769

6870
/// <summary>
6971
/// Whether or not this effect is active.
7072
/// </summary>
73+
[YamlIgnore]
7174
public bool IsActive { get; internal set; }
7275

7376
/// <summary>

LabExtended/API/Custom/Effects/CustomTickingEffect.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using LabExtended.Utilities.Update;
33

44
using UnityEngine;
5+
using YamlDotNet.Serialization;
56

67
namespace LabExtended.API.Custom.Effects;
78

@@ -12,11 +13,11 @@ namespace LabExtended.API.Custom.Effects;
1213
public class CustomTickingEffect : CustomPlayerEffect
1314
{
1415
private float delayTime = 0f;
15-
16+
1617
/// <summary>
1718
/// Custom delay between each tick.
1819
/// </summary>
19-
public virtual float Delay { get; } = 0f;
20+
public virtual float Delay { get; set; } = 0f;
2021

2122
/// <summary>
2223
/// Called once a frame.

0 commit comments

Comments
 (0)