cow can be milked
This commit is contained in:
parent
c40aec0022
commit
4e286d74ce
7 changed files with 51 additions and 15 deletions
|
|
@ -23,15 +23,15 @@ namespace Actions {
|
|||
private ActionManager() {
|
||||
_clickActionHandlers = new List<ClickActionHandler>();
|
||||
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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>();
|
||||
_animal = gameObject.GetComponent<Animal>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<SpriteRenderer>();
|
||||
_animator = gameObject.GetComponent<Animator>();
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ namespace Shop {
|
|||
_playerController.ChangeMoney(-Element.price);
|
||||
// Debug.Log("Buying Animal: " + Element.displayName);
|
||||
}
|
||||
|
||||
PlaceAnimalRandomlyOnScreen();
|
||||
_animalShop.RemoveElement(Element, 1);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue