Пример #1
0
        private bool CheckCurrentToilEndOrFail()
        {
            CaravanToil curToil = this.CurToil;

            if (this.globalFailConditions != null)
            {
                for (int i = 0; i < this.globalFailConditions.Count; i++)
                {
                    JobCondition jobCondition = this.globalFailConditions[i]();
                    if (jobCondition != JobCondition.Ongoing)
                    {
                        this.EndJobWith(jobCondition);
                        return(true);
                    }
                }
            }
            if (curToil != null && curToil.endConditions != null)
            {
                for (int j = 0; j < curToil.endConditions.Count; j++)
                {
                    JobCondition jobCondition2 = curToil.endConditions[j]();
                    if (jobCondition2 != JobCondition.Ongoing)
                    {
                        this.EndJobWith(jobCondition2);
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
        public static CaravanToil GotoObject(TargetIndex ind, CaravanArrivalAction arrivalAction = null)
        {
            int         tileInt = -1;
            CaravanToil toil    = new CaravanToil();

            toil.initAction = delegate
            {
                //Log.Message("GoToObject1");
                tileInt = CurJob(toil.actor).GetTarget(ind).WorldObject.Tile;
                //Log.Message("GoToObject2");
                toil.actor.pather.StartPath(tileInt, arrivalAction, true);
                //Log.Message("GoToObject3");
            };
            toil.tickAction = delegate
            {
                if (tileInt < 0)
                {
                    tileInt = CurJob(toil.actor).GetTarget(ind).WorldObject.Tile;
                }
                if (toil.actor.Tile == tileInt)
                {
                    //Log.Message("GoToObject4a");
                    CurTracker(toil.actor).curDriver.Notify_PatherArrived();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            //toil.FailOnDespawnedOrNull(ind);
            return(toil);
        }
Пример #3
0
        public static CaravanToil GotoTile(TargetIndex ind, CaravanArrivalAction arrivalAction = null)
        {
            CaravanToil toil = new CaravanToil();

            toil.initAction = delegate
            {
                Caravan actor = toil.actor;
                actor.pather.StartPath(Find.World.GetComponent <CaravanJobGiver>().CurJob(actor).GetTarget(ind).Tile, arrivalAction);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            //toil.FailOnDespawnedOrNull(ind);
            return(toil);
        }
Пример #4
0
        public static CaravanToil GotoTile(TargetIndex ind, CaravanArrivalAction arrivalAction = null)
        {
            var toil = new CaravanToil();

            toil.initAction = () =>
            {
                var actor = toil.actor;
                actor.pather.StartPath(CaravanJobsUtility.GetCaravanJobGiver().CurJob(actor).GetTarget(ind).Tile,
                                       arrivalAction);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            //toil.FailOnDespawnedOrNull(ind);
            return(toil);
        }
Пример #5
0
        // Verse.AI.ToilEffects
        public static CaravanToil WithProgressBar(this CaravanToil CaravanToil, TargetIndex ind,
                                                  Func <float> progressGetter, bool interpolateBetweenActorAndTarget = false, float offsetZ = -0.5f)
        {
            WorldObject_ProgressBar progressBar = null;

            CaravanToil.AddPreTickAction(delegate
            {
                if (CaravanToil.actor.Faction != Faction.OfPlayer)
                {
                    return;
                }
                var curProgress = Mathf.Clamp01(progressGetter());
                //Log.Message(curProgress.ToString());
                //WorldProgressBarDrawer.DrawProgressBarOnGUIFor(target, curProgress);
                if (progressBar == null)
                {
                    progressBar =
                        (WorldObject_ProgressBar)WorldObjectMaker.MakeWorldObject(
                            DefDatabase <WorldObjectDef> .GetNamed("WorldObject_ProgressBar"));
                    progressBar.Tile = Find.World.GetComponent <CaravanJobGiver>().CurJob(CaravanToil.actor)
                                       .GetTarget(ind).Tile;
                    progressBar.offset = offsetZ;
                    Find.WorldObjects.Add(progressBar);
                }
                else
                {
                    progressBar.curProgress = Mathf.Clamp01(progressGetter());
                    if (CaravanToil.actor == null || !CaravanToil.actor.Spawned ||
                        CaravanToil.actor.Tile != Find.World.GetComponent <CaravanJobGiver>().CurJob(CaravanToil.actor)
                        .GetTarget(ind).Tile)
                    {
                        if (progressBar.Spawned)
                        {
                            Find.WorldObjects.Remove(progressBar);
                        }
                    }
                }
            });
            CaravanToil.AddFinishAction(delegate
            {
                if (progressBar != null && progressBar.Spawned)
                {
                    Find.WorldObjects.Remove(progressBar);
                    progressBar = null;
                }
            });
            return(CaravanToil);
        }
Пример #6
0
 public void JumpToToil(CaravanToil to)
 {
     this.SetNextToil(to);
     this.ReadyForNextToil();
 }
Пример #7
0
 private void SetNextToil(CaravanToil to)
 {
     this.curToilIndex = this.toils.IndexOf(to) - 1;
 }
Пример #8
0
 public void DriverTick()
 {
     try
     {
         this.ticksLeftThisToil--;
         this.debugTicksSpentThisToil++;
         if (this.CurToil == null)
         {
             //if (!this.caravan.stances.FullBodyBusy || this.CanStartNextToilInBusyStance)
             //{
             this.ReadyForNextToil();
             //}
         }
         else if (!this.CheckCurrentToilEndOrFail())
         {
             if (this.curToilCompleteMode == ToilCompleteMode.Delay)
             {
                 if (this.ticksLeftThisToil <= 0)
                 {
                     this.ReadyForNextToil();
                     return;
                 }
             }
             else if (this.curToilCompleteMode == ToilCompleteMode.FinishedBusy) //&& !this.caravan.stances.FullBodyBusy)
             {
                 this.ReadyForNextToil();
                 return;
             }
             if (this.wantBeginNextToil)
             {
                 this.TryActuallyStartNextToil();
             }
             else if (this.curToilCompleteMode == ToilCompleteMode.Instant && this.debugTicksSpentThisToil > 300)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     this.caravan,
                     " had to be broken from frozen state. He was doing job ",
                     this.CurJob,
                     ", toilindex=",
                     this.curToilIndex
                 }));
                 this.ReadyForNextToil();
             }
             else
             {
                 CaravanJob curJob = this.CurJob;
                 if (this.CurToil.preTickActions != null)
                 {
                     CaravanToil curToil = this.CurToil;
                     for (int i = 0; i < curToil.preTickActions.Count; i++)
                     {
                         curToil.preTickActions[i]();
                         if (this.CurJob != curJob)
                         {
                             return;
                         }
                         if (this.CurToil != curToil || this.wantBeginNextToil)
                         {
                             return;
                         }
                     }
                 }
                 if (this.CurToil.tickAction != null)
                 {
                     this.CurToil.tickAction();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Find.World.GetComponent <CaravanJobGiver>().Tracker(caravan).StartErrorRecoverJob(string.Concat(new object[]
         {
             "Exception in Tick (pawn=",
             this.caravan,
             ", job=",
             this.CurJob,
             ", CurToil=",
             this.curToilIndex,
             "): ",
             ex
         }));
     }
 }