forked from aly/qstbak
35 lines
1.5 KiB
C#
35 lines
1.5 KiB
C#
using System;
|
|
using System.Numerics;
|
|
using Questionable.Model.Gathering;
|
|
|
|
namespace Questionable.Model;
|
|
|
|
public static class GatheringMath
|
|
{
|
|
private static readonly Random Rng = new Random();
|
|
|
|
public static (Vector3, int, float) CalculateLandingLocation(GatheringLocation location)
|
|
{
|
|
int num = ((!location.IsCone()) ? Rng.Next(0, 360) : Rng.Next(location.MinimumAngle.GetValueOrDefault(), location.MaximumAngle.GetValueOrDefault()));
|
|
float num2 = (float)Rng.Next((int)(location.CalculateMinimumDistance() * 100f), (int)(location.CalculateMaximumDistance() * 100f)) / 100f;
|
|
return (CalculateLandingLocation(location.Position, num, num2), num, num2);
|
|
}
|
|
|
|
public static Vector3 CalculateLandingLocation(GatheringLocation location, float angleScale, float rangeScale)
|
|
{
|
|
int degrees = ((!location.IsCone()) ? ((int)(rangeScale * 360f)) : (location.MinimumAngle.GetValueOrDefault() + (int)(angleScale * (float)(location.MaximumAngle.GetValueOrDefault() - location.MinimumAngle.GetValueOrDefault()))));
|
|
float range = location.CalculateMinimumDistance() + rangeScale * (location.CalculateMaximumDistance() - location.CalculateMinimumDistance());
|
|
return CalculateLandingLocation(location.Position, degrees, range);
|
|
}
|
|
|
|
private static Vector3 CalculateLandingLocation(Vector3 position, int degrees, float range)
|
|
{
|
|
float num = 0f - (float)((double)degrees * Math.PI / 180.0);
|
|
return new Vector3
|
|
{
|
|
X = position.X + range * (float)Math.Sin(num),
|
|
Y = position.Y,
|
|
Z = position.Z + range * (float)Math.Cos(num)
|
|
};
|
|
}
|
|
}
|