public override void Begin(Precondition.Context context) { base.smi.sm.rescuer.Set(context.consumerState.gameObject, base.smi); base.smi.sm.rescueTarget.Set(gameObject, base.smi); base.smi.sm.deliverTarget.Set(gameObject.GetSMI <BeIncapacitatedChore.StatesInstance>().master.GetChosenClinic(), base.smi); base.Begin(context); }
public override void Begin(Precondition.Context context) { if ((UnityEngine.Object)context.consumerState.consumer == (UnityEngine.Object)null) { Debug.LogError("MournChore null context.consumer"); } else if (base.smi == null) { Debug.LogError("MournChore null smi"); } else if (base.smi.sm == null) { Debug.LogError("MournChore null smi.sm"); } else { Grave x = FindGraveToMournAt(); if ((UnityEngine.Object)x == (UnityEngine.Object)null) { Debug.LogError("MournChore no grave"); } else { base.smi.sm.mourner.Set(context.consumerState.gameObject, base.smi); base.Begin(context); } } }
public virtual void Begin(Precondition.Context context) { if ((UnityEngine.Object)driver != (UnityEngine.Object)null) { Debug.LogErrorFormat("Chore.Begin driver already set {0} {1} {2}, provider {3}, driver {4} -> {5}", id, GetType(), choreType.Id, provider, driver, context.consumerState.choreDriver); } if ((UnityEngine.Object)provider == (UnityEngine.Object)null) { Debug.LogErrorFormat("Chore.Begin provider is null {0} {1} {2}, provider {3}, driver {4}", id, GetType(), choreType.Id, provider, driver); } driver = context.consumerState.choreDriver; StateMachine.Instance sMI = GetSMI(); StateMachine.Instance instance = sMI; instance.OnStop = (Action <string, StateMachine.Status>)Delegate.Combine(instance.OnStop, new Action <string, StateMachine.Status>(OnStateMachineStop)); KSelectable component = driver.GetComponent <KSelectable>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { component.SetStatusItem(Db.Get().StatusItemCategories.Main, GetStatusItem(), this); } sMI.StartSM(); if (onBegin != null) { onBegin(this); } }
public override void Begin(Precondition.Context context) { base.smi.sm.requestedrationcount.Set(base.smi.GetComponent <StateMachineController>().GetSMI <RationMonitor.Instance>().GetRationsRemaining(), base.smi); base.smi.sm.ediblesource.Set(context.consumerState.gameObject.GetComponent <Sensors>().GetSensor <ClosestEdibleSensor>().GetEdible(), base.smi); base.smi.sm.deliverypoint.Set(gameObject, base.smi); base.smi.sm.deliverer.Set(context.consumerState.gameObject, base.smi); base.Begin(context); }
public virtual void CollectChores(ChoreConsumerState consumer_state, List <Precondition.Context> succeeded_contexts, List <Precondition.Context> failed_contexts, bool is_attempting_override) { Precondition.Context item = new Precondition.Context(this, consumer_state, is_attempting_override, null); item.RunPreconditions(); if (item.IsSuccess()) { succeeded_contexts.Add(item); } else { failed_contexts.Add(item); } }
public static void GatherNearbyFetchChores(FetchChore root_chore, Precondition.Context context, int x, int y, int radius, List <Precondition.Context> succeeded_contexts, List <Precondition.Context> failed_contexts) { ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate(); GameScenePartitioner.Instance.GatherEntries(x - radius, y - radius, radius * 2 + 1, radius * 2 + 1, GameScenePartitioner.Instance.fetchChoreLayer, pooledList); for (int i = 0; i < pooledList.Count; i++) { ScenePartitionerEntry scenePartitionerEntry = pooledList[i]; FetchChore fetchChore = scenePartitionerEntry.obj as FetchChore; fetchChore.CollectChoresFromGlobalChoreProvider(context.consumerState, succeeded_contexts, failed_contexts, true); } pooledList.Recycle(); }
/// <summary> /// Checks for a destination cell to mingle. The printing pod is the backup if no /// rec rooms are found. /// </summary> /// <returns>true if a mingle cell is available, or false otherwise.</returns> private static bool HasMingleCell(ref Precondition.Context context, object data) { bool hasCell = false; if (data is FinishMingleChore mc) { int target = mc.smi.GetMingleCell(); var user = context.consumerState?.navigator; hasCell = Grid.IsValidCell(target) && user != null && user.GetNavigationCost( target) >= 0; } return(hasCell); }
public Delivery(Precondition.Context context, float amount_to_be_fetched, Action <FetchChore> on_cancelled) { this = default(Delivery); this.chore = (context.chore as FetchChore); amount = this.chore.originalAmount; destination = this.chore.destination; this.chore.SetOverrideTarget(context.consumerState.consumer); onCancelled = on_cancelled; onFetchChoreCleanup = OnFetchChoreCleanup; this.chore.FetchAreaBegin(context, amount_to_be_fetched); FetchChore chore = this.chore; chore.onCleanup = (Action <Chore>)Delegate.Combine(chore.onCleanup, onFetchChoreCleanup); }
public override void Begin(Precondition.Context context) { if ((UnityEngine.Object)context.consumerState.consumer == (UnityEngine.Object)null) { Debug.LogError("EATCHORE null context.consumer"); } else { RationMonitor.Instance sMI = context.consumerState.consumer.GetSMI <RationMonitor.Instance>(); if (sMI == null) { Debug.LogError("EATCHORE null RationMonitor.Instance"); } else { Edible edible = sMI.GetEdible(); if ((UnityEngine.Object)edible.gameObject == (UnityEngine.Object)null) { Debug.LogError("EATCHORE null edible.gameObject"); } else if (base.smi == null) { Debug.LogError("EATCHORE null smi"); } else if (base.smi.sm == null) { Debug.LogError("EATCHORE null smi.sm"); } else if (base.smi.sm.ediblesource == null) { Debug.LogError("EATCHORE null smi.sm.ediblesource"); } else { base.smi.sm.ediblesource.Set(edible.gameObject, base.smi); KCrashReporter.Assert(edible.FoodInfo.CaloriesPerUnit > 0f, edible.GetProperName() + " has invalid calories per unit. Will result in NaNs"); AmountInstance amountInstance = Db.Get().Amounts.Calories.Lookup(gameObject); float num = (amountInstance.GetMax() - amountInstance.value) / edible.FoodInfo.CaloriesPerUnit; KCrashReporter.Assert(num > 0f, "EatChore is requesting an invalid amount of food"); base.smi.sm.requestedfoodunits.Set(num, base.smi); base.smi.sm.eater.Set(context.consumerState.gameObject, base.smi); base.Begin(context); } } } }
public override void Begin(Precondition.Context context) { if ((UnityEngine.Object)context.consumerState.consumer == (UnityEngine.Object)null) { Debug.LogError("EquipChore null context.consumer"); } else if (base.smi == null) { Debug.LogError("EquipChore null smi"); } else if (base.smi.sm == null) { Debug.LogError("EquipChore null smi.sm"); } else if (base.smi.sm.equippable_source == null) { Debug.LogError("EquipChore null smi.sm.equippable_source"); } else { base.smi.sm.equipper.Set(context.consumerState.gameObject, base.smi); base.Begin(context); } }
/// <summary> /// Checks for a destination cell to mingle. The printing pod is the backup if no /// rec rooms are found. /// </summary> /// <returns>true if a mingle cell is available, or false otherwise.</returns> private static bool HasMingleCell(ref Precondition.Context context, object data) { return(data is FinishMingleChore mc && Grid.IsValidCell(mc.smi.GetMingleCell())); }
public override void Begin(Precondition.Context context) { base.smi.sm.rancher.Set(context.consumerState.gameObject, base.smi); base.Begin(context); }
public virtual bool CanPreempt(Precondition.Context context) { return(IsPreemptable); }
public void Begin(Precondition.Context context) { base.sm.fetcher.Set(context.consumerState.gameObject, base.smi); chores.Clear(); chores.Add(rootChore); Grid.CellToXY(Grid.PosToCell(rootChore.destination.transform.GetPosition()), out int x, out int y); ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList = ListPool <Precondition.Context, FetchAreaChore> .Allocate(); ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList2 = ListPool <Precondition.Context, FetchAreaChore> .Allocate(); if (rootChore.allowMultifetch) { GatherNearbyFetchChores(rootChore, context, x, y, 3, pooledList, pooledList2); } float num = Mathf.Max(1f, Db.Get().Attributes.CarryAmount.Lookup(context.consumerState.consumer).GetTotalValue()); Pickupable pickupable = context.data as Pickupable; if ((UnityEngine.Object)pickupable == (UnityEngine.Object)null) { Debug.Assert(pooledList.Count > 0, "succeeded_contexts was empty"); Precondition.Context context2 = pooledList[0]; FetchChore fetchChore = (FetchChore)context2.chore; Debug.Assert(fetchChore != null, "fetch_chore was null"); DebugUtil.LogWarningArgs("Missing root_fetchable for FetchAreaChore", fetchChore.destination, fetchChore.tags[0]); pickupable = fetchChore.FindFetchTarget(context.consumerState); } Debug.Assert((UnityEngine.Object)pickupable != (UnityEngine.Object)null, "root_fetchable was null"); List <Pickupable> list = new List <Pickupable>(); list.Add(pickupable); float num2 = pickupable.UnreservedAmount; float minTakeAmount = pickupable.MinTakeAmount; int x2 = 0; int y2 = 0; Grid.CellToXY(Grid.PosToCell(pickupable.transform.GetPosition()), out x2, out y2); int num3 = 6; x2 -= num3 / 2; y2 -= num3 / 2; ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList3 = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate(); GameScenePartitioner.Instance.GatherEntries(x2, y2, num3, num3, GameScenePartitioner.Instance.pickupablesLayer, pooledList3); Tag prefabTag = pickupable.GetComponent <KPrefabID>().PrefabTag; for (int i = 0; i < pooledList3.Count; i++) { ScenePartitionerEntry scenePartitionerEntry = pooledList3[i]; if (num2 > num) { break; } Pickupable pickupable2 = scenePartitionerEntry.obj as Pickupable; KPrefabID component = pickupable2.GetComponent <KPrefabID>(); if (!(component.PrefabTag != prefabTag) && !(pickupable2.UnreservedAmount <= 0f)) { component.UpdateTagBits(); if (component.HasAllTags_AssumeLaundered(ref rootChore.requiredTagBits) && !component.HasAnyTags_AssumeLaundered(ref rootChore.forbiddenTagBits) && !list.Contains(pickupable2) && rootContext.consumerState.consumer.CanReach(pickupable2)) { float unreservedAmount = pickupable2.UnreservedAmount; list.Add(pickupable2); num2 += unreservedAmount; if (list.Count >= 10) { break; } } } } pooledList3.Recycle(); num2 = Mathf.Min(num, num2); if (minTakeAmount > 0f) { num2 -= num2 % minTakeAmount; } deliveries.Clear(); float num4 = Mathf.Min(rootChore.originalAmount, num2); if (minTakeAmount > 0f) { num4 -= num4 % minTakeAmount; } deliveries.Add(new Delivery(rootContext, num4, OnFetchChoreCancelled)); float num5 = num4; for (int j = 0; j < pooledList.Count; j++) { if (num5 >= num2) { break; } Precondition.Context context3 = pooledList[j]; FetchChore fetchChore2 = context3.chore as FetchChore; if (fetchChore2 != rootChore && context3.IsSuccess() && (UnityEngine.Object)fetchChore2.overrideTarget == (UnityEngine.Object)null && (UnityEngine.Object)fetchChore2.driver == (UnityEngine.Object)null && fetchChore2.tagBits.AreEqual(ref rootChore.tagBits)) { num4 = Mathf.Min(fetchChore2.originalAmount, num2 - num5); if (minTakeAmount > 0f) { num4 -= num4 % minTakeAmount; } chores.Add(fetchChore2); deliveries.Add(new Delivery(context3, num4, OnFetchChoreCancelled)); num5 += num4; if (deliveries.Count >= 10) { break; } } } num5 = Mathf.Min(num5, num2); float num6 = num5; fetchables.Clear(); for (int k = 0; k < list.Count; k++) { if (num6 <= 0f) { break; } Pickupable pickupable3 = list[k]; num6 -= pickupable3.UnreservedAmount; fetchables.Add(pickupable3); } fetchAmountRequested = num5; reservations.Clear(); pooledList.Recycle(); pooledList2.Recycle(); }
public override void Begin(Precondition.Context context) { base.smi.sm.rancher.Set(context.consumerState.gameObject, base.smi); base.smi.sm.creature.Set(base.smi.fixedCapturePoint.targetCapturable.gameObject, base.smi); base.Begin(context); }
public override void Begin(Precondition.Context context) { base.smi.Begin(context); base.Begin(context); }
public FetchAreaChore(Precondition.Context context) : base(context.chore.choreType, (IStateMachineTarget)context.consumerState.consumer, context.consumerState.choreProvider, false, (Action <Chore>)null, (Action <Chore>)null, (Action <Chore>)null, context.masterPriority.priority_class, context.masterPriority.priority_value, false, true, 0, false, ReportManager.ReportType.WorkTime) { showAvailabilityInHoverText = false; base.smi = new StatesInstance(this, context); }
public virtual void PrepareChore(ref Precondition.Context context) { }
public StatesInstance(FetchAreaChore master, Precondition.Context context) : base(master) { rootContext = context; rootChore = (context.chore as FetchChore); }