Added items load
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using reallife_gamemode.Model;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
@@ -12,11 +15,35 @@ using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class InventoryManager
|
||||
public class InventoryManager : Script
|
||||
{
|
||||
public static IItem GetItemById(this int id, DatabaseContext context = null)
|
||||
public static List<IItem> itemList;
|
||||
|
||||
public static void LoadItems()
|
||||
{
|
||||
return
|
||||
itemList = new List<IItem>();
|
||||
|
||||
Type[] allTypes = Assembly.GetExecutingAssembly().GetTypes();
|
||||
foreach (Type item in allTypes)
|
||||
{
|
||||
if (item.GetInterfaces().Contains((typeof(IItem))))
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"Loading Item {item.Name}");
|
||||
if (Activator.CreateInstance(item) is IItem o)
|
||||
{
|
||||
if(GetItemById(o.Id) != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Double ItemID found: {o.Id} | {o.Name}");
|
||||
}
|
||||
itemList.Add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IItem GetItemById(int id)
|
||||
{
|
||||
return itemList.Find(i => i.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user