mirror of
https://gitgud.io/AbstractConcept/rimworld-animations-patch.git
synced 2024-08-15 00:43:27 +00:00
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using Verse;
|
|
|
|
namespace Rimworld_Animations_Patch
|
|
{
|
|
public static class MathUtility
|
|
{
|
|
public static float Repeat(float value, float min, float max)
|
|
{
|
|
if (Mathf.Abs(max) < Mathf.Abs(min))
|
|
{
|
|
Log.Error("RepeatDual: min value must be greater than max value");
|
|
return -1;
|
|
}
|
|
|
|
float range = max - min;
|
|
float m = value % range;
|
|
|
|
if (m < 0)
|
|
{ m = range + m; }
|
|
|
|
return min + m;
|
|
}
|
|
|
|
public static IntVec3 FindRandomCellNearPawn(Pawn pawn, int maxRadius)
|
|
{
|
|
if (maxRadius > 0)
|
|
{
|
|
for (int radius = 1; radius < maxRadius; radius++)
|
|
{
|
|
IEnumerable<IntVec3> cells = GenRadial.RadialCellsAround(pawn.Position, radius + 0.75f, false).Where(x => x.Standable(pawn.Map) && x.GetRoom(pawn.Map) == pawn.GetRoom());
|
|
|
|
if (cells?.Any() == true && cells.Count() > 0)
|
|
{ return cells.RandomElement(); }
|
|
}
|
|
}
|
|
|
|
return GenAdj.RandomAdjacentCellCardinal(pawn);
|
|
}
|
|
|
|
public static float ClampAngle(float angle)
|
|
{
|
|
return angle < 0f ? 360f - (angle % 360) : angle % 360f;
|
|
}
|
|
}
|
|
}
|