diff --git a/Assets/Scripts/Cleaning_workshop.cs b/Assets/Scripts/Cleaning_workshop.cs index 3d5d213..465c175 100644 --- a/Assets/Scripts/Cleaning_workshop.cs +++ b/Assets/Scripts/Cleaning_workshop.cs @@ -5,22 +5,50 @@ using UnityEngine; //Define the behavior of a cleaning workshop public class Cleaning_workshop : Workshop { - // List stock = new List(); //List of mug in workshop + List stock = new List(); //List of mug in workshop //Handle objects interactions w/ Workshop //Return wether the object is taken from tavernkeeper public override bool use(GameObject object_used) { - if(object_used != null && object_used.tag=="Grabable") + if(object_used != null) { - Mug mug = object_used.GetComponent(); - if (mug!= null && mug.content is null && mug.dirty) //Mug dirty & empty + //TODO : Gérer grabable autre que Mug + if(object_used.tag=="Grabable") { - Debug.Log(object_used.name+ "cleaned by"+gameObject.name); - mug.dirty=false; - return false; + //Stock and empty mug + Mug mug = object_used.GetComponent(); + if (mug!= null) + { + Debug.Log(object_used.name+ " stocked in "+gameObject.name); + if (mug.content != null)//Empty mug + mug.consume(); + stock.Add(object_used); + return true; //Object taken + } + } + else if(object_used.tag=="Player") + { + Tavernkeeper_controller player = object_used.GetComponent(); + if(player!=null && currentMug!=null) + { + Mug mug = currentMug.GetComponent(); + mug.dirty=false; + player.grab(currentMug); + } } } return false; } + + // Update is called once per frame + void Update() + { + //Set current mug if there's stock + if(currentMug is null && stock.Count>0) + { + currentMug=stock[0]; + stock.RemoveAt(0); + } + } } diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index a954489..6ae1587 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -20,14 +20,18 @@ public class Tavernkeeper_controller : MonoBehaviour float horizontal; float vertical; float hands; + string currentHand; Vector2 lookDirection = new Vector2(1,0); Rigidbody2D rigidbody2d; Animator animator; - //TODO: assigner automatiquement à une autre mains si pleine - public void grab(GameObject obj, string hand) + public void grab(GameObject obj, string hand=null) { + //Default hand + if(hand is null) + hand = currentHand; + //Test if(!hand_container.ContainsKey(hand)) { @@ -98,15 +102,10 @@ public class Tavernkeeper_controller : MonoBehaviour actionTimer= action_cd; isInteracting=true; if(hands>0) - { - // Debug.Log("Left hand"); - handAction("left"); - } + currentHand="left"; else - { - // Debug.Log("Right hand"); - handAction("right"); - } + currentHand="right"; + handAction(currentHand); } }