using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using RimWorld; using rjw.Modules.Interactions.Helpers; using rjw.Modules.Interactions.Objects; using UnityEngine; using Verse; using Verse.AI; using rjw.Modules.Interactions.Enums; namespace Rimworld_Animations { public static class AnimationUtility { public static void StartAnimation(List participants) { participants[0].Drawer.renderer.SetAnimation(AnimationDefOf.TestAnimation1); participants[1].Drawer.renderer.SetAnimation(AnimationDefOf.TestAnimation2); } //startgroupanimator with anchor //don't anchor to self if anchor is self public static void StartGroupAnimation(List participants, GroupAnimationDef groupAnimationDef, int reorder, Thing anchor) { int seed = GenTicks.TicksGame; for (int i = 0; i < participants.Count; i++) { if (anchor is Pawn pawn && pawn == participants[i]) { List allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder); participants[i].TryGetComp().PlayGroupAnimation(allAnimationsForPawn); } else { //each participant gets their own unique extendedanimatoranchor, important for scribe_deep saving List allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder); BaseExtendedAnimatorAnchor animatorAnchor = new ExtendedAnimatorAnchor_Thing(anchor); participants[i].TryGetComp().PlayGroupAnimation(allAnimationsForPawn, animatorAnchor); } } } //startgroupanimation without anchor; just play where standing public static void StartGroupAnimation(List participants, GroupAnimationDef groupAnimationDef, int reorder) { int seed = GenTicks.TicksGame; for (int i = 0; i < participants.Count; i++) { List allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder); participants[i].TryGetComp().PlayGroupAnimation(allAnimationsForPawn); } } public static void StopGroupAnimation(List participants) { foreach(Pawn pawn in participants) { pawn.TryGetComp()?.StopAnimating(); } } public static void StopGroupAnimation(Pawn participant) { participant.TryGetComp()?.StopAnimating(); } public static GroupAnimationDef FindGroupAnimation(List participants, out int reorder) { // go through each context in each GroupAnimationDef // if you find one where it returns canAnimationBeUsed (and reorders), // return that animation int reorder2 = 0; DefDatabase.AllDefsListForReading.TryRandomElement((GroupAnimationDef x) => x.canAnimationBeUsed(participants, out reorder2), out GroupAnimationDef result); reorder = reorder2; if (result != null) return result; return null; } } }