TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

162 lines
3.4 KiB
C#

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<Weapon>("config/");
return totalItems.Length - 1;
}
public bool isStackable(int id)
{
if (id == -1)
{
return false;
}
return OnDemandLoader.Load<Weapon>("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<Weapon>("config/" + id).WearSlot;
}
public bool isWearable(int id)
{
if (id == -1)
{
return false;
}
return OnDemandLoader.Load<Weapon>("config/" + id).WearSlot != -1;
}
public string getProjectile(int id)
{
if (id == -1)
{
return "";
}
return OnDemandLoader.Load<Weapon>("config/" + id).projectile;
}
public string getFireSound(int id)
{
if (id == -1)
{
return "";
}
return OnDemandLoader.Load<Weapon>("config/" + id).fireSound;
}
public string getEmptyShotSound(int id)
{
if (id == -1)
{
return "";
}
return OnDemandLoader.Load<Weapon>("config/" + id).emptySound;
}
public string getItemName(int id)
{
if (id == -1)
{
return "";
}
//Debug.Log($"Item Def getItemName ID: {id}");
string itemName = OnDemandLoader.Load<Weapon>("config/" + id).name;
return $"<b>{itemName}</b>";
}
public string getItemLevel(int id)
{
if (id == -1) return "";
Weapon itemData = OnDemandLoader.Load<Weapon>("config/" + id);
if (!itemData.Forgeable) return "";
int itemLevel = (int)itemData.WeaponLevel + 1; //negate zero-indexing
return $"[<color=#FFFFFF><b>Level {itemLevel}</b></color>]";
}
public float getReloadTime(int id)
{
if (id == -1)
{
return 0.0f;
}
return OnDemandLoader.Load<Weapon>("config/" + id).reloadTime;
}
public int getMaxAmmo(int id)
{
if (id == -1)
{
return 0;
}
return OnDemandLoader.Load<Weapon>("config/" + id).ammoClipAmount;
}
public Weapon.WEAPON_TYPE getType(int id)
{
if (id == -1)
{
return Weapon.WEAPON_TYPE.NONE;
}
return OnDemandLoader.Load<Weapon>("config/" + id).weaponType;
}
public string getDescription(int id)
{
if (id == -1)
{
return "";
}
string description = OnDemandLoader.Load<Weapon>("config/" + id).description;
return $"<color=#FFFFFF>{description}</color>";
}
public bool isThrowable(int id)
{
if (id == -1)
{
return false;
}
return OnDemandLoader.Load<Weapon>("config/" + id).isThrowable;
}
}