IW4M-Admin/Plugins/Stats/Cheat/Strain.cs
RaidMax 4006c09045 add most played command
hopefully fixed thread lock?
started work on elo rating
2018-05-15 23:57:37 -05:00

72 lines
2.1 KiB
C#

using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
namespace IW4MAdmin.Plugins.Stats.Cheat
{
class Strain : ITrackable
{
private const double StrainDecayBase = 0.9;
private double CurrentStrain;
private Vector3 LastAngle;
private double LastDeltaTime;
private double LastDistance;
public int TimesReachedMaxStrain { get; private set; }
public double GetStrain(bool isDamage, int damage, Vector3 newAngle, double deltaTime)
{
if (LastAngle == null)
LastAngle = newAngle;
LastDeltaTime = deltaTime;
double decayFactor = GetDecay(deltaTime);
CurrentStrain *= decayFactor;
#if DEBUG
Console.WriteLine($"Decay Factor = {decayFactor} ");
#endif
double[] distance = Helpers.Extensions.AngleStuff(newAngle, LastAngle);
LastDistance = distance[0] + distance[1];
// this happens on first kill
if ((distance[0] == 0 && distance[1] == 0) ||
deltaTime == 0 ||
double.IsNaN(CurrentStrain))
{
return CurrentStrain;
}
double newStrain = Math.Pow(distance[0] + distance[1], 0.99) / deltaTime;
if (damage < 100 && isDamage)
{
newStrain *= Math.Pow(damage, 2) / 10000.0;
}
else if (damage > 100)
{
newStrain *= damage / 100.0;
}
CurrentStrain += newStrain;
if (CurrentStrain > Thresholds.MaxStrainBan)
TimesReachedMaxStrain++;
LastAngle = newAngle;
return CurrentStrain;
}
public string GetTrackableValue()
{
return $"Strain - {CurrentStrain}, Angle - {LastAngle}, Delta Time - {LastDeltaTime}, Distance - {LastDistance}";
}
private double GetDecay(double deltaTime) => Math.Pow(StrainDecayBase, Math.Pow(2.0, deltaTime / 250.0) / 1000.0);
}
}