Further checks to make sure pawn doesn't clip oob

This commit is contained in:
Platinum 2020-04-16 11:51:26 -07:00
parent 65b08eb2f4
commit d70bd8b912
4 changed files with 56 additions and 15 deletions

View File

@ -28,16 +28,28 @@ namespace Rimworld_Animations {
if(value == true) {
xxx.DrawNude(pawn);
} else {
pawn.Position = anchor.ToIntVec3();
pawn.Notify_Teleported(false, true);
pawn.pather.StopDead();
pawn.Drawer.renderer.graphics.ResolveAllGraphics();
resetPosition = true;
}
PortraitsCache.SetDirty(pawn);
}
}
private bool Animating;
public bool resetPosition {
get {
if (resetPos) {
resetPos = false;
return true;
}
return false;
}
set {
resetPos = value;
}
}
private bool Animating, resetPos = false;
private bool mirror = false;
private int actor;
@ -45,6 +57,7 @@ namespace Rimworld_Animations {
private int curStage = 0;
private float clipPercent = 0;
public IntVec3 positionReset;
public Vector3 anchor, deltaPos, headBob;
public float bodyAngle, headAngle;
public Rot4 headFacing, bodyFacing;
@ -55,11 +68,13 @@ namespace Rimworld_Animations {
public void setAnchor(IntVec3 pos)
{
positionReset = pos;
anchor = pos.ToVector3Shifted();
}
public void setAnchor(Thing thing) {
//center on bed
positionReset = thing.Position;
if(thing is Building_Bed) {
anchor = thing.Position.ToVector3();
if (((Building_Bed)thing).SleepingSlotsCount == 2) {
@ -117,16 +132,17 @@ namespace Rimworld_Animations {
public override void CompTick() {
base.CompTick();
if(Animating) {
if(isAnimating) {
tickAnim();
if (pawn?.jobs?.curDriver == null || (pawn?.jobs?.curDriver != null && !(pawn?.jobs?.curDriver is rjw.JobDriver_Sex))) {
isAnimating = false;
}
}
}
public void animatePawn(ref Vector3 rootLoc, ref float angle, ref Rot4 bodyFacing, ref Rot4 headFacing) {
if(!Animating) {
if(!isAnimating) {
return;
}
rootLoc = anchor + deltaPos;
@ -142,13 +158,13 @@ namespace Rimworld_Animations {
public void tickAnim() {
if (!Animating) return;
if (!isAnimating) return;
animTicks++;
if (animTicks < anim.animationTimeTicks) {
tickStage();
} else {
Animating = false;
isAnimating = false;
}
}

View File

@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.AI;
namespace Rimworld_Animations {
@ -13,13 +14,36 @@ namespace Rimworld_Animations {
public static class HarmonyPatch_Pawn_DrawTracker {
public static bool Prefix(ref Pawn ___pawn, ref Vector3 __result) {
if(___pawn.TryGetComp<CompBodyAnimator>() != null && ___pawn.TryGetComp<CompBodyAnimator>().isAnimating) {
__result = ___pawn.TryGetComp<CompBodyAnimator>().anchor + ___pawn.TryGetComp<CompBodyAnimator>().deltaPos;
___pawn.Position = __result.ToIntVec3();
return false;
if(___pawn.TryGetComp<CompBodyAnimator>() != null) {
if(___pawn.TryGetComp<CompBodyAnimator>().isAnimating) {
__result = ___pawn.TryGetComp<CompBodyAnimator>().anchor + ___pawn.TryGetComp<CompBodyAnimator>().deltaPos;
___pawn.Position = __result.ToIntVec3();
return false;
} else if(___pawn.TryGetComp<CompBodyAnimator>().resetPosition) {
//resetting position to anchor
__result = ___pawn.TryGetComp<CompBodyAnimator>().anchor;
___pawn.Position = ___pawn.TryGetComp<CompBodyAnimator>().positionReset;
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(Pawn_PathFollower), "StartPath")]
public static class HarmonyPatch_ResetPositionIfPathing {
public static void Prefix(ref Pawn ___pawn) {
if(___pawn.TryGetComp<CompBodyAnimator>() != null) {
if(___pawn.TryGetComp<CompBodyAnimator>().isAnimating || ___pawn.TryGetComp<CompBodyAnimator>().resetPosition) {
___pawn.TryGetComp<CompBodyAnimator>().isAnimating = false;
___pawn.Position = ___pawn.TryGetComp<CompBodyAnimator>().positionReset;
}
}
}
}
}

View File

@ -146,9 +146,10 @@ namespace Rimworld_Animations {
for (int i = 0; i < parteners.Count; i++) {
//prevents pawns who started a new anim from stopping their new anim
if (!((parteners[i].jobs.curDriver as JobDriver_SexBaseInitiator) != null && (parteners[i].jobs.curDriver as JobDriver_SexBaseInitiator).Target != __instance.pawn))
if (!((parteners[i].jobs.curDriver as JobDriver_SexBaseInitiator) != null && (parteners[i].jobs.curDriver as JobDriver_SexBaseInitiator).Target != __instance.pawn)) {
parteners[i].TryGetComp<CompBodyAnimator>().isAnimating = false;
}
}
__instance.Target.TryGetComp<CompBodyAnimator>().isAnimating = false;