ProjetPatate/Assets/Scripts/Cleaning_workshop.cs

59 lines
1.9 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);
2020-12-10 14:38:20 +01:00
if (mug.content != null)//Empty mug
mug.consume();
stock.Add(userObject);
2020-12-10 14:38:20 +01:00
return true; //Object taken
}
}
else if(userObject.tag=="Player" && currentMug!=null) //Give clean mug
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;
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()
{
//Set current mug if there's stock
if(currentMug is null && stock.Count>0)
{
currentMug=stock[0];
stock.RemoveAt(0);
}
}
2020-12-07 17:23:47 +01:00
}