public static CaravanToil GotoTile(TargetIndex ind, CaravanArrivalAction arrivalAction = null) { var toil = new CaravanToil(); toil.initAction = () => { var actor = toil.actor; actor.pather.StartPath(CaravanJobsUtility.GetCaravanJobGiver().CurJob(actor).GetTarget(ind).Tile, arrivalAction); }; toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; //toil.FailOnDespawnedOrNull(ind); return(toil); }
// Verse.AI.ToilEffects public static CaravanToil WithProgressBar(this CaravanToil CaravanToil, TargetIndex ind, Func <float> progressGetter, bool interpolateBetweenActorAndTarget = false, float offsetZ = -0.5f) { WorldObject_ProgressBar progressBar = null; CaravanToil.AddPreTickAction(() => { if (CaravanToil.actor.Faction != Faction.OfPlayer) { return; } var curProgress = Mathf.Clamp01(progressGetter()); //Log.Message(curProgress.ToString()); //WorldProgressBarDrawer.DrawProgressBarOnGUIFor(target, curProgress); if (progressBar == null) { progressBar = (WorldObject_ProgressBar)WorldObjectMaker.MakeWorldObject(MiscDefOf.WorldObject_ProgressBar); progressBar.Tile = CaravanJobsUtility.GetCaravanJobGiver().CurJob(CaravanToil.actor) .GetTarget(ind).Tile; progressBar.offset = offsetZ; Find.WorldObjects.Add(progressBar); } else { progressBar.curProgress = Mathf.Clamp01(progressGetter()); if (CaravanToil.actor == null || !CaravanToil.actor.Spawned || CaravanToil.actor.Tile != CaravanJobsUtility.GetCaravanJobGiver().CurJob(CaravanToil.actor) .GetTarget(ind).Tile) { if (progressBar.Spawned) { Find.WorldObjects.Remove(progressBar); } } } }); CaravanToil.AddFinishAction(() => { if (progressBar != null && progressBar.Spawned) { Find.WorldObjects.Remove(progressBar); progressBar = null; } }); return(CaravanToil); }
public void Cleanup() { if (finishActions != null) { for (var i = 0; i < finishActions.Count; i++) { try { finishActions[i](); } catch (Exception ex) { var curJob = CaravanJobsUtility.GetCaravanJobGiver().CurJob(actor); Log.Error($"Pawn {actor} threw exception while executing toil's finish action ({i}), curJob={curJob}: {ex}"); } } } }
private static Caravan_JobTracker CurTracker(Caravan c) { return(CaravanJobsUtility.GetCaravanJobGiver().Tracker(c)); }
private static CaravanJob CurJob(Caravan c) { return(CaravanJobsUtility.GetCaravanJobGiver().CurJob(c)); }