diff --git a/Assets/Resources/Cow.prefab b/Assets/Resources/Cow.prefab index 31b8184..1d5d7b1 100644 --- a/Assets/Resources/Cow.prefab +++ b/Assets/Resources/Cow.prefab @@ -162,7 +162,7 @@ MonoBehaviour: selectedSprite: {fileID: 21300000, guid: 432d303bbfc9d6f409aa93b6081306e5, type: 3} displayName: Cow description: Mach Milch, hat Fell - price: 500 + price: 1000 --- !u!95 &3084876974777557816 Animator: serializedVersion: 4 diff --git a/Assets/Resources/Items/Milk.asset b/Assets/Resources/Items/Milk.asset index 91618e8..7c85411 100644 --- a/Assets/Resources/Items/Milk.asset +++ b/Assets/Resources/Items/Milk.asset @@ -17,4 +17,4 @@ MonoBehaviour: a bad recursive function)) selectedSprite: {fileID: 21300000, guid: 3631bf5004a46da468c1d42552930a70, type: 3} defaultSprite: {fileID: 21300000, guid: a337e98cbd47bcb45b90e7cb9327ee16, type: 3} - price: 30 + price: 100 diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 043da8a..42c2c77 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -9094,6 +9094,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2} - {fileID: 11400000, guid: 6bac44b5c4527b641a3ae772d217ec43, type: 2} - {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2} + - {fileID: 11400000, guid: 0bcda05603855fd41b020c7e57fc520e, type: 2} --- !u!114 &1800469992 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Actions/ActionManager.cs b/Assets/Scripts/Actions/ActionManager.cs index 16ba036..050bfe3 100644 --- a/Assets/Scripts/Actions/ActionManager.cs +++ b/Assets/Scripts/Actions/ActionManager.cs @@ -23,15 +23,15 @@ namespace Actions { private ActionManager() { _clickActionHandlers = new List(); _nextDayActionHandlers = new List(); - instantiateClickActionHandlers(); - instantiateNextDayActionHandlers(); + InstantiateClickActionHandlers(); + InstantiateNextDayActionHandlers(); } - private void instantiateNextDayActionHandlers() { + private void InstantiateNextDayActionHandlers() { _nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler()); } - private void instantiateClickActionHandlers() { + private void InstantiateClickActionHandlers() { _clickActionHandlers.Add(new GrassTileClickHoeActionHandler()); _clickActionHandlers.Add(new GrassTileClickShovelActionHandler()); _clickActionHandlers.Add(new GrassTileClickFenceActionHandler()); @@ -43,6 +43,8 @@ namespace Actions { _clickActionHandlers.Add(new WaterTileClickShovelActionHandler()); _clickActionHandlers.Add(new WaterTileClickFishingRodActionHandler()); + + _clickActionHandlers.Add(new CowAnimalClickActionHandler()); } public void ClickAction(GameObject gameObject, UsableItem usableItem) { diff --git a/Assets/Scripts/Actions/ClickActionHandlers.cs b/Assets/Scripts/Actions/ClickActionHandlers.cs index f6094ea..a60af0c 100644 --- a/Assets/Scripts/Actions/ClickActionHandlers.cs +++ b/Assets/Scripts/Actions/ClickActionHandlers.cs @@ -89,14 +89,16 @@ namespace Assets.Scripts.Actions { } public abstract class AbstractAnimalClickActionHandler : ClickActionHandler { - public void InvokeAction(GameObject gameObject) { + protected Animal _animal; + + public virtual void InvokeAction(GameObject gameObject) { throw new System.NotImplementedException(); } - public bool Matches(GameObject gameObject, UsableItem usableItem) { + public virtual bool Matches(GameObject gameObject, UsableItem usableItem) { bool rv = false; try { - gameObject.GetComponent(); + _animal = gameObject.GetComponent(); rv = true; } catch { } @@ -265,4 +267,18 @@ namespace Assets.Scripts.Actions { return rv; } } + + public class CowAnimalClickActionHandler : AbstractAnimalClickActionHandler { + public override void InvokeAction(GameObject gameObject) { + Inventory.instance.AddElement(_animal.producedItem, 1); + } + + public override bool Matches(GameObject gameObject, UsableItem usableItem) { + bool rv = base.Matches(gameObject, usableItem); + if(rv) { + rv = _animal.displayName.Equals("Cow") && usableItem.ID == ItemContainer.Instance.GetItemIdByName("Bucket"); + } + return rv; + } + } } \ No newline at end of file diff --git a/Assets/Scripts/Animal.cs b/Assets/Scripts/Animal.cs index 3c6b821..e489a07 100644 --- a/Assets/Scripts/Animal.cs +++ b/Assets/Scripts/Animal.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using Actions; using UnityEngine; using Random = UnityEngine.Random; @@ -8,6 +9,7 @@ public class Animal : MonoBehaviour { private SpriteRenderer _spriteRenderer; private Animator _animator; private int _animMoveID; + private bool _canBeMilked; public int SellPrice => Convert.ToInt32(price * 0.8); @@ -25,14 +27,19 @@ public class Animal : MonoBehaviour { _spriteRenderer = gameObject.GetComponent(); _animator = gameObject.GetComponent(); _animMoveID = Animator.StringToHash("moving"); - + + _canBeMilked = true; _spriteRenderer.sprite = defaultSprite; + HouseController.NewDayEvent.AddListener(InvertCanBeMilked); + // Move the Animal in any random direction every 1-5s InvokeRepeating(nameof(MoveInRandomDirection), 2f, Random.Range(1f, 5f)); } - // Moves the Animal in any random direction for a random amount of time + /** + * Moves the Animal in any random direction for a random amount of time + */ private void MoveInRandomDirection() { IEnumerator Move() { float randTime = Random.Range(0.5f, 1f); @@ -60,9 +67,20 @@ public class Animal : MonoBehaviour { StartCoroutine(Move()); } + /** + * Invert the _canBeMilked bool + */ + private void InvertCanBeMilked() { + _canBeMilked = !_canBeMilked; + } + + /** + * Milk cow if possible + */ private void OnMouseDown() { - //TODO: TEMP!!!! - Destroy(gameObject); - //ActionManager.Instance.HandleAction(gameObject, PlayerController.instance.SelectedItem); + if(_canBeMilked) { + ActionManager.Instance.ClickAction(gameObject, PlayerController.instance.SelectedItem); + _canBeMilked = false; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Shop/AnimalShopSlot.cs b/Assets/Scripts/Shop/AnimalShopSlot.cs index 411f4ea..3539d87 100644 --- a/Assets/Scripts/Shop/AnimalShopSlot.cs +++ b/Assets/Scripts/Shop/AnimalShopSlot.cs @@ -34,7 +34,6 @@ namespace Shop { _playerController.ChangeMoney(-Element.price); // Debug.Log("Buying Animal: " + Element.displayName); } - PlaceAnimalRandomlyOnScreen(); _animalShop.RemoveElement(Element, 1); } else {