using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ItemDef { // private singleton instance private static ItemDef instance = new ItemDef(); // Implement Singleton design public static ItemDef GetInstance() { if (instance == null) { instance = new ItemDef(); } return instance; } public int GetTotalItems() { Weapon[] totalItems = OnDemandLoader.LoadAll("config/"); return totalItems.Length - 1; } public bool isStackable(int id) { if (id == -1) { return false; } return OnDemandLoader.Load("config/" + id).maxStack != -1; } public int getItemID(int id) { if (id == -1) return -1; return id; } public int getItemSlot(int id) { if (id == -1) { return -1; } return OnDemandLoader.Load("config/" + id).WearSlot; } public bool isWearable(int id) { if (id == -1) { return false; } return OnDemandLoader.Load("config/" + id).WearSlot != -1; } public string getProjectile(int id) { if (id == -1) { return ""; } return OnDemandLoader.Load("config/" + id).projectile; } public string getFireSound(int id) { if (id == -1) { return ""; } return OnDemandLoader.Load("config/" + id).fireSound; } public string getEmptyShotSound(int id) { if (id == -1) { return ""; } return OnDemandLoader.Load("config/" + id).emptySound; } public string getItemName(int id) { if (id == -1) { return ""; } //Debug.Log($"Item Def getItemName ID: {id}"); string itemName = OnDemandLoader.Load("config/" + id).name; return $"{itemName}"; } public string getItemLevel(int id) { if (id == -1) return ""; Weapon itemData = OnDemandLoader.Load("config/" + id); if (!itemData.Forgeable) return ""; int itemLevel = (int)itemData.WeaponLevel + 1; //negate zero-indexing return $"[Level {itemLevel}]"; } public float getReloadTime(int id) { if (id == -1) { return 0.0f; } return OnDemandLoader.Load("config/" + id).reloadTime; } public int getMaxAmmo(int id) { if (id == -1) { return 0; } return OnDemandLoader.Load("config/" + id).ammoClipAmount; } public Weapon.WEAPON_TYPE getType(int id) { if (id == -1) { return Weapon.WEAPON_TYPE.NONE; } return OnDemandLoader.Load("config/" + id).weaponType; } public string getDescription(int id) { if (id == -1) { return ""; } string description = OnDemandLoader.Load("config/" + id).description; return $"{description}"; } public bool isThrowable(int id) { if (id == -1) { return false; } return OnDemandLoader.Load("config/" + id).isThrowable; } }