2018-05-03 01:25:49 -04:00
|
|
|
|
using SharedLibraryCore.Helpers;
|
2018-05-11 00:52:20 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-05-03 01:25:49 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Cheat
|
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
class Strain
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
private const double StrainDecayBase = 0.9;
|
2018-05-03 01:25:49 -04:00
|
|
|
|
private double CurrentStrain;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
public double LastDistance { get; private set; }
|
|
|
|
|
public Vector3 LastAngle { get; private set; }
|
|
|
|
|
public double LastDeltaTime { get; private set; }
|
2018-05-03 01:25:49 -04:00
|
|
|
|
|
2019-06-24 17:56:47 -04:00
|
|
|
|
public double GetStrain(double killDistance, Vector3 newAngle, double deltaTime)
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
|
|
|
|
if (LastAngle == null)
|
|
|
|
|
LastAngle = newAngle;
|
|
|
|
|
|
2018-05-11 00:52:20 -04:00
|
|
|
|
LastDeltaTime = deltaTime;
|
|
|
|
|
|
2018-05-03 01:25:49 -04:00
|
|
|
|
double decayFactor = GetDecay(deltaTime);
|
|
|
|
|
CurrentStrain *= decayFactor;
|
|
|
|
|
double[] distance = Helpers.Extensions.AngleStuff(newAngle, LastAngle);
|
2018-05-11 00:52:20 -04:00
|
|
|
|
LastDistance = distance[0] + distance[1];
|
2018-05-03 01:25:49 -04:00
|
|
|
|
|
2018-10-28 21:47:56 -04:00
|
|
|
|
#if DEBUG == true
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Console.WriteLine($"Angle Between = {LastDistance}");
|
|
|
|
|
Console.WriteLine($"Distance From Target = {killDistance}");
|
|
|
|
|
Console.WriteLine($"Time Offset = {deltaTime}");
|
|
|
|
|
Console.WriteLine($"Decay Factor = {decayFactor} ");
|
2018-10-28 21:47:56 -04:00
|
|
|
|
#endif
|
2018-05-03 01:25:49 -04:00
|
|
|
|
// this happens on first kill
|
|
|
|
|
if ((distance[0] == 0 && distance[1] == 0) ||
|
2018-05-16 00:57:37 -04:00
|
|
|
|
deltaTime == 0 ||
|
2018-05-03 01:25:49 -04:00
|
|
|
|
double.IsNaN(CurrentStrain))
|
|
|
|
|
{
|
|
|
|
|
return CurrentStrain;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 21:47:56 -04:00
|
|
|
|
double newStrain = Math.Pow(LastDistance, 0.99) / deltaTime;
|
2018-05-20 22:35:56 -04:00
|
|
|
|
newStrain *= killDistance / 1000.0;
|
2018-05-16 00:57:37 -04:00
|
|
|
|
|
2018-05-05 16:36:26 -04:00
|
|
|
|
CurrentStrain += newStrain;
|
2018-05-03 01:25:49 -04:00
|
|
|
|
|
|
|
|
|
LastAngle = newAngle;
|
|
|
|
|
return CurrentStrain;
|
|
|
|
|
}
|
2018-05-11 00:52:20 -04:00
|
|
|
|
|
2018-05-16 00:57:37 -04:00
|
|
|
|
private double GetDecay(double deltaTime) => Math.Pow(StrainDecayBase, Math.Pow(2.0, deltaTime / 250.0) / 1000.0);
|
2018-05-03 01:25:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|