added chicken
added bucket cow can now be milked
This commit is contained in:
parent
4e286d74ce
commit
8dc7f78803
26 changed files with 1141 additions and 101 deletions
|
|
@ -29,6 +29,8 @@ namespace Actions {
|
|||
|
||||
private void InstantiateNextDayActionHandlers() {
|
||||
_nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler());
|
||||
|
||||
_nextDayActionHandlers.Add(new ChickenAnimalNextDayActionHandler());
|
||||
}
|
||||
|
||||
private void InstantiateClickActionHandlers() {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,24 @@ namespace Actions {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AbstractAnimalNextDayActionHandler : NextDayActionHandler{
|
||||
protected Animal _animal;
|
||||
public virtual void InvokeAction(GameObject gameObject) {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual bool Matches(GameObject gameObject) {
|
||||
bool rv = false;
|
||||
try {
|
||||
_animal = gameObject.GetComponent<Animal>();
|
||||
rv = true;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public class FarmlandTileNextDayActionHandler : AbstractFarmlandTileNextDayActionHandler {
|
||||
public override void InvokeAction(GameObject gameObject) {
|
||||
|
|
@ -87,4 +105,18 @@ namespace Actions {
|
|||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChickenAnimalNextDayActionHandler : AbstractAnimalNextDayActionHandler {
|
||||
public override void InvokeAction(GameObject gameObject) {
|
||||
Inventory.instance.AddElement(_animal.producedItem, Random.Range(1, 5));
|
||||
}
|
||||
|
||||
public override bool Matches(GameObject gameObject) {
|
||||
bool rv = base.Matches(gameObject);
|
||||
if(rv) {
|
||||
rv = _animal.displayName.Equals("Chicken");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,7 @@ public class Animal : MonoBehaviour {
|
|||
private Rigidbody2D _rigidbody;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
private Animator _animator;
|
||||
private int _animMoveID;
|
||||
private bool _canBeMilked;
|
||||
private int _animatorMoveID;
|
||||
|
||||
public int SellPrice => Convert.ToInt32(price * 0.8);
|
||||
|
||||
|
|
@ -26,13 +25,10 @@ public class Animal : MonoBehaviour {
|
|||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
_spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
|
||||
_animator = gameObject.GetComponent<Animator>();
|
||||
_animMoveID = Animator.StringToHash("moving");
|
||||
_animatorMoveID = 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));
|
||||
}
|
||||
|
|
@ -58,29 +54,12 @@ public class Animal : MonoBehaviour {
|
|||
}
|
||||
|
||||
_rigidbody.velocity = movementSpeed * direction;
|
||||
_animator.SetBool(_animMoveID, true);
|
||||
_animator.SetBool(_animatorMoveID, true);
|
||||
yield return new WaitForSeconds(randTime);
|
||||
_rigidbody.velocity = new Vector2(0f, 0f);
|
||||
_animator.SetBool(_animMoveID, false);
|
||||
_animator.SetBool(_animatorMoveID, false);
|
||||
}
|
||||
|
||||
StartCoroutine(Move());
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the _canBeMilked bool
|
||||
*/
|
||||
private void InvertCanBeMilked() {
|
||||
_canBeMilked = !_canBeMilked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Milk cow if possible
|
||||
*/
|
||||
private void OnMouseDown() {
|
||||
if(_canBeMilked) {
|
||||
ActionManager.Instance.ClickAction(gameObject, PlayerController.instance.SelectedItem);
|
||||
_canBeMilked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Assets/Scripts/Cow.cs
Normal file
29
Assets/Scripts/Cow.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Actions;
|
||||
using UnityEngine;
|
||||
|
||||
public class Cow : Animal {
|
||||
private bool _canBeMilked;
|
||||
|
||||
private void Awake() {
|
||||
_canBeMilked = true;
|
||||
HouseController.NewDayEvent.AddListener(UpdateCanBeMilked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the _canBeMilked bool
|
||||
*/
|
||||
private void UpdateCanBeMilked() {
|
||||
Debug.Log("_ca" + _canBeMilked);
|
||||
_canBeMilked = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Milk if cow is able to be milked
|
||||
*/
|
||||
private void OnMouseDown() {
|
||||
if(_canBeMilked) {
|
||||
ActionManager.Instance.ClickAction(gameObject, PlayerController.instance.SelectedItem);
|
||||
_canBeMilked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Cow.cs.meta
Normal file
11
Assets/Scripts/Cow.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3abcd021be6e8cd429909d1140d61699
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue