Quick fix to Cleaning_workshop + working currentMug in Production_workshop + cleaner Logs

This commit is contained in:
Antoine H 2020-12-10 14:58:15 +01:00
parent c8682b208a
commit 825de9e1b1
3 changed files with 33 additions and 25 deletions

View file

@ -9,32 +9,36 @@ public class Cleaning_workshop : Workshop
//Handle objects interactions w/ Workshop //Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper //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 //TODO : Gérer grabable autre que Mug
if(object_used.tag=="Grabable") if(userObject.tag=="Grabable")
{ {
//Stock and empty mug //Stock and empty mug
Mug mug = object_used.GetComponent<Mug>(); Mug mug = userObject.GetComponent<Mug>();
if (mug!= null) 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 if (mug.content != null)//Empty mug
mug.consume(); mug.consume();
stock.Add(object_used); stock.Add(userObject);
return true; //Object taken 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<Tavernkeeper_controller>(); Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
if(player!=null && currentMug!=null) Mug mug = currentMug.GetComponent<Mug>();
if(player!=null && mug !=null)
{ {
Mug mug = currentMug.GetComponent<Mug>(); Debug.Log(gameObject.name+" give "+currentMug.name+" to "+userObject.name);
//Clean mug
mug.dirty=false; mug.dirty=false;
//Give mug
player.grab(currentMug); player.grab(currentMug);
currentMug=null;
} }
} }
} }

View file

@ -20,36 +20,40 @@ public class Production_workshop : Workshop
{ {
// Debug.Log(userObject.tag); // Debug.Log(userObject.tag);
//TODO : Gérer Grabable qui ne sont pas des mugs ? //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<Mug>(); Mug mug = userObject.GetComponent<Mug>();
if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop 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); Debug.Log(userObject.name+ " stocked in "+gameObject.name);
mug.fill(new Consumable(product_name,product_value,product_sprite)); currentMug=userObject;
stock--; return true; //Object taken
return false;
} }
else else
{ {
Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock); Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock);
return false;
} }
} }
else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug
{ {
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>(); Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
return false; Mug mug = currentMug.GetComponent<Mug>();
} if(player!=null && mug !=null)
else {
{ Debug.Log(gameObject.name+" give "+currentMug.name+" filled with "+product_name+" to "+userObject.name);
return false; //Fill mug
mug.fill(new Consumable(product_name,product_value,product_sprite));
stock--;
//Give mug
player.grab(currentMug);
currentMug=null;
}
} }
} }
else else
{ {
Debug.Log(gameObject.name+" doesn't handle : "+userObject); Debug.Log(gameObject.name+" doesn't handle : "+userObject);
return false;
} }
return false; //Object not taken
} }
} }

View file

@ -31,7 +31,7 @@ public class Tavernkeeper_controller : MonoBehaviour
//Default hand //Default hand
if(hand is null) if(hand is null)
hand = currentHand; hand = currentHand;
//Test //Test
if(!hand_container.ContainsKey(hand)) if(!hand_container.ContainsKey(hand))
{ {
@ -151,13 +151,13 @@ public class Tavernkeeper_controller : MonoBehaviour
{ {
if(hand_container[hand] is null) //No object in hands 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 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 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 //Object taken by usable
// Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name);
hand_container[hand]=null; hand_container[hand]=null;
} }
} }