Questionable/Questionable.Model/GatheringMath.cs

55 lines
1.9 KiB
C#
Raw Permalink Normal View History

2024-08-03 09:17:20 +00:00
using System;
using System.Numerics;
using Questionable.Model.Gathering;
2024-08-05 15:19:17 +00:00
namespace Questionable.Model;
2024-08-03 09:17:20 +00:00
public static class GatheringMath
{
2024-08-05 15:19:17 +00:00
private static readonly Random Rng = new Random();
2024-08-03 09:17:20 +00:00
public static (Vector3, int, float) CalculateLandingLocation(GatheringLocation location)
{
int degrees;
if (location.IsCone())
2024-08-05 15:19:17 +00:00
degrees = Rng.Next(
2024-08-03 09:17:20 +00:00
location.MinimumAngle.GetValueOrDefault(),
location.MaximumAngle.GetValueOrDefault());
else
2024-08-05 15:19:17 +00:00
degrees = Rng.Next(0, 360);
2024-08-03 09:17:20 +00:00
2024-08-05 15:19:17 +00:00
float range = Rng.Next(
2024-08-11 19:22:19 +00:00
(int)(location.CalculateMinimumDistance() * 100),
(int)(location.CalculateMaximumDistance() * 100))
/ 100f;
2024-08-03 09:17:20 +00:00
return (CalculateLandingLocation(location.Position, degrees, range), degrees, range);
}
public static Vector3 CalculateLandingLocation(GatheringLocation location, float angleScale, float rangeScale)
{
int degrees;
if (location.IsCone())
degrees = location.MinimumAngle.GetValueOrDefault()
+ (int)(angleScale * (location.MaximumAngle.GetValueOrDefault() -
location.MinimumAngle.GetValueOrDefault()));
else
degrees = (int)(rangeScale * 360);
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 rad = -(float)(degrees * Math.PI / 180);
return new Vector3
{
X = position.X + range * (float)Math.Sin(rad),
Y = position.Y,
Z = position.Z + range * (float)Math.Cos(rad)
};
}
}