diff --git a/Assets/Scenes/Level01.unity b/Assets/Scenes/Level01.unity index 4bef6414699500a823b838b3e94f9d0399d644db..c01aff7caaa71255659ad3e3b5a37fa21998ec7b 100644 --- a/Assets/Scenes/Level01.unity +++ b/Assets/Scenes/Level01.unity @@ -692,7 +692,7 @@ MonoBehaviour: - {fileID: 933997770} pet: {fileID: 0} petCount: 0 - isPaused: 0 + isPaused: 1 spawnCount: 0 isTimer: 1 --- !u!114 &14871715 diff --git a/Assets/Scripts/DataUtils/GameData.cs b/Assets/Scripts/DataUtils/GameData.cs index 9355d8a2cb662d5c1ae5496e63a6cc0bcac92c7c..7ad37e962fe64685aec28a49a561cca0e97689f8 100644 --- a/Assets/Scripts/DataUtils/GameData.cs +++ b/Assets/Scripts/DataUtils/GameData.cs @@ -20,6 +20,8 @@ public class GameData public int currentQuest; public float shopKeeperTime; public string timestamp; + public bool isShopKeeper; + public float increment; // Constructor buat default values kalau new game public GameData() @@ -36,8 +38,10 @@ public class GameData this.currentWeapon = 0; this.currentScene = 1; this.currentQuest = 0; - this.shopKeeperTime = 120f; + this.shopKeeperTime = 60f; this.timestamp = string.Empty; + this.isShopKeeper = false; + this.increment = 50; } public GameData(int currentScene) @@ -56,6 +60,8 @@ public class GameData this.currentQuest = 0; this.shopKeeperTime = 120f; this.timestamp = string.Empty; + this.isShopKeeper = false; + this.increment = 50; } } diff --git a/Assets/Scripts/Helpers/SaveRadius.cs b/Assets/Scripts/Helpers/SaveRadius.cs index 04646be33a8589a5394d8889c93d2182f70060dd..2c215577f2da63009770f458b52fb44c33236ba1 100644 --- a/Assets/Scripts/Helpers/SaveRadius.cs +++ b/Assets/Scripts/Helpers/SaveRadius.cs @@ -49,7 +49,7 @@ public class SaveRadius : MonoBehaviour { saveUI.text = "Game Saved Successfully"; - yield return new WaitForSeconds(1f); + yield return new WaitForSeconds(2f); saveUI.text = "Press Z to save the game"; } diff --git a/Assets/Scripts/Managers/DataPersistenceManager.cs b/Assets/Scripts/Managers/DataPersistenceManager.cs index 1019d91eb51f762b329162ada31091b979a07115..a7fabd94d526f7501205767253e13f23496ebf6d 100644 --- a/Assets/Scripts/Managers/DataPersistenceManager.cs +++ b/Assets/Scripts/Managers/DataPersistenceManager.cs @@ -166,6 +166,7 @@ public class DataPersistenceManager : MonoBehaviour for (int i = dataPersistenceList.Count-1; i >= 0; i--) { dataPersistenceList[i].LoadData(gameData); + Debug.Log(dataPersistenceList[i].ToString()); } Debug.Log("Load Game called"); diff --git a/Assets/Scripts/Managers/EnemyManager.cs b/Assets/Scripts/Managers/EnemyManager.cs index 2102e0be836826380a0f03b00324ea04727508be..80a35241be96edf45dc36f405fea0f9ee01e3c6d 100644 --- a/Assets/Scripts/Managers/EnemyManager.cs +++ b/Assets/Scripts/Managers/EnemyManager.cs @@ -98,7 +98,7 @@ namespace Nightmare { for (int i = 0; i < petCount; i++) { - GameObject instantiatedItem = Instantiate(pet, enemyInstance.transform.position, Quaternion.identity); + GameObject instantiatedItem = Instantiate(pet, enemyInstance.transform); instantiatedItem.transform.SetParent(enemyInstance.transform); } } diff --git a/Assets/Scripts/Managers/LevelManager.cs b/Assets/Scripts/Managers/LevelManager.cs index 7da27f2b44f0c9e72a543a717a64e7d5424548a7..b521a2b75281506496ac173507ed4173dc919564 100644 --- a/Assets/Scripts/Managers/LevelManager.cs +++ b/Assets/Scripts/Managers/LevelManager.cs @@ -46,6 +46,7 @@ namespace Nightmare public SaveRadius saveHouse; public InstructionManager instructionManager; public bool skipQuest = false; + public bool safe = true; public static LevelManager Instance; private void Awake() @@ -65,17 +66,16 @@ namespace Nightmare { this.currentIndex = data.currentScene; this.currentQuest = data.currentQuest; + this.isShopKeeper = data.isShopKeeper; + this.safe = false; Debug.Log("Load data scene and quest " + this.currentIndex + " " + this.currentQuest); } public void SaveData(ref GameData data) { data.currentScene = this.currentIndex; - if (this.currentQuest >= 1) - { - int indexQuest = currentQuest; - data.currentQuest = this.currentQuest-1; - } + data.currentQuest = this.currentQuest; + data.isShopKeeper = this.isShopKeeper; Debug.Log("Save data scene and quest " + this.currentIndex + " " + this.currentQuest); } @@ -101,7 +101,13 @@ namespace Nightmare } else { announcementDuration -= Time.deltaTime; - } + } + + if (!safe) + { + FindObjects(); + safe = true; + } // Track Shopkeeper if (isShopKeeper) @@ -628,6 +634,53 @@ namespace Nightmare skipQuest = false; } + public void FindObjects() + { + if (shopKeeper == null) + { + shopKeeper = GameObject.FindGameObjectWithTag("ShopKeeper"); + timerCanvas = shopKeeper.GetComponent<CollisionDetection>().timerObject; + } + + if (saveHouse == null) + { + GameObject house = GameObject.FindGameObjectWithTag("SaveHouse"); + saveHouse = house.GetComponent<SaveRadius>(); + } + + if (instructionManager == null) + { + instructionManager = FindObjectOfType<InstructionManager>(); + } + + // Get announcement + if (announcementText == null) + { + GameObject obj = GameObject.FindGameObjectWithTag("Announcement"); + announcementText = obj.GetComponent<TMPro.TextMeshProUGUI>(); + } + + if (questText == null) + { + // Get quest + GameObject obj2 = GameObject.FindGameObjectWithTag("Quest"); + questText = obj2.GetComponent<TMPro.TextMeshProUGUI>(); + if (questText) questText.text = ""; + } + + if (enemyManager == null) + { + // Get enemy manager + enemyManager = FindObjectsOfType<EnemyManager>(); + + foreach (EnemyManager enemyManager in enemyManager) + { + enemyManager.isPaused = true; + enemyManager.isTimer = false; + } + } + } + public void SkipQuest() { if (skipQuest) diff --git a/Assets/Scripts/Managers/RewardManager.cs b/Assets/Scripts/Managers/RewardManager.cs index 66e6b2735bad837ed74b446c44f70f69e0b67aca..e3d164f204ce398b7f6984495a97f2f989c633f8 100644 --- a/Assets/Scripts/Managers/RewardManager.cs +++ b/Assets/Scripts/Managers/RewardManager.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class RewardManager : MonoBehaviour +public class RewardManager : MonoBehaviour, IDataPersistence { public PlayerCoin coins; public float increment = 50; @@ -18,4 +18,16 @@ public class RewardManager : MonoBehaviour currentReward = LevelManager.Instance.currentQuest + 1; } } + + public void LoadData(GameData data) + { + this.increment = data.increment; + this.currentReward = data.currentReward; + } + + public void SaveData(ref GameData data) + { + data.increment = this.increment; + data.currentReward = this.currentReward; + } } diff --git a/Assets/Scripts/Player/PlayerCoin.cs b/Assets/Scripts/Player/PlayerCoin.cs index dcbe00bb04a9a0a52dafffb21d1b2b422692e255..5ab888285a3bfa128e24b4cdcbf0eeb4913f3b4c 100644 --- a/Assets/Scripts/Player/PlayerCoin.cs +++ b/Assets/Scripts/Player/PlayerCoin.cs @@ -2,16 +2,10 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class PlayerCoin : MonoBehaviour +public class PlayerCoin : MonoBehaviour, IDataPersistence { public float coin = 0; - // Start is called before the first frame update - void Start() - { - coin = 0; - } - public void AddCoins(float coins) { coin += coins; @@ -22,4 +16,14 @@ public class PlayerCoin : MonoBehaviour coin -= coins; if (coin < 0) coin = 0; } + + public void LoadData(GameData data) + { + this.coin = data.coin; + } + + public void SaveData(ref GameData data) + { + data.coin = this.coin; + } }