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

@@ -28,6 +28,8 @@ namespace reallife_gamemode
NAPI.Server.SetAutoRespawnAfterDeath(false); NAPI.Server.SetAutoRespawnAfterDeath(false);
NAPI.Data.SetWorldData("playerCreatorDimension", 0); NAPI.Data.SetWorldData("playerCreatorDimension", 0);
InventoryManager.LoadItems();
TuningManager.AddTuningGarage(new Vector3(-341, -134, 38.5), new Vector3(-334, -143, 41)); TuningManager.AddTuningGarage(new Vector3(-341, -134, 38.5), new Vector3(-334, -143, 41));
using (var context = new DatabaseContext()) using (var context = new DatabaseContext())

View File

@@ -36,12 +36,12 @@ namespace reallife_gamemode.Server.Commands
return; return;
} }
List<UserItem> itemList = player.GetData("items"); List<UserItem> itemList = player.GetUser().GetItems();
foreach (var item in itemList) foreach (var item in itemList)
{ {
IItem iitem = item; IItem iitem = InventoryManager.GetItemById(item.ItemId);
player.SendChatMessage(item. + ); player.SendChatMessage("Item: ~g~" + iitem.Name);
} }
} }

View File

@@ -130,6 +130,13 @@ namespace reallife_gamemode.Server.Entities
//TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt. //TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt.
} }
public List<UserItem> GetItems()
{
using(var dbContext = new DatabaseContext())
{
return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id);
}
}
public bool IsAdmin(AdminLevel level) => AdminLevel >= level; public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
} }
} }

View File

@@ -1,7 +1,10 @@
using reallife_gamemode.Model; using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Inventory.Interfaces; using reallife_gamemode.Server.Inventory.Interfaces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
/** /**
@@ -12,11 +15,35 @@ using System.Text;
namespace reallife_gamemode.Server.Managers 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);
} }
} }
} }