Decomposition des Workshop

This commit is contained in:
Antoine H 2020-12-10 13:51:16 +01:00
parent 4aa2aef787
commit f71d1e8b62
4 changed files with 73 additions and 65 deletions

View file

@ -2,57 +2,16 @@
using System.Collections.Generic;
using UnityEngine;
//Define the behavior of a workshop (producer of Consumable)
//Define the behavior of a workshop
[RequireComponent(typeof(Collider2D))]
public class Workshop : MonoBehaviour, IUsable
public abstract class Workshop : MonoBehaviour, IUsable
{
public string product_name;
public int product_value;
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
protected 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 userObject)
{
if(userObject != null)
{
// Debug.Log(userObject.tag);
//TODO : Gérer Grabable qui ne sont pas des mugs ?
if(userObject.tag=="Grabable")
{
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
{
return false;
}
}
else
{
Debug.Log(gameObject.name+" doesn't handle : "+userObject);
return false;
}
}
public abstract bool use(GameObject userObject);
// Start is called before the first frame update
void Start()
@ -62,10 +21,4 @@ public class Workshop : MonoBehaviour, IUsable
if(gameObject.tag != "Usable")
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
}
// Update is called once per frame
void Update()
{
}
}