Skip to content

Commit

Permalink
UPDATE 1.0.1 | Make effect more smoothly
Browse files Browse the repository at this point in the history
  • Loading branch information
Vretu-Dev authored Sep 10, 2024
1 parent d5e3396 commit db543bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
37 changes: 32 additions & 5 deletions AdrenalinRush/AdrenalinRush.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
using System;
using System.Collections.Generic;
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
using MEC;
using PlayerEffects = CustomPlayerEffects;

namespace AdrenalinRush {
namespace AdrenalinRush
{
public class AdrenalinRush : Plugin<Config>
{
public override string Name => "Adrenalin Rush";
public override string Author => "Vretu";
public override string Prefix { get; } = "AR";
public override Version Version => new Version(1, 0, 0);
public override Version Version => new Version(1, 0, 1);
public override Version RequiredExiledVersion { get; } = new Version(8, 9, 8);

public override void OnEnabled()
{
Exiled.Events.Handlers.Player.UsedItem += OnUsedItem;
base.OnEnabled();
}

public override void OnDisabled()
{
Exiled.Events.Handlers.Player.UsedItem -= OnUsedItem;
base.OnDisabled();
}

// Handler for Using Adrenaline
private void OnUsedItem(UsedItemEventArgs ev)
{
if (ev.Item.Type == ItemType.Adrenaline)
{
ev.Player.EnableEffect(EffectType.MovementBoost, Config.BoostIntensity, Config.BoostDuration);
Timing.RunCoroutine(ApplySmoothBoost(ev.Player));
}
}
private IEnumerator<float> ApplySmoothBoost(Player player)
{
float currentIntensity = 0f;
float increment = Config.BoostIntensity / Config.SpeedIncrease; // Adjust how fast the boost grows
float duration = Config.BoostDuration;
float stepDuration = duration / Config.Steps; // Number of steps after speed is refreshed in the duration

// Enable movement boost effect for full duration setting in config
player.EnableEffect(EffectType.MovementBoost, duration);

// Retrieve active movement boost effect
var movementBoost = player.ReferenceHub.playerEffectsController.GetEffect<PlayerEffects.MovementBoost>();

// Smooth increase intensity
while (currentIntensity < Config.BoostIntensity)
{
currentIntensity += increment;
movementBoost.Intensity = (byte)currentIntensity;
yield return Timing.WaitForSeconds(stepDuration);
}
// Maximum intensity
movementBoost.Intensity = Config.BoostIntensity;
}

}
}
9 changes: 8 additions & 1 deletion AdrenalinRush/config.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using Exiled.API.Interfaces;
using System.ComponentModel;

namespace AdrenalinRush
{
public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
public int BoostDuration { get; set; } = 3;
[Description("Duration time of effect in seconds.")]
public int BoostDuration { get; set; } = 4;
[Description("It's effect Intensity. Same as Remote Admin.")]
public byte BoostIntensity { get; set; } = 30;
[Description("Adjust how fast the boost grows. It's BoostIntensity / SpeedIncrease. For example [30 Intensity / 4s Duration = 7,5 IntensityBoost per second].")]
public int SpeedIncrease { get; set; } = 4;
[Description("Number of steps after speed is refreshed. Higher value = refreshing more frequently.")]
public int Steps { get; set; } = 5;
}
}

0 comments on commit db543bc

Please sign in to comment.