Refactored inventory system
This commit is contained in:
@@ -226,21 +226,19 @@ namespace reallife_gamemode.Server.Managers
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(itemId));
|
||||
IItem iItem = InventoryManager.GetItemById(fItem.ItemId);
|
||||
|
||||
List<UserItem> itemList = player.GetUser().GetItems();
|
||||
UserItem userItem = itemList.FirstOrDefault(i => i.ItemId == iItem.Id);
|
||||
IItem iItem = GetItemById(fItem.ItemId);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "use":
|
||||
case "use":
|
||||
player.SendChatMessage("use item: " + iItem.Name);
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Essen existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
if (fItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
@@ -248,9 +246,10 @@ namespace reallife_gamemode.Server.Managers
|
||||
|
||||
if (iItem is IUsableItem usableItemObj)
|
||||
{
|
||||
usableItemObj.Use(userItem, player);
|
||||
usableItemObj.Use(fItem);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
else player.SendChatMessage("not useable");
|
||||
break;
|
||||
case "drop":
|
||||
|
||||
@@ -260,17 +259,18 @@ namespace reallife_gamemode.Server.Managers
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
if (fItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj2)
|
||||
if (iItem is IDroppableItem usableItemObj2)
|
||||
{
|
||||
Random r = new Random();
|
||||
//fItem.Amount -= amount;
|
||||
usableItemObj2.Drop(userItem, player);
|
||||
NAPI.Object.CreateObject(3777723516, new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8), new Vector3(0, 0, r.Next(0, 360)), 0);
|
||||
NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.6), 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
|
||||
fItem.Amount -= amount;
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user