ProjetPatate/Assets/Scripts/Workshops/Cleaning_workshop.cs

83 lines
2.8 KiB
C#
Raw Normal View History

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
public override bool use(GameObject userObject)
2020-12-07 17:23:47 +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
if(userObject.tag=="Grabable")
2020-12-07 17:23:47 +01:00
{
2020-12-10 14:38:20 +01:00
//Stock and empty mug
Mug mug = userObject.GetComponent<Mug>();
2020-12-10 14:38:20 +01:00
if (mug!= null)
{
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
2021-01-19 10:46:47 +01:00
mug.take();
stock.Add(userObject);
2020-12-10 14:38:20 +01:00
return true; //Object taken
}
}
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
{
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
{
Debug.Log(gameObject.name+" give "+currentMug.name+" to "+userObject.name);
//Clean mug
2020-12-10 14:38:20 +01:00
mug.dirty=false;
//Give mug
2020-12-10 14:38:20 +01:00
player.grab(currentMug);
currentMug=null;
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()
{
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);
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;
if(UIPrepTimer != null) //Display UI prep timer
{
UIPrepTimer.SetValue(prepTimer/prepTime);
2021-01-13 14:59:50 +01:00
// UIPrepTimer.DisplayIcon(false);
UIPrepTimer.gameObject.SetActive(true);
}
2020-12-10 14:38:20 +01:00
}
}
2020-12-07 17:23:47 +01:00
}