rimworld-animations-patch_m.../Source/Scripts/Patches/HarmonyPatch_CompBodyAnimator.cs
AbstractConcept 8e6918ae70 First commit
2022-09-09 20:22:08 -05:00

46 lines
1.6 KiB
C#

using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
using RimWorld;
using Verse;
using AlienRace;
using Rimworld_Animations;
namespace Rimworld_Animations_Patch
{
[StaticConstructorOnStartup]
[HarmonyPatch(typeof(CompBodyAnimator), "calculateDrawValues")]
public static class HarmonyPatch_CompBodyAnimator_calculateDrawValues
{
public static void Postfix(CompBodyAnimator __instance)
{
if (__instance?.pawn == null)
{ return; }
if (BasicSettings.autoscaleDeltaPos)
{
__instance.deltaPos.x *= __instance.pawn.RaceProps.baseBodySize;
__instance.deltaPos.z *= __instance.pawn.RaceProps.baseBodySize;
}
if (__instance.pawn.IsInBed(out Building bed) &&
__instance.pawn.GetAnimationData().animationDef.actors[__instance.pawn.GetAnimationData().actorID].requiredGenitals.NullOrEmpty() == false &&
__instance.pawn.GetAnimationData().animationDef.actors[__instance.pawn.GetAnimationData().actorID].requiredGenitals.Contains("Bed"))
{
__instance.bodyAngle += ((float)bed.Rotation.AsInt - 2f) * 90;
if (__instance.bodyAngle < 0) __instance.bodyAngle = 360 - ((-1f * __instance.bodyAngle) % 360);
if (__instance.bodyAngle > 360) __instance.bodyAngle %= 360;
__instance.headAngle += ((float)bed.Rotation.AsInt - 2f) * 90;
if (__instance.headAngle < 0) __instance.headAngle = 360 - ((-1f * __instance.headAngle) % 360);
if (__instance.headAngle > 360) __instance.headAngle %= 360;
__instance.deltaPos = __instance.deltaPos.RotatedBy(-(float)bed.Rotation.AsAngle);
}
}
}
}