public static void _ctor(Toil __instance) { if (SimpleSidearms.ToolAutoSwitch == true) { Toil toil = __instance; toil.AddPreInitAction(delegate { if (toil.activeSkill != null && toil.activeSkill() != null && toil.GetActor() != null) { //Log.Message("Pawn " + toil.GetActor().Label + " initializing toil that uses skill " + toil.activeSkill().label); bool usingAppropriateTool = WeaponAssingment.equipBestWeaponFromInventoryByStatModifiers(toil.GetActor(), SkillStatMap.Map[toil.activeSkill()]); if (usingAppropriateTool) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(toil.GetActor()); if (pawnMemory != null) { pawnMemory.autotoolToil = toil; } } } }); toil.AddFinishAction(delegate { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(toil.GetActor()); if (pawnMemory != null && pawnMemory.autotoolToil == toil) { pawnMemory.delayIdleSwitchTimestamp = Find.TickManager.TicksGame; } pawnMemory.autotoolToil = null; }); } }
// Token: 0x060000E0 RID: 224 RVA: 0x0000577C File Offset: 0x0000397C public Toil Synchronise() { var t = new Toil { defaultCompleteMode = ToilCompleteMode.Delay }; t.initAction = delegate() { t.GetActor().jobs.curDriver.ticksLeftThisToil = 10000; leadReady = supportReady = false; }; t.tickAction = delegate() { t.GetActor().skills.GetSkill(SkillDefOf.Social).Learn(0.5f, false); if (t.GetActor() == Lead) { leadReady = true; } else if (t.GetActor() == Support) { supportReady = true; } if (leadReady && supportReady) { Lead.jobs.curDriver.ticksLeftThisToil = 0; Support.jobs.curDriver.ticksLeftThisToil = 0; leadReady = supportReady = false; } }; return(t); }
public static Toil CheckDuplicates(Toil jumpToil, TargetIndex CarrierInd, TargetIndex HaulableInd) { Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); TargetInfo target = toil.actor.jobs.curJob.GetTarget(HaulableInd); if (target.Thing.def.stackLimit <= 1) { return; } List <TargetInfo> targetQueue = toil.actor.jobs.curJob.GetTargetQueue(HaulableInd); if (!targetQueue.NullOrEmpty() && target.Thing.def.defName == targetQueue.First().Thing.def.defName) { toil.actor.jobs.curJob.SetTarget(HaulableInd, targetQueue.First()); Find.Reservations.Reserve(actor, targetQueue.First()); targetQueue.RemoveAt(0); toil.actor.jobs.curDriver.JumpToToil(jumpToil); return; } Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; Apparel_Backpack backpack = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Apparel_Backpack; if (cart == null && backpack == null) { Log.Error(actor.LabelCap + " Report: Don't have Carrier"); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); return; } int curItemCount = (cart != null ? cart.storage.Count : backpack.slotsComp.slots.Count) + targetQueue.Count; int curItemStack = (cart != null ? cart.storage.TotalStackCount : backpack.slotsComp.slots.TotalStackCount) + targetQueue.Sum(item => item.Thing.stackCount); int maxItem = cart != null ? cart.MaxItem : backpack.MaxItem; int maxStack = cart != null ? cart.MaxStack : backpack.MaxStack; if (curItemCount >= maxItem || curItemStack >= maxStack) { return; } //Check target's nearby Thing thing = GenClosest.ClosestThing_Global_Reachable(actor.Position, ListerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.Touch, TraverseParms.For(actor, Danger.Some), NearbyCell, item => !targetQueue.Contains(item) && item.def.defName == target.Thing.def.defName && !item.IsBurning() && Find.Reservations.CanReserve(actor, item)); if (thing != null) { toil.actor.jobs.curJob.SetTarget(HaulableInd, thing); Find.Reservations.Reserve(actor, thing); toil.actor.jobs.curDriver.JumpToToil(jumpToil); } }; return(toil); }
public static Toil CallAnimalCart(TargetIndex CartInd, TargetIndex Ind, Pawn pawn = null) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } Job job; if (pawn != null) { job = new Job(HaulJobDefOf.StandBy, pawn.Position, defaultWaitWorker); } else { job = new Job(HaulJobDefOf.StandBy, toil.actor.jobs.curJob.GetTarget(Ind), defaultWaitWorker); } cart.mountableComp.Driver.jobs.StartJob(job, JobCondition.InterruptForced); }; return(toil); }
public static void Postfix(Toil __instance) { if (__instance == null) { return; } __instance.AddPreInitAction(delegate { Pawn pawn = __instance.GetActor(); if (pawn == null || pawn.Dead || pawn.equipment == null || pawn.inventory == null || !pawn.RaceProps.Humanlike) { return; } if (pawn.Drafted) { GrabYourToolMod.Instance.ClearMemory(pawn); return; } SkillDef activeSkill = pawn.CurJob?.RecipeDef?.workSkill; if (__instance.activeSkill != null && __instance.activeSkill() != null) { activeSkill = __instance.activeSkill(); } if (activeSkill != null) { ToolMemory memory = GrabYourToolMod.Instance.GetMemory(pawn); if (!memory.UpdateSkill(activeSkill)) { return; } // Don't do it if this job uses weapons (i.e. hunting) if (activeSkill == SkillDefOf.Shooting || activeSkill == SkillDefOf.Melee) { memory.UpdateUsingTool(null, false); } // Check currently equipped item else if (pawn.equipment.Primary != null && ToolMemoryTracker.HasReleventStatModifiers(pawn.equipment.Primary, activeSkill)) { memory.UpdateUsingTool(null, true); } // Try and find something else in inventory else { memory.UpdateUsingTool(pawn.equipment.Primary, ToolMemoryTracker.EquipAppropriateWeapon(pawn, activeSkill)); } } else { GrabYourToolMod.Instance.ClearMemory(pawn); } }); }
public static Toil CheckDuplicates(Toil jumpToil, TargetIndex CarrierInd, TargetIndex HaulableInd) { Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); TargetInfo target = toil.actor.jobs.curJob.GetTarget(HaulableInd); if (target.Thing.def.stackLimit <= 1) return; List<TargetInfo> targetQueue = toil.actor.jobs.curJob.GetTargetQueue(HaulableInd); if (!targetQueue.NullOrEmpty() && target.Thing.def.defName == targetQueue.First().Thing.def.defName) { toil.actor.jobs.curJob.SetTarget(HaulableInd, targetQueue.First()); Find.Reservations.Reserve(actor, targetQueue.First()); targetQueue.RemoveAt(0); toil.actor.jobs.curDriver.JumpToToil(jumpToil); return; } Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; Apparel_Backpack backpack = toil.actor.jobs.curJob.GetTarget(CarrierInd).Thing as Apparel_Backpack; if (cart == null && backpack == null) { Log.Error(actor.LabelCap + " Report: Don't have Carrier"); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); return; } int curItemCount = (cart != null ? cart.storage.Count : actor.inventory.container.Count) + targetQueue.Count; int curItemStack = (cart != null ? cart.storage.TotalStackCount : actor.inventory.container.TotalStackCount) + targetQueue.Sum(item => item.Thing.stackCount); int maxItem = cart != null ? cart.MaxItem : backpack.MaxItem; int maxStack = cart != null ? cart.MaxStack : backpack.MaxStack; if (curItemCount >= maxItem || curItemStack >= maxStack) return; //Check target's nearby Thing thing = GenClosest.ClosestThing_Global_Reachable(actor.Position, ListerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.Touch, TraverseParms.For(actor, Danger.Some), NearbyCell, item => !targetQueue.Contains(item) && item.def.defName == target.Thing.def.defName && !FireUtility.IsBurning(item) && Find.Reservations.CanReserve(actor, item)); if (thing != null) { toil.actor.jobs.curJob.SetTarget(HaulableInd, thing); Find.Reservations.Reserve(actor, thing); toil.actor.jobs.curDriver.JumpToToil(jumpToil); return; } }; return toil; }
private Toil TalkToAnimal(TargetIndex tameeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); actor.interactions.TryInteractWith(Mount, InteractionDefOf.AnimalChat); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 150; toil.AddFinishAction(delegate { Log.Message("finishAction mountee"); Pawn actor = toil.GetActor(); ExtendedPawnData pawnData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(actor); pawnData.mount = (Pawn)((Thing)actor.CurJob.GetTarget(tameeInd)); TextureUtility.setDrawOffset(pawnData); }); return(toil); }
// Token: 0x060000E1 RID: 225 RVA: 0x000057E4 File Offset: 0x000039E4 public static Toil Wait(int iTicks) { var toil = new Toil { defaultCompleteMode = ToilCompleteMode.Delay }; toil.initAction = delegate() { toil.GetActor().jobs.curDriver.ticksLeftThisToil = iTicks; }; return(toil); }
// Token: 0x060000E2 RID: 226 RVA: 0x00005834 File Offset: 0x00003A34 public Toil ThrowDramaticMote(Pawn p1, ThingDef mote, int ticks) { var toil = new Toil { defaultCompleteMode = ToilCompleteMode.Delay }; toil.initAction = delegate() { toil.GetActor().jobs.curDriver.ticksLeftThisToil = ticks; }; toil.tickAction = delegate() { stage.ticksIntoThisPerformance++; if (toil.GetActor().jobs.curDriver.ticksLeftThisToil % 100 == 0) { MoteMaker.ThrowMetaIcon(toil.GetActor().Position, toil.GetActor().Map, mote); } toil.GetActor().skills.GetSkill(SkillDefOf.Social).Learn(1.5f, false); }; return(toil); }
// Token: 0x060000DC RID: 220 RVA: 0x00005550 File Offset: 0x00003750 public Toil FaceDirection(Rot4 dir) { var t = new Toil { defaultCompleteMode = ToilCompleteMode.Instant }; t.initAction = delegate() { t.GetActor().Rotation = dir; }; return(t); }
private static Toil ReachTarget(Pawn target) { Toil toil = new Toil(); toil.AddFailCondition(() => target == null || target.Destroyed || target.Downed || !target.Spawned || target.Dead); toil.socialMode = 0; toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; toil.initAction = delegate { toil.GetActor().pather.StartPath(target, PathEndMode.Touch); }; return(toil); }
private static Toil TalkToAnimal(TargetIndex tameeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); Pawn recipient = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd); actor.interactions.TryInteractWith(recipient, InteractionDefOf.AnimalChat); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 270; return(toil); }
private Toil TalkToAnimal(Pawn animal) { Toil toil = new Toil(); toil.AddFailCondition(delegate { return(animal.CurJob.def != GUC_JobDefOf.Mounted); }); toil.initAction = delegate { Pawn actor = toil.GetActor(); actor.interactions.TryInteractWith(animal, InteractionDefOf.AnimalChat); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 150; return(toil); }
/// <summary> /// gets the 'talk to animal' toil /// </summary> /// <param name="tameeInd">The tamee ind.</param> /// <returns></returns> protected virtual Toil TalkToAnimal(TargetIndex tameeInd) { var toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); var recipient = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd); actor.interactions.TryInteractWith(recipient, PMInteractionDefOf.FormerHumanAnimalChat); }; toil.FailOn(() => !CanInteractNow); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 270; return(toil); }
public static Toil DismountAt(TargetIndex CartInd, TargetIndex StoreCellInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } cart.GetComp<CompMountable>().DismountAt(toil.actor.jobs.curJob.GetTarget(StoreCellInd).Cell); }; return toil; }
public static Toil ClaimBedIfNonMedical(TargetIndex ind, TargetIndex claimantIndex = TargetIndex.None) { Toil claim = new Toil(); claim.initAction = delegate { Pawn actor = claim.GetActor(); Pawn pawn = (claimantIndex != 0) ? ((Pawn)actor.CurJob.GetTarget(claimantIndex).Thing) : actor; if (pawn.ownership != null) { pawn.ownership.ClaimBedIfNonMedical((Building_Bed)actor.CurJob.GetTarget(ind).Thing); } }; claim.FailOnDespawnedOrNull(ind); return(claim); }
public static Toil CallAnimalCart(TargetIndex CartInd, TargetIndex Ind) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } Job job = new Job(jobDefStandby, toil.actor.jobs.curJob.GetTarget(Ind), defaultWaitWorker); cart.mountableComp.Driver.jobs.StartJob(job, JobCondition.InterruptForced); }; return toil; }
public static Toil DismountAt(TargetIndex CartInd, TargetIndex StoreCellInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } cart.GetComp <CompMountable>().DismountAt(toil.actor.jobs.curJob.GetTarget(StoreCellInd).Cell); }; return(toil); }
public static Toil MountOn(TargetIndex CartInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); ThingWithComps cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as ThingWithComps; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } cart.TryGetComp <CompMountable>().MountOn(actor); }; return(toil); }
public static Toil MountOtherOn(TargetIndex CartInd, Pawn patient) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Wheel chair is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } cart.mountableComp.MountOn(patient); }; return(toil); }
// Token: 0x06000091 RID: 145 RVA: 0x00005434 File Offset: 0x00003634 private static Toil AbuseTarget(Pawn target) { Toil toil = new Toil(); toil.AddFailCondition(() => target == null || target.Destroyed || target.Downed || !target.Spawned || target.Dead); toil.socialMode = RandomSocialMode.Off; toil.initAction = delegate() { Pawn actor = toil.GetActor(); if (Rand.Value < 0.3f) { actor.interactions.TryInteractWith(target, InteractionDefOf.Chitchat); return; } actor.interactions.TryInteractWith(target, InteractionDefOf.DeepTalk); }; return(toil); }
private Toil TalkToAnimal(TargetIndex tameeInd) { Toil toil = new Toil(); toil.AddFailCondition(delegate { return(Mount.CurJob.def != GUC_JobDefOf.Mounted); }); //toil.AddFailCondition(delegate { return Mount.CurJob.targetA.Thing != pawn; }); toil.initAction = delegate { Pawn actor = toil.GetActor(); actor.interactions.TryInteractWith(Mount, InteractionDefOf.AnimalChat); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 150; toil.AddFinishAction(delegate { FinishAction(); }); return(toil); }
private Toil StartFeedAnimal(TargetIndex tameeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); Pawn pawn = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd); PawnUtility.ForceWait(pawn, 270, actor); Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty); if (thing == null) { actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame; int num = FoodUtility.StackCountForNutrition(feedNutritionLeft, thing.GetStatValue(StatDefOf.Nutrition)); int stackCount = thing.stackCount; Thing thing2 = actor.inventory.innerContainer.Take(thing, Mathf.Min(num, stackCount)); actor.carryTracker.TryStartCarry(thing2); actor.CurJob.SetTarget(TargetIndex.B, thing2); float num2 = (float)thing2.stackCount * thing2.GetStatValue(StatDefOf.Nutrition); ticksLeftThisToil = Mathf.CeilToInt(270f * (num2 / RequiredNutritionPerFeed(pawn))); if (num <= stackCount) { feedNutritionLeft = 0f; } else { feedNutritionLeft -= num2; if (feedNutritionLeft < 0.001f) { feedNutritionLeft = 0f; } } } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.activeSkill = () => SkillDefOf.Animals; return(toil); }
private static Toil FlirtWithTarget(Pawn target) { Toil toil = new Toil(); toil.AddFailCondition(() => target == null || target.Destroyed || target.Downed || !target.Spawned || target.Dead); toil.socialMode = 0; toil.initAction = delegate { Pawn actor = toil.GetActor(); if (actor.relations.DirectRelationExists(PawnRelationDefOf.Lover, target)) { actor.interactions.TryInteractWith(target, InteractionDefOf.MarriageProposal); } else { actor.interactions.TryInteractWith(target, InteractionDefOf.RomanceAttempt); } }; return(toil); }
private static Toil AbuseTarget(Pawn target) { Toil toil = new Toil(); toil.AddFailCondition(() => target == null || target.Destroyed || target.Downed || !target.Spawned || target.Dead); toil.socialMode = 0; toil.initAction = delegate { Pawn actor = toil.GetActor(); if (Rand.Value < 0.3f) { actor.interactions.TryInteractWith(target, InteractionDefOf.Insult); } else { actor.interactions.TryInteractWith(target, DefDatabase <InteractionDef> .GetNamed("Slight")); } }; return(toil); }
public static Toil ReleaseAnimalCart(TargetIndex CartInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } if (cart.mountableComp.IsMounted && cart.mountableComp.Driver.CurJob.def == jobDefStandby) { cart.mountableComp.Driver.jobs.curDriver.EndJobWith(JobCondition.Succeeded); } }; return(toil); }
private Toil StartFeedAnimal(TargetIndex tameeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); Pawn pawn = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd); PawnUtility.ForceWait(pawn, 270, actor, false); Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty, 0f, false); if (thing == null) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); } else { actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame; int num = FoodUtility.StackCountForNutrition(thing.def, this.feedNutritionLeft); int stackCount = thing.stackCount; Thing thing2 = actor.inventory.innerContainer.Take(thing, Mathf.Min(num, stackCount)); actor.carryTracker.TryStartCarry(thing2); actor.CurJob.SetTarget(TargetIndex.B, thing2); float num2 = (float)thing2.stackCount * thing2.def.ingestible.nutrition; base.ticksLeftThisToil = Mathf.CeilToInt((float)(270.0 * (num2 / JobDriver_InteractAnimal.RequiredNutritionPerFeed(pawn)))); if (num <= stackCount) { this.feedNutritionLeft = 0f; } else { this.feedNutritionLeft -= num2; if (this.feedNutritionLeft < 0.0010000000474974513) { this.feedNutritionLeft = 0f; } } } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; return(toil); }
public static Toil MakeAndSpawnThingRandomRange(ThingDef def, int min, int max) { Toil toil = new Toil(); toil.initAction = () => { int num = Rand.Range(min,max); List<Thing> things = new List<Thing>(); while (num > 0) { Thing thing = ThingMaker.MakeThing(def); int num2 = UnityEngine.Mathf.Min(num, def.stackLimit); thing.stackCount = num2; num -= num2; things.Add(thing); } IntVec3 pos = toil.GetActor().jobs.curJob.targetA.Cell; foreach (var thing in things) { GenSpawn.Spawn(thing, pos); } }; return toil; }
public static Toil MakeAndSpawnThingRandomRange(ThingDef def, int min, int max) { Toil toil = new Toil(); toil.initAction = () => { int num = Rand.Range(min, max); List <Thing> things = new List <Thing>(); while (num > 0) { Thing thing = ThingMaker.MakeThing(def); int num2 = UnityEngine.Mathf.Min(num, def.stackLimit); thing.stackCount = num2; num -= num2; things.Add(thing); } IntVec3 pos = toil.GetActor().jobs.curJob.targetA.Cell; foreach (var thing in things) { GenSpawn.Spawn(thing, pos); } }; return(toil); }
public static Toil WaitAnimalCart(TargetIndex CartInd, TargetIndex HaulableInd) { Toil toil = new Toil(); int tickTime = 0; toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } tickTime = 0; if (cart.mountableComp.IsMounted) { //Worker is arrival and Animal cart is coming if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && !actor.Position.AdjacentTo8WayOrInside(cart)) { tickTime = 0; } //Worker is arrival and Animal cart is arrival else if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && actor.Position.AdjacentTo8WayOrInside(cart)) { toil.actor.jobs.curDriver.ReadyForNextToil(); } //Worker is arrival but Animal cart is missing else { Job job = new Job(jobDefStandby, actor.jobs.curJob.GetTarget(HaulableInd), defaultWaitWorker); cart.mountableComp.Driver.jobs.StartJob(job, JobCondition.InterruptForced); } } else { toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); } }; toil.tickAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } if (Find.TickManager.TicksGame % tickCheckInterval == 0) { if (cart.mountableComp.IsMounted) { //Animal cart is arrival if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && actor.Position.AdjacentTo8WayOrInside(cart)) { toil.actor.jobs.curDriver.ReadyForNextToil(); } //Animal cart would never come. Imcompletable. else if (cart.mountableComp.Driver.CurJob.def != jobDefStandby || tickTime >= defaultWaitWorker) { toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); } } else { toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); } } }; toil.defaultCompleteMode = ToilCompleteMode.Never; return(toil); }
public static Toil FindStoreCellForCart(TargetIndex CartInd) { const int NearbyCell = 8; const int RegionCellOffset = 16; IntVec3 invalid = new IntVec3(0, 0, 0); #if DEBUG StringBuilder stringBuilder = new StringBuilder(); #endif Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } //Find Valid Storage foreach (IntVec3 cell in GenRadial.RadialCellsAround(cart.Position, NearbyCell, false)) { if (cell.IsValidStorageFor(cart) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { storeCell = cell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif } } if (storeCell == IntVec3.Invalid) { //Regionwise Flood-fill cellFinder int regionInd = 0; List<Region> regions = new List<Region>(); regions.Add(cart.Position.GetRegion()); #if DEBUG stringBuilder.AppendLine(actor.LabelCap + " Report"); #endif bool flag1 = false; while (regionInd < regions.Count) { #if DEBUG stringBuilder.AppendLine("Region id: " + regions[regionInd].id); #endif if (regions[regionInd].extentsClose.Center.InHorDistOf(cart.Position, NearbyCell + RegionCellOffset)) { IntVec3 foundCell = IntVec3.Invalid; IntVec3 distCell = (regionInd > 0)? regions[regionInd - 1].extentsClose.Center : cart.Position; float distFoundCell = float.MaxValue; foreach (IntVec3 cell in regions[regionInd].Cells) { //Find best cell for placing cart if (cell.GetEdifice() == null && cell.GetZone() == null && cell.Standable() && !GenAdj.CellsAdjacentCardinal(cell, Rot4.North, IntVec2.One).Any(cardinal => cardinal.GetEdifice() is Building_Door) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { if (distCell.DistanceToSquared(cell) < distFoundCell) { foundCell = cell; distFoundCell = distCell.DistanceToSquared(cell); flag1 = true; } } } if (flag1 == true) { storeCell = foundCell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif break; } foreach (RegionLink link in regions[regionInd].links) { if (regions.Contains(link.RegionA) == false) regions.Add(link.RegionA); if (regions.Contains(link.RegionB) == false) regions.Add(link.RegionB); } } regionInd++; } } //Log.Message(stringBuilder.ToString()); /* //Home Area if (storeCell == IntVec3.Invalid) foreach (IntVec3 cell in Find.AreaHome.ActiveCells.Where(cell => (cell.GetZone() == null || cell.IsValidStorageFor(cart)) && cell.Standable() && cell.GetEdifice() == null)) if (cell.DistanceToSquared(cart.Position) < NearbyCell) storeCell = cell; */ ReservationUtility.Reserve(actor, storeCell); toil.actor.jobs.curJob.targetB = (storeCell != invalid && storeCell != IntVec3.Invalid) ? storeCell : cart.Position; }; return toil; }
public static Toil ReleaseAnimalCart(TargetIndex CartInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } if (cart.mountableComp.IsMounted && cart.mountableComp.Driver.CurJob.def == jobDefStandby) cart.mountableComp.Driver.jobs.curDriver.EndJobWith(JobCondition.Succeeded); }; return toil; }
public static Toil FindStoreCellForCart(TargetIndex CartInd) { const int NearbyCell = 8; const int RegionCellOffset = 16; IntVec3 invalid = new IntVec3(0, 0, 0); #if DEBUG StringBuilder stringBuilder = new StringBuilder(); #endif Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } //Find Valid Storage foreach (IntVec3 cell in GenRadial.RadialCellsAround(cart.Position, NearbyCell, false)) { if (cell.IsValidStorageFor(cart) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { storeCell = cell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif } } if (storeCell == IntVec3.Invalid) { //Regionwise Flood-fill cellFinder int regionInd = 0; List <Region> regions = new List <Region>(); regions.Add(cart.Position.GetRegion()); #if DEBUG stringBuilder.AppendLine(actor.LabelCap + " Report"); #endif bool flag1 = false; while (regionInd < regions.Count) { #if DEBUG stringBuilder.AppendLine("Region id: " + regions[regionInd].id); #endif if (regions[regionInd].extentsClose.Center.InHorDistOf(cart.Position, NearbyCell + RegionCellOffset)) { IntVec3 foundCell = IntVec3.Invalid; IntVec3 distCell = (regionInd > 0)? regions[regionInd - 1].extentsClose.Center : cart.Position; float distFoundCell = float.MaxValue; foreach (IntVec3 cell in regions[regionInd].Cells) { //Find best cell for placing cart if (cell.GetEdifice() == null && cell.GetZone() == null && cell.Standable() && !GenAdj.CellsAdjacentCardinal(cell, Rot4.North, IntVec2.One).Any(cardinal => cardinal.GetEdifice() is Building_Door) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { if (distCell.DistanceToSquared(cell) < distFoundCell) { foundCell = cell; distFoundCell = distCell.DistanceToSquared(cell); flag1 = true; } } } if (flag1 == true) { storeCell = foundCell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif break; } foreach (RegionLink link in regions[regionInd].links) { if (regions.Contains(link.RegionA) == false) { regions.Add(link.RegionA); } if (regions.Contains(link.RegionB) == false) { regions.Add(link.RegionB); } } } regionInd++; } } //Log.Message(stringBuilder.ToString()); /* * //Home Area * if (storeCell == IntVec3.Invalid) * foreach (IntVec3 cell in Find.AreaHome.ActiveCells.Where(cell => (cell.GetZone() == null || cell.IsValidStorageFor(cart)) && cell.Standable() && cell.GetEdifice() == null)) * if (cell.DistanceToSquared(cart.Position) < NearbyCell) * storeCell = cell; */ ReservationUtility.Reserve(actor, storeCell); toil.actor.jobs.curJob.targetB = (storeCell != invalid && storeCell != IntVec3.Invalid) ? storeCell : cart.Position; }; return(toil); }
public static void _ctor(Toil __instance) { if (SimpleSidearms.ToolAutoSwitch == true) { Toil toil = __instance; if (toil == null) { return; } toil.AddPreInitAction(delegate { Pawn pawn = toil.GetActor(); if (pawn == null || !pawn.IsValidSidearmsCarrier()) { return; } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory == null) { return; } pawnMemory.CheckIfStillOnAutotoolJob(); StatDef activeStat = pawn.CurJob?.RecipeDef?.workSpeedStat; SkillDef activeSkill = null; if (toil.activeSkill != null && toil.activeSkill() != null) { activeSkill = toil.activeSkill(); } else { activeSkill = pawn.CurJob?.RecipeDef?.workSkill; } List <StatDef> possiblyActiveStats = new List <StatDef>(); if (activeStat != null) { possiblyActiveStats.Add(activeStat); } else if (activeSkill != null && SkillStatMap.Map.ContainsKey(activeSkill)) { possiblyActiveStats.AddRange(SkillStatMap.Map[activeSkill]); } bool usingAppropriateTool = WeaponAssingment.equipBestWeaponFromInventoryByStatModifiers(toil.GetActor(), possiblyActiveStats); if (usingAppropriateTool) { if (pawnMemory != null) { pawnMemory.autotoolToil = toil; pawnMemory.autotoolJob = pawn.CurJobDef; } } }); toil.AddFinishAction(delegate { Pawn pawn = toil.GetActor(); if (!pawn.IsValidSidearmsCarrier()) { return; } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory != null) { if (pawnMemory.autotoolToil == toil) { pawnMemory.delayIdleSwitchTimestamp = Find.TickManager.TicksGame; } else { pawnMemory.autotoolToil = null; } } }); } }
protected override IEnumerable<Toil> MakeNewToils() { //Set what will cause the job to fail this.FailOnBurningImmobile(RepairStationIndex); this.FailOnDestroyedOrForbidden(RepairStationIndex); this.FailOn(delegate { return Droid != null && !Droid.ShouldGetRepairs; }); //Reserve the repair station yield return Toils_Reserve.Reserve(RepairStationIndex); //Go to the repair station interaction cell yield return Toils_Goto.GotoThing(RepairStationIndex, PathEndMode.InteractionCell); //Make a new toil that sets the droid to repair mode, then wait until fully repaired IRepairable droid = pawn as IRepairable; Building_RepairStation rps = TargetThingA as Building_RepairStation; Toil toil = new Toil(); toil.FailOnDestroyedOrForbidden(RepairStationIndex); toil.FailOn(() => { Pawn p = toil.GetActor(); Building_RepairStation rps2 = TargetThingA as Building_RepairStation; if (!(p is IRepairable)) return true; if (p.Position != TargetThingA.InteractionCell) return true; if (rps2 == null || !rps2.IsAvailable(p)) return true; return false; }); toil.initAction = () => { //Log.Message("initAction"); droid.BeingRepaired = true; rps.RegisterRepairee(droid); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = rps.Def.ticksPerRepairCycle * droid.RepairsNeededCount + 1; toil.tickAction = () => { //Log.Message("Toil tick"); if ( droid.RepairStation != null && Find.TickManager.TicksGame % droid.RepairStation.Def.ticksPerRepairCycle == 0) { if (droid.RepairStation.Power != null && !droid.RepairStation.Power.PowerOn) { return; } //Log.Message("Repaired"); droid.RepairTick(); } }; toil.AddFinishAction(delegate { //Log.Message("Finish action"); rps.DeregisterRepairee(droid); droid.BeingRepaired = false; }); toil.WithEffect(DefDatabase<EffecterDef>.GetNamed("Repair"), TargetIndex.A); toil.WithSustainer(() => { return DefDatabase<SoundDef>.GetNamed("Interact_Repair"); }); yield return toil; }
public static Toil WaitAnimalCart(TargetIndex CartInd, TargetIndex HaulableInd) { Toil toil = new Toil(); int tickTime = 0; toil.initAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } tickTime = 0; if (cart.mountableComp.IsMounted) { //Worker is arrival and Animal cart is coming if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && !actor.Position.AdjacentTo8WayOrInside(cart)) tickTime = 0; //Worker is arrival and Animal cart is arrival else if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && actor.Position.AdjacentTo8WayOrInside(cart)) toil.actor.jobs.curDriver.ReadyForNextToil(); //Worker is arrival but Animal cart is missing else { Job job = new Job(jobDefStandby, actor.jobs.curJob.GetTarget(HaulableInd), defaultWaitWorker); cart.mountableComp.Driver.jobs.StartJob(job, JobCondition.InterruptForced); } } else toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); }; toil.tickAction = () => { Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } if (Find.TickManager.TicksGame % tickCheckInterval == 0) if (cart.mountableComp.IsMounted) { //Animal cart is arrival if (cart.mountableComp.Driver.CurJob.def == jobDefStandby && actor.Position.AdjacentTo8WayOrInside(cart)) toil.actor.jobs.curDriver.ReadyForNextToil(); //Animal cart would never come. Imcompletable. else if (cart.mountableComp.Driver.CurJob.def != jobDefStandby || tickTime >= defaultWaitWorker) toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); } else toil.actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable); }; toil.defaultCompleteMode = ToilCompleteMode.Never; return toil; }