Exemplo n.º 1
0
        public static Toil SipWater(Pawn drinker, Need_Water pawnNeed, CompWaterContainer waterContainer, bool wornByActor)
        {
            var toil = new Toil();
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration = sipTicks;
            toil.initAction = delegate
            {
                bool fromThing = toil.actor.jobs.curJob.GetTarget(TargetIndex.A).HasThing;
                if (fromThing)
                {
                    toil.FailOnForbidden(TargetIndex.A);
                    if (!wornByActor)
                    {
                        toil.FailOnDespawned(TargetIndex.A);
                    }
                }

                float wantDrink = Math.Min(pawnNeed.HydrationWantedLitres, sipLitres);
                float didDrink = pawnNeed.DrinkFrom(waterContainer, wantDrink);
            };
            toil.FailOn(() => waterContainer.IsEmpty);

            // TODO: toil.WithEffect();
            toil.WithSustainer(delegate
            {
                if (drinker.RaceProps.Humanlike)
                {
                    return DefDatabase<SoundDef>.GetNamed(drinkSoundName);
                }
                return null;
            });
            return toil;
        }