2020-12-07 17:23:47 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
//Define the behavior of a cleaning workshop
|
2020-12-10 13:51:16 +01:00
|
|
|
|
public class Cleaning_workshop : Workshop
|
2020-12-07 17:23:47 +01:00
|
|
|
|
{
|
2020-12-10 14:38:20 +01:00
|
|
|
|
List<GameObject> stock = new List<GameObject>(); //List of mug in workshop
|
2020-12-07 17:23:47 +01:00
|
|
|
|
|
|
|
|
|
//Handle objects interactions w/ Workshop
|
|
|
|
|
//Return wether the object is taken from tavernkeeper
|
2020-12-10 14:58:15 +01:00
|
|
|
|
public override bool use(GameObject userObject)
|
2020-12-07 17:23:47 +01:00
|
|
|
|
{
|
2020-12-10 14:58:15 +01:00
|
|
|
|
if(userObject != null)
|
2020-12-07 17:23:47 +01:00
|
|
|
|
{
|
2020-12-10 14:38:20 +01:00
|
|
|
|
//TODO : Gérer grabable autre que Mug
|
2020-12-10 14:58:15 +01:00
|
|
|
|
if(userObject.tag=="Grabable")
|
2020-12-07 17:23:47 +01:00
|
|
|
|
{
|
2020-12-10 14:38:20 +01:00
|
|
|
|
//Stock and empty mug
|
2020-12-10 14:58:15 +01:00
|
|
|
|
Mug mug = userObject.GetComponent<Mug>();
|
2020-12-10 14:38:20 +01:00
|
|
|
|
if (mug!= null)
|
|
|
|
|
{
|
2020-12-10 14:58:15 +01:00
|
|
|
|
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
2021-01-19 10:46:47 +01:00
|
|
|
|
mug.take();
|
2020-12-10 14:58:15 +01:00
|
|
|
|
stock.Add(userObject);
|
2021-01-08 11:05:45 +01:00
|
|
|
|
|
2020-12-10 14:38:20 +01:00
|
|
|
|
return true; //Object taken
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-08 11:05:45 +01:00
|
|
|
|
else if(userObject.tag=="Player" && prepTimer<prepTime && currentMug != null) //Prepare currentMug
|
|
|
|
|
{
|
|
|
|
|
continueUse(userObject);
|
|
|
|
|
}
|
|
|
|
|
else if(userObject.tag=="Player" && prepTimer>=prepTime) //Give tavernkeeper currentMug if cleaned
|
2020-12-10 14:38:20 +01:00
|
|
|
|
{
|
2020-12-10 14:58:15 +01:00
|
|
|
|
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
|
|
|
|
|
Mug mug = currentMug.GetComponent<Mug>();
|
|
|
|
|
if(player!=null && mug !=null)
|
2020-12-10 14:38:20 +01:00
|
|
|
|
{
|
2020-12-10 14:58:15 +01:00
|
|
|
|
Debug.Log(gameObject.name+" give "+currentMug.name+" to "+userObject.name);
|
|
|
|
|
//Clean mug
|
2020-12-10 14:38:20 +01:00
|
|
|
|
mug.dirty=false;
|
2020-12-10 14:58:15 +01:00
|
|
|
|
//Give mug
|
2020-12-10 14:38:20 +01:00
|
|
|
|
player.grab(currentMug);
|
2020-12-10 14:58:15 +01:00
|
|
|
|
currentMug=null;
|
2021-01-08 11:05:45 +01:00
|
|
|
|
|
|
|
|
|
UIPrepTimer.gameObject.SetActive(false); //Turn off UI prep timer
|
2020-12-10 14:38:20 +01:00
|
|
|
|
}
|
2020-12-07 17:23:47 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-10 14:38:20 +01:00
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2021-01-13 16:03:20 +01:00
|
|
|
|
if(currentMug!=null)
|
|
|
|
|
Debug.Log(stock.Count+ " - CurrentMug: "+currentMug.name+" "+currentMug.GetComponent<Mug>().dirty);
|
2020-12-10 14:38:20 +01:00
|
|
|
|
//Set current mug if there's stock
|
|
|
|
|
if(currentMug is null && stock.Count>0)
|
|
|
|
|
{
|
|
|
|
|
currentMug=stock[0];
|
|
|
|
|
stock.RemoveAt(0);
|
2021-01-08 11:05:45 +01:00
|
|
|
|
|
2021-01-13 16:03:20 +01:00
|
|
|
|
Mug mug = currentMug.GetComponent<Mug>();
|
|
|
|
|
if(mug.content != null)//Empty mug
|
|
|
|
|
{
|
|
|
|
|
mug.consume();
|
|
|
|
|
prepTimer=0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if(!mug.dirty)//Mug already clean
|
|
|
|
|
prepTimer=prepTime;
|
|
|
|
|
|
2021-01-08 11:05:45 +01:00
|
|
|
|
if(UIPrepTimer != null) //Display UI prep timer
|
|
|
|
|
{
|
|
|
|
|
UIPrepTimer.SetValue(prepTimer/prepTime);
|
2021-01-13 14:59:50 +01:00
|
|
|
|
// UIPrepTimer.DisplayIcon(false);
|
2021-01-08 11:05:45 +01:00
|
|
|
|
UIPrepTimer.gameObject.SetActive(true);
|
|
|
|
|
}
|
2020-12-10 14:38:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-07 17:23:47 +01:00
|
|
|
|
}
|