Finish interaction on items
This commit is contained in:
@@ -223,12 +223,61 @@ namespace reallife_gamemode.Server.Managers
|
||||
[RemoteEvent("itemInteract")]
|
||||
public void ItemInteract(Client player, string type, string itemId, int amount)
|
||||
{
|
||||
switch (type)
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
case "use":
|
||||
break;
|
||||
case "drop":
|
||||
break;
|
||||
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);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "use":
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Essen existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj)
|
||||
{
|
||||
usableItemObj.Use(userItem, player);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
fItem.Amount -= amount;
|
||||
}
|
||||
break;
|
||||
case "drop":
|
||||
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Item existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj2)
|
||||
{
|
||||
fItem.Amount -= amount;
|
||||
usableItemObj2.Use(userItem, player);
|
||||
NAPI.Object.CreateObject(1017479830, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), new Vector3(0, 0, 0), 0);
|
||||
NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", new Vector3(player.Position.X, player.Position.Y, player.Position.Z), 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user