Ajout Consumable

This commit is contained in:
Antoine H 2020-12-04 21:49:58 +01:00
parent 80704e1ba3
commit 16248cdf16
6 changed files with 220 additions and 11 deletions

View file

@ -9,13 +9,22 @@ public class Client_controller : MonoBehaviour
public float waitingTime = 10.0f; //Patience after ordering
GameObject currentMug;
public bool use(GameObject new_mug)
public bool use(GameObject object_used)
{
if(new_mug != null && new_mug.tag=="Mug")
if(object_used != null && object_used.tag=="Mug")
{
Debug.Log(gameObject.name+" take "+new_mug.name);
currentMug = new_mug;
return true; //Object taken from tavernkeeper
Mug mug = object_used.GetComponent<Mug>();
if (mug.content != null)
{
Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type);
currentMug = object_used;
return true; //Object taken from tavernkeeper
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false;
}
}
else
{

View file

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
//Represents consumable : sprite and informations
public class Consumable //: MonoBehaviour
{
private HashSet<string> allowed_types = new HashSet<string>(new [] {"beer", "pression", "vodka"});
private string _type;
private int _value;
private Sprite _sprite;
//Read-only accessors
public string Type
{
get{ return _type;}
// set{}
}
public int Value
{
get{ return _value;}
// set{}
}
public Sprite Sprite
{
get{ return _sprite;}
// set{}
}
//TODO : Handle sprite = null
public Consumable(string type, int value, Sprite sprite)
{
if(!allowed_types.Contains(type))
{
throw new Exception("Invalid consumable type :"+type);
}
_type=type;
_value=value;
_sprite=sprite;
}
}

View file

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

View file

@ -6,8 +6,8 @@ using UnityEngine;
public class Mug : MonoBehaviour, IGrabable
{
public int size = 1; //Size (1 or 2 hands) of the object
bool dirty = false;
int content = 1;
// bool dirty = false;
public Consumable content= null; //new Consumable("beer",1,null);
public void use()
{
@ -23,13 +23,20 @@ public class Mug : MonoBehaviour, IGrabable
gameObject.transform.position = position;
}
public void fill(int new_content)
public void fill(Consumable new_content)
{
content = new_content;
if(content is null)
{
content = new_content;
}
else
{
Debug.Log(gameObject.name+" cannot be filled (already full) with "+new_content.Type);
}
}
public void consume()
{
content=0;
content=null;
}
// Start is called before the first frame update