protected override IEnumerable <Toil> MakeNewToils() { //Tools.Warn("make new toil", true); this.FailOnDespawnedOrNull(TargetIndex.A); this.FailOn(delegate { CompExtinguishable compExtinguishable = null; compExtinguishable = job.targetA.Thing.TryGetComp <CompExtinguishable>(); return(!(compExtinguishable != null && compExtinguishable.WantsFlick())); }); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch)); yield return(Toils_General.Wait(15).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch)); Toil finalize = new Toil(); finalize.initAction = delegate { Pawn actor = finalize.actor; ThingWithComps thingWithComps = (ThingWithComps)actor.CurJob.targetA.Thing; for (int i = 0; i < thingWithComps.AllComps.Count; i++) { //Tools.Warn("Found "+i+" comp",true); if (thingWithComps.AllComps[i] is CompExtinguishable compExtinguishable && compExtinguishable.WantsFlick()) { //Tools.Warn("found extinguish", true); compExtinguishable.DoFlick(); } } }; finalize.defaultCompleteMode = ToilCompleteMode.Instant; yield return(finalize); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if (t.Faction != pawn.Faction) { //Log.Warning("strike! bench not mine"); return(false); } Building building = t as Building; if (building == null) { //Log.Warning("strike! building null"); return(false); } // HERE IF IT FAILS if (building.IsForbidden(pawn)) { // Log.Warning("strike! forbiden"); return(false); } LocalTargetInfo target = building; if (!pawn.CanReserve(target, 1, -1, null, forced)) { //Log.Warning("strike! cant reserver"); return(false); } CompExtinguishable comp = null; comp = building.TryGetComp <CompExtinguishable>(); if (comp == null) { //Tools.Warn("extinguish comp null",true); return(false); } if (building.IsBurning()) { //Tools.Warn("builiding on fire", true); return(false); } if (!comp.WantsFlick()) { //Tools.Warn("no work needed", true); return(false); } return(true); }