public static IEnumerable <Toil> GoToMap(Pawn pawn, Map dest, JobDriver instance) { Toil end = new Toil { initAction = delegate() { } }; yield return(new Toil { initAction = delegate() { if (pawn.Map == dest) { instance.JumpToToil(end); } } }); Toil setStairs = GetSetStairs(pawn, dest); var goToStairs = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell); if (pawn.HostileTo(Faction.OfPlayer)) { pawn.CurJob.canBash = true; } Toil useStairs = Toils_General.Wait(60, 0); useStairs.WithProgressBarToilDelay(TargetIndex.C, false, -0.5f); //ToilFailConditions.FailOnDespawnedNullOrForbidden<Toil>(useStairs, TargetIndex.C); //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell); Toil teleport = GetTeleport(pawn, dest, instance, setStairs); yield return(setStairs); yield return(goToStairs); yield return(useStairs); yield return(teleport); yield return(end); }
public static IEnumerable <Toil> GoToMap(Pawn pawn, Map dest, JobDriver instance) { Toil end = new Toil { initAction = delegate() { ZLogger.Message("if (pawn.Map == dest): " + pawn.Map + " - " + dest); } }; yield return(new Toil { initAction = delegate() { if (pawn.Map == dest) { instance.JumpToToil(end); } } }); Toil setStairs = new Toil { initAction = delegate() { var ZTracker = ZUtils.ZTracker; ZLogger.Message("Pawn.map: " + pawn.Map); ZLogger.Message("Dest Map: " + dest); ZTracker.ReCheckStairs(); ZLogger.Message("1 Total count of stairs up: " + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsUp).Count()); ZLogger.Message("1 Total count of stairs down: " + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsDown).Count()); ZLogger.Message("2 Total count of stairs up: " + ZTracker.stairsUp[pawn.Map].Count); ZLogger.Message("2 Total count of stairs down: " + ZTracker.stairsDown[pawn.Map].Count); if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(dest)) { var stairs = ZTracker.stairsDown[pawn.Map]; if (stairs?.Count() > 0) { pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position))); } else { ZLogger.Pause(pawn + " cant find stairs down"); } } else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(dest)) { var stairs = ZTracker.stairsUp[pawn.Map]; if (stairs?.Count() > 0) { pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(y => IntVec3Utility.DistanceTo(pawn.Position, y.Position))); } else { ZLogger.Pause(pawn + " cant find stairs up"); } } else { pawn.CurJob.targetC = null; } } }; var goToStairs = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell); Toil useStairs = Toils_General.Wait(60, 0); ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f); //ToilFailConditions.FailOnDespawnedNullOrForbidden<Toil>(useStairs, TargetIndex.C); //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell); Toil teleport = new Toil { initAction = delegate() { var ZTracker = ZUtils.ZTracker; if (pawn.CurJob.targetC.Thing is Building_StairsUp stairsUp) { Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map); if (map == null) { map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position); if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsUp.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true); } else { if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsUp.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper); stairsUp.shouldSpawnStairsUpper = false; } } else if (pawn.CurJob.targetC.Thing is Building_StairsDown stairsDown) { Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map); if (map == null) { map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position); if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsDown.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true); } else { if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsDown.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow); stairsDown.shouldSpawnStairsBelow = false; } } if (pawn.Map != dest) { instance.JumpToToil(setStairs); } } }; yield return(setStairs); yield return(goToStairs); yield return(useStairs); yield return(teleport); yield return(end); } }
public static IEnumerable <Toil> Toils_GoToThingMap(Pawn pawn, Thing selectedStairs, Thing thing, JobDriver instance) { Toil setStairs = new Toil { initAction = delegate() { var ZTracker = Current.Game.GetComponent <ZLevelsManager>(); ZLogger.Message("Pawn: " + pawn); ZLogger.Message("Pawn.map: " + pawn.Map); ZLogger.Message("thing: " + thing); ZLogger.Message("thing.Map: " + thing.Map); ZLogger.Message("pawn.CurJob: " + pawn.jobs.curJob); if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(thing.Map)) { var stairs = ZTracker.stairsDown[pawn.Map]; if (stairs?.Count() > 0) { selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)); } } else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(thing.Map)) { var stairs = ZTracker.stairsUp[pawn.Map]; if (stairs?.Count() > 0) { selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)); } } pawn.jobs.curJob.targetC = new LocalTargetInfo(selectedStairs); } }; yield return(setStairs); yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell)); Toil useStairs = Toils_General.Wait(60, 0); ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f); ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.C); //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell); yield return(useStairs); yield return(new Toil { initAction = delegate() { var ZTracker = Current.Game.GetComponent <ZLevelsManager>(); if (selectedStairs is Building_StairsUp stairsUp) { Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map); if (map == null) { map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position); if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsUp.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true); } else { if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsUp.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper); stairsUp.shouldSpawnStairsUpper = false; } } else if (selectedStairs is Building_StairsDown stairsDown) { Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map); if (map == null) { map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position); if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsDown.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true); } else { if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0) { var comp = map.GetComponent <MapComponentZLevel>(); comp.DoGeneration = true; comp.path = stairsDown.pathToPreset; } ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow); stairsDown.shouldSpawnStairsBelow = false; } } if (pawn.Map != thing.Map) { instance.JumpToToil(setStairs); } } });