This commit is contained in:
AbstractConcept 2022-10-01 21:14:35 -05:00
parent d18d422a94
commit fcf187c7dd
22 changed files with 184 additions and 41 deletions

View file

@ -30,10 +30,10 @@ namespace Rimworld_Animations_Patch
if (isPortrait)
{ renderFlags |= PawnRenderFlags.Portrait; }
bodyPartRecord = pawn?.def?.race?.body?.AllParts?.FirstOrDefault(x => x.def.defName == bodyAddon?.bodyPart || x.customLabel == bodyAddon?.bodyPart);
bodyPartRecord = pawn.def?.race?.body?.AllParts?.FirstOrDefault(x => x.def.defName == bodyAddon?.bodyPart || x.customLabel == bodyAddon?.bodyPart);
alignsWithHead = bodyAddon.alignWithHead || (bodyPartRecord != null && bodyPartRecord.IsInGroup(BodyPartGroupDefOf.FullHead));
GenerateOffsets();
UpdateVisibility();
}
@ -115,7 +115,10 @@ namespace Rimworld_Animations_Patch
{
if (pawn == null || bodyAddon == null) return false;
if (pawn.CurrentBed()?.def.building.bed_showSleeperBody == false && bodyAddon.drawnInBed == false)
if (renderFlags.FlagSet(PawnRenderFlags.Portrait) == false && pawn.CurrentBed()?.def.building.bed_showSleeperBody == false && bodyAddon.drawnInBed == false)
{ return false; }
if (renderFlags.FlagSet(PawnRenderFlags.Portrait) == false && (pawn.GetPosture() == PawnPosture.LayingOnGroundNormal || pawn.GetPosture() == PawnPosture.LayingOnGroundFaceUp) && bodyAddon.drawnOnGround == false)
{ return false; }
if (bodyAddon.backstoryRequirement.NullOrEmpty() == false && pawn.story?.AllBackstories?.Any((Backstory x) => x.identifier == bodyAddon.backstoryRequirement) == false)
@ -130,26 +133,25 @@ namespace Rimworld_Animations_Patch
if (bodyAddon.bodyTypeRequirement.NullOrEmpty() == false && pawn.story?.bodyType.ToString() != bodyAddon.bodyTypeRequirement)
{ return false; }
if ((pawn.GetPosture() == PawnPosture.LayingOnGroundNormal || pawn.GetPosture() == PawnPosture.LayingOnGroundFaceUp) && bodyAddon.drawnOnGround == false)
{ return false; }
return true;
}
public void UpdateVisibility()
{
if (pawn == null || bodyAddon == null) return;
if (pawn == null || bodyAddon == null || bodyPartRecord == null) return;
canDraw = true;
if (pawn.health?.hediffSet?.GetNotMissingParts()?.Contains(bodyPartRecord) == false)
{ bodyPartMissing = true; return; }
if (pawn?.apparel?.WornApparel == null || pawn.apparel.WornApparel.NullOrEmpty())
{ return; }
foreach (Apparel apparel in pawn.apparel.WornApparel)
{
CompApparelVisibility comp = apparel?.TryGetComp<CompApparelVisibility>();
if (comp == null) continue;
LoadRimNudeData(comp);
if (comp.isBeingWorn == false) continue;

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using HarmonyLib;
using BabiesAndChildren;
using BabiesAndChildren.api;
namespace Rimworld_Animations_Patch
{
[StaticConstructorOnStartup]
public static class HarmonyPatch_BabiesAndChildren
{
static HarmonyPatch_BabiesAndChildren()
{
try
{
((Action)(() =>
{
if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "babies.and.children.continued.13"))
{
(new Harmony("Rimworld_Animations_Patch")).Patch(AccessTools.Method(typeof(AnimationPatchUtility), "ShouldNotDrawAddonsForPawn"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_BabiesAndChildren), "Prefix_ShouldNotDrawAddonsForPawn")));
(new Harmony("Rimworld_Animations_Patch")).Patch(AccessTools.Method(typeof(AnimationPatchUtility), "GetBodySize"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_BabiesAndChildren), "Prefix_GetBodySize")));
}
}))();
}
catch (TypeLoadException ex) { }
}
public static bool Prefix_ShouldNotDrawAddonsForPawn(ref bool __result, Pawn pawn)
{
__result = AgeStages.IsYoungerThan(pawn, AgeStages.Child, false);
return false;
}
public static bool Prefix_GetBodySize(ref float __result, Pawn pawn)
{
__result = pawn.ShouldBeScaled() ? ChildrenUtility.GetBodySize(pawn) : 1f;
return false;
}
}
}

