public static Toil WaitForWaiter(TargetIndex diningSpotInd, TargetIndex waiterInd) { var toil = new Toil(); toil.initAction = () => GetDriver(toil).wantsToOrder = true; toil.tickAction = () => { if (diningSpotInd != 0 && toil.actor.CurJob.GetTarget(diningSpotInd).IsValid) { toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(diningSpotInd).Cell); } if (!GetDriver(toil).wantsToOrder) { GetDriver(toil).ReadyForNextToil(); } }; toil.AddFinishAction(() => GetDriver(toil).wantsToOrder = false); toil.defaultDuration = 1500; //toil.WithProgressBarToilDelay(TargetIndex.A); // TODO: Turn this off later? Or make it go backwards? toil.defaultCompleteMode = ToilCompleteMode.Never; toil.FailOnDestroyedOrNull(diningSpotInd); toil.FailOnDurationExpired(); // Duration over? Fail job! toil.socialMode = RandomSocialMode.Normal; return(toil); }
public static Toil DrawWater(TargetIndex drawerIndex, int drawTicks) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(drawerIndex).Thing; var building = thing as IBuilding_DrinkWater; if (building == null || building.WaterType == WaterType.Undefined || building.WaterType == WaterType.NoWater || !building.CanDrawFor(actor)) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } actor.rotationTracker.FaceCell(actor.Position); actor.jobs.curDriver.ticksLeftThisToil = drawTicks; }; toil.tickAction = delegate { toil.actor.GainComfortFromCellIfPossible(); }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.FailOnDestroyedOrNull(drawerIndex); // エフェクト追加 toil.WithEffect(DefDatabase <EffecterDef> .GetNamed("Cook"), drawerIndex); toil.PlaySustainerOrSound(DefDatabase <SoundDef> .GetNamed("Recipe_CookMeal")); return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { Pawn target = this.TargetA.Thing as Pawn; float xp = 5f * Mathf.Pow(5f, target.RaceProps.wildness); this.FailOnDestroyedNullOrForbidden(TargetIndex.A); yield return(DSFIToils_Moving.GotoNearTarget(TargetIndex.A, Danger.Some, moveDistance, lookDistance)); Toil observing = Toils_General.Wait(1500); observing.FailOnDestroyedOrNull(TargetIndex.A); observing.socialMode = RandomSocialMode.SuperActive; observing.handlingFacing = true; observing.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null)); observing.tickAction = () => { if (pawn.IsHashIntervalTick(20)) { pawn.skills.Learn(SkillDefOf.Animals, 5f); pawn.rotationTracker.FaceTarget(target); if (!pawn.CanSee(target) || !pawn.Position.InHorDistOf(target.Position, lookDistance)) { this.ReadyForNextToil(); } } }; yield return(observing); yield break; }
public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; if (carrier.storage.Count <= 0) { return; } toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First()); Thing dropThing = toil.actor.jobs.curJob.targetA.Thing; IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell; Thing dummy; SlotGroup slotGroup = Find.SlotGroupManager.SlotGroupAt(destLoc); // if (destLoc.GetStorable() == null) if (slotGroup != null && slotGroup.Settings.AllowedToAccept(dropThing)) { Find.DesignationManager.RemoveAllDesignationsOn(dropThing); carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy); } //Check cell queue is adjacent List <TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd); for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++) { if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null) { Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]); carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy); cells.RemoveAt(i); i--; } } //Check item queue is valid storage for adjacent cell foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc)) { if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && adjCell.IsValidStorageFor(carrier.storage.First())) { Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First()); carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy); } } }; toil.FailOnDestroyedOrNull(CarrierInd); return(toil); }
public static Toil makeCleanToil(TargetIndex progListIndex, TargetIndex filthListIndex, Toil nextTarget) { Toil toil = new Toil(); toil.initAction = delegate() { Filth filth = toil.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth; var progQue = toil.actor.jobs.curJob.GetTargetQueue(progListIndex); progQue[0] = new IntVec3(0, 0, (int)filth.def.filth.cleaningWorkToReduceThickness * filth.thickness); }; toil.tickAction = delegate() { Filth filth = toil.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth; var progQue = toil.actor.jobs.curJob.GetTargetQueue(progListIndex); IntVec3 iv = progQue[0].Cell; iv.x += 1; iv.y += 1; if (iv.x > filth.def.filth.cleaningWorkToReduceThickness) { filth.ThinFilth(); iv.x = 0; if (filth.Destroyed) { toil.actor.records.Increment(RecordDefOf.MessesCleaned); toil.actor.jobs.curDriver.ReadyForNextToil(); return; } } progQue[0] = iv; }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.WithEffect(EffecterDefOf.Clean, filthListIndex); toil.WithProgressBar(filthListIndex, delegate() { var q = toil.actor.CurJob.GetTargetQueue(progListIndex)[0]; float result = (float)q.Cell.y / q.Cell.z; return(result); } , true, -0.5f); toil.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth); toil.JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget); toil.JumpIfOutsideHomeArea(filthListIndex, nextTarget); toil.FailOnDestroyedOrNull(TargetIndex.A); return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(new Toil { defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = 150 }); Toil killFire = new Toil(); killFire.initAction = delegate { this.$this.TargetFire.Destroy(DestroyMode.Vanish); this.$this.pawn.records.Increment(RecordDefOf.FiresExtinguished); }; killFire.FailOnDestroyedOrNull(TargetIndex.A); killFire.defaultCompleteMode = ToilCompleteMode.Instant; yield return(killFire); }
protected override IEnumerable <Toil> MakeNewToils() { Toil toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 150; yield return(toil); Toil toil2 = new Toil(); toil2.initAction = delegate { TargetFire.Destroy(); pawn.records.Increment(RecordDefOf.FiresExtinguished); }; toil2.FailOnDestroyedOrNull(TargetIndex.A); toil2.defaultCompleteMode = ToilCompleteMode.Instant; yield return(toil2); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: { Toil extinguishDelay = new Toil(); extinguishDelay.defaultCompleteMode = ToilCompleteMode.Delay; extinguishDelay.defaultDuration = 150; this.$current = extinguishDelay; if (!this.$disposing) { this.$PC = 1; } return(true); } case 1u: killFire = new Toil(); killFire.initAction = delegate() { base.TargetFire.Destroy(DestroyMode.Vanish); this.pawn.records.Increment(RecordDefOf.FiresExtinguished); }; killFire.FailOnDestroyedOrNull(TargetIndex.A); killFire.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = killFire; if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: this.$PC = -1; break; } return(false); }
public static Toil StartCarryFromInventory(TargetIndex thingIndex) { // 水(食事)を持ち物から取り出す Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing thing = curJob.GetTarget(thingIndex).Thing; if (actor.inventory != null && thing != null) { actor.inventory.innerContainer.Take(thing); actor.carryTracker.TryStartCarry(thing); } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; toil.FailOnDestroyedOrNull(thingIndex); return(toil); }
public Verb_UseAbility verb = new Verb_UseAbility(); // = this.pawn.CurJob.verbToUse as Verb_UseAbility; protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A)); this.verb = this.pawn.CurJob.verbToUse as Verb_UseAbility; if (base.TargetA.HasThing) { if (!base.GetActor().IsFighting() ? true : !verb.UseAbilityProps.canCastInMelee && !this.job.endIfCantShootTargetFromCurPos) { Toil toil = Toils_Combat.GotoCastPosition(TargetIndex.A, false); yield return(toil); toil = null; } } if (this.Context == AbilityContext.Player) { Find.Targeter.targetingVerb = this.verb; } Pawn targetPawn = null; if (this.TargetThingA != null) { targetPawn = TargetThingA as Pawn; } if (targetPawn != null) { //yield return Toils_Combat.CastVerb(TargetIndex.A, false); Toil combatToil = new Toil(); combatToil.FailOnDestroyedOrNull(TargetIndex.A); combatToil.FailOnDespawnedOrNull(TargetIndex.A); //combatToil.FailOnDowned(TargetIndex.A); //CompAbilityUserMagic comp = this.pawn.GetComp<CompAbilityUserMagic>(); //JobDriver curDriver = this.pawn.jobs.curDriver; combatToil.initAction = delegate { this.verb = combatToil.actor.jobs.curJob.verbToUse as Verb_UseAbility; this.duration = (int)((this.verb.verbProps.warmupTime * 60) * this.pawn.GetStatValue(StatDefOf.AimingDelayFactor, false)); if (this.pawn.RaceProps.Humanlike) { if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { RemoveMimicAbility(verb); } if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.TM_Psionic)) { PsionicEnergyCost(verb); } if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.DeathKnight)) { HateCost(verb); } if (verb.Ability.CooldownTicksLeft != -1) { this.EndJobWith(JobCondition.Incompletable); } } LocalTargetInfo target = combatToil.actor.jobs.curJob.GetTarget(TargetIndex.A); verb.TryStartCastOn(target, false, false); using (IEnumerator <Hediff> enumerator = this.pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator()) { while (enumerator.MoveNext()) { Hediff rec = enumerator.Current; if (rec.def == TorannMagicDefOf.TM_PossessionHD || rec.def == TorannMagicDefOf.TM_DisguiseHD || rec.def == TorannMagicDefOf.TM_DisguiseHD_I || rec.def == TorannMagicDefOf.TM_DisguiseHD_II || rec.def == TorannMagicDefOf.TM_DisguiseHD_III) { this.pawn.health.RemoveHediff(rec); } } } }; combatToil.tickAction = delegate { if (Find.TickManager.TicksGame % 12 == 0) { if (verb.Ability.Def == TorannMagicDefOf.TM_Artifact_TraitThief || verb.Ability.Def == TorannMagicDefOf.TM_Artifact_TraitInfuse) { float direction = Rand.Range(0, 360); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Psi_Arcane"), pawn.DrawPos, pawn.Map, Rand.Range(.1f, .4f), 0.2f, .02f, .1f, 0, Rand.Range(8, 10), direction, direction); } else { TM_MoteMaker.ThrowCastingMote(pawn.DrawPos, pawn.Map, Rand.Range(1.2f, 2f)); } } this.duration--; }; combatToil.AddFinishAction(delegate { if (this.duration <= 5 && !this.pawn.DestroyedOrNull() && !this.pawn.Dead && !this.pawn.Downed) { //ShootLine shootLine; //bool validTarg = verb.TryFindShootLineFromTo(pawn.Position, TargetLocA, out shootLine); //bool inRange = (pawn.Position - TargetLocA).LengthHorizontal < verb.verbProps.range; //if (inRange && validTarg) //{ verb.Ability.PostAbilityAttempt(); this.pawn.ClearReservationsForJob(this.job); //} } }); //if (combatToil.actor.CurJob != this.job) //{ // curDriver.ReadyForNextToil(); //} combatToil.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(combatToil); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; //Toil toil1 = new Toil() //{ // initAction = () => curJob.Ability.PostAbilityAttempt(), // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil1; } else { if ((pawn.Position - TargetLocA).LengthHorizontal < verb.verbProps.range) { if (TargetLocA.IsValid && TargetLocA.InBounds(pawn.Map) && !TargetLocA.Fogged(pawn.Map)) //&& TargetLocA.Walkable(pawn.Map) { ShootLine shootLine; bool validTarg = verb.TryFindShootLineFromTo(pawn.Position, TargetLocA, out shootLine); if (validTarg) { //yield return Toils_Combat.CastVerb(TargetIndex.A, false); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; this.duration = (int)((verb.verbProps.warmupTime * 60) * this.pawn.GetStatValue(StatDefOf.AimingDelayFactor, false)); Toil toil = new Toil(); toil.initAction = delegate { this.verb = toil.actor.jobs.curJob.verbToUse as Verb_UseAbility; if (this.pawn.RaceProps.Humanlike) { if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { RemoveMimicAbility(verb); } if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.TM_Psionic)) { PsionicEnergyCost(verb); } if (verb.Ability.CooldownTicksLeft != -1) { this.EndJobWith(JobCondition.Incompletable); } } LocalTargetInfo target = toil.actor.jobs.curJob.GetTarget(TargetIndex.A); //TargetLocA; // bool canFreeIntercept2 = false; verb.TryStartCastOn(target, false, canFreeIntercept2); using (IEnumerator <Hediff> enumerator = this.pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator()) { while (enumerator.MoveNext()) { Hediff rec = enumerator.Current; if (rec.def == TorannMagicDefOf.TM_PossessionHD || rec.def == TorannMagicDefOf.TM_DisguiseHD || rec.def == TorannMagicDefOf.TM_DisguiseHD_I || rec.def == TorannMagicDefOf.TM_DisguiseHD_II || rec.def == TorannMagicDefOf.TM_DisguiseHD_III) { this.pawn.health.RemoveHediff(rec); } } } }; toil.tickAction = delegate { if (Find.TickManager.TicksGame % 12 == 0) { TM_MoteMaker.ThrowCastingMote(pawn.DrawPos, pawn.Map, Rand.Range(1.2f, 2f)); } this.duration--; }; toil.AddFinishAction(delegate { if (this.duration <= 5 && !this.pawn.DestroyedOrNull() && !this.pawn.Dead && !this.pawn.Downed) { verb.Ability.PostAbilityAttempt(); this.pawn.ClearReservationsForJob(this.job); } }); toil.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(toil); //Toil toil1 = new Toil() //{ // initAction = () => curJob.Ability.PostAbilityAttempt(), // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil1; } else { //No LoS if (pawn.IsColonist) { Messages.Message("TM_OutOfLOS".Translate( pawn.LabelShort ), MessageTypeDefOf.RejectInput); } pawn.ClearAllReservations(false); } } else { pawn.ClearAllReservations(false); } } else { if (pawn.IsColonist) { //out of range Messages.Message("TM_OutOfRange".Translate(), MessageTypeDefOf.RejectInput); } } } }
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); }
public static Toil CollectInCarrier(TargetIndex CarrierInd, TargetIndex HaulableInd) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing haulThing = curJob.GetTarget(HaulableInd).Thing; Vehicle_Cart carrier = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; //Check haulThing is human_corpse. If other race has apparel, It need to change Find.DesignationManager.RemoveAllDesignationsOn(haulThing); //if (haulThing.ThingID.IndexOf("Human_Corpse") <= -1 ? false : true) //{ // Corpse corpse = (Corpse)haulThing; // List<Apparel> wornApparel = corpse.innerPawn.apparel.WornApparel; // // //Drop wornApparel. wornApparel cannot Add to container directly because it will be duplicated. // corpse.innerPawn.apparel.DropAll(corpse.innerPawn.Position, false); // // //Transfer in container // foreach (Thing apparel in wornApparel) // { // if (carrier.storage.TryAdd(apparel)) // { // apparel.holder = carrier.GetContainer(); // apparel.holder.owner = carrier; // } // } //} //Collecting TargetIndex ind if (carrier.storage.TryAdd(haulThing)) { haulThing.holder = carrier.GetContainer(); haulThing.holder.owner = carrier; } List <TargetInfo> thingList = curJob.GetTargetQueue(HaulableInd); for (int i = 0; i < thingList.Count; i++) { if (actor.Position.AdjacentTo8Way(thingList[i].Thing.Position)) { if (carrier.storage.TryAdd(thingList[i].Thing)) { thingList[i].Thing.holder = carrier.GetContainer(); thingList[i].Thing.holder.owner = carrier; } thingList.RemoveAt(i); i--; } } }; toil.FailOn(() => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing haulThing = curJob.GetTarget(HaulableInd).Thing; Vehicle_Cart carrier = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart; if (!carrier.storage.CanAcceptAnyOf(haulThing) && actor.Position.IsAdjacentTo8WayOrInside(haulThing.Position, haulThing.Rotation, haulThing.RotatedSize)) { return(true); } return(false); }); toil.FailOnDestroyedOrNull(CarrierInd); return(toil); }
public static Toil ChewCorpse(Pawn chewer, float durationMultiplier, TargetIndex ind) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(ind).Thing; actor.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt(500 * durationMultiplier); if (thing.Spawned) { thing.Map.physicalInteractionReservationManager.Reserve(chewer, actor.CurJob, thing); } }; toil.tickAction = delegate { if (chewer != toil.actor) { toil.actor.rotationTracker.FaceCell(chewer.Position); } else { Thing thing = toil.actor.CurJob.GetTarget(ind).Thing; if (thing != null && thing.Spawned) { toil.actor.rotationTracker.FaceCell(thing.Position); } } }; toil.WithProgressBar(ind, delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(ind).Thing; if (thing == null) { return(1f); } return(1f - toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round(500 * durationMultiplier)); }, false, -0.5f); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.FailOnDestroyedOrNull(ind); toil.AddFinishAction(delegate { if (chewer == null) { return; } if (chewer.CurJob == null) { return; } Thing thing = chewer.CurJob.GetTarget(ind).Thing; if (thing == null) { return; } if (chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing)) { chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing); } }); toil.handlingFacing = true; AddChewEffects(toil, chewer, ind); return(toil); }
public Toil DrinkCorpse(float durationMultiplier) { report = "ROM_ConsumeJob2".Translate(); var drinkCorpse = new Toil { initAction = delegate { Thing thing = Victim.Corpse; pawn.rotationTracker.FaceCell(TargetA.Thing.Position); if (!thing.IngestibleNow) { pawn.jobs.EndCurrentJob(JobCondition.Incompletable); return; } pawn.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt(thing.def.ingestible.baseIngestTicks * durationMultiplier); }, tickAction = delegate { pawn.GainComfortFromCellIfPossible(); } }; drinkCorpse.WithProgressBar(TargetIndex.A, delegate { var thing = pawn?.CurJob?.GetTarget(TargetIndex.B).Thing; if (thing == null) { return(1f); } return(1f - (pawn.jobs.curDriver.ticksLeftThisToil / Mathf.Round(thing.def.ingestible.baseIngestTicks * durationMultiplier))); }); drinkCorpse.defaultCompleteMode = ToilCompleteMode.Delay; drinkCorpse.WithEffect(EffecterDefOf.EatMeat, TargetIndex.A); drinkCorpse.FailOnDestroyedOrNull(TargetIndex.B); drinkCorpse.PlaySustainerOrSound(() => SoundDefOf.RawMeat_Eat); drinkCorpse.AddFinishAction(delegate { //Log.Message("11"); if (pawn?.CurJob == null) { return; } if (Cocoon == null) { return; } var thing = job.GetTarget(TargetIndex.B).Thing; if (thing == null) { return; } pawn.ClearAllReservations(); }); return(drinkCorpse); }
protected override IEnumerable <Toil> MakeNewToils() { bool flag; yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A)); Verb_UseAbility curJob = this.pawn.CurJob.verbToUse as Verb_UseAbility; if (base.TargetA.HasThing) { flag = (!base.GetActor().IsFighting() ? true : !curJob.UseAbilityProps.canCastInMelee); if (flag) { Toil toil = Toils_Combat.GotoCastPosition(TargetIndex.A, false); yield return(toil); toil = null; } } if (this.Context == AbilityContext.Player) { Find.Targeter.targetingVerb = curJob; } Pawn targetPawn = null; if (this.TargetThingA != null) { targetPawn = TargetThingA as Pawn; } if (targetPawn != null) { //yield return Toils_Combat.CastVerb(TargetIndex.A, false); Toil combatToil = new Toil(); combatToil.FailOnDestroyedOrNull(TargetIndex.A); combatToil.FailOnDespawnedOrNull(TargetIndex.A); //combatToil.FailOnDowned(TargetIndex.A); //CompAbilityUserMagic comp = this.pawn.GetComp<CompAbilityUserMagic>(); this.duration = (int)((curJob.verbProps.warmupTime * 60) * this.pawn.GetStatValue(StatDefOf.AimingDelayFactor, false)); //JobDriver curDriver = this.pawn.jobs.curDriver; combatToil.initAction = delegate { arg_45_0 = combatToil.actor.jobs.curJob.verbToUse; if (this.pawn.RaceProps.Humanlike) { if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { CompAbilityUserMight mightComp = this.pawn.GetComp <CompAbilityUserMight>(); CompAbilityUserMagic magicComp = this.pawn.GetComp <CompAbilityUserMagic>(); if (mightComp.mimicAbility != null && mightComp.mimicAbility.MainVerb.verbClass == arg_45_0.verbProps.verbClass) { mightComp.RemovePawnAbility(mightComp.mimicAbility); } if (magicComp.mimicAbility != null && magicComp.mimicAbility.MainVerb.verbClass == arg_45_0.verbProps.verbClass) { magicComp.RemovePawnAbility(magicComp.mimicAbility); } } } LocalTargetInfo target = combatToil.actor.jobs.curJob.GetTarget(TargetIndex.A); // bool canFreeIntercept2 = false; arg_45_0.TryStartCastOn(target, false, false); using (IEnumerator <Hediff> enumerator = this.pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator()) { while (enumerator.MoveNext()) { Hediff rec = enumerator.Current; if (rec.def == TorannMagicDefOf.TM_PossessionHD || rec.def == TorannMagicDefOf.TM_DisguiseHD || rec.def == TorannMagicDefOf.TM_DisguiseHD_I || rec.def == TorannMagicDefOf.TM_DisguiseHD_II || rec.def == TorannMagicDefOf.TM_DisguiseHD_III) { this.pawn.health.RemoveHediff(rec); } } } }; combatToil.tickAction = delegate { if (Find.TickManager.TicksGame % 12 == 0) { TM_MoteMaker.ThrowCastingMote(pawn.DrawPos, pawn.Map, Rand.Range(1.2f, 2f)); } this.duration--; }; combatToil.AddFinishAction(delegate { if (this.duration <= 5) { curJob.Ability.PostAbilityAttempt(); } }); //if (combatToil.actor.CurJob != this.job) //{ // curDriver.ReadyForNextToil(); //} combatToil.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(combatToil); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; //Toil toil1 = new Toil() //{ // initAction = () => curJob.Ability.PostAbilityAttempt(), // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil1; } else { if ((pawn.Position - TargetLocA).LengthHorizontal < curJob.verbProps.range) { if (TargetLocA.IsValid && TargetLocA.InBounds(pawn.Map) && !TargetLocA.Fogged(pawn.Map) && TargetLocA.Walkable(pawn.Map)) { ShootLine shootLine; bool validTarg = curJob.TryFindShootLineFromTo(pawn.Position, TargetLocA, out shootLine); if (validTarg) { //yield return Toils_Combat.CastVerb(TargetIndex.A, false); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; this.duration = (int)((curJob.verbProps.warmupTime * 60) * this.pawn.GetStatValue(StatDefOf.AimingDelayFactor, false)); Toil toil = new Toil(); toil.initAction = delegate { arg_45_0 = toil.actor.jobs.curJob.verbToUse; if (this.pawn.RaceProps.Humanlike) { if (this.pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { CompAbilityUserMight mightComp = this.pawn.GetComp <CompAbilityUserMight>(); CompAbilityUserMagic magicComp = this.pawn.GetComp <CompAbilityUserMagic>(); if (mightComp.mimicAbility != null && mightComp.mimicAbility.MainVerb.verbClass == arg_45_0.verbProps.verbClass) { mightComp.RemovePawnAbility(mightComp.mimicAbility); } if (magicComp.mimicAbility != null && magicComp.mimicAbility.MainVerb.verbClass == arg_45_0.verbProps.verbClass) { magicComp.RemovePawnAbility(magicComp.mimicAbility); } } } LocalTargetInfo target = toil.actor.jobs.curJob.GetTarget(TargetIndex.A); bool canFreeIntercept2 = false; arg_45_0.TryStartCastOn(target, false, canFreeIntercept2); using (IEnumerator <Hediff> enumerator = this.pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator()) { while (enumerator.MoveNext()) { Hediff rec = enumerator.Current; if (rec.def == TorannMagicDefOf.TM_PossessionHD || rec.def == TorannMagicDefOf.TM_DisguiseHD || rec.def == TorannMagicDefOf.TM_DisguiseHD_I || rec.def == TorannMagicDefOf.TM_DisguiseHD_II || rec.def == TorannMagicDefOf.TM_DisguiseHD_III) { this.pawn.health.RemoveHediff(rec); } } } }; toil.tickAction = delegate { if (Find.TickManager.TicksGame % 12 == 0) { TM_MoteMaker.ThrowCastingMote(pawn.DrawPos, pawn.Map, Rand.Range(1.2f, 2f)); } this.duration--; }; toil.AddFinishAction(delegate { if (this.duration <= 5) { curJob.Ability.PostAbilityAttempt(); } }); toil.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(toil); //Toil toil1 = new Toil() //{ // initAction = () => curJob.Ability.PostAbilityAttempt(), // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil1; } else { //No LoS if (pawn.IsColonist) { Messages.Message("TM_OutOfLOS".Translate(new object[] { pawn.LabelShort }), MessageTypeDefOf.RejectInput); } } } } else { if (pawn.IsColonist) { //out of range Messages.Message("TM_OutOfRange".Translate(), MessageTypeDefOf.RejectInput); } } } }
public static Toil ChewIngestible(Pawn chewer, float durationMultiplier, TargetIndex ingestibleInd, TargetIndex eatSurfaceInd = TargetIndex.None) { Toil toil = new Toil(); toil.initAction = delegate() { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing; if (!thing.IngestibleNow) { chewer.jobs.EndCurrentJob(JobCondition.Incompletable, true); } else { actor.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt((float)thing.def.ingestible.baseIngestTicks * durationMultiplier); if (thing.Spawned) { thing.Map.physicalInteractionReservationManager.Reserve(chewer, actor.CurJob, thing); } } }; toil.tickAction = delegate() { if (chewer != toil.actor) { toil.actor.rotationTracker.FaceCell(chewer.Position); } else { Thing thing = toil.actor.CurJob.GetTarget(ingestibleInd).Thing; if (thing != null && thing.Spawned) { toil.actor.rotationTracker.FaceCell(thing.Position); } else if (eatSurfaceInd != TargetIndex.None && toil.actor.CurJob.GetTarget(eatSurfaceInd).IsValid) { toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(eatSurfaceInd).Cell); } } toil.actor.GainComfortFromCellIfPossible(); }; toil.WithProgressBar(ingestibleInd, delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing; float result; if (thing == null) { result = 1f; } else { result = 1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round((float)thing.def.ingestible.baseIngestTicks * durationMultiplier); } return(result); }, false, -0.5f); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.FailOnDestroyedOrNull(ingestibleInd); toil.AddFinishAction(delegate { if (chewer != null) { if (chewer.CurJob != null) { Thing thing = chewer.CurJob.GetTarget(ingestibleInd).Thing; if (thing != null) { if (chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing)) { chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing); } } } } }); toil.handlingFacing = true; Toils_Ingest.AddIngestionEffects(toil, chewer, ingestibleInd, eatSurfaceInd); return(toil); }
static IEnumerable <Toil> prepToils(JobDriver_Ingest driver, Toil chewToil) { if ((bool)LeatingFromInventory.GetValue(driver)) { yield return(Toils_Misc.TakeItemFromInventoryToCarrier(driver.pawn, TargetIndex.A)); } else { yield return((Toil)LReserveFood.Invoke(driver, new object[] { })); Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(Toils_Jump.JumpIf(gotoToPickup, () => driver.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); yield return(Toils_Jump.Jump(chewToil)); yield return(gotoToPickup); yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, driver.pawn)); gotoToPickup = null; } if (driver.job.takeExtraIngestibles > 0) { foreach (Toil toil in (IEnumerable <Toil>)LTakeExtraIngestibles.Invoke(driver, new object[] { })) { yield return(toil); } } if (!driver.pawn.Drafted) { yield return(reserveChewSpot(driver.pawn, TargetIndex.A, TargetIndex.B)); Toil gotospot = gotoSpot(TargetIndex.B).FailOnDestroyedOrNull(TargetIndex.A); if (!Utility.IncapableOfCleaning(driver.pawn)) { TargetIndex filthListIndex = TargetIndex.B; TargetIndex progIndex = TargetIndex.A; Toil FilthList = new Toil(); FilthList.initAction = delegate() { Job curJob = FilthList.actor.jobs.curJob; // if (curJob.GetTargetQueue(filthListIndex).NullOrEmpty()) { LocalTargetInfo A = curJob.GetTarget(filthListIndex); if (!A.HasThing) { return; } IEnumerable <Filth> l = Utility.SelectAllFilth(FilthList.actor, A, Settings.adv_clean_num); Utility.AddFilthToQueue(curJob, filthListIndex, l, FilthList.actor); FilthList.actor.ReserveAsManyAsPossible(curJob.GetTargetQueue(filthListIndex), curJob); curJob.GetTargetQueue(filthListIndex).Add(A); } }; yield return(FilthList); yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty())); Toil nextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(filthListIndex, true); yield return(nextTarget); yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty())); yield return(Toils_Goto.GotoThing(filthListIndex, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget).JumpIfOutsideHomeArea(filthListIndex, nextTarget)); // if (driver.job.GetTargetQueue(progIndex).Count == 0) { driver.job.GetTargetQueue(progIndex).Add(new IntVec3(0, 0, 0)); } // Toil clean = new Toil(); clean.initAction = delegate() { Filth filth = clean.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth; var progQue = clean.actor.jobs.curJob.GetTargetQueue(progIndex); progQue[0] = new IntVec3(0, 0, (int)filth.def.filth.cleaningWorkToReduceThickness * filth.thickness); }; clean.tickAction = delegate() { Filth filth = clean.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth; var progQue = clean.actor.jobs.curJob.GetTargetQueue(progIndex); IntVec3 iv = progQue[0].Cell; iv.x += 1; iv.y += 1; if (iv.x > filth.def.filth.cleaningWorkToReduceThickness) { filth.ThinFilth(); iv.x = 0; if (filth.Destroyed) { clean.actor.records.Increment(RecordDefOf.MessesCleaned); driver.ReadyForNextToil(); return; } } progQue[0] = iv; }; clean.defaultCompleteMode = ToilCompleteMode.Never; clean.WithEffect(EffecterDefOf.Clean, filthListIndex); clean.WithProgressBar(filthListIndex, delegate() { var q = driver.job.GetTargetQueue(progIndex)[0]; float result = (float)q.Cell.y / q.Cell.z; return(result); } , true, -0.5f); clean.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth); clean.JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget); clean.JumpIfOutsideHomeArea(filthListIndex, nextTarget); clean.FailOnDestroyedOrNull(TargetIndex.A); yield return(clean); yield return(Toils_Jump.Jump(nextTarget)); } yield return(gotospot); } yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A)); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { bool flag; yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A)); Verb_UseAbility curJob = this.pawn.CurJob.verbToUse as Verb_UseAbility; if (base.TargetA.HasThing) { flag = (!base.GetActor().IsFighting() ? true : !curJob.UseAbilityProps.canCastInMelee); if (flag) { Toil toil = Toils_Combat.GotoCastPosition(TargetIndex.A, false); yield return(toil); toil = null; } } if (this.Context == AbilityContext.Player) { Find.Targeter.targetingVerb = curJob; } Pawn targetPawn = null; if (this.TargetThingA != null) { targetPawn = TargetThingA as Pawn; } if (targetPawn != null) { //yield return Toils_Combat.CastVerb(TargetIndex.A, false); Toil combatToil = new Toil(); combatToil.FailOnDestroyedOrNull(TargetIndex.A); combatToil.FailOnDespawnedOrNull(TargetIndex.A); //combatToil.FailOnDowned(TargetIndex.A); //CompAbilityUserMagic comp = this.pawn.GetComp<CompAbilityUserMagic>(); this.duration = (int)((curJob.verbProps.warmupTime * 60) * this.pawn.GetStatValue(StatDefOf.AimingDelayFactor, false)); //JobDriver curDriver = this.pawn.jobs.curDriver; combatToil.initAction = delegate { Verb arg_45_0 = combatToil.actor.jobs.curJob.verbToUse; LocalTargetInfo target = combatToil.actor.jobs.curJob.GetTarget(TargetIndex.A); // bool canFreeIntercept2 = false; arg_45_0.TryStartCastOn(target, false, false); }; combatToil.tickAction = delegate { this.duration--; }; combatToil.AddFinishAction(delegate { if (this.duration <= 5) { curJob.Ability.PostAbilityAttempt(); } }); //if (combatToil.actor.CurJob != this.job) //{ // curDriver.ReadyForNextToil(); //} combatToil.defaultCompleteMode = ToilCompleteMode.FinishedBusy; yield return(combatToil); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; //Toil toil1 = new Toil() //{ // initAction = () => curJob.Ability.PostAbilityAttempt(), // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil1; } else { if ((pawn.Position - TargetLocA).LengthHorizontal < curJob.verbProps.range) { if (TargetLocA.IsValid && TargetLocA.InBounds(pawn.Map) && !TargetLocA.Fogged(pawn.Map) && TargetLocA.Walkable(pawn.Map)) { ShootLine shootLine; bool validTarg = curJob.TryFindShootLineFromTo(pawn.Position, TargetLocA, out shootLine); if (validTarg) { yield return(Toils_Combat.CastVerb(TargetIndex.A, false)); //Toil toil2 = new Toil() //{ // initAction = () => // { // if (curJob.UseAbilityProps.isViolent) // { // JobDriver_CastAbilityVerb.CheckForAutoAttack(this.pawn); // } // }, // defaultCompleteMode = ToilCompleteMode.Instant //}; //yield return toil2; Toil toil1 = new Toil() { initAction = () => curJob.Ability.PostAbilityAttempt(), defaultCompleteMode = ToilCompleteMode.Instant }; yield return(toil1); } else { //No LoS if (pawn.IsColonist) { Messages.Message("TM_OutOfLOS".Translate(new object[] { pawn.LabelShort }), MessageTypeDefOf.RejectInput); } } } } else { if (pawn.IsColonist) { //out of range Messages.Message("TM_OutOfRange".Translate(), MessageTypeDefOf.RejectInput); } } } }
private static Toil DrinkSomeone(TargetIndex thingIndex, Func <Toil, Func <LocalTargetInfo> > funcGetter) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(thingIndex).Thing; var comp = thing.TryGetComp <CompWaterSource>(); if (comp == null || comp.SourceType != CompProperties_WaterSource.SourceType.Item) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } actor.rotationTracker.FaceCell(actor.Position); if (!thing.CanDrinkWaterNow()) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } actor.jobs.curDriver.ticksLeftThisToil = comp.BaseDrinkTicks; if (thing.Spawned) { thing.Map.physicalInteractionReservationManager.Reserve(actor, actor.CurJob, thing); } }; toil.tickAction = delegate { toil.actor.GainComfortFromCellIfPossible(); }; toil.WithProgressBar(thingIndex, delegate { Pawn actor = toil.actor; Thing thing = actor.CurJob.GetTarget(thingIndex).Thing; var comp = thing.TryGetComp <CompWaterSource>(); if (thing == null || comp == null || comp.SourceType != CompProperties_WaterSource.SourceType.Item) { return(1f); } return(1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / (float)comp.BaseDrinkTicks); }, false, -0.5f); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.FailOnDestroyedOrNull(thingIndex); toil.AddFinishAction(delegate { Pawn actor = toil.actor; if (actor == null) { return; } if (actor.CurJob == null) { return; } Thing thing = actor.CurJob.GetTarget(thingIndex).Thing; if (thing == null) { return; } if (actor.Map.physicalInteractionReservationManager.IsReservedBy(actor, thing)) { actor.Map.physicalInteractionReservationManager.Release(actor, actor.CurJob, thing); } }); // エフェクト追加 toil.WithEffect(delegate { Pawn actor = toil.actor; LocalTargetInfo target = toil.actor.CurJob.GetTarget(thingIndex); if (!target.HasThing) { return(null); } EffecterDef effecter = null; var comp = target.Thing.TryGetComp <CompWaterSource>(); if (comp != null) { effecter = comp.GetEffect; } return(effecter); }, funcGetter(toil)); toil.PlaySustainerOrSound(delegate { Pawn actor = toil.actor; if (!actor.RaceProps.Humanlike) { return(null); } LocalTargetInfo target = toil.actor.CurJob.GetTarget(thingIndex); if (!target.HasThing) { return(null); } var comp = target.Thing.TryGetComp <CompWaterSource>(); if (comp == null) { return(null); } return(comp.Props.getSound); }); return(toil); }