Working Cleaning_workshop

This commit is contained in:
Antoine H 2020-12-10 14:38:20 +01:00
parent f71d1e8b62
commit c8682b208a
2 changed files with 44 additions and 17 deletions

View file

@ -5,22 +5,50 @@ using UnityEngine;
//Define the behavior of a cleaning workshop
public class Cleaning_workshop : Workshop
{
// List<GameObject> stock = new List<GameObject>(); //List of mug in workshop
List<GameObject> stock = new List<GameObject>(); //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<Mug>();
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<Mug>();
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<Tavernkeeper_controller>();
if(player!=null && currentMug!=null)
{
Mug mug = currentMug.GetComponent<Mug>();
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);
}
}
}