public void SpawnConsumables() { factory = FactoryProducer.GetFactory(FactoryType.Consumable); potion = factory.GetConsumableFactory(ConsumableType.Potion); food = factory.GetConsumableFactory(ConsumableType.Food); potion.Consume(); food.Consume(); }
private IEnumerator useConsumableAction(string type, int partialCount, object properties) { yield return(null); currentConsumable = definitions.GetConsumable(type); if (currentConsumable != null) { currentConsumable.SetGameServerClient(this); yield return(currentConsumable.Consume(partialCount, type, properties)); } }
private void Die() { transform.Rotate(90, 0, 0); _renderer.material.color = Color.gray; _rigidBody.AddForce((transform.position - _planet.transform.position).normalized, ForceMode.Impulse); Debug.Log("Twippie mort :( thirst : " + Mathf.FloorToInt(_thirst) + " hunger : " + Mathf.FloorToInt(_hunger) + " _fatigue : " + Mathf.FloorToInt(_sleepiness)); _objectManager.RemoveObject(this); if (_stats != null) { _stats.enabled = false; } Destroy(LineRenderer); _consumable?.Consume(); Destroy(this); }
public static async Task ConsumeAsync(this IConsumable self, uint count) { var invokeResult = default(bool?); self.Consume(count, () => invokeResult = true, () => invokeResult = false); while (!invokeResult.HasValue) { await Task.Delay(MillisecondsDelay); } if (!invokeResult.Value) { throw new InvalidOperationException(); } }
private IEnumerator Eat(IConsumable consumable) { if (_arrival.FinishZone.Taken) { SetDestination(DefineGoal()); _eat = null; yield break; } _consumable = consumable; _arrival.FinishZone.Taken = true; consumable.Reserve(); while (consumable.Consuming(_hunger)) { _hunger = UpdateValue(_hunger, -20); _rigidBody.velocity = Vector3.zero; _rigidBody.angularVelocity = Vector3.zero; yield return(null); } _consumable = null; consumable.Consume(); SetDestination(DefineGoal()); _eat = null; }
public void AddToInventory(GameObject item, bool switchToItem = false) { if (item.GetComponentInChildren <Weapon>() != null) { GameObject obj = Instantiate(item, transform); obj.SetActive(false); inventory.Add(obj); if (switchToItem) { EnableInventoryItem(inventory.Count - 1); } Debug.Log(string.Format("Added {0} to player inventory", item)); } else if (item.GetComponentInChildren <IConsumable>() != null) { GameObject realItem = Instantiate(item); IConsumable consumable = realItem.GetComponentInChildren <IConsumable>(); consumable.Consume(transform.root.gameObject); } else if (item.GetComponent <Key>() != null) { keyCount++; } }
/// <summary> /// The Pet will not eat food when sick. /// </summary> void Eat(IConsumable consumable) { if (IsHealthy()) { consumable.Consume(); } else if (IsAlive()) { if (consumable is Medicine) consumable.Consume(); } }