rimworld-animations-patch_m.../Source/Scripts/Patches/HarmonyPatch_CompBodyAnimator.cs

49 lines
1.7 KiB
C#
Raw Normal View History

2022-09-10 01:22:08 +00:00
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; }
2023-02-06 00:41:57 +00:00
// Scale delta by body size
2022-09-10 01:22:08 +00:00
if (BasicSettings.autoscaleDeltaPos)
{
__instance.deltaPos.x *= __instance.pawn.RaceProps.baseBodySize;
__instance.deltaPos.z *= __instance.pawn.RaceProps.baseBodySize;
}
2023-02-06 00:41:57 +00:00
// In-bed specific animations cause the actors to turn to match its facing
2022-09-10 01:22:08 +00:00
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);
}
}
}
}