public static Toil WaitForWaiter(TargetIndex diningSpotInd, TargetIndex waiterInd) { var toil = new Toil(); toil.initAction = () => GetDriver(toil).wantsToOrder = true; toil.tickAction = () => { if (diningSpotInd != 0 && toil.actor.CurJob.GetTarget(diningSpotInd).IsValid) { toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(diningSpotInd).Cell); } if (!GetDriver(toil).wantsToOrder) { GetDriver(toil).ReadyForNextToil(); } }; toil.AddFinishAction(() => GetDriver(toil).wantsToOrder = false); toil.defaultDuration = 1500; //toil.WithProgressBarToilDelay(TargetIndex.A); // TODO: Turn this off later? Or make it go backwards? toil.defaultCompleteMode = ToilCompleteMode.Never; toil.FailOnDestroyedOrNull(diningSpotInd); toil.FailOnDurationExpired(); // Duration over? Fail job! toil.socialMode = RandomSocialMode.Normal; return(toil); }
public static Toil WaitForMeal(TargetIndex mealInd) { var toil = new Toil(); toil.initAction = () => { var order = toil.actor.GetRestaurant().Orders.GetOrderFor(toil.actor); if (order?.delivered == true && (order.consumable?.Spawned == true || order.consumable?.ParentHolder == toil.actor.inventory)) { var food = order.consumable; toil.actor.CurJob.SetTarget(mealInd, food); Log.Message($"{toil.actor.NameShortColored} has already received order: {food.Label}"); if (toil.actor.inventory.Contains(food)) { //Log.Message($"{toil.actor.NameShortColored} has {food.Label} in inventory."); GetDriver(toil).ReadyForNextToil(); } else if (food.Position.AdjacentTo8Way(toil.actor.Position)) { //Log.Message($"{toil.actor.NameShortColored} has {food.Label} on table."); food.DeSpawn(); //var amount = toil.actor.inventory.innerContainer.TryAdd(order.consumable, 1, false); //Log.Message($"{toil.actor.NameShortColored} received {amount} of {food.LabelShort} to his inventory."); GetDriver(toil).ReadyForNextToil(); } else { Log.Message($"{toil.actor.NameShortColored}'s food is somewhere else ({food?.Position}). Will wait."); toil.actor.CurJob.SetTarget(mealInd, null); order.delivered = false; } } else if (order?.delivered == true) { // Order not spawned? Already eaten it, or something happened to it // Let it go. Log.Warning($"{toil.actor.NameShortColored}'s food is gone. Already eaten?"); GetDriver(toil).EndJobWith(JobCondition.QueuedNoLongerValid); } }; toil.tickAction = () => { var target = toil.actor.CurJob.GetTarget(mealInd); if (target.HasThing && target.IsValid && target.Thing.ParentHolder == toil.actor.inventory) { // Waiting done // Set job.count to amount to consume (important for taking to carrier!) toil.actor.CurJob.count = target.Thing.stackCount; GetDriver(toil).ReadyForNextToil(); } }; toil.defaultDuration = 1500; //toil.WithProgressBarToilDelay(TargetIndex.A); // TODO: Turn this off later? Or make it go backwards? toil.defaultCompleteMode = ToilCompleteMode.Never; toil.FailOnDurationExpired(); // Duration over? Fail job! toil.socialMode = RandomSocialMode.Normal; return(toil); }