2019-06-30 14:37:59 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-05-03 01:25:49 -04:00
|
|
|
|
using System;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models;
|
2018-05-03 01:25:49 -04:00
|
|
|
|
|
|
|
|
|
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;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
double[] distance = Utilities.AngleStuff(newAngle, LastAngle);
|
2018-05-11 00:52:20 -04:00
|
|
|
|
LastDistance = distance[0] + distance[1];
|
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
|
|
|
|
}
|
|
|
|
|
}
|