mirror of
https://gitgud.io/AbstractConcept/rimworld-animations-patch.git
synced 2024-08-15 00:43:27 +00:00
47 lines
1.3 KiB
C#
47 lines
1.3 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++)
|
|
{
|
|
List<IntVec3> cells = GenRadial.RadialCellsAround(pawn.Position, radius + 0.75f, false).Where(x => x.Standable(pawn.Map) && x.GetRoom(pawn.Map) == pawn.GetRoom())?.ToList();
|
|
|
|
if (cells.NullOrEmpty() == false && cells.Count > 0)
|
|
{ return cells.RandomElement(); }
|
|
}
|
|
}
|
|
|
|
return GenAdj.RandomAdjacentCellCardinal(pawn);
|
|
}
|
|
}
|
|
}
|