50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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;
|
|
|
|
/**
|
|
* @overview Life of German Reallife - Managers InventoryManager (InventoryManager.cs)
|
|
* @author hydrant, VegaZ
|
|
* @copyright (c) 2008 - 2018 Life of German
|
|
*/
|
|
|
|
namespace reallife_gamemode.Server.Managers
|
|
{
|
|
public class InventoryManager : Script
|
|
{
|
|
public static List<IItem> itemList;
|
|
|
|
public static void LoadItems()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|