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 = true; private IntVec3 cellPosition; public override void PostExposeData() { base.PostExposeData(); Scribe_Values.Look(ref position, "position", default); Scribe_Values.Look(ref cellPosition, "cellPosition", default); } 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(); 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); } /*public bool IsBeingWorn() { Pawn pawn = apparel.Wearer; if (apparel.def.apparel.wornGraphicPath.NullOrEmpty()) { return true; } foreach (ApparelGraphicRecord record in pawn.Drawer.renderer.graphics.apparelGraphics) { if (record.sourceApparel == apparel) { return true; } } return false; }*/ } } //var methodInfo = AccessTools.Method(typeof(GenPlace), "TryFindPlaceSpotNear", null, null); //object[] parameters = new object[] { apparel.Wearer.Position, default(Rot4), apparel.Wearer.Map, apparel.Wearer, false, null, null }; //object result = methodInfo.Invoke(null, parameters); /*bool _result = (bool)result; if (_result) { bestSpot = (IntVec3)parameters[5]; DebugMode.Message("Best position: " + bestSpot.ToString()); }*/