cow can be milked
This commit is contained in:
parent
c40aec0022
commit
4e286d74ce
7 changed files with 51 additions and 15 deletions
|
|
@ -162,7 +162,7 @@ MonoBehaviour:
|
||||||
selectedSprite: {fileID: 21300000, guid: 432d303bbfc9d6f409aa93b6081306e5, type: 3}
|
selectedSprite: {fileID: 21300000, guid: 432d303bbfc9d6f409aa93b6081306e5, type: 3}
|
||||||
displayName: Cow
|
displayName: Cow
|
||||||
description: Mach Milch, hat Fell
|
description: Mach Milch, hat Fell
|
||||||
price: 500
|
price: 1000
|
||||||
--- !u!95 &3084876974777557816
|
--- !u!95 &3084876974777557816
|
||||||
Animator:
|
Animator:
|
||||||
serializedVersion: 4
|
serializedVersion: 4
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,4 @@ MonoBehaviour:
|
||||||
a bad recursive function))
|
a bad recursive function))
|
||||||
selectedSprite: {fileID: 21300000, guid: 3631bf5004a46da468c1d42552930a70, type: 3}
|
selectedSprite: {fileID: 21300000, guid: 3631bf5004a46da468c1d42552930a70, type: 3}
|
||||||
defaultSprite: {fileID: 21300000, guid: a337e98cbd47bcb45b90e7cb9327ee16, type: 3}
|
defaultSprite: {fileID: 21300000, guid: a337e98cbd47bcb45b90e7cb9327ee16, type: 3}
|
||||||
price: 30
|
price: 100
|
||||||
|
|
|
||||||
|
|
@ -9094,6 +9094,7 @@ MonoBehaviour:
|
||||||
- {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2}
|
- {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2}
|
||||||
- {fileID: 11400000, guid: 6bac44b5c4527b641a3ae772d217ec43, type: 2}
|
- {fileID: 11400000, guid: 6bac44b5c4527b641a3ae772d217ec43, type: 2}
|
||||||
- {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2}
|
- {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 0bcda05603855fd41b020c7e57fc520e, type: 2}
|
||||||
--- !u!114 &1800469992
|
--- !u!114 &1800469992
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ namespace Actions {
|
||||||
private ActionManager() {
|
private ActionManager() {
|
||||||
_clickActionHandlers = new List<ClickActionHandler>();
|
_clickActionHandlers = new List<ClickActionHandler>();
|
||||||
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
||||||
instantiateClickActionHandlers();
|
InstantiateClickActionHandlers();
|
||||||
instantiateNextDayActionHandlers();
|
InstantiateNextDayActionHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void instantiateNextDayActionHandlers() {
|
private void InstantiateNextDayActionHandlers() {
|
||||||
_nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler());
|
_nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void instantiateClickActionHandlers() {
|
private void InstantiateClickActionHandlers() {
|
||||||
_clickActionHandlers.Add(new GrassTileClickHoeActionHandler());
|
_clickActionHandlers.Add(new GrassTileClickHoeActionHandler());
|
||||||
_clickActionHandlers.Add(new GrassTileClickShovelActionHandler());
|
_clickActionHandlers.Add(new GrassTileClickShovelActionHandler());
|
||||||
_clickActionHandlers.Add(new GrassTileClickFenceActionHandler());
|
_clickActionHandlers.Add(new GrassTileClickFenceActionHandler());
|
||||||
|
|
@ -43,6 +43,8 @@ namespace Actions {
|
||||||
|
|
||||||
_clickActionHandlers.Add(new WaterTileClickShovelActionHandler());
|
_clickActionHandlers.Add(new WaterTileClickShovelActionHandler());
|
||||||
_clickActionHandlers.Add(new WaterTileClickFishingRodActionHandler());
|
_clickActionHandlers.Add(new WaterTileClickFishingRodActionHandler());
|
||||||
|
|
||||||
|
_clickActionHandlers.Add(new CowAnimalClickActionHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,16 @@ namespace Assets.Scripts.Actions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AbstractAnimalClickActionHandler : ClickActionHandler {
|
public abstract class AbstractAnimalClickActionHandler : ClickActionHandler {
|
||||||
public void InvokeAction(GameObject gameObject) {
|
protected Animal _animal;
|
||||||
|
|
||||||
|
public virtual void InvokeAction(GameObject gameObject) {
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Matches(GameObject gameObject, UsableItem usableItem) {
|
public virtual bool Matches(GameObject gameObject, UsableItem usableItem) {
|
||||||
bool rv = false;
|
bool rv = false;
|
||||||
try {
|
try {
|
||||||
gameObject.GetComponent<Animal>();
|
_animal = gameObject.GetComponent<Animal>();
|
||||||
rv = true;
|
rv = true;
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
@ -265,4 +267,18 @@ namespace Assets.Scripts.Actions {
|
||||||
return rv;
|
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;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using Actions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
|
@ -8,6 +9,7 @@ public class Animal : MonoBehaviour {
|
||||||
private SpriteRenderer _spriteRenderer;
|
private SpriteRenderer _spriteRenderer;
|
||||||
private Animator _animator;
|
private Animator _animator;
|
||||||
private int _animMoveID;
|
private int _animMoveID;
|
||||||
|
private bool _canBeMilked;
|
||||||
|
|
||||||
public int SellPrice => Convert.ToInt32(price * 0.8);
|
public int SellPrice => Convert.ToInt32(price * 0.8);
|
||||||
|
|
||||||
|
|
@ -26,13 +28,18 @@ public class Animal : MonoBehaviour {
|
||||||
_animator = gameObject.GetComponent<Animator>();
|
_animator = gameObject.GetComponent<Animator>();
|
||||||
_animMoveID = Animator.StringToHash("moving");
|
_animMoveID = Animator.StringToHash("moving");
|
||||||
|
|
||||||
|
_canBeMilked = true;
|
||||||
_spriteRenderer.sprite = defaultSprite;
|
_spriteRenderer.sprite = defaultSprite;
|
||||||
|
|
||||||
|
HouseController.NewDayEvent.AddListener(InvertCanBeMilked);
|
||||||
|
|
||||||
// Move the Animal in any random direction every 1-5s
|
// Move the Animal in any random direction every 1-5s
|
||||||
InvokeRepeating(nameof(MoveInRandomDirection), 2f, Random.Range(1f, 5f));
|
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() {
|
private void MoveInRandomDirection() {
|
||||||
IEnumerator Move() {
|
IEnumerator Move() {
|
||||||
float randTime = Random.Range(0.5f, 1f);
|
float randTime = Random.Range(0.5f, 1f);
|
||||||
|
|
@ -60,9 +67,20 @@ public class Animal : MonoBehaviour {
|
||||||
StartCoroutine(Move());
|
StartCoroutine(Move());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invert the _canBeMilked bool
|
||||||
|
*/
|
||||||
|
private void InvertCanBeMilked() {
|
||||||
|
_canBeMilked = !_canBeMilked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Milk cow if possible
|
||||||
|
*/
|
||||||
private void OnMouseDown() {
|
private void OnMouseDown() {
|
||||||
//TODO: TEMP!!!!
|
if(_canBeMilked) {
|
||||||
Destroy(gameObject);
|
ActionManager.Instance.ClickAction(gameObject, PlayerController.instance.SelectedItem);
|
||||||
//ActionManager.Instance.HandleAction(gameObject, PlayerController.instance.SelectedItem);
|
_canBeMilked = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,6 @@ namespace Shop {
|
||||||
_playerController.ChangeMoney(-Element.price);
|
_playerController.ChangeMoney(-Element.price);
|
||||||
// Debug.Log("Buying Animal: " + Element.displayName);
|
// Debug.Log("Buying Animal: " + Element.displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceAnimalRandomlyOnScreen();
|
PlaceAnimalRandomlyOnScreen();
|
||||||
_animalShop.RemoveElement(Element, 1);
|
_animalShop.RemoveElement(Element, 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue