From 998cc81e0afe62bfb78a35c6dcc9b78154dc684a Mon Sep 17 00:00:00 2001 From: Antoine H Date: Thu, 7 Jan 2021 14:45:19 +0100 Subject: [PATCH] First Reward system (Gold) --- Assets/Scenes/Tests/SampleScene.unity | 2 +- Assets/Scripts/Client_controller.cs | 10 +++++++--- Assets/Scripts/GameSystems/ClientManager.cs | 8 +++++++- Assets/Scripts/GameSystems/GameSystem.cs | 15 +++++++++++++++ Assets/Scripts/Mug.cs | 4 +++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index be14f23..ed56c1d 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -7784,7 +7784,7 @@ MonoBehaviour: m_EditorClassIdentifier: prepTime: 2 product_name: beer - product_value: 1 + product_value: 10 product_sprite: {fileID: 21300000, guid: 17d59b2d4d882c04480a40119a442279, type: 3} stock: 5 --- !u!61 &1165291009 diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index 4eaa481..398b4f4 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -82,13 +82,13 @@ public class Client_controller : MonoBehaviour, IUsable } else { - Debug.Log("Display order (or something else) of "+gameObject.name); + Debug.Log(gameObject.name+" doesn't want that"); return false; } } else { - Debug.Log("Display order (or something else) of "+gameObject.name); + Debug.Log(gameObject.name+" doesn't want that"); return false; } } @@ -161,7 +161,11 @@ public class Client_controller : MonoBehaviour, IUsable Mug obj = currentMug.GetComponent(); if(obj !=null) { - obj.consume(); + //Reward + Consumable content = obj.consume(); + int money = (int)(content.Value*(1.0f+waitTimer/waitingTime)); //Reward = value order + Tips (value * waitTime) + ClientManager.Instance.clientReward(money); + //Drop mug obj.drop(gameObject.transform.position+ (Vector3)Vector2.down * 0.2f); currentMug=null; diff --git a/Assets/Scripts/GameSystems/ClientManager.cs b/Assets/Scripts/GameSystems/ClientManager.cs index 4c0c02c..92cb6ab 100644 --- a/Assets/Scripts/GameSystems/ClientManager.cs +++ b/Assets/Scripts/GameSystems/ClientManager.cs @@ -6,7 +6,7 @@ using UnityEditor; //Define the system managing the clients. (Singleton) public sealed class ClientManager : MonoBehaviour { - int nbMaxClients = 10; + int nbMaxClients = 1; bool clientSpawnReady = false; float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) float maxTimeNewClients = 2.0f; @@ -40,6 +40,12 @@ public sealed class ClientManager : MonoBehaviour return false; //No new client } + //TODO: Reputation + public void clientReward(int money) + { + GameSystem.Instance.gold+=money; + } + //Destroy a client public void clientLeave(GameObject client) { diff --git a/Assets/Scripts/GameSystems/GameSystem.cs b/Assets/Scripts/GameSystems/GameSystem.cs index 46d1c31..a2cf4c3 100644 --- a/Assets/Scripts/GameSystems/GameSystem.cs +++ b/Assets/Scripts/GameSystems/GameSystem.cs @@ -14,6 +14,20 @@ public sealed class GameSystem : MonoBehaviour float slowScale = 0.5f; //Default scale for slow mode private float fixedDeltaTime; + //TODO : Effect on gold change + //Money + private int _gold; + public int gold + { + get{return _gold;} + set{ + if(value<0) + value=0; + _gold = value; + Debug.Log("Gold : "+_gold); + } + } + public void startService() { serviceTimer=serviceTime; @@ -71,6 +85,7 @@ public sealed class GameSystem : MonoBehaviour void Start() { startService(); + gold=0; } // Update is called once per frame diff --git a/Assets/Scripts/Mug.cs b/Assets/Scripts/Mug.cs index b989baf..a4f98d1 100644 --- a/Assets/Scripts/Mug.cs +++ b/Assets/Scripts/Mug.cs @@ -43,10 +43,12 @@ public class Mug : MonoBehaviour, IGrabable Debug.Log(gameObject.name+" cannot be filled (already full) with "+new_content.Type); } } - public void consume() //Empty Mug of its Consumable + public Consumable consume() //Return Mug content and empty it { + Consumable output = content; content=null; dirty = true; //Used and dirty + return output; } // Start is called before the first frame update