public static Toil PlaySustainerOrSound(this Toil toil, Func <SoundDef> soundDefGetter) { Sustainer sustainer = null; toil.AddPreInitAction(delegate { SoundDef soundDef2 = soundDefGetter(); if (soundDef2 != null && !soundDef2.sustain) { soundDef2.PlayOneShot(new TargetInfo(toil.GetActor().Position, toil.GetActor().Map, false)); } }); toil.AddPreTickAction(delegate { if (sustainer == null || sustainer.Ended) { SoundDef soundDef = soundDefGetter(); if (soundDef != null && soundDef.sustain) { SoundInfo info = SoundInfo.InMap(toil.actor, MaintenanceType.PerTick); sustainer = soundDef.TrySpawnSustainer(info); } } else { sustainer.Maintain(); } }); return(toil); }
public static Toil PlaySoundAtStart(this Toil toil, SoundDef sound) { toil.AddPreInitAction(delegate { sound.PlayOneShot(new TargetInfo(toil.GetActor().Position, toil.GetActor().Map, false)); }); return(toil); }
public static Toil PlaySoundAtEnd(this Toil toil, SoundDef sound) { toil.AddFinishAction(delegate { sound.PlayOneShot(new TargetInfo(toil.GetActor().Position, toil.GetActor().Map)); }); return(toil); }
public static Toil ClearTarget(TargetIndex ind) { Toil toil = new Toil(); toil.initAction = delegate { toil.GetActor().CurJob.SetTarget(ind, null); }; return(toil); }
public static Toil PutCarriedThingInInventory() { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); if (actor.carryTracker.CarriedThing != null && !actor.carryTracker.innerContainer.TryTransferToContainer(actor.carryTracker.CarriedThing, actor.inventory.innerContainer)) { actor.carryTracker.TryDropCarriedThing(actor.Position, actor.carryTracker.CarriedThing.stackCount, ThingPlaceMode.Near, out var _); } }; return(toil); }
public static Toil PutCarriedThingInInventory() { Toil toil = new Toil(); toil.initAction = () => { var actor = toil.GetActor(); if (actor.carryTracker.CarriedThing != null) { //Try transfer to inventory if (!actor.carryTracker.innerContainer.TryTransferToContainer(actor.carryTracker.CarriedThing, actor.inventory.innerContainer)) { //Failed: try drop Thing unused; actor.carryTracker.TryDropCarriedThing(actor.Position, actor.carryTracker.CarriedThing.stackCount, ThingPlaceMode.Near, out unused); } } }; return(toil); }