public void CmdEatFood(GameObject food, string fromSlot, bool isDrink) { if (Inventory[fromSlot].Item == null) { //Already been eaten or the food is no longer in hand return; } FoodBehaviour baseFood = food.GetComponent <FoodBehaviour>(); if (isDrink) { soundNetworkActions.CmdPlaySoundAtPlayerPos("Slurp"); } else { soundNetworkActions.CmdPlaySoundAtPlayerPos("EatFood"); } PlayerHealth playerHealth = GetComponent <PlayerHealth>(); //FIXME: remove health and blood changes after TDM //and use this Cmd for healing hunger and applying //food related attributes instead: playerHealth.AddHealth(baseFood.healAmount); playerHealth.BloodLevel += baseFood.healAmount; playerHealth.StopBleeding(); InventoryManager.UpdateInvSlot(true, "", null, Inventory[fromSlot].UUID); equipment.ClearItemSprite(fromSlot); PoolManager.Instance.PoolNetworkDestroy(food); }
void FindVisibleResources(int need) { switch (need) { case 1: for (int i = 0; i < fov.visibleTargets.Count; i++) { if (fov.visibleTargets[i].gameObject.tag == "Water") { // Para detectar agua hay que usar la grid } Debug.Log("Tengo sed."); } break; case 2: for (int i = 0; i < fov.visibleTargets.Count; i++) { if (fov.visibleTargets[i].gameObject.tag == "Food") { Debug.Log("A comer!!!"); distance = Vector3.Distance(transform.position, fov.visibleTargets[i].gameObject.transform.position); if (distance < prevDistance) { prevDistance = distance; nearestFood = fov.visibleTargets[i].gameObject.transform; nutrients = nearestFood.GetComponent <FoodBehaviour>(); } } } break; case 3: for (int i = 0; i < fov.visibleTargets.Count; i++) { if (fov.visibleTargets[i].gameObject.tag == "Couple") { distance = Vector3.Distance(transform.position, fov.visibleTargets[i].gameObject.transform.position); if (distance < prevDistance) { prevDistance = distance; nearestCouple = fov.visibleTargets[i].gameObject.transform; if (nearestCouple.GetComponent <AnimalBehaviour>().male != male && nearestCouple.GetComponentInChildren <AnimalBehaviour>().reproduction) { Debug.Log("A follar!!!"); } else { fov.visibleTargets.Remove(nearestCouple); nearestCouple = null; } } } } break; } }
public void Reset() { _currentFood = null; _foodSpawned = null; FoodImage.transform.localScale = Vector3.zero; RemoveFoodSpawnDelegate(); RemoveImageFromContainer(); }
void EatFood(FoodBehaviour food) { if (FoodEatingCooldown <= 0.0f && food.FoodAmount >= 0.0f) { Hunger -= food.Eat(HungerBite); FoodEatingCooldown += EatingInterval; } }
void OnTriggerEnter(Collider other) { FoodBehaviour food = other.GetComponent <FoodBehaviour>(); if (food) { ImTouchingThisFood = new System.WeakReference <FoodBehaviour>(food); } }
private void Eat(GameObject foodObject) { FoodBehaviour food = foodObject.GetComponent <FoodBehaviour>(); if (food) { Heal(food.Eat()); } }
void OnTriggerExit(Collider other) { FoodBehaviour food = other.GetComponent <FoodBehaviour>(); FoodBehaviour imTouchingThisFood; if (ImTouchingThisFood != null && ImTouchingThisFood.TryGetTarget(out imTouchingThisFood) && food == imTouchingThisFood) { ImTouchingThisFood = null; } }
//Check if the item is edible and eat it private bool CheckEdible() { FoodBehaviour baseFood = CurrentSlot.Item.GetComponent <FoodBehaviour>(); if (baseFood != null) { baseFood.TryEat(); return(true); } return(false); }
private void AddDelegate(GameObject food) { if (food != null) { RemoveFoodSpawnDelegate(); _foodSpawned = food.GetComponent <FoodBehaviour>(); if (_foodSpawned != null) { _foodSpawned.OnFoodStoppedMoving += ContainerOnFoodStoppedMoving; } } }
void OnCollisionEnter(Collision col) { if (!landed && col.gameObject.tag == "floor") { if (landsound) { audio.PlayOneShot(landsound); } landed = true; } else if (col.gameObject.tag == "block" || col.gameObject.tag == "enemy") { if (powerup_active != PowerupType.Transparency) { if (hitsound) { audio.PlayOneShot(hitsound); } rigidbody.AddForce(Vector3.up * knockback.y + Vector3.forward * knockback.x, ForceMode.Impulse); } } else if (col.gameObject.tag == "food") { if (powerup_active != PowerupType.Transparency) { if (eatsound) { audio.PlayOneShot(eatsound); } FoodBehaviour food = col.gameObject.GetComponent <FoodBehaviour>(); SceneBuilder.Instance.SendMessage("UpdateScore", food.food_type); Destroy(col.gameObject); } } else if (col.gameObject.tag == "powerup") { if (powerup_active == PowerupType.None) { if (eatsound) { audio.PlayOneShot(eatsound); } PowerupBehaviour powerup = col.gameObject.GetComponent <PowerupBehaviour>(); powerup_owned = powerup.powerup_type; PowerupDisplay.Instance.SendMessage("UpdateType", powerup_owned); Destroy(col.gameObject); } } }
void OnSceneGUI() { FoodBehaviour food = target as FoodBehaviour; Handles.BeginGUI(); Vector2 location = HandleUtility.WorldToGUIPoint(food.transform.TransformPoint(Vector3.up * 4.0f)); GUILayout.Window(0, new Rect(location, new Vector2(150, 50)), (id) => { GUILayout.BeginVertical(); if (GUILayout.Button("Replenish")) { Debug.Log("Replenished!"); food.FoodAmount = 1.0f; } GUILayout.EndVertical(); }, "Food"); Handles.EndGUI(); }
private void OnTriggerEnter2D(Collider2D collision) { //TODO :: 꼬치에 순차적으로 들어감 if (collision.CompareTag("Food")) { FoodBehaviour food = collision.GetComponent <FoodBehaviour>(); food.GetComponent <Rigidbody2D>().simulated = false; food.transform.SetParent(transform); foodObjects.Add(collision.gameObject); food.gameObject.layer = LayerMask.NameToLayer("Stick"); Vector3 foodPosition = transform.position; foodPosition.x = ((float)(foods.Count + 1) / (float)maxFoodCount) * stickSize + stickPoint.position.x; food.MoveStick(foodPosition); AddFood(food.GetFood()); } }
public void CmdEatFood(GameObject food, string fromSlot, bool isDrink) { if (Inventory[fromSlot].Item == null) { //Already been eaten or the food is no longer in hand return; } FoodBehaviour baseFood = food.GetComponent <FoodBehaviour>(); if (isDrink) { SoundManager.PlayNetworkedAtPos("Slurp", transform.position); } else { SoundManager.PlayNetworkedAtPos("EatFood", transform.position); } PlayerHealth playerHealth = GetComponent <PlayerHealth>(); //FIXME: remove health and blood changes after TDM //and use this Cmd for healing hunger and applying //food related attributes instead: playerHealth.AddHealth(baseFood.healAmount); playerHealth.bloodSystem.BloodLevel += baseFood.healAmount; playerHealth.bloodSystem.StopBleeding(); InventoryManager.UpdateInvSlot(true, "", null, Inventory[fromSlot].UUID); equipment.ClearItemSprite(fromSlot); PoolManager.Instance.PoolNetworkDestroy(food); GameObject leavings = baseFood.leavings; if (leavings != null) { leavings = ItemFactory.SpawnItem(leavings); AddItemToUISlot(leavings, fromSlot); } }
public static System.WeakReference <GameObject> GetClosestNonEmptyFood(Vector3 point) { GameObject[] food = GameObject.FindGameObjectsWithTag("Food"); float closestDistanceSqr = Mathf.Infinity; int index = Random.Range(0, food.Length); if (food.Length > 0) { for (int i = 0; i < food.Length; i++) { float distanceSqr = (point - food[i].transform.position).sqrMagnitude; FoodBehaviour foodB = food[i].GetComponent <FoodBehaviour>(); if (foodB && distanceSqr < closestDistanceSqr && foodB.FoodAmount > 0.0f) { index = i; closestDistanceSqr = distanceSqr; } } return(new System.WeakReference <GameObject>(food[index])); } return(null); }
private bool CheckEdible(GameObject itemInHand) { FoodBehaviour baseFood = itemInHand.GetComponent <FoodBehaviour>(); if (baseFood == null || UIManager.CurrentIntent == Intent.Harm) { return(false); } if (PlayerManager.LocalPlayer == gameObject) { //Clicked on yourself, try to eat the food baseFood.TryEat(); } else { //Clicked on someone else //TODO create a new method on FoodBehaviour for feeding others //and use that here } return(true); }
void Update() { if (!isInput) { return; } if (Input.GetMouseButtonDown(0)) { isHold = true; SoundManager.Instance.PlaySFX(SoundManager.SFX_SOUND.CATCH); UpdateMousePosition(); RaycastHit2D hit = Physics2D.Raycast(mainCamera.ScreenToWorldPoint(mouseScreenPosition) , Vector3.forward , Mathf.Infinity); if (hit) { if (isGive && hit.collider.gameObject.CompareTag("NPC")) { //TODO :: NPC에게 줌 SetInput(false); SetGive(false); cookingManager.FinalCook(); } else if (!isGive && hit.collider.gameObject.CompareTag("FoodSlot")) { FoodSlot slot = hit.collider.gameObject.GetComponent <FoodSlot>(); GameObject g = Instantiate(foodPrefab, transform); g.transform.localPosition = Vector3.zero; SetTarget(g.transform); g.GetComponent <Collider2D>().enabled = false; target.GetComponent <Rigidbody2D>().simulated = false; FoodBehaviour food = g.GetComponent <FoodBehaviour>(); food.SetFood(slot.FoodID); food.startMoveStick += RemoveTarget; } } } else if (Input.GetMouseButtonUp(0)) { isHold = false; if (target == null) { return; } target.GetComponent <Collider2D>().enabled = true; target.GetComponent <Rigidbody2D>().simulated = true; target.SetParent(null); RemoveTarget(); } if (isHold) { UpdateMousePosition(); transform.position = mouseWorldPosition; } }
void Update() { FoodEatingCooldown = Mathf.Max(0.0f, FoodEatingCooldown - Time.deltaTime); BarkCooldown = Mathf.Max(0.0f, BarkCooldown - Time.deltaTime); if (SleepyTime > 0.0f) { float noiseLevel = 0.0f; if (noiseLevel > 0.2f) { // wake up grumpy and go somewhere else quieter つ´Д`)つ internalState = "つ´Д`)つ"; BarkGrumpy(); } else { // sleepy time ( ु⁎ᴗ_ᴗ⁎)ु.。zZ internalState = "( ु⁎ᴗ_ᴗ⁎)ु.。zZ"; agent.isStopped = true; Energy += Time.deltaTime * SleepRecovery; SleepyTime -= Time.deltaTime; } } else if (Energy < 0.1f) { SleepyTime = Mathf.Min(1.0f, SleepyTime + 1.0f); } else if (Hunger > 0.5f) { GameObject iWantThisFood = null; if (IWantThisFood != null && IWantThisFood.TryGetTarget(out iWantThisFood)) { // walk towards food FoodBehaviour imTouchingThisFood = null; if (ImTouchingThisFood != null && ImTouchingThisFood.TryGetTarget(out imTouchingThisFood)) { // yum yum ლ(´ڡ`ლ) internalState = "ლ(´ڡ`ლ)"; EatFood(imTouchingThisFood); IWantThisFood = null; ImTouchingThisFood = null; } else { // go walk towards food ԅ(♡﹃♡ԅ) internalState = "ԅ(♡﹃♡ԅ)"; UpdateTarget(iWantThisFood.transform.position, 1.0f); } } else { System.WeakReference <GameObject> foodObject = SceneManager.GetClosestNonEmptyFood(transform.position); if (foodObject.TryGetTarget(out iWantThisFood)) { IWantThisFood = foodObject; } else { // whaaaa? no food around Щ(º̩̩́Дº̩̩̀щ) internalState = "Щ(º̩̩́Дº̩̩̀щ)"; // sulk and bark a bit BarkSad(); } } } else { // go play! internalState = "(^ω^)"; Energy -= Time.deltaTime * EnergySpendingPlaying; Hunger += Time.deltaTime * HungerRate; ToyBoredom += Time.deltaTime * ToyBoredomRate; if (ToyBoredom >= 1.0f) { IWantThisToy = null; ToyBoredom = 0.0f; } GameObject iWantThisToy = null; if (IWantThisToy != null && IWantThisToy.TryGetTarget(out iWantThisToy)) { UpdateTarget(iWantThisToy.transform.position, 2.0f); BarkHappy(); ToyBehaviour toy = null; if (ImTouchingThisToy != null && ImTouchingThisToy.TryGetTarget(out toy)) { toy.ShootUpRandomDirection(); ImTouchingThisToy = null; } } else { System.WeakReference <GameObject> toyObject = SceneManager.GetRandomToy(); if (toyObject.TryGetTarget(out iWantThisToy)) { IWantThisToy = toyObject; } else { } } } }
void Start() { food = GetComponent <FoodBehaviour>(); }