protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDespawnedOrNull(TargetIndex.A); this.FailOnAggroMentalState(TargetIndex.A); this.FailOn(() => !StrippableUtility.CanBeStrippedByColony(this.$this.TargetThingA)); Toil gotoThing = new Toil(); gotoThing.initAction = delegate { this.$this.pawn.pather.StartPath(this.$this.TargetThingA, PathEndMode.ClosestTouch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); yield return(Toils_General.Wait(60).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f)); yield return(new Toil { initAction = delegate { Thing thing = this.$this.job.targetA.Thing; Designation designation = this.$this.Map.designationManager.DesignationOn(thing, DesignationDefOf.Strip); if (designation != null) { designation.Delete(); } IStrippable strippable = thing as IStrippable; if (strippable != null) { strippable.Strip(); } this.$this.pawn.records.Increment(RecordDefOf.BodiesStripped); }, defaultCompleteMode = ToilCompleteMode.Instant }); }
protected override IEnumerable <Toil> MakeNewToils() { this.Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (this.RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => this.Map.designationManager.DesignationOn(t, this.RequiredDesignation) != null)); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true)); Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue); if (this.RequiredDesignation != null) { gotoThing.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation); } yield return(gotoThing); Toil cut = new Toil(); cut.tickAction = delegate() { Pawn actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, this.xpPerTick, false); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); float num = statValue; Plant plant = this.Plant; num *= Mathf.Lerp(3.3f, 1f, plant.Growth); this.workDone += num; if (this.workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true)) { Vector3 loc = (this.pawn.DrawPos + plant.DrawPos) / 2f; MoteMaker.ThrowText(loc, this.Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { int num2 = plant.YieldNow(); if (num2 > 0) { Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null); thing.stackCount = num2; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, this.Map, ThingPlaceMode.Near, null, null); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); this.workDone = 0f; this.ReadyForNextToil(); return; } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); if (this.RequiredDesignation != null) { cut.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation); } cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => this.workDone / this.Plant.def.plant.harvestWork, true, -0.5f); cut.PlaySustainerOrSound(() => this.Plant.def.plant.soundHarvesting); cut.activeSkill = (() => SkillDefOf.Plants); yield return(cut); Toil plantWorkDoneToil = this.PlantWorkDoneToil(); if (plantWorkDoneToil != null) { yield return(plantWorkDoneToil); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); yield return(Toils_Reserve.ReserveQueue(TargetIndex.A, 1, -1, null)); var initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A)); var checkNextQueuedTarget = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch) .JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, checkNextQueuedTarget)); var cut = new Toil(); cut.tickAction = delegate { var actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, xpPerTick, false); } var statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); var num = statValue; var plant = Plant; workDone += num; if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true)) { var loc = (pawn.DrawPos + plant.DrawPos) / 2f; MoteMaker.ThrowText(loc, Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { var num2 = plant.YieldNow(); if (num2 > 0) { var thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null); thing.stackCount = num2; GenPlace.TryPlaceThing(thing, actor.Position, Map, ThingPlaceMode.Near, null); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0f; ReadyForNextToil(); } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, true, -0.5f); cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); yield return(cut); yield return(checkNextQueuedTarget); yield return(Toils_Jump.JumpIfHaveTargetInQueue(TargetIndex.A, initExtractTargetFromQueue)); }
// Token: 0x06000035 RID: 53 RVA: 0x00003DB8 File Offset: 0x00001FB8 protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); Toil build = new Toil(); build.initAction = delegate() { IntVec3 root = build.actor.Position; Region region = build.actor.GetRegion(RegionType.Set_Passable); bool flag = region == null; if (!flag) { RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null || r.door.Open, delegate(Region r) { List <Thing> list = r.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn); for (int i = 0; i < list.Count; i++) { Pawn pawn = list[i] as Pawn; float num = Mathf.Clamp01(pawn.health.capacities.GetLevel(PawnCapacityDefOf.Hearing)); bool flag2 = num > 0f && pawn.Position.InHorDistOf(root, 15f * num); if (flag2) { pawn.HearClamor(build.actor, ClamorDefOf.Construction); } } return(false); }, 15, RegionType.Set_Passable); } }; build.tickAction = delegate() { Pawn actor = build.actor; Frame frame = this.Frame; float num = 1f; float value = actor.records.GetValue(RecordDefOf.ThingsConstructed); float num2 = value / 20f; bool flag = num2 < 1f; if (flag) { num2 = 1f; } bool flag2 = frame.Stuff != null; if (flag2) { num *= frame.Stuff.GetStatValueAbstract(StatDefOf.ConstructionSpeedFactor, null); } float workToBuild = frame.WorkToBuild; bool flag3 = actor.Faction == Faction.OfPlayer && actor.RaceProps.Animal; if (flag3) { bool flag4 = Rand.Value < 1f - Mathf.Pow(num2, num / workToBuild); if (flag4) { frame.FailConstruction(actor); this.ReadyForNextToil(); return; } } bool flag5 = frame.def.entityDefToBuild is TerrainDef; if (flag5) { this.Map.snowGrid.SetDepth(frame.Position, 0f); } frame.workDone += num; bool flag6 = frame.workDone >= workToBuild; if (flag6) { frame.CompleteConstruction(actor); this.ReadyForNextToil(); } }; build.WithEffect(() => ((Frame)build.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing).ConstructionEffect, TargetIndex.A); build.FailOnDespawnedNullOrForbidden(TargetIndex.A); build.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); build.defaultCompleteMode = ToilCompleteMode.Delay; build.defaultDuration = 5000; build.activeSkill = (() => SkillDefOf.Construction); yield return(build); yield break; }
Toil HarvestSeedsToil() { var toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Never; toil.tickAction = delegate { var actor = toil.actor; var plant = Plant; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Growing, xpPerTick, true); } workDone += actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true)) { MoteMaker.ThrowText((actor.DrawPos + plant.DrawPos) / 2f, actor.Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { int plantYield = plant.YieldNow(); ThingDef harvestedThingDef; var seedDef = plant.def.blueprintDef as SeedDef; if (seedDef != null) { float parameter = Mathf.Min(Mathf.InverseLerp(plant.def.plant.harvestMinGrowth, 0.9f, plant.Growth), 1f); if (seedDef.seed.seedFactor > 0 && Rand.Value < seedDef.seed.baseChance * parameter) { int count; if (Rand.Value < seedDef.seed.extraChance) { count = 2; } else { count = 1; } Thing seeds = ThingMaker.MakeThing(seedDef, null); seeds.stackCount = Mathf.RoundToInt(seedDef.seed.seedFactor * count); GenPlace.TryPlaceThing(seeds, actor.Position, actor.Map, ThingPlaceMode.Near); } plantYield = Mathf.RoundToInt(plantYield * seedDef.seed.harvestFactor); harvestedThingDef = seedDef.harvest; } else { harvestedThingDef = plant.def.plant.harvestedThingDef; } if (plantYield > 0) { var thing = ThingMaker.MakeThing(harvestedThingDef, null); thing.stackCount = plantYield; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, actor.Map, ThingPlaceMode.Near, null); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0; ReadyForNextToil(); return; } }; toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); toil.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); toil.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, true, -0.5f); toil.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(TargetIndex.A, 1)); var toil = new Toil { initAction = delegate { pawn.pather.StartPath(TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival }; toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(toil); yield return(new Toil { initAction = delegate { var itemToGather = job.targetA.Thing; //bool flag = false; Thing itemToGatherSplit; if (itemToGather.def.stackLimit > 1 && itemToGather.stackCount > 1) { itemToGatherSplit = itemToGather.SplitOff(1); } else { itemToGatherSplit = itemToGather; } //Find the compslotloadable var pawn_EquipmentTracker = pawn.equipment; if (pawn_EquipmentTracker != null) { //Log.Message("2"); var thingWithComps = pawn_EquipmentTracker .Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); if (thingWithComps != null) { //Log.Message("3"); var CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>(); if (CompSlotLoadable != null) { CompSlotLoadable.TryLoadSlot(itemToGather); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } //if (flag) //{ // thingWithComps.DeSpawn(); //} } } } }, defaultCompleteMode = ToilCompleteMode.Instant }); }
Toil SowSeedToil() { var toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Never; toil.initAction = delegate { var actor = toil.actor; if (IsActorCarryingAppropriateSeed(actor, job.plantDefToSow)) { var plant = (Plant)GenSpawn.Spawn(job.plantDefToSow, TargetLocA, actor.Map); plant.Growth = 0; plant.sown = true; job.targetC = plant; actor.Reserve(job.targetC, job, 1); sowWorkDone = 0; } else { EndJobWith(JobCondition.Incompletable); } }; toil.tickAction = delegate { var actor = toil.actor; var plant = (Plant)job.targetC.Thing; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, 0.22f); } if (plant.LifeStage != PlantLifeStage.Sowing) { Log.Error(this + " getting sowing work while not in Sowing life stage.", false); } sowWorkDone += StatExtension.GetStatValue(actor, StatDefOf.PlantWorkSpeed, true); if (sowWorkDone >= plant.def.plant.sowWork) { if (!IsActorCarryingAppropriateSeed(actor, job.plantDefToSow)) { EndJobWith(JobCondition.Incompletable); return; } if (actor.carryTracker.CarriedThing.stackCount <= 1) { actor.carryTracker.CarriedThing.Destroy(DestroyMode.Cancel); } else { actor.carryTracker.CarriedThing.stackCount--; } plant.Growth = 0.05f; plant.Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things); actor.records.Increment(RecordDefOf.PlantsSown); ReadyForNextToil(); } }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); toil.WithEffect(EffecterDefOf.Sow, TargetIndex.A); toil.WithProgressBar(TargetIndex.A, () => sowWorkDone / job.plantDefToSow.plant.sowWork, true, -0.5f); toil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow); toil.AddFinishAction(delegate { var actor = toil.actor; var thing = job.targetC.Thing; if (thing != null) { var plant = (Plant)thing; if (sowWorkDone < plant.def.plant.sowWork && !thing.Destroyed) { thing.Destroy(DestroyMode.Vanish); } actor.Map.reservationManager.Release(job.targetC, actor, job); job.targetC = null; } }); return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null)); yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.AdjacentSowBlocker(job.plantDefToSow, TargetA.Cell, Map) != null).FailOn(() => !job.plantDefToSow.CanEverPlantAt(TargetLocA, Map))); Toil sowToil = new Toil() { initAction = delegate { TargetThingA = GenSpawn.Spawn(job.plantDefToSow, TargetLocA, Map); pawn.Reserve(TargetThingA, job); PlantWithSecondary plant = (PlantWithSecondary)TargetThingA; plant.Growth = 0f; plant.sown = true; }, tickAction = delegate { Pawn actor = GetActor(); if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Growing, 0.11f, false); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); float num = statValue; PlantWithSecondary plant = Plant; if (plant.LifeStage != PlantLifeStage.Sowing) { Log.Error(this + " getting sowing work while not in Sowing life stage."); } sowWorkDone += num; if (sowWorkDone >= plant.def.plant.sowWork) { plant.Growth = 0.05f; plant.Sec_Growth = 0.05f; Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things); actor.records.Increment(RecordDefOf.PlantsSown); ReadyForNextToil(); return; } }, defaultCompleteMode = ToilCompleteMode.Never }; sowToil.FailOnDespawnedNullOrForbidden(TargetIndex.A); sowToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); sowToil.WithEffect(EffecterDefOf.Sow, TargetIndex.A); sowToil.WithProgressBar(TargetIndex.A, () => sowWorkDone / Plant.def.plant.sowWork, true, -0.5f); sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow); sowToil.AddFinishAction(delegate { if (TargetThingA != null) { PlantWithSecondary plant = (PlantWithSecondary)GetActor().CurJob.GetTarget(TargetIndex.A).Thing; if (sowWorkDone < plant.def.plant.sowWork && !TargetThingA.Destroyed) { TargetThingA.Destroy(DestroyMode.Vanish); } } }); yield return(sowToil); if (pawn.story.traits.HasTrait(TraitDefOf.GreenThumb)) { yield return(new Toil { initAction = delegate { pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.GreenThumbHappy, null); } }); } }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnIncapable(PawnCapacityDefOf.Manipulation); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch)); Toil toil = Toils_General.Wait(useDuration); toil.WithProgressBarToilDelay(TargetIndex.A); toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); toil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); yield return(toil); Toil use = new Toil(); use.initAction = delegate { Pawn actor = use.actor; actor.CurJob.targetA.Thing.TryGetComp <CompHasButton>().DoPress(actor); }; use.defaultCompleteMode = ToilCompleteMode.Instant; yield return(use); yield return(Toils_General.Wait(makeRequestDuration)); Toil request = new Toil(); request.initAction = delegate { CompMeeseeksMemory compMeeseeksMemory = pawn.GetComp <CompMeeseeksMemory>(); if (compMeeseeksMemory != null) { Pawn newestCreated = null; if (compMeeseeksMemory.CreatedMeeseeks.Count > 0) { newestCreated = compMeeseeksMemory.CreatedMeeseeks[compMeeseeksMemory.CreatedMeeseeks.Count - 1]; } if (newestCreated != null) { CompMeeseeksMemory newCreatedMemory = newestCreated.GetComp <CompMeeseeksMemory>(); if (newCreatedMemory != null) { newCreatedMemory.CopyJobDataFrom(compMeeseeksMemory); if (compMeeseeksMemory.givenTask) { newestCreated.jobs.EndCurrentJob(JobCondition.InterruptOptional); } else { newCreatedMemory.temporarilyBlockTask = false; } } } } MentalState_MeeseeksMakeMeeseeks mentalState = pawn.MentalState as MentalState_MeeseeksMakeMeeseeks; if (mentalState != null && mentalState.doOnce) { pawn.MentalState.RecoverFromState(); } }; request.defaultCompleteMode = ToilCompleteMode.Instant; yield return(request); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDespawnedOrNull(TargetIndex.A); this.FailOnThingMissingDesignation(TargetIndex.A, DesignationDefOf.RearmTrap); gotoThing = new Toil(); gotoThing.initAction = delegate() { this.pawn.pather.StartPath(base.TargetThingA, PathEndMode.Touch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.$current = gotoThing; if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: this.$current = Toils_General.Wait(800, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: { Toil finalize = new Toil(); finalize.initAction = delegate() { Thing thing = this.job.targetA.Thing; Designation designation = base.Map.designationManager.DesignationOn(thing, DesignationDefOf.RearmTrap); if (designation != null) { designation.Delete(); } Building_TrapRearmable building_TrapRearmable = thing as Building_TrapRearmable; building_TrapRearmable.Rearm(); this.pawn.records.Increment(RecordDefOf.TrapsRearmed); }; finalize.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = finalize; if (!this.$disposing) { this.$PC = 3; } return(true); } case 3u: this.$PC = -1; break; } return(false); }
// Token: 0x06000051 RID: 81 RVA: 0x00005676 File Offset: 0x00003876 protected override IEnumerable <Toil> MakeNewToils() { Pawn pawn = base.GetActor(); this.FailOnBurningImmobile(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); Toil toil = new Toil { tickAction = delegate() { } }; Toil prepare = toil; prepare.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); prepare.FailOnDespawnedNullOrForbidden(TargetIndex.A); prepare.defaultCompleteMode = ToilCompleteMode.Delay; prepare.defaultDuration = 300; yield return(prepare); yield return(Toils_General.Do(delegate { JobCondition JC; if (this.TargetA.Thing != null && this.TargetA.Thing.Spawned) { MSExoticUtility.DoMSCondom(pawn, this.TargetA.Thing.def); int stack = this.TargetA.Thing.stackCount; if (stack > 1) { stack--; this.TargetA.Thing.stackCount = stack; } else { this.TargetA.Thing.Destroy(DestroyMode.Vanish); } JC = JobCondition.Succeeded; } else { JC = JobCondition.Incompletable; } Thing thing; if (pawn == null) { thing = null; } else { Pawn_Ownership ownership = pawn.ownership; thing = (ownership?.OwnedBed); } Thing LovinBed = thing; if (LovinBed != null) { Pawn partnerInMyBed = JobDriver_MSWearCondom.GetCondomPartnerInMyBed(pawn, LovinBed as Building_Bed); if (partnerInMyBed != null && partnerInMyBed.health.capacities.CanBeAwake) { Job newLovin = new Job(JobDefOf.Lovin, partnerInMyBed, LovinBed); if (newLovin != null) { Pawn pawn2 = pawn; if (pawn2 != null) { Pawn_JobTracker jobs = pawn2.jobs; if (jobs != null) { jobs.jobQueue.EnqueueFirst(newLovin, null); } } } } } this.EndJobWith(JC); })); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => Map.designationManager.DesignationOn(t, RequiredDesignation) != null)); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true)); Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue); if (RequiredDesignation != null) { gotoThing.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } yield return(gotoThing); Toil cut = new Toil(); cut.tickAction = delegate { Pawn actor = cut.actor; Job curJob = actor.jobs.curJob; curJob.expiryInterval = -1; float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); float num = statValue; Plant plant = Plant; num *= Mathf.Lerp(3.3f, 1f, plant.Growth); workDone += num; if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { int num2 = plant.YieldNow(); if (num2 > 0) { Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null); thing.stackCount = num2; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, Map, ThingPlaceMode.Near, null, null); } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0f; ReadyForNextToil(); return; } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); if (RequiredDesignation != null) { cut.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, true, -0.5f); cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); cut.activeSkill = (() => SkillDefOf.Plants); yield return(cut); Toil plantWorkDoneToil = PlantWorkDoneToil(); if (plantWorkDoneToil != null) { yield return(plantWorkDoneToil); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); }
protected override IEnumerable <Toil> MakeNewToils() { Toil meditate = new Toil { socialMode = RandomSocialMode.Off }; if (FromBed) { this.KeepLyingDown(TargetIndex.B); meditate = Toils_LayDown.LayDown(TargetIndex.B, job.GetTarget(TargetIndex.B).Thing is Building_Bed, lookForOtherJobs: false, canSleep: false); } else { yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); meditate.initAction = delegate { LocalTargetInfo target = job.GetTarget(TargetIndex.C); if (target.IsValid) { faceDir = target.Cell - pawn.Position; } else { faceDir = (job.def.faceDir.IsValid ? job.def.faceDir : Rot4.Random).FacingCell; } }; if (Focus != null) { meditate.FailOnDespawnedNullOrForbidden(TargetIndex.C); if (pawn.HasPsylink && Focus.Thing != null) { meditate.FailOn(() => Focus.Thing.GetStatValueForPawn(StatDefOf.MeditationFocusStrength, pawn) < float.Epsilon); } } meditate.handlingFacing = true; } meditate.defaultCompleteMode = ToilCompleteMode.Delay; meditate.defaultDuration = job.def.joyDuration; meditate.FailOn(() => !MeditationUtility.CanMeditateNow(pawn) || !MeditationUtility.SafeEnvironmentalConditions(pawn, base.TargetLocA, base.Map)); meditate.AddPreTickAction(delegate { bool flag = pawn.GetTimeAssignment() == TimeAssignmentDefOf.Meditate; if (job.ignoreJoyTimeAssignment) { Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy; if (!flag && psychicEntropy.TargetPsyfocus < psychicEntropy.CurrentPsyfocus && (psychicEntropy.TargetPsyfocus < job.psyfocusTargetLast || job.wasOnMeditationTimeAssignment)) { EndJobWith(JobCondition.InterruptForced); return; } job.psyfocusTargetLast = psychicEntropy.TargetPsyfocus; job.wasOnMeditationTimeAssignment = flag; } if (faceDir.IsValid && !FromBed) { pawn.rotationTracker.FaceCell(pawn.Position + faceDir); } MeditationTick(); if (ModLister.RoyaltyInstalled && MeditationFocusDefOf.Natural.CanPawnUse(pawn)) { int num = GenRadial.NumCellsInRadius(MeditationUtility.FocusObjectSearchRadius); for (int i = 0; i < num; i++) { IntVec3 c = pawn.Position + GenRadial.RadialPattern[i]; if (c.InBounds(pawn.Map)) { Plant plant = c.GetPlant(pawn.Map); if (plant != null && plant.def == ThingDefOf.Plant_TreeAnima) { plant.TryGetComp <CompSpawnSubplant>()?.AddProgress_NewTmp(AnimaTreeSubplantProgressPerTick); } } } } }); yield return(meditate); }
private IEnumerable <Toil> Clipboard() { yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); yield return(Toils_Reserve.ReserveQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A)); Toil checkNextQueuedTarget = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, checkNextQueuedTarget)); Toil cut = new Toil() { tickAction = delegate { Pawn actor = GetActor(); if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Growing, 0.11f); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); float num = statValue; workDone += num; if (workDone >= Duration) { if (Plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && Plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true)) { Vector3 loc = (pawn.DrawPos + Plant.DrawPos) / 2f; MoteMaker.ThrowText(loc, Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { Thing thing = Plant.CollectSecondaryThing(); if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, Map, ThingPlaceMode.Near); actor.records.Increment(RecordDefOf.PlantsHarvested); // If there is a SeedsPlease seed, try to drop it if (Plant.seedDef != null) { int stack = Rand.RangeInclusive(-1, 1); if (pawn.skills != null) { stack += GenMath.RoundRandom(pawn.skills.GetSkill(SkillDefOf.Growing).Level / 8f); } if (stack > 0) { Thing seed = ThingMaker.MakeThing(Plant.seedDef); seed.stackCount = stack; GenPlace.TryPlaceThing(seed, pawn.Position, pawn.Map, ThingPlaceMode.Near); } } } } Plant.def.plant.soundHarvestFinish.PlayOneShot(actor); workDone = 0f; ReadyForNextToil(); return; } } }; cut.FailOn(() => !Plant.Sec_HarvestableNow); cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => workDone / Duration, true, -0.5f); cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); yield return(cut); yield return(checkNextQueuedTarget); yield return(Toils_Jump.JumpIfHaveTargetInQueue(TargetIndex.A, initExtractTargetFromQueue)); }
protected override IEnumerable <Toil> MakeNewToils() { var ZTracker = ZUtils.ZTracker; if (pawn.Map == this.job.targetA.Thing.Map && pawn.Map == ZTracker.jobTracker[pawn].dest) { ZLogger.Message("pawn map and thing map and dest map are same, yield breaking in JobDriver_HaulThingToDest"); yield break; } yield return(new Toil { initAction = delegate() { this.savedThing = this.job.targetA.Thing; ZLogger.Message("1111111111111: " + this.savedThing); ZLogger.Message("Saved thing: " + this.savedThing); ZLogger.Message("TargetA: " + this.job.targetA.Thing); } }); Toil reserveItem = Toils_Reserve.Reserve(TargetIndex.A); ZLogger.Message(pawn + " 8 ZUtils.ZTracker.jobTracker[pawn].dest: " + TargetA.Thing.Map); foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), TargetA.Thing.Map, this)) { ZLogger.Message(pawn + " 9 ZUtils.ZTracker.jobTracker[pawn].dest: " + TargetA.Thing.Map); yield return(toil); } yield return(new Toil { initAction = delegate() { ZLogger.Message("Trying to reserve " + job.targetA + " for " + pawn + " - " + job); } }); yield return(reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A)); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)); yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A)); if (job.haulOpportunisticDuplicates) { yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true)); } yield return(new Toil { initAction = delegate() { ZLogger.Message("22222222222222: " + this.savedThing); ZLogger.Message("Saved thing: " + this.savedThing); ZLogger.Message("TargetA: " + this.job.targetA.Thing); } }); yield return(new Toil { initAction = delegate() { try { if (ZTracker.jobTracker.ContainsKey(pawn)) { if (ZTracker.jobTracker[pawn].mainJob.targetA.Thing != null && ZTracker.jobTracker[pawn].mainJob.targetA.Thing == this.savedThing && ZTracker.jobTracker[pawn].mainJob.targetA.Thing != TargetA.Thing) { ZTracker.jobTracker[pawn].mainJob.targetA = new LocalTargetInfo(TargetA.Thing); } else if (ZTracker.jobTracker[pawn].mainJob.targetB.Thing != null && ZTracker.jobTracker[pawn].mainJob.targetB.Thing == this.savedThing && ZTracker.jobTracker[pawn].mainJob.targetB.Thing != TargetA.Thing) { ZTracker.jobTracker[pawn].mainJob.targetB = new LocalTargetInfo(TargetA.Thing); } try { for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueA.Count - 1; i >= 0; i--) { var target = ZTracker.jobTracker[pawn].mainJob.targetQueueA[i]; if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) { ZTracker.jobTracker[pawn].mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing); } } } catch { } try { for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--) { var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i]; if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) { if (ZTracker.jobTracker[pawn].mainJob.targetQueueB[i].Thing.stackCount == 0) { ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing); ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetA.Thing.stackCount; break; } else { if (ZTracker.jobTracker[pawn].mainJob.targetQueueB .Where(x => x.Thing == TargetA.Thing).Count() == 0) { var newTarget = new LocalTargetInfo(TargetA.Thing); ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.Add(newTarget); ZTracker.jobTracker[this.pawn].mainJob.countQueue.Add(newTarget.Thing.stackCount); int ind = ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing); ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.RemoveAt(ind); ZTracker.jobTracker[this.pawn].mainJob.countQueue.RemoveAt(ind); break; } } } } } catch { } } } catch (Exception ex) { Log.Error("Z-Tracker produced an error in JobDriver_HaulThingToStairs class. Report about it to devs. Error: " + ex); } } }); yield return(new Toil { initAction = delegate() { ZLogger.Message("33333333333333: " + this.savedThing); ZLogger.Message("Saved thing: " + this.savedThing); ZLogger.Message("TargetA: " + this.job.targetA.Thing); } }); ZLogger.Message(pawn + " 6 ZUtils.ZTracker.jobTracker[pawn].dest: " + ZTracker.jobTracker[pawn].dest); foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), ZTracker.jobTracker[pawn].dest, this)) { ZLogger.Message(pawn + " 7 ZUtils.ZTracker.jobTracker[pawn].dest: " + ZTracker.jobTracker[pawn].dest); yield return(toil); } }
public static void Postfix(ref Toil __result) { __result = __result.FailOnDespawnedNullOrForbidden(TargetIndex.A); }
public override IEnumerable <Toil> MakeNewToils() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var ZTracker = ZUtils.ZTracker; - 5", true); var ZTracker = ZUtils.ZTracker; yield return(new Toil { initAction = delegate() { Log.Message("pawn.Map: " + pawn.Map); Log.Message("this.job.targetA.Thing.Map: " + this.job.targetA.Thing?.Map); Log.Message("ZTracker.jobTracker[pawn].targetDest.Map: " + ZTracker.jobTracker[pawn].targetDest.Map); if (pawn.Map == this.job.targetA.Thing?.Map && pawn.Map == ZTracker.jobTracker[pawn].targetDest.Map) { ZLogger.Message("pawn map and thing map and dest map are same, yield breaking in JobDriver_HaulThingToDest"); this.EndJobWith(JobCondition.InterruptForced); } this.savedThing = this.job.targetA.Thing; } }); Toil reserveItem = Toils_Reserve.Reserve(TargetIndex.A); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (TargetA.Thing?.Map != null) - 12", true); if (TargetA.Thing?.Map != null) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), new TargetInfo(TargetA.Thing).Map, this)) - 13", true); foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), new TargetInfo(TargetA.Thing).Map, this)) { yield return(new Toil { initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return toil; - 14", true); } }); yield return(toil); } } Toil toilGoto = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch); yield return(new Toil { initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A); - 16", true); } }); yield return(reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A)); yield return(new Toil { initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return toilGoto; - 17", true); } }); yield return(toilGoto); yield return(new Toil { initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A); - 18", true); } }); yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A)); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (job.haulOpportunisticDuplicates) - 19", true); if (job.haulOpportunisticDuplicates) { yield return(new Toil { initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true); - 20", true); } }); yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true)); } yield return(Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(toilGoto, TargetIndex.A)); yield return(new Toil { initAction = delegate() { Log.Message("Pawn: " + pawn); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (ZTracker.jobTracker.TryGetValue(pawn, out JobTracker jobTracker)) - 23", true); if (ZTracker.jobTracker.TryGetValue(pawn, out JobTracker jobTracker)) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetA.Thing != null && jobTracker.mainJob.targetA.Thing == this.savedThing && jobTracker.mainJob.targetA.Thing != TargetA.Thing) - 24", true); if (jobTracker.mainJob.targetA.Thing != null && jobTracker.mainJob.targetA.Thing == this.savedThing && jobTracker.mainJob.targetA.Thing != TargetA.Thing) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetA = new LocalTargetInfo(TargetA.Thing); - 25", true); jobTracker.mainJob.targetA = new LocalTargetInfo(TargetA.Thing); } else if (jobTracker.mainJob.targetB.Thing != null && jobTracker.mainJob.targetB.Thing == this.savedThing && jobTracker.mainJob.targetB.Thing != TargetA.Thing) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetB = new LocalTargetInfo(TargetA.Thing); - 27", true); jobTracker.mainJob.targetB = new LocalTargetInfo(TargetA.Thing); } Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueA != null) - 28", true); if (jobTracker.mainJob.targetQueueA != null) { for (int i = jobTracker.mainJob.targetQueueA.Count - 1; i >= 0; i--) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var target = jobTracker.mainJob.targetQueueA[i]; - 29", true); var target = jobTracker.mainJob.targetQueueA[i]; Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) - 30", true); if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing); - 31", true); jobTracker.mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing); } } } Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueB != null) - 32", true); if (jobTracker.mainJob.targetQueueB != null) { for (int i = jobTracker.mainJob.targetQueueB.Count - 1; i >= 0; i--) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var target = jobTracker.mainJob.targetQueueB[i]; - 33", true); var target = jobTracker.mainJob.targetQueueB[i]; Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) - 34", true); if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueB[i].Thing.stackCount == 0) - 35", true); if (jobTracker.mainJob.targetQueueB[i].Thing.stackCount == 0) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing); - 36", true); jobTracker.mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue[i] = TargetA.Thing.stackCount; - 37", true); jobTracker.mainJob.countQueue[i] = TargetA.Thing.stackCount; Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - break; - 38", true); break; } else if (!jobTracker.mainJob.targetQueueB.Any(x => x.Thing == TargetA.Thing)) { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var newTarget = new LocalTargetInfo(TargetA.Thing); - 40", true); var newTarget = new LocalTargetInfo(TargetA.Thing); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB.Add(newTarget); - 41", true); jobTracker.mainJob.targetQueueB.Add(newTarget); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue.Add(newTarget.Thing.stackCount); - 42", true); jobTracker.mainJob.countQueue.Add(newTarget.Thing.stackCount); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - int ind = jobTracker.mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing); - 43", true); int ind = jobTracker.mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB.RemoveAt(ind); - 44", true); jobTracker.mainJob.targetQueueB.RemoveAt(ind); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue.RemoveAt(ind); - 45", true); jobTracker.mainJob.countQueue.RemoveAt(ind); Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - break; - 46", true); break; } } } } } } });
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDespawnedOrNull(TargetIndex.A); this.FailOnAggroMentalState(TargetIndex.A); this.FailOn(() => !StrippableUtility.CanBeStrippedByColony(base.TargetThingA)); gotoThing = new Toil(); gotoThing.initAction = delegate() { this.pawn.pather.StartPath(base.TargetThingA, PathEndMode.ClosestTouch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.$current = gotoThing; if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: this.$current = Toils_General.Wait(60, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: { Toil strip = new Toil(); strip.initAction = delegate() { Thing thing = this.job.targetA.Thing; Designation designation = base.Map.designationManager.DesignationOn(thing, DesignationDefOf.Strip); if (designation != null) { designation.Delete(); } IStrippable strippable = thing as IStrippable; if (strippable != null) { strippable.Strip(); } this.pawn.records.Increment(RecordDefOf.BodiesStripped); }; strip.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = strip; if (!this.$disposing) { this.$PC = 3; } return(true); } case 3u: this.$PC = -1; break; } return(false); }
protected override IEnumerable <Toil> MakeNewToils() { Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (RequiredDesignation != null) ? ((Func <Thing, bool>)((Thing t) => base.Map.designationManager.DesignationOn(t, RequiredDesignation) != null)) : null); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A)); Toil toil = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue); if (RequiredDesignation != null) { toil.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } yield return(toil); Toil cut = new Toil(); cut.tickAction = delegate { Pawn actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, xpPerTick); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed); Plant plant = Plant; statValue *= Mathf.Lerp(3.3f, 1f, plant.Growth); workDone += statValue; if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && !plant.Blighted && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield)) { MoteMaker.ThrowText((pawn.DrawPos + plant.DrawPos) / 2f, base.Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { int num = plant.YieldNow(); if (num > 0) { Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef); thing.stackCount = num; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(value: true); } Find.QuestManager.Notify_PlantHarvested(actor, thing); GenPlace.TryPlaceThing(thing, actor.Position, base.Map, ThingPlaceMode.Near); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0f; ReadyForNextToil(); } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); if (RequiredDesignation != null) { cut.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, interpolateBetweenActorAndTarget: true); cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); cut.activeSkill = (() => SkillDefOf.Plants); yield return(cut); Toil toil2 = PlantWorkDoneToil(); if (toil2 != null) { yield return(toil2); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); }
protected override IEnumerable <Toil> MakeNewToils() { Building_FishingSpot fishingSpot = this.job.GetTarget(FishingSpotIndex).Thing as Building_FishingSpot; int fishingDuration = (int)(baseFishingDuration * Rand.Range(0.2f, 1.8f) * fishingSpot.MapFishTracker.DifficultyMultiplier / (ModController.Settings.FishingEfficiency)); Thing thingCaught = null; yield return(Toils_Goto.GotoThing(FishingSpotIndex, fishingSpot.InteractionCell) .FailOnDespawnedNullOrForbidden(FishingSpotIndex)); Toil fishToil = new Toil() { initAction = () => { if (Find.TickManager.TicksGame > fishingSpot.lastFishingStartTick + 60000 * fishingSpot.FishingFrequency) { fishingSpot.lastFishingStartTick = Find.TickManager.TicksGame; } }, tickAction = () => { this.pawn.skills.Learn(job.def.joySkill, job.def.joyXpPerTick); if (pawn.CurJob.GetTarget(FishingSpotIndex).IsValid) { pawn.rotationTracker.FaceCell(pawn.CurJob.GetTarget(FishingSpotIndex).Cell); } }, handlingFacing = true, defaultDuration = fishingDuration, defaultCompleteMode = ToilCompleteMode.Delay }; yield return(fishToil.FailOnDespawnedNullOrForbidden(FishingSpotIndex)); Toil catchFishToil = new Toil() { initAction = () => { string eventText; if (Rand.Value < pawn.GetStatValue(ResourceBank.StatDefOf.FishingChance)) { if (fishingSpot.FishStock > 0 && fishingSpot.FishByWeight.Count > 0) { FishDef fishDefToCatch = fishingSpot.FishByWeight.RandomElementByWeight(item => item.Item1).Item2; if (fishDefToCatch.fishProperties.CanBite && Rand.Value < pawn.GetStatValue(ResourceBank.StatDefOf.FishBiteChance)) { float damage = Rand.Range(fishDefToCatch.fishProperties.BiteDamageRange.min, fishDefToCatch.fishProperties.BiteDamageRange.max); eventText = string.Format(ResourceBank.Strings.FishingTradegyText.Translate(), this.pawn.Name.ToStringShort.CapitalizeFirst(), fishDefToCatch.label); Find.LetterStack.ReceiveLetter(ResourceBank.Strings.FishingTradegyTitle.Translate(), eventText, LetterDefOf.NegativeEvent, this.pawn); this.pawn.TakeDamage(new DamageInfo(fishDefToCatch.fishProperties.BiteDamageDef, damage, 0f, -1f, this.pawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown, this.pawn)); return; } fishingSpot.FishCaught(); bool roeFish = false; if (fishDefToCatch.fishProperties.HasRoe && fishDefToCatch.fishProperties.RoeDef != null && fishDefToCatch.fishProperties.SpawningYearRange != null) { int day = GenDate.DayOfYear(Find.TickManager.TicksAbs, Find.WorldGrid.LongLatOf(this.Map.Tile).x); if (fishDefToCatch.fishProperties.SpawningYearRange.min <= day && day <= fishDefToCatch.fishProperties.SpawningYearRange.max) { if (Rand.Value < ModController.Settings.roeChance) { roeFish = true; } } } if (roeFish) { thingCaught = ThingMaker.MakeThing(fishDefToCatch.fishProperties.RoeDef, null); } else { thingCaught = ThingMaker.MakeThing(fishDefToCatch, null); } thingCaught.stackCount = 1; eventText = ResourceBank.Strings.FishingSuccess.Translate(this.pawn.Name.ToStringShort.CapitalizeFirst(), fishDefToCatch.label); NotifyFishingSuccess(eventText); } else if (Rand.Value < ModController.Settings.junkChance) { //catch non-fish float treasureChance = ModController.Settings.treasureChanceStandart; if (fishingSpot.DeepTerrain) { treasureChance *= treasureDeepAdditionalChance; } ThingSetMakerParams parms = default(ThingSetMakerParams); parms.countRange = new IntRange(1, 1); if (Rand.Value <= treasureChance) { parms.maxTotalMass = ModController.Settings.MaxTreasureMass; parms.totalMarketValueRange = new FloatRange(100.0f, ModController.Settings.treasureMaxValue); parms.qualityGenerator = QualityGenerator.Reward; List <Thing> list = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(parms); thingCaught = list.RandomElement(); eventText = ResourceBank.Strings.FishingCaughtTreasureText.Translate(this.pawn.Name.ToStringShort.CapitalizeFirst(), thingCaught.def.label); NotifyCaughtTreasure(eventText); } else { parms.maxTotalMass = ModController.Settings.MaxJunkMass; parms.qualityGenerator = QualityGenerator.BaseGen; List <Thing> list = ResourceBank.ThingSetMakerDefOf.Fishing_ItemJunk.root.Generate(parms); thingCaught = list.RandomElement(); eventText = ResourceBank.Strings.FishingCaughtJunkText.Translate(this.pawn.Name.ToStringShort.CapitalizeFirst(), thingCaught.def.label); NotifyCaughtJunk(eventText); } } } else { eventText = ResourceBank.Strings.FishingCaughtNothingText.Translate(this.pawn.Name.ToStringShort.CapitalizeFirst()); MoteMaker.ThrowMetaIcon(this.pawn.Position, this.Map, ThingDefOf.Mote_IncapIcon); NotifyCaughtNothing(eventText); this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable); return; } } }; yield return(catchFishToil); //yield return FinishAndStartHaul(fishingCatch); Toil toilFinishAndStartHaul = new Toil(); toilFinishAndStartHaul.initAction = delegate { Pawn actor = toilFinishAndStartHaul.actor; Job curJob = actor.jobs.curJob; Bill bill = curJob.bill; Log.Message(bill.recipe.defName); Log.Message(thingCaught.def.defName); if (curJob.bill.GetStoreMode() == BillStoreModeDefOf.DropOnFloor) { if (!GenPlace.TryPlaceThing(thingCaught, actor.Position, actor.Map, ThingPlaceMode.Near)) { Log.Error(actor + " could not drop recipe product " + thingCaught + " near " + actor.Position); } actor.jobs.EndCurrentJob(JobCondition.Succeeded); } else { IntVec3 foundCell = IntVec3.Invalid; if (curJob.bill.GetStoreMode() == BillStoreModeDefOf.BestStockpile) { StoreUtility.TryFindBestBetterStoreCellFor(thingCaught, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out foundCell); } else if (curJob.bill.GetStoreMode() == BillStoreModeDefOf.SpecificStockpile) { if (curJob.bill.GetStoreZone().Accepts(thingCaught)) { StoreUtility.TryFindBestBetterStoreCellForIn(thingCaught, actor, actor.Map, StoragePriority.Unstored, actor.Faction, curJob.bill.GetStoreZone().slotGroup, out foundCell); } else { if (!GenPlace.TryPlaceThing(thingCaught, actor.Position, actor.Map, ThingPlaceMode.Near)) { Log.Error(actor + " could not drop recipe product " + thingCaught + " near " + actor.Position); } actor.jobs.EndCurrentJob(JobCondition.Succeeded); } } else { Log.ErrorOnce("Unknown store mode", 9158246); } if (foundCell.IsValid) { actor.carryTracker.TryStartCarry(thingCaught); curJob.SetTarget(HaulableInd, thingCaught); curJob.SetTarget(StoreCellInd, foundCell); curJob.count = 99999; } else { if (!GenPlace.TryPlaceThing(thingCaught, actor.Position, actor.Map, ThingPlaceMode.Near)) { Log.Error("Bill doer could not drop product " + thingCaught + " near " + actor.Position); } actor.jobs.EndCurrentJob(JobCondition.Succeeded); } } }; yield return(toilFinishAndStartHaul); yield return(Toils_Reserve.Reserve(StoreCellInd)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(StoreCellInd); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(StoreCellInd, carryToCell, storageMode: true, tryStoreInSameStorageIfSpotCantHoldWholeStack: true)); Toil recount = new Toil(); recount.initAction = delegate { Bill_Production bill_Production = recount.actor.jobs.curJob.bill as Bill_Production; if (bill_Production != null && bill_Production.repeatMode == BillRepeatModeDefOf.TargetCount) { Map.resourceCounter.UpdateResourceCounts(); } }; yield return(recount); }
public override IEnumerable <Toil> MakeNewToils() { this.FailOnIncapable(PawnCapacityDefOf.Manipulation); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)); if (_Necron == null) { Log.Warning("ERROR!!!! _Necron null"); yield break; } if (!DamagedNecron.Spawned && !DamagedNecron.Corpse.Spawned) { Log.Warning("ERROR!!!! DamagedNecron despawned"); yield break; } if (DamagedNecron == null) { Log.Warning("ERROR!!!! DamagedNecron null"); yield break; } if (!_Necron.PawnHediffs.NullOrEmpty()) { // Log.Message("CHECKING!!!! _Necron Damage"); foreach (Hediff hd in _Necron.PawnHediffs) { if (hd.def.hediffClass == typeof(Hediff_Injury)) { // Log.Message("INJURY!!!!"); this.useDuration += (int)(((hd.Severity * DamagedNecron.BodySize)) * (_Necron.UnhealableHediffs.Contains(hd) ? 3 : 1)); } else if (hd.def.hediffClass == typeof(Hediff_MissingPart) && !DamagedNecron.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(hd.Part)) { // Log.Message("MISSING PART!!!!"); this.useDuration += (int)(((300 * DamagedNecron.BodySize) * hd.Severity) * (_Necron.UnhealableHediffs.Contains(hd) ? 3 : 1)); } else { // Log.Message("STILL CHECKING!!!!"); if (hd.def.hediffClass != typeof(Hediff_Implant) && hd.def.hediffClass != typeof(Hediff_MissingPart)) { // Log.Message("NOT IMPLANT OR MISSINGPART!!!!"); } // Log.Message(string.Format("Missed {0} {1} on {2}", hd.LabelCap, hd.def.hediffClass, hd.Part.LabelCap)); } } } else { // Log.Warning("ERROR!!!! DamagedNecron null"); } if (DamagedNecron.Dead) { this.useDuration = (int)(500 * DamagedNecron.BodySize); } Toil prepare = Toils_General.Wait(this.useDuration, TargetIndex.A); prepare.NPCWithProgressBarToilDelay(TargetIndex.A, false, -0.5f); prepare.FailOnDespawnedNullOrForbidden(TargetIndex.A); prepare.WithEffect(EffecterDefOf.ConstructMetal, TargetIndex.A); prepare.PlaySustainerOrSound(() => SoundDefOf.Crunch); if (DamagedNecron.Dead) { yield return(prepare); Toil use = new Toil(); use.initAction = delegate() { Pawn Spyder = use.actor; _Necron.TryRevive(true); }; use.defaultCompleteMode = ToilCompleteMode.Instant; yield return(use); } else { if (DamagedNecron.Downed) { yield return(prepare); Toil use = new Toil(); use.initAction = delegate() { Pawn Spyder = use.actor; foreach (Hediff hd in _Necron.PawnHediffs) { DamagedNecron.health.RemoveHediff(hd); } }; use.defaultCompleteMode = ToilCompleteMode.Instant; yield return(use); if (_Necron.originalWeapon != null) { ThingWithComps thing = _Necron.originalWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (DamagedNecron.inventory.innerContainer.Contains(thing)) { DamagedNecron.inventory.innerContainer.Remove(thing); } DamagedNecron.equipment.AddEquipment(thing); } if (_Necron.secondryWeapon != null) { ThingWithComps thing = _Necron.secondryWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (DamagedNecron.inventory.innerContainer.Contains(thing)) { DamagedNecron.inventory.innerContainer.Remove(thing); } // DamagedNecron.equipment.AdMechAddOffHandEquipment(thing); } } } yield break; }
protected override IEnumerable <Toil> MakeNewToils() { Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true)); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue)); Toil cut = new Toil(); Plant plant = (Plant)Thing; CompHarvestableReagent reagent = Thing.TryGetComp <CompHarvestableReagent>(); cut.tickAction = delegate { Pawn actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(DefDatabase <SkillDef> .GetNamed("Alchemy", true), xpPerTick, false); } float statValue = actor.GetStatValue(DefDatabase <StatDef> .GetNamed("ReagentHarvestingSpeed"), true); float num = statValue; workDone += num; if (!reagent.IsSecondaryHarvest) { if (plant != null) { if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(DefDatabase <StatDef> .GetNamed("ReagentHarvestingYield"), true)) { Vector3 loc = (pawn.DrawPos + plant.DrawPos) / 2f; MoteMaker.ThrowText(loc, Map, "TextMote_ReagentHarvestFailed".Translate(), 3.65f); } else { int num2 = plant.YieldNow(); if (num2 > 0) { Thing harvestedThing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null); harvestedThing.stackCount = num2; if (actor.Faction != Faction.OfPlayer) { harvestedThing.SetForbidden(true, true); } GenPlace.TryPlaceThing(harvestedThing, actor.Position, Map, ThingPlaceMode.Near, null); actor.records.Increment(DefDatabase <RecordDef> .GetNamed("ReagentsHarvested")); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0f; ReadyForNextToil(); return; } } // Animal // Inanimate } else { if (workDone >= reagent.HarvestWork) { if (reagent.HarvestedThingDef != null) { if (actor.RaceProps.Humanlike && reagent.HarvestFailable && Rand.Value > actor.GetStatValue(DefDatabase <StatDef> .GetNamed("ReagentHarvestingYield"), true)) { Vector3 loc = (pawn.DrawPos + reagent.parent.DrawPos) / 2f; MoteMaker.ThrowText(loc, Map, "TextMote_ReagentHarvestFailed".Translate(), 3.65f); } else { int num2 = reagent.YieldNow(); if (num2 > 0) { Thing harvestedThing = ThingMaker.MakeThing(reagent.HarvestedThingDef, null); harvestedThing.stackCount = num2; if (actor.Faction != Faction.OfPlayer) { harvestedThing.SetForbidden(true, true); } GenPlace.TryPlaceThing(harvestedThing, actor.Position, Map, ThingPlaceMode.Near, null); actor.records.Increment(DefDatabase <RecordDef> .GetNamed("ReagentsHarvested")); } } } if (plant != null) { plant.def.plant.soundHarvestFinish.PlayOneShot(actor); } reagent.ReagentCollected(actor); workDone = 0f; ReadyForNextToil(); return; } } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); if (!reagent.IsSecondaryHarvest) { if (plant != null) { cut.WithProgressBar(TargetIndex.A, () => workDone / plant.def.plant.harvestWork, true, -0.5f); cut.PlaySustainerOrSound(() => plant.def.plant.soundHarvesting); } // Animals } else { cut.WithProgressBar(TargetIndex.A, () => workDone / reagent.HarvestWork, true, -0.5f); if (plant != null) { cut.PlaySustainerOrSound(() => plant.def.plant.soundHarvesting); } } yield return(cut); Toil workDoneToil = WorkDoneToil(); if (workDoneToil != null) { yield return(workDoneToil); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); Toil gotoThing = new Toil(); gotoThing.initAction = delegate { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.Touch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil enchanting = new Toil();//actions performed to enchant an item enchanting.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); enchanting.FailOnDestroyedOrNull(TargetIndex.A); enchanting.initAction = delegate { actor = enchanting.actor; thing = TargetThingA; thingLoc = thing.Position; if (!(thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon || thing.def.IsApparel)) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); Log.Message("Failed to initialize enchanting - invalid item type."); } else if (thing.def.defName.Contains("TM_Artifact")) { Messages.Message("TM_CannotEnchantArtifact".Translate( actor.LabelShort, thing.LabelShort ), MessageTypeDefOf.RejectInput); actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); } }; enchanting.tickAction = delegate { if (thing.Position != thingLoc || thing.Destroyed) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); Log.Message("Failed to complete enchanting - item being enchanted not at enchanting location or destroyed"); } if (Find.TickManager.TicksGame % 5 == 0) { TM_MoteMaker.ThrowEnchantingMote(TargetLocA.ToVector3Shifted(), actor.Map, .6f); } }; enchanting.WithProgressBar(TargetIndex.A, delegate { if (thing == null) { return(1f); } return(1f - (float)enchanting.actor.jobs.curDriver.ticksLeftThisToil / 240); }, false, 0f); enchanting.defaultCompleteMode = ToilCompleteMode.Delay; enchanting.defaultDuration = 240; enchanting.AddFinishAction(delegate { CompEnchantedItem enchantment = thing.TryGetComp <CompEnchantedItem>(); CompEnchant enchantingItem = actor.TryGetComp <CompEnchant>(); CompAbilityUserMagic pawnComp = actor.TryGetComp <CompAbilityUserMagic>(); if (enchantment != null && enchantingItem != null && enchanting.actor.jobs.curDriver.ticksLeftThisToil < 1) { if (EnchantItem(enchantingItem.enchantingContainer[0], enchantment)) { enchantingItem.enchantingContainer[0].SplitOff(1).Destroy(DestroyMode.Vanish); pawnComp.Mana.CurLevel -= .5f; int num = Rand.Range(130, 180); pawnComp.MagicUserXP += num; MoteMaker.ThrowText(actor.DrawPos, actor.Map, "XP +" + num, -1f); MoteMaker.ThrowText(TargetLocA.ToVector3Shifted(), actor.Map, "TM_Enchanted".Translate(), -1); SoundStarter.PlayOneShotOnCamera(TorannMagicDefOf.ItemEnchanted, null); } else { Messages.Message("TM_NothingEnchanted".Translate(actor.LabelShort, thing.LabelShort, enchantingItem.enchantingContainer[0].LabelShort), MessageTypeDefOf.RejectInput); } //DestroyEnchantingStone(enchantingItem.innerContainer[0]); } else { Log.Message("Detected null enchanting comp."); } }); yield return(enchanting); }
//reserve, goto, take, check for more. Branches off to "all over the place" protected override IEnumerable <Toil> MakeNewToils() { CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>(); HashSet <Thing> carriedThings = takenToInventory.GetHashSet(); DesignationDef HaulUrgentlyDesignation = DefDatabase <DesignationDef> .GetNamed("HaulUrgentlyDesignation", false); //Thanks to AlexTD for the more dynamic search range float searchForOthersRangeFraction = 0.5f; float distanceToOthers = 0f; Toil wait = Toils_General.Wait(2); Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null); Toil calculateExtraDistanceToGo = new Toil { initAction = () => { if (StoreUtility.TryFindStoreCellNearColonyDesperate(this.job.targetA.Thing, this.pawn, out IntVec3 storeLoc)) { distanceToOthers = (storeLoc - job.targetA.Thing.Position).LengthHorizontal * searchForOthersRangeFraction; } } }; yield return(calculateExtraDistanceToGo); Toil checkForOtherItemsToHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, null); Toil checkForOtherItemsToUrgentlyHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, (Thing x) => pawn.Map.designationManager.DesignationOn(x)?.def == HaulUrgentlyDesignation); yield return(reserveTargetA); Toil gotoThing = new Toil { initAction = () => { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival, }; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil takeThing = new Toil { initAction = () => { Pawn actor = this.pawn; Thing thing = actor.CurJob.GetTarget(TargetIndex.A).Thing; Toils_Haul.ErrorCheckForCarry(actor, thing); //get max we can pick up int num = Mathf.Min(thing.stackCount, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); // yo dawg, I heard you like delegates so I put delegates in your delegate, so you can delegate your delegates. // because compilers don't respect IF statements in delegates and toils are fully iterated over as soon as the job starts. try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { CombatExtended.CompInventory ceCompInventory = actor.GetComp <CombatExtended.CompInventory>(); ceCompInventory.CanFitInInventory(thing, out num, false, false); } }))(); } catch (TypeLoadException) { } //can't store more, so queue up hauling if we can + end the current job (smooth/instant transition) if (num <= 0) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); if (haul?.TryMakePreToilReservations(actor) ?? false) { actor.jobs.jobQueue.EnqueueFirst(haul, new JobTag?(JobTag.Misc)); } actor.jobs.curDriver.JumpToToil(wait); } else { bool isUrgent = false; if (ModCompatibilityCheck.AllowToolIsActive) { //check BEFORE absorbing the thing, designation disappears when it's in inventory :^) if (pawn.Map.designationManager.DesignationOn(thing)?.def == HaulUrgentlyDesignation) { isUrgent = true; } } actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num), true); takenToInventory.RegisterHauledItem(thing); try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { CombatExtended.CompInventory ceCompInventory = actor.GetComp <CombatExtended.CompInventory>(); ceCompInventory.UpdateInventory(); } }))(); } catch (TypeLoadException) { } if (isUrgent) { actor.jobs.curDriver.JumpToToil(checkForOtherItemsToUrgentlyHaulToInventory); } } } }; yield return(takeThing); yield return(checkForOtherItemsToHaulToInventory); //we end the job in there, so only one of the checks for duplicates gets called. yield return(checkForOtherItemsToUrgentlyHaulToInventory); yield return(wait); }
//get next, goto, take, check for more. Branches off to "all over the place" protected override IEnumerable <Toil> MakeNewToils() { CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>(); Toil wait = Toils_General.Wait(2); Toil nextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A); //also does count yield return(nextTarget); //honestly the workgiver checks for encumbered, so until CE checks are in this is unnecessary //yield return CheckForOverencumbered();//Probably redundant without CE checks Toil gotoThing = new Toil { initAction = () => { pawn.pather.StartPath(TargetThingA, PathEndMode.ClosestTouch); }, defaultCompleteMode = ToilCompleteMode.PatherArrival }; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil takeThing = new Toil { initAction = () => { Pawn actor = pawn; Thing thing = actor.CurJob.GetTarget(TargetIndex.A).Thing; Toils_Haul.ErrorCheckForCarry(actor, thing); //get max we can pick up int countToPickUp = Mathf.Min(job.count, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); Log.Message($"{actor} is hauling to inventory {thing}:{countToPickUp}"); // yo dawg, I heard you like delegates so I put delegates in your delegate, so you can delegate your delegates. // because compilers don't respect IF statements in delegates and toils are fully iterated over as soon as the job starts. try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { //CombatExtended.CompInventory ceCompInventory = actor.GetComp<CombatExtended.CompInventory>(); //ceCompInventory.CanFitInInventory(thing, out countToPickUp); } }))(); } catch (TypeLoadException) { } if (countToPickUp > 0) { Thing splitThing = thing.SplitOff(countToPickUp); bool shouldMerge = takenToInventory.GetHashSet().Any(x => x.def == thing.def); actor.inventory.GetDirectlyHeldThings().TryAdd(splitThing, shouldMerge); takenToInventory.RegisterHauledItem(splitThing); try { ((Action)(() => { if (ModCompatibilityCheck.CombatExtendedIsActive) { //CombatExtended.CompInventory ceCompInventory = actor.GetComp<CombatExtended.CompInventory>(); //ceCompInventory.UpdateInventory(); } }))(); } catch (TypeLoadException) { } } //thing still remains, so queue up hauling if we can + end the current job (smooth/instant transition) //This will technically release the reservations in the queue, but what can you do if (thing.Spawned) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); if (haul?.TryMakePreToilReservations(actor, false) ?? false) { actor.jobs.jobQueue.EnqueueFirst(haul, JobTag.Misc); } actor.jobs.curDriver.JumpToToil(wait); } } }; yield return(takeThing); yield return(Toils_Jump.JumpIf(nextTarget, () => !job.targetQueueA.NullOrEmpty())); //Find more to haul, in case things spawned while this was in progess yield return(new Toil { initAction = () => { List <Thing> haulables = pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(); WorkGiver_HaulToInventory haulMoreWork = DefDatabase <WorkGiverDef> .AllDefsListForReading.First(wg => wg.Worker is WorkGiver_HaulToInventory).Worker as WorkGiver_HaulToInventory; Thing haulMoreThing = GenClosest.ClosestThing_Global(pawn.Position, haulables, 12, t => haulMoreWork.HasJobOnThing(pawn, t)); //WorkGiver_HaulToInventory found more work nearby if (haulMoreThing != null) { Log.Message($"{pawn} hauling again : {haulMoreThing}"); Job haulMoreJob = haulMoreWork.JobOnThing(pawn, haulMoreThing); if (haulMoreJob.TryMakePreToilReservations(pawn, false)) { pawn.jobs.jobQueue.EnqueueFirst(haulMoreJob, JobTag.Misc); EndJobWith(JobCondition.Succeeded); } } } }); //maintain cell reservations on the trip back //TODO: do that when we carry things //I guess that means TODO: implement carrying the rest of the items in this job instead of falling back on HaulToStorageJob yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.ClosestTouch)); yield return(new Toil //Queue next job { initAction = () => { Pawn actor = pawn; Job curJob = actor.jobs.curJob; LocalTargetInfo storeCell = curJob.targetB; Job unloadJob = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory, storeCell); if (unloadJob.TryMakePreToilReservations(actor, false)) { actor.jobs.jobQueue.EnqueueFirst(unloadJob, JobTag.Misc); EndJobWith(JobCondition.Succeeded); //This will technically release the cell reservations in the queue, but what can you do } } }); yield return(wait); }
protected override IEnumerable <Toil> MakeNewToils() { Toil meditate = new Toil { socialMode = RandomSocialMode.Off }; if (FromBed) { this.KeepLyingDown(TargetIndex.B); meditate = Toils_LayDown.LayDown(TargetIndex.B, job.GetTarget(TargetIndex.B).Thing is Building_Bed, lookForOtherJobs: false, canSleep: false); } else { yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); meditate.initAction = delegate { LocalTargetInfo target = job.GetTarget(TargetIndex.C); if (target.IsValid) { faceDir = target.Cell - pawn.Position; } else { faceDir = (job.def.faceDir.IsValid ? job.def.faceDir : Rot4.Random).FacingCell; } }; if (Focus != null) { meditate.FailOnDespawnedNullOrForbidden(TargetIndex.C); } meditate.handlingFacing = true; } meditate.defaultCompleteMode = ToilCompleteMode.Delay; meditate.defaultDuration = job.def.joyDuration; meditate.FailOn(() => !MeditationUtility.CanMeditateNow(pawn) || !MeditationUtility.SafeEnvironmentalConditions(pawn, base.TargetLocA, base.Map)); meditate.AddPreTickAction(delegate { if (faceDir.IsValid && !FromBed) { pawn.rotationTracker.FaceCell(pawn.Position + faceDir); } pawn.GainComfortFromCellIfPossible(); MeditationTick(); if (ModLister.RoyaltyInstalled && MeditationFocusDefOf.Natural.CanPawnUse(pawn)) { int num = GenRadial.NumCellsInRadius(MeditationUtility.FocusObjectSearchRadius); for (int i = 0; i < num; i++) { IntVec3 c = pawn.Position + GenRadial.RadialPattern[i]; if (c.InBounds(pawn.Map)) { Plant plant = c.GetPlant(pawn.Map); if (plant != null && plant.def == ThingDefOf.Plant_TreeAnima) { plant.TryGetComp <CompSpawnSubplant>()?.AddProgress(AnimaTreeSubplantProgressPerTick); } } } } }); meditate.AddFinishAction(delegate { if (sustainer != null) { sustainer.End(); } }); yield return(meditate); }