ProjetPatate/Assets/Scripts/Workshop.cs

72 lines
2.4 KiB
C#
Raw Normal View History

2020-12-05 13:38:13 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2020-12-05 15:22:00 +01:00
//Define the behavior of a workshop (producer of Consumable)
2020-12-05 13:38:13 +01:00
[RequireComponent(typeof(Collider2D))]
public class Workshop : MonoBehaviour, IUsable
2020-12-05 13:38:13 +01:00
{
public string product_name;
public int product_value;
public Sprite product_sprite;
2020-12-05 15:22:00 +01:00
public float prepTime = 2.0f; //Time for preparation of product
2020-12-07 17:22:30 +01:00
public int stock = 5; //Stock of product
GameObject currentMug = null; //Mug currently stocked in workshop
2020-12-05 13:38:13 +01:00
2020-12-05 15:22:00 +01:00
//Handle objects interactions w/ Workshop
2020-12-05 13:38:13 +01:00
//Return wether the object is taken from tavernkeeper
public bool use(GameObject userObject)
2020-12-05 13:38:13 +01:00
{
if(userObject != null)
2020-12-05 13:38:13 +01:00
{
// Debug.Log(userObject.tag);
//TODO : Gérer Grabable qui ne sont pas des mugs ?
if(userObject.tag=="Grabable")
2020-12-05 13:38:13 +01:00
{
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>();
2020-12-05 13:38:13 +01:00
return false;
}
else
{
return false;
}
}
else
{
Debug.Log(gameObject.name+" doesn't handle : "+userObject);
2020-12-05 13:38:13 +01:00
return false;
}
}
// Start is called before the first frame update
void Start()
{
2020-12-07 17:22:30 +01:00
if(gameObject.layer != LayerMask.NameToLayer("Interactions"))
Debug.LogWarning(gameObject.name+" layer should be set to 'Interactions' to work properly");
2020-12-10 11:57:23 +01:00
if(gameObject.tag != "Usable")
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
2020-12-05 13:38:13 +01:00
}
// Update is called once per frame
void Update()
{
}
}