rimworld-animations-patch_m.../Source/Scripts/Comps/CompApparelVisibility.cs
AbstractConcept 38ec4f86c1 v 2.0.0
2023-02-04 01:13:57 -06:00

56 lines
No EOL
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
using UnityEngine;
using Rimworld_Animations;
using HarmonyLib;
namespace Rimworld_Animations_Patch
{
public class CompApparelVisibility : ThingComp
{
public Apparel apparel => base.parent as Apparel;
public Vector3 position;
public float rotation = 0f;
public bool? isBeingWorn = null;
public bool coversChest = false;
public bool coversGroin = false;
public bool coversBelly = false;
public RimNudeDataStatus rimNudeDataStatus = RimNudeDataStatus.NotLoaded;
private IntVec3 cellPosition;
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(ref position, "position", default);
Scribe_Values.Look(ref rotation, "rotation", 0);
Scribe_Values.Look(ref cellPosition, "cellPosition", default);
}
// Used to find a place to have clothes thrown onto the floor
public void GenerateFloorPosition(IntVec3 apparelCell, Vector2 apparelOffset = default)
{
Pawn pawn = apparel.Wearer;
// Reuse an old location for thrown clothes if the wearer is not too far away from it
if ((cellPosition - pawn.Position).LengthManhattan <= 2 && cellPosition.GetRoom(pawn.Map) == pawn.GetRoom())
{ return; }
CompBodyAnimator comp = pawn.TryGetComp<CompBodyAnimator>();
if (comp == null || comp.isAnimating == false)
{ return; }
cellPosition = apparelCell;
apparel.Rotation = Rot4.Random;
Vector3 offset = new Vector3(Rand.Gaussian(apparelOffset.x, apparelOffset.y), 0f, Rand.Gaussian(apparelOffset.x, apparelOffset.y));
position = cellPosition.ToVector3() + offset + new Vector3(0.5f, AltitudeLayer.ItemImportant.AltitudeFor() - Mathf.Clamp(apparel.def.apparel.LastLayer.drawOrder/100000f, 0f, 1f), 0.5f);
rotation = 120 * (-1f + 2f * Rand.Value);
}
}
}