protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(InstrumentInd); Toil gotoThing = new Toil(); gotoThing.initAction = delegate { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(InstrumentInd); yield return(gotoThing); Toil dropInstruments = new Toil(); dropInstruments.initAction = delegate { List <Thing> instruments = pawn.inventory.innerContainer.Where(x => PerformanceManager.IsInstrument(x)).ToList(); Thing result; foreach (Thing instrument in instruments) { pawn.inventory.innerContainer.TryDrop(instrument, pawn.Position, pawn.Map, ThingPlaceMode.Near, out result); } }; yield return(dropInstruments); yield return(Toils_Haul.TakeToInventory(InstrumentInd, 1)); }
private static bool Prefix(Pawn_InventoryTracker __instance, ref ThingCount __result) { if (__instance.innerContainer.Count == 0) { __result = default; return(false); } tmpDrugsToKeep.Clear(); if (__instance.pawn.drugs?.CurrentPolicy != null) { var currentPolicy = __instance.pawn.drugs.CurrentPolicy; for (var i = 0; i < currentPolicy.Count; i++) { if (currentPolicy[i].takeToInventory > 0) { tmpDrugsToKeep.Add(new ThingDefCount(currentPolicy[i].drug, currentPolicy[i].takeToInventory)); } } } Thing bestInstrument = null; if (!__instance.pawn.NonHumanlikeOrWildMan() && !__instance.pawn.WorkTagIsDisabled(WorkTags.Artistic)) { var artSkill = __instance.pawn.skills.GetSkill(SkillDefOf.Artistic).levelInt; IEnumerable <Thing> heldInstruments = __instance.innerContainer .Where(PerformanceManager.IsInstrument) .Where(x => !x.TryGetComp <CompMusicalInstrument>().Props.isBuilding) .OrderByDescending(x => x.TryGetComp <CompMusicalInstrument>().WeightedSuitability(artSkill)); if (heldInstruments.Any()) { bestInstrument = heldInstruments.FirstOrDefault(); } } if (tmpDrugsToKeep.Any() || bestInstrument != null) { foreach (var thing in __instance.innerContainer) { if (thing.def.IsDrug) { var num = -1; for (var k = 0; k < tmpDrugsToKeep.Count; k++) { if (thing.def != tmpDrugsToKeep[k].ThingDef) { continue; } num = k; break; } if (num < 0) { __result = new ThingCount(thing, thing.stackCount); return(false); } if (thing.stackCount > tmpDrugsToKeep[num].Count) { __result = new ThingCount(thing, thing.stackCount - tmpDrugsToKeep[num].Count); return(false); } tmpDrugsToKeep[num] = new ThingDefCount(tmpDrugsToKeep[num].ThingDef, tmpDrugsToKeep[num].Count - thing.stackCount); } else if (PerformanceManager.IsInstrument(thing)) { if (bestInstrument == null) { __result = new ThingCount(thing, thing.stackCount); return(false); } if (bestInstrument.GetHashCode() == thing.GetHashCode()) { continue; } __result = new ThingCount(thing, thing.stackCount); return(false); } else { __result = new ThingCount(thing, thing.stackCount); return(false); } } __result = default; return(false); } __result = new ThingCount(__instance.innerContainer[0], __instance.innerContainer[0].stackCount); return(false); }
// this function does three things: // it adds generic delegate functions to globalFailConditions (inherited from IJobEndable) via `This.EndOn...` extensions // it also yield returns a collection of toils: some generic, some custom // it also interacts with the JoyUtility static class so the pawns get joy protected override IEnumerable <Toil> MakeNewToils() { this.EndOnDespawnedOrNull(MusicSpotParentInd, JobCondition.Incompletable); //Verse.Log.Message(String.Format("Gather Spot ID = {0}", TargetA.Thing.GetHashCode())); Pawn musician = this.pawn; this.FailOnDestroyedNullOrForbidden(InstrumentInd); Thing instrument = this.TargetC.Thing; Thing venue = this.TargetA.Thing; CompProperties_MusicalInstrument props = instrument.TryGetComp <CompMusicalInstrument>().Props; if (props.isBuilding) { this.FailOn(() => PowerMissing(instrument)); // go to where instrument is yield return(Toils_Goto.GotoThing(InstrumentInd, PathEndMode.InteractionCell) .FailOnSomeonePhysicallyInteracting(InstrumentInd)); yield return(GetPlayToil(musician, instrument, venue)); } else { if (instrument.ParentHolder != musician.inventory) { // go to where instrument is yield return(Toils_Goto.GotoThing(InstrumentInd, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(InstrumentInd)); //drop other instruments if any List <Thing> heldInstruments = pawn.inventory.innerContainer.Where(x => PerformanceManager.IsInstrument(x)).ToList(); if (heldInstruments.Any()) { Toil dropInstruments = new Toil(); dropInstruments.initAction = delegate { Thing result; foreach (Thing heldInstrument in heldInstruments) { pawn.inventory.innerContainer.TryDrop(heldInstrument, pawn.Position, pawn.Map, ThingPlaceMode.Near, out result); } }; yield return(dropInstruments); } // pick up instrument yield return(Toils_Haul.StartCarryThing(InstrumentInd)); } else { //get instrument out ready to play yield return(Toils_Misc.TakeItemFromInventoryToCarrier(musician, InstrumentInd)); } // go to the sitting / standing spot yield return(Toils_Goto.GotoCell(StandingSpotOrChairInd, PathEndMode.OnCell)); yield return(GetPlayToil(musician, instrument, venue)); //yield return Toils_General.PutCarriedThingInInventory(); } }