示例#1
0
        public static Toil PlaySustainerOrSound(this Toil toil, Func <SoundDef> soundDefGetter)
        {
            Sustainer sustainer = null;

            toil.AddPreInitAction(delegate
            {
                SoundDef soundDef2 = soundDefGetter();
                if (soundDef2 != null && !soundDef2.sustain)
                {
                    soundDef2.PlayOneShot(new TargetInfo(toil.GetActor().Position, toil.GetActor().Map, false));
                }
            });
            toil.AddPreTickAction(delegate
            {
                if (sustainer == null || sustainer.Ended)
                {
                    SoundDef soundDef = soundDefGetter();
                    if (soundDef != null && soundDef.sustain)
                    {
                        SoundInfo info = SoundInfo.InMap(toil.actor, MaintenanceType.PerTick);
                        sustainer      = soundDef.TrySpawnSustainer(info);
                    }
                }
                else
                {
                    sustainer.Maintain();
                }
            });
            return(toil);
        }
示例#2
0
        public static Toil WithEffect(this Toil toil, Func <EffecterDef> effecterDefGetter, Func <LocalTargetInfo> effectTargetGetter)
        {
            Effecter effecter = null;

            toil.AddPreTickAction(delegate
            {
                if (effecter == null)
                {
                    EffecterDef effecterDef = effecterDefGetter();
                    if (effecterDef != null)
                    {
                        effecter = effecterDef.Spawn();
                    }
                }
                else
                {
                    effecter.EffectTick(toil.actor, effectTargetGetter().ToTargetInfo(toil.actor.Map));
                }
            });
            toil.AddFinishAction(delegate
            {
                if (effecter != null)
                {
                    effecter.Cleanup();
                    effecter = null;
                }
            });
            return(toil);
        }
示例#3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil gotoCell = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell);

            gotoCell.AddPreTickAction(delegate
            {
                if (this.$this.job.exitMapOnArrival && this.$this.pawn.Map.exitMapGrid.IsExitCell(this.$this.pawn.Position))
                {
                    this.$this.TryExitMap();
                }
            });
            gotoCell.FailOn(() => this.$this.job.failIfCantJoinOrCreateCaravan && !CaravanExitMapUtility.CanExitMapAndJoinOrCreateCaravanNow(this.$this.pawn));
            yield return(gotoCell);

            yield return(new Toil
            {
                initAction = delegate
                {
                    if (this.$this.pawn.mindState != null && this.$this.pawn.mindState.forcedGotoPosition == this.$this.TargetA.Cell)
                    {
                        this.$this.pawn.mindState.forcedGotoPosition = IntVec3.Invalid;
                    }
                    if (this.$this.job.exitMapOnArrival && (this.$this.pawn.Position.OnEdge(this.$this.pawn.Map) || this.$this.pawn.Map.exitMapGrid.IsExitCell(this.$this.pawn.Position)))
                    {
                        this.$this.TryExitMap();
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil toil = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell);

            toil.AddPreTickAction(delegate
            {
                if (job.exitMapOnArrival && pawn.Map.exitMapGrid.IsExitCell(pawn.Position))
                {
                    TryExitMap();
                }
            });
            toil.FailOn(() => job.failIfCantJoinOrCreateCaravan && !CaravanExitMapUtility.CanExitMapAndJoinOrCreateCaravanNow(pawn));
            yield return(toil);

            Toil toil2 = new Toil();

            toil2.initAction = delegate
            {
                if (pawn.mindState != null && pawn.mindState.forcedGotoPosition == base.TargetA.Cell)
                {
                    pawn.mindState.forcedGotoPosition = IntVec3.Invalid;
                }
                if (job.exitMapOnArrival && (pawn.Position.OnEdge(pawn.Map) || pawn.Map.exitMapGrid.IsExitCell(pawn.Position)))
                {
                    TryExitMap();
                }
            };
            toil2.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil2);
        }
 public static Toil JumpIf(this Toil toil, Func <bool> jumpCondition, Toil jumpToil)
 {
     toil.AddPreTickAction(delegate
     {
         if (jumpCondition())
         {
             toil.actor.jobs.curDriver.JumpToToil(jumpToil);
         }
     });
     return(toil);
 }
        public static Toil WithProgressBar(this Toil toil, TargetIndex ind, Func <float> progressGetter, bool interpolateBetweenActorAndTarget = false, float offsetZ = -0.5f)
        {
            Effecter effecter = null;

            toil.AddPreTickAction(delegate
            {
                if (toil.actor.Faction != Faction.OfPlayer)
                {
                    return;
                }
                if (effecter == null)
                {
                    EffecterDef progressBar = EffecterDefOf.ProgressBar;
                    effecter = progressBar.Spawn();
                }
                else
                {
                    LocalTargetInfo target = toil.actor.CurJob.GetTarget(ind);
                    if (!target.IsValid || (target.HasThing && !target.Thing.Spawned))
                    {
                        effecter.EffectTick(toil.actor, TargetInfo.Invalid);
                    }
                    else if (interpolateBetweenActorAndTarget)
                    {
                        effecter.EffectTick(toil.actor.CurJob.GetTarget(ind).ToTargetInfo(toil.actor.Map), toil.actor);
                    }
                    else
                    {
                        effecter.EffectTick(toil.actor.CurJob.GetTarget(ind).ToTargetInfo(toil.actor.Map), TargetInfo.Invalid);
                    }
                    MoteProgressBar mote = ((SubEffecter_ProgressBar)effecter.children[0]).mote;
                    if (mote != null)
                    {
                        mote.progress = Mathf.Clamp01(progressGetter());
                        mote.offsetZ  = offsetZ;
                    }
                }
            });
            toil.AddFinishAction(delegate
            {
                if (effecter != null)
                {
                    effecter.Cleanup();
                    effecter = null;
                }
            });
            return(toil);
        }
示例#7
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil gotoCell = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell);

            gotoCell.AddPreTickAction(delegate
            {
                if (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0038: stateMachine*/)._0024this.job.exitMapOnArrival && ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0038: stateMachine*/)._0024this.pawn.Map.exitMapGrid.IsExitCell(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0038: stateMachine*/)._0024this.pawn.Position))
                {
                    ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0038: stateMachine*/)._0024this.TryExitMap();
                }
            });
            gotoCell.FailOn(() => ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_004f: stateMachine*/)._0024this.job.failIfCantJoinOrCreateCaravan && !CaravanExitMapUtility.CanExitMapAndJoinOrCreateCaravanNow(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_004f: stateMachine*/)._0024this.pawn));
            yield return(gotoCell);

            /*Error: Unable to find new state assignment for yield return*/;
        }