View file

@ -12,7 +12,7 @@ using rjw;
namespace Rimworld_Animations_Patch
{
[StaticConstructorOnStartup]
/*[StaticConstructorOnStartup]
[HarmonyPatch(typeof(PawnRenderer), "RenderPawnInternal", new Type[]
{
typeof(Vector3),
@ -67,7 +67,7 @@ namespace Rimworld_Animations_Patch
}
}
}
}
}*/
[StaticConstructorOnStartup]
[HarmonyPatch(typeof(PawnGraphicSet), "ResolveAllGraphics")]

View file

@ -38,6 +38,4 @@ namespace Rimworld_Animations_Patch
__instance?.pawn?.TryGetComp<CompPawnSexData>()?.UpdateBodyAddonVisibility();
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using HarmonyLib;
using RJW_Events;
namespace Rimworld_Animations_Patch
{
[StaticConstructorOnStartup]
public static class HarmonyPatch_RJWEvents
{
static HarmonyPatch_RJWEvents()
{
try
{
((Action)(() =>
{
if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "c0ffee.rjw.events"))
{
(new Harmony("Rimworld_Animations_Patch")).Patch(AccessTools.Method(typeof(ThinkNode_ConditionalNude), "Satisfied"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_RJWEvents), "Postfix_ThinkNode_ConditionalNude_Satisfied")));
}
}))();
}
catch (TypeLoadException ex) { }
}
public static bool Postfix_ThinkNode_ConditionalNude_Satisfied(ref bool __result, Pawn pawn)
{
if (__result == false && pawn?.apparel?.WornApparel != null)
{
// If 'isBeingWorn' has a value, the apparel has already been checked if it should be discarded
if (pawn.apparel.WornApparel.Any(x => x.TryGetComp<CompApparelVisibility>() != null && x.TryGetComp<CompApparelVisibility>().isBeingWorn.HasValue))
{ __result = true; }
}
return false;
}
}
}

View file

