Factorisation des interactions IGrabable
This commit is contained in:
parent
c254d73103
commit
eacf4f2711
7 changed files with 76 additions and 44 deletions
|
@ -11,31 +11,43 @@ public class Workshop : MonoBehaviour
|
|||
public Sprite product_sprite;
|
||||
public float prepTime = 2.0f; //Time for preparation of product
|
||||
public int stock = 5; //Stock of product
|
||||
// GameObject currentMug = null; //Mug currently stocked in workshop
|
||||
GameObject currentMug = null; //Mug currently stocked in workshop
|
||||
|
||||
//Handle objects interactions w/ Workshop
|
||||
//Return wether the object is taken from tavernkeeper
|
||||
public bool use(GameObject object_used)
|
||||
public bool use(GameObject userObject)
|
||||
{
|
||||
if(object_used != null && object_used.tag=="Mug")
|
||||
if(userObject != null)
|
||||
{
|
||||
Mug mug = object_used.GetComponent<Mug>();
|
||||
if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop
|
||||
if(userObject.tag=="Mug")
|
||||
{
|
||||
Debug.Log(gameObject.name+" fill "+object_used.name+ " with "+product_name);
|
||||
mug.fill(new Consumable(product_name,product_value,product_sprite));
|
||||
stock--;
|
||||
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;
|
||||
}
|
||||
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
|
||||
{
|
||||
Debug.Log(object_used.name+" cannot be filled with "+product_name+ " -stock:"+stock);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(gameObject.name+" doesn't handle : "+object_used);
|
||||
Debug.Log(gameObject.name+" doesn't handle : "+userObject);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue