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
//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 mug = userObject.GetComponent<Mug>();
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<Tavernkeeper_controller>();
if(player!=null && currentMug!=null)
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
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;
//Give mug
player.grab(currentMug);
currentMug=null;
}
}
}

View file

@ -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<Mug>();
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<Tavernkeeper_controller>();
return false;
}
else
{
return false;
Mug mug = currentMug.GetComponent<Mug>();
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
}
}

View file

@ -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;
}
}