예제 #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //this.FailOnIncapable(PawnCapacityDefOf.Manipulation);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil prepare = Toils_General.Wait(useDuration, TargetIndex.None);

            prepare.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            prepare.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            prepare.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            yield return(prepare);

            Toil use = new Toil();

            use.initAction = delegate()
            {
                Pawn       actor      = use.actor;
                CompUsable compUsable = actor.CurJob.targetA.Thing.TryGetComp <CompUsable>();
                compUsable.UsedBy(actor);
            };
            use.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(use);

            yield break;
        }
예제 #2
0
 // Creates a menu option to use an item. "tar" is expected to be a pawn, corpse or null if it doesn't apply (in which
 // case the pawn will presumably use the item on themself). "required_work" can also be null.
 public static FloatMenuOption make_option(this CompUsable usa, string label, Pawn p, LocalTargetInfo tar, WorkTypeDef required_work)
 {
     if ((tar != null) && (!p.CanReserve(tar)))
     {
         string key  = "Reserved";
         string text = TranslatorFormattedStringExtensions.Translate(key);
         return(new FloatMenuOption(label + " (" + text + ")", null, MenuOptionPriority.DisabledOption));
     }
     else if ((tar != null) && (!p.CanReach(tar, PathEndMode.Touch, Danger.Some)))
     {
         string key  = "NoPath";
         string text = TranslatorFormattedStringExtensions.Translate(key);
         return(new FloatMenuOption(label + " (" + text + ")", null, MenuOptionPriority.DisabledOption));
     }
     else if ((required_work != null) && p.story.WorkTypeIsDisabled(required_work))
     {
         string key  = "CannotPrioritizeWorkTypeDisabled";
         string text = TranslatorFormattedStringExtensions.Translate(key, required_work.gerundLabel);
         return(new FloatMenuOption(label + " (" + text + ")", null, MenuOptionPriority.DisabledOption));
     }
     else
     {
         return(new FloatMenuOption(
                    label,
                    delegate
         {
             usa.start_job(p, tar);
         },
                    MenuOptionPriority.Default));
     }
 }
예제 #3
0
 // Creates a menu option to use an item. "tar" is expected to be a pawn, corpse or null if it doesn't apply (in which
 // case the pawn will presumably use the item on themself). "required_work" can also be null.
 public static FloatMenuOption make_option(this CompUsable usa, string label, Pawn p, LocalTargetInfo tar, WorkTypeDef required_work)
 {
     if ((tar != null) && (!p.CanReserve(tar)))
     {
         return(new FloatMenuOption(label + " (" + "Reserved".Translate() + ")", null, MenuOptionPriority.DisabledOption));
     }
     else if ((tar != null) && (!p.CanReach(tar, PathEndMode.Touch, Danger.Deadly)))
     {
         return(new FloatMenuOption(label + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.DisabledOption));
     }
     else if ((required_work != null) && p.story.WorkTypeIsDisabled(required_work))
     {
         return(new FloatMenuOption(label + " (" + "CannotPrioritizeWorkTypeDisabled".Translate(new object[] { required_work.gerundLabel }) + ")", null, MenuOptionPriority.DisabledOption));
     }
     else
     {
         return(new FloatMenuOption(
                    label,
                    delegate
         {
             usa.start_job(p, tar);
         },
                    MenuOptionPriority.Default));
     }
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.pawn.jobs.curJob.count = 1;
            this.FailOnDestroyedOrNull(TargetIndex.A);
            if (!base.TargetThingA.IsForbidden(this.pawn))
            {
                this.FailOnForbidden(TargetIndex.A);
            }
            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));

            Toil toil = Toils_Reserve.Reserve(TargetIndex.A, 1);

            yield return(toil);

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, false));

            if (base.CurJob.haulOpportunisticDuplicates)
            {
                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(toil, TargetIndex.A, TargetIndex.B, false, null));
            }
            Toil toil3 = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(toil3);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, toil3, true));



            Toil toil2 = new Toil();

            toil2.defaultCompleteMode = ToilCompleteMode.Delay;
            toil2.defaultDuration     = 100;
            toil2.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            toil2.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(toil2);

            yield return(new Toil
            {
                initAction = delegate
                {
                    Pawn actor = this.pawn;
                    CompUsable compUsable = actor.CurJob.targetA.Thing.TryGetComp <CompUsable>();
                    compUsable.UsedBy(actor);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
예제 #5
0
 // Tries to get p started on the job of using an item on either another pawn or on themself (if "other" is null).
 // Of course in order for this method to work, the item's useJob has to be able to handle use on another pawn. This
 // is true for the holokey and bondage gear in RJW but not the items in the core game
 public static void start_job(this CompUsable usa, Pawn p, LocalTargetInfo tar)
 {
     if (p.CanReserveAndReach(usa.parent, PathEndMode.Touch, Danger.Some) &&
         ((tar == null) || p.CanReserveAndReach(tar, PathEndMode.Touch, Danger.Some)))
     {
         var comfor = usa.parent.GetComp <CompForbiddable>();
         if (comfor != null)
         {
             comfor.Forbidden = false;
         }
         var job = new Job(((CompProperties_Usable)usa.props).useJob, usa.parent, tar);
         p.jobs.TryTakeOrderedJob(job);
     }
 }
 static void Postfix(ref string __result, CompUsable __instance)
 {
     __result = __result + " (" + __instance.parent.LabelCap + ")";
 }