diff --git a/Assets/Scripts/Cleaning_workshop.cs b/Assets/Scripts/Cleaning_workshop.cs index 465c175..a1606d8 100644 --- a/Assets/Scripts/Cleaning_workshop.cs +++ b/Assets/Scripts/Cleaning_workshop.cs @@ -9,32 +9,36 @@ public class Cleaning_workshop : Workshop //Handle objects interactions w/ Workshop //Return wether the object is taken from tavernkeeper - public override bool use(GameObject object_used) + public override bool use(GameObject userObject) { - if(object_used != null) + if(userObject != null) { //TODO : Gérer grabable autre que Mug - if(object_used.tag=="Grabable") + if(userObject.tag=="Grabable") { //Stock and empty mug - Mug mug = object_used.GetComponent(); + Mug mug = userObject.GetComponent(); if (mug!= null) { - Debug.Log(object_used.name+ " stocked in "+gameObject.name); + Debug.Log(userObject.name+ " stocked in "+gameObject.name); if (mug.content != null)//Empty mug mug.consume(); - stock.Add(object_used); + stock.Add(userObject); return true; //Object taken } } - else if(object_used.tag=="Player") + else if(userObject.tag=="Player" && currentMug!=null) //Give clean mug { - Tavernkeeper_controller player = object_used.GetComponent(); - if(player!=null && currentMug!=null) + Tavernkeeper_controller player = userObject.GetComponent(); + Mug mug = currentMug.GetComponent(); + if(player!=null && mug !=null) { - Mug mug = currentMug.GetComponent(); + Debug.Log(gameObject.name+" give "+currentMug.name+" to "+userObject.name); + //Clean mug mug.dirty=false; + //Give mug player.grab(currentMug); + currentMug=null; } } } diff --git a/Assets/Scripts/Production_workshop.cs b/Assets/Scripts/Production_workshop.cs index 8240811..3344504 100644 --- a/Assets/Scripts/Production_workshop.cs +++ b/Assets/Scripts/Production_workshop.cs @@ -20,36 +20,40 @@ public class Production_workshop : Workshop { // Debug.Log(userObject.tag); //TODO : Gérer Grabable qui ne sont pas des mugs ? - if(userObject.tag=="Grabable") + if(userObject.tag=="Grabable" && currentMug is null) { Mug mug = userObject.GetComponent(); if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop { - Debug.Log(gameObject.name+" fill "+userObject.name+ " with "+product_name); - mug.fill(new Consumable(product_name,product_value,product_sprite)); - stock--; - return false; + Debug.Log(userObject.name+ " stocked in "+gameObject.name); + currentMug=userObject; + return true; //Object taken } else { Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock); - return false; } } else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug { Tavernkeeper_controller player = userObject.GetComponent(); - return false; - } - else - { - return false; + Mug mug = currentMug.GetComponent(); + if(player!=null && mug !=null) + { + Debug.Log(gameObject.name+" give "+currentMug.name+" filled with "+product_name+" to "+userObject.name); + //Fill mug + mug.fill(new Consumable(product_name,product_value,product_sprite)); + stock--; + //Give mug + player.grab(currentMug); + currentMug=null; + } } } else { Debug.Log(gameObject.name+" doesn't handle : "+userObject); - return false; } + return false; //Object not taken } } diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 6ae1587..53f1042 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -31,7 +31,7 @@ public class Tavernkeeper_controller : MonoBehaviour //Default hand if(hand is null) hand = currentHand; - + //Test if(!hand_container.ContainsKey(hand)) { @@ -151,13 +151,13 @@ public class Tavernkeeper_controller : MonoBehaviour { if(hand_container[hand] is null) //No object in hands { + // Debug.Log(gameObject.name+" use "+hit_object.name); usable.use(gameObject); //Tavernkeeper interacting directly w/ usable - Debug.Log(gameObject.name+" use "+hit_object.name); } else if(usable.use(hand_container[hand])) //Interactions w/ object in hands { - // Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name); //Object taken by usable + // Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name); hand_container[hand]=null; } }