@ -95,7 +95,6 @@ namespace Rimworld_Animations_Patch
DebugMode.Message("Running animation: " + anim.defName);
List<Pawn> pawnsToAnimate = pawn.GetAllSexParticipants();
Pawn Target = pawn.GetSexReceiver();
foreach (Pawn participant in pawnsToAnimate)
{
@ -109,7 +108,9 @@ namespace Rimworld_Animations_Patch
public static bool Prefix_DrawAddons(PawnRenderFlags renderFlags, Vector3 vector, Vector3 headOffset, Pawn pawn, Quaternion quat, Rot4 rotation)
{
if (!(pawn.def is ThingDef_AlienRace alienProps) || renderFlags.FlagSet(PawnRenderFlags.Invisible)) return false;
if (AnimationPatchUtility.ShouldNotDrawAddonsForPawn(pawn))
{ return false; }
// Try to draw apparel thrown on ground
if (ApparelSettings.clothesThrownOnGround)
{ ApparelAnimationUtility.TryToDrawApparelOnFloor(pawn); }
@ -168,8 +169,22 @@ namespace Rimworld_Animations_Patch
bodyAddonAngle = bodyAddonAngle < 0f ? 360f - (bodyAddonAngle % 360) : bodyAddonAngle % 360f;
float combinedAngle = (bodyAngle + bodyAddonAngle) < 0f ? 360f + ((bodyAngle + bodyAddonAngle) % 360) : (bodyAngle + bodyAddonAngle) % 360f;
Vector3 bodyAddonPosition = vector + (bodyAddonDatum.alignsWithHead ? headOffset : Vector3.zero) + bodyAddonDatum.GetOffset(rotation).RotatedBy(angle: bodyAngle);
Vector3 vector_ = vector;
Vector3 headOffset_ = bodyAddonDatum.alignsWithHead ? headOffset : Vector3.zero;
Vector3 bodyAddonOffset_ = bodyAddonDatum.GetOffset(apparentRotation).RotatedBy(angle: bodyAngle);
if (pawn.ageTracker.Adult == false)
{
float bodySize = AnimationPatchUtility.GetBodySize(pawn);
addonGraphic.drawSize = new Vector2(1.5f * bodySize, 1.5f * bodySize); // Doesn't seem to be a need to scale by body part draw size (re: Orassians)
Vector2 multi = AnimationPatchUtility.GetRaceSpecificOffsetMultipliers(pawn, bodyAddon.bodyPart);
bodyAddonOffset_.x *= bodySize * multi.x;
bodyAddonOffset_.z *= bodySize * multi.y;
}
Vector3 bodyAddonPosition = vector_ + headOffset_ + bodyAddonOffset_;
// Draw the addon if visible
if (canDraw)
{

View file

@ -6,25 +6,9 @@ using System.Threading.Tasks;
using RimWorld;
using Verse;
using HarmonyLib;
using RJW_Events;
namespace Rimworld_Animations_Patch
{
[HarmonyPatch(typeof(ThinkNode_ConditionalNude), "Satisfied")]
public static class HarmonyPatch_ThinkNode_ConditionalNude
{
public static void Postfix(ref bool __result, Pawn pawn)
{
if (__result == false && pawn?.apparel?.WornApparel != null)
{
// If 'isBeingWorn' has a value, the apparel has already been checked if it should be discarded
if (pawn.apparel.WornApparel.Any(x => x.TryGetComp<CompApparelVisibility>() != null && x.TryGetComp<CompApparelVisibility>().isBeingWorn.HasValue))
{ __result = true; return; }
}
}
}
[HarmonyPatch(typeof(ThoughtWorker_Precept_GroinChestHairOrFaceUncovered), "HasUncoveredGroinChestHairOrFace")]
public static class HarmonyPatch_ThoughtWorker_Precept_GroinChestHairOrFaceUncovered
{

View file

@ -172,5 +172,43 @@ namespace Rimworld_Animations_Patch
return anchor;
}
}
public static bool ShouldNotDrawAddonsForPawn(Pawn pawn)
{
return false;
}
public static float GetBodySize(Pawn pawn)
{
return 1f;
}
private static Dictionary<string, Vector3> raceSpecifocChildMultipliers = new Dictionary<string, Vector3>()
{
{ "Alien_Orassan", new Vector3(1.4f, 1.4f, 1.4f) },
{ "Alien_Cutebold", new Vector3(1.2f, 1f, 1f) },
};
public static Vector2 GetRaceSpecificOffsetMultipliers(Pawn pawn, string bodypart)
{
Vector2 multiplierVector = new Vector2();
if (GetBodySize(pawn) == 1f || raceSpecifocChildMultipliers.TryGetValue(pawn.def.defName, out Vector3 raceVector) == false)
{ raceVector = new Vector3(1f, 1f, 1f); }
if (bodypart?.ToLower() == "tail")
{
multiplierVector.x = raceVector.z;
multiplierVector.y = raceVector.x;
}
else
{
multiplierVector.x = raceVector.y;
multiplierVector.y = raceVector.x;
}
return multiplierVector;
}
}
}