Beispiel #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //this.FailOnDespawnedOrNull(TargetIndex.A);
            this.FailOn(delegate
            {
                Designation designation = this.Map.designationManager.DesignationOn(this.TargetThingA, DesignationDefOf_Reconfigure.Reconfigure);
                return(designation == null);
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            yield return(Toils_General.Wait(100, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch));

            Toil finalize = new Toil();

            finalize.initAction = delegate
            {
                Pawn           actor = finalize.actor;
                ThingWithComps thing = (ThingWithComps)actor.CurJob.targetA.Thing;

                CompReconfigurable comp = thing.TryGetComp <CompReconfigurable>();
                if (comp != null && comp.NeedToReconfigure)
                {
                    //replace here
                    ThingWithComps replacement = (ThingWithComps)ThingMaker.MakeThing(comp.Props.resultDef, thing.Stuff);
                    replacement.SetFactionDirect(thing.Faction);
                    var spawned = GenSpawn.Spawn(replacement, thing.Position, thing.Map, thing.Rotation);
                    spawned.HitPoints = thing.HitPoints;
                    Find.Selector.Select(spawned, false);
                }

                Designation designation = this.Map.designationManager.DesignationOn(thing, DesignationDefOf_Reconfigure.Reconfigure);
                if (designation != null)
                {
                    designation.Delete();
                }
            };
            finalize.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(finalize);
        }