Added items load

This commit is contained in:
Lennart Kampshoff
2018-10-27 13:18:22 +02:00
parent 39cb03b2ec
commit cf10c52ab0
4 changed files with 43 additions and 7 deletions

View File

@@ -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);
}
}
}