From f71d1e8b62611466cf10fde8811d83235e63c262 Mon Sep 17 00:00:00 2001 From: Antoine H Date: Thu, 10 Dec 2020 13:51:16 +0100 Subject: [PATCH] Decomposition des Workshop --- Assets/Scripts/Cleaning_workshop.cs | 17 ++----- Assets/Scripts/Production_workshop.cs | 55 ++++++++++++++++++++++ Assets/Scripts/Production_workshop.cs.meta | 11 +++++ Assets/Scripts/Workshop.cs | 55 ++-------------------- 4 files changed, 73 insertions(+), 65 deletions(-) create mode 100644 Assets/Scripts/Production_workshop.cs create mode 100644 Assets/Scripts/Production_workshop.cs.meta diff --git a/Assets/Scripts/Cleaning_workshop.cs b/Assets/Scripts/Cleaning_workshop.cs index 6fa7366..3d5d213 100644 --- a/Assets/Scripts/Cleaning_workshop.cs +++ b/Assets/Scripts/Cleaning_workshop.cs @@ -3,16 +3,15 @@ using System.Collections.Generic; using UnityEngine; //Define the behavior of a cleaning workshop -public class Cleaning_workshop : MonoBehaviour +public class Cleaning_workshop : Workshop { - public float cleanTime=2.0f; //Time to clean a mug // List stock = new List(); //List of mug in workshop //Handle objects interactions w/ Workshop //Return wether the object is taken from tavernkeeper - public bool use(GameObject object_used) + public override bool use(GameObject object_used) { - if(object_used != null && object_used.tag=="Mug") + if(object_used != null && object_used.tag=="Grabable") { Mug mug = object_used.GetComponent(); if (mug!= null && mug.content is null && mug.dirty) //Mug dirty & empty @@ -24,14 +23,4 @@ public class Cleaning_workshop : MonoBehaviour } return false; } - // Start is called before the first frame update - void Start() - { - } - - // Update is called once per frame - void Update() - { - - } } diff --git a/Assets/Scripts/Production_workshop.cs b/Assets/Scripts/Production_workshop.cs new file mode 100644 index 0000000..8240811 --- /dev/null +++ b/Assets/Scripts/Production_workshop.cs @@ -0,0 +1,55 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +//Define the behavior of a production workshop +public class Production_workshop : Workshop +{ + // public float prepTime = 2.0f; //Time for preparation of product + + public string product_name; + public int product_value; + public Sprite product_sprite; + public int stock = 5; //Stock of product + + //Handle objects interactions w/ Workshop + //Return wether the object is taken from tavernkeeper + public override bool use(GameObject userObject) + { + if(userObject != null) + { + // Debug.Log(userObject.tag); + //TODO : Gérer Grabable qui ne sont pas des mugs ? + if(userObject.tag=="Grabable") + { + Mug mug = userObject.GetComponent(); + if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop + { + Debug.Log(gameObject.name+" fill "+userObject.name+ " with "+product_name); + mug.fill(new Consumable(product_name,product_value,product_sprite)); + stock--; + return false; + } + else + { + Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock); + return false; + } + } + else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug + { + Tavernkeeper_controller player = userObject.GetComponent(); + return false; + } + else + { + return false; + } + } + else + { + Debug.Log(gameObject.name+" doesn't handle : "+userObject); + return false; + } + } +} diff --git a/Assets/Scripts/Production_workshop.cs.meta b/Assets/Scripts/Production_workshop.cs.meta new file mode 100644 index 0000000..bf8e57f --- /dev/null +++ b/Assets/Scripts/Production_workshop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcf63a52df2d5404e8f76b4e989d7360 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Workshop.cs b/Assets/Scripts/Workshop.cs index f5d0f8c..6bebe43 100644 --- a/Assets/Scripts/Workshop.cs +++ b/Assets/Scripts/Workshop.cs @@ -2,57 +2,16 @@ using System.Collections.Generic; using UnityEngine; -//Define the behavior of a workshop (producer of Consumable) +//Define the behavior of a workshop [RequireComponent(typeof(Collider2D))] -public class Workshop : MonoBehaviour, IUsable +public abstract class Workshop : MonoBehaviour, IUsable { - public string product_name; - public int product_value; - public Sprite product_sprite; public float prepTime = 2.0f; //Time for preparation of product - public int stock = 5; //Stock of product - GameObject currentMug = null; //Mug currently stocked in workshop + protected GameObject currentMug = null; //Mug currently stocked in workshop //Handle objects interactions w/ Workshop //Return wether the object is taken from tavernkeeper - public bool use(GameObject userObject) - { - if(userObject != null) - { - // Debug.Log(userObject.tag); - //TODO : Gérer Grabable qui ne sont pas des mugs ? - if(userObject.tag=="Grabable") - { - Mug mug = userObject.GetComponent(); - if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop - { - Debug.Log(gameObject.name+" fill "+userObject.name+ " with "+product_name); - mug.fill(new Consumable(product_name,product_value,product_sprite)); - stock--; - return false; - } - else - { - Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock); - return false; - } - } - else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug - { - Tavernkeeper_controller player = userObject.GetComponent(); - return false; - } - else - { - return false; - } - } - else - { - Debug.Log(gameObject.name+" doesn't handle : "+userObject); - return false; - } - } + public abstract bool use(GameObject userObject); // Start is called before the first frame update void Start() @@ -62,10 +21,4 @@ public class Workshop : MonoBehaviour, IUsable if(gameObject.tag != "Usable") Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly"); } - - // Update is called once per frame - void Update() - { - - } }