Skip to content

Commit

Permalink
Fix tranq gun resistances never getting reduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Mar 3, 2021
1 parent 5a21c03 commit e97a57a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions CustomItems/Items/TranquilizerGun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class TranquilizerGun : CustomWeapon
[Description("Everytime a player is tranquilized, they gain a resistance to further tranquilizations, reducing the duration of future effects. This number signifies the exponential modifier used to determine how much time is removed from the effect.")]
public float ResistanceModifier { get; set; } = 1.2f;

/// <summary>
/// Gets or sets a value indicating how often player resistances are reduced.
/// </summary>
[Description("How often the plugin should reduce the resistance amount for players, in seconds.")]
public float ResistanceFalloffDelay { get; set; } = 120f;

/// <summary>
/// Gets or sets a value indicating whether or not tranquilized targets should drop all of their items.
/// </summary>
Expand All @@ -96,10 +102,18 @@ public class TranquilizerGun : CustomWeapon
public override void Destroy()
{
tranquilizedPlayers.Clear();
Timing.KillCoroutines($"{nameof(TranquilizerGun)}-{Id}-reducer");

base.Destroy();
}

/// <inheritdoc/>
protected override void SubscribeEvents()
{
Timing.RunCoroutine(ReduceResistances(), $"{nameof(TranquilizerGun)}-{Id}-reducer");
base.SubscribeEvents();
}

/// <inheritdoc/>
protected override void OnHurting(HurtingEventArgs ev)
{
Expand Down Expand Up @@ -193,5 +207,16 @@ private IEnumerator<float> DoTranquilize(Player player, float duration)

player.Position = oldPosition;
}

private IEnumerator<float> ReduceResistances()
{
for (; ;)
{
foreach (Player player in tranquilizedPlayers.Keys)
tranquilizedPlayers[player] = Mathf.Max(0, tranquilizedPlayers[player] / 2);

yield return Timing.WaitForSeconds(ResistanceFalloffDelay);
}
}
}
}
2 changes: 1 addition & 1 deletion CustomItems/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.8.0")]
[assembly: AssemblyVersion("2.1.9.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]

0 comments on commit e97a57a

Please sign in to comment.