Add Workshop (+tag)

This commit is contained in:
Antoine H 2020-12-05 13:38:13 +01:00
parent 16248cdf16
commit 538f05aa15
6 changed files with 114 additions and 15 deletions

View file

@ -7,18 +7,27 @@ public class Client_controller : MonoBehaviour
{
public float consumeTime = 3.0f; //Time to consume currentMug
public float waitingTime = 10.0f; //Patience after ordering
GameObject currentMug;
GameObject currentMug = null;
//Return wether the object is taken from tavernkeeper
public bool use(GameObject object_used)
{
if(object_used != null && object_used.tag=="Mug")
if(currentMug is null) //No mug in hand
{
Mug mug = object_used.GetComponent<Mug>();
if (mug.content != null)
if(object_used != null && object_used.tag=="Mug")
{
Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type);
currentMug = object_used;
return true; //Object taken from tavernkeeper
Mug mug = object_used.GetComponent<Mug>();
if (mug!= null && mug.content != null)
{
Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type);
currentMug = object_used;
return true;
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false;
}
}
else
{
@ -28,8 +37,8 @@ public class Client_controller : MonoBehaviour
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false; //Object not taken from tavernkeeper
Debug.Log(gameObject.name+" already consumming "+currentMug.name);
return false;
}
}

View file

@ -80,6 +80,7 @@ public class Tavernkeeper_controller : MonoBehaviour
}
//Handle action with hands
//TODO : Factoriser actions des IGrabable et actions des Clients/Workshop
void handAction(string hand)
{
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
@ -119,6 +120,20 @@ public class Tavernkeeper_controller : MonoBehaviour
}
}
}
else if(hit_object.tag == "Workshop")
{
// Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name);
Workshop workshop = hit_object.GetComponent<Workshop>();
if(workshop!=null)
{
if(workshop.use(hand_container[hand])) //Interactions w/ object in hands
{
//Object taken by workshop
// Destroy(hand_container[hand]);
hand_container[hand]=null;
}
}
}
}
}
//Full hand : drop

View file

@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider2D))]
public class Workshop : MonoBehaviour
{
public string product_name;
public int product_value;
public Sprite product_sprite;
public float prepTime = 2.0f;
protected int _stock = 5;
//Return wether the object is taken from tavernkeeper
public bool use(GameObject object_used)
{
if(object_used != null && object_used.tag=="Mug")
{
Mug mug = object_used.GetComponent<Mug>();
if (mug!= null && mug.content is null && _stock>0)
{
Debug.Log(gameObject.name+" fill "+object_used.name+ " with "+product_name);
mug.fill(new Consumable(product_name,product_value,product_sprite));
_stock--;
return false;
}
else
{
Debug.Log(object_used.name+" cannot be filled with "+product_name+ " -stock:"+_stock);
return false;
}
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5e4020837a3c5214f90b5688a1e4faa2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: