Add /eat command

This commit is contained in:
VegaZ
2018-10-28 00:33:58 +02:00
parent cf10c52ab0
commit 052e632082
6 changed files with 85 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Commands;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Inventory.Interfaces;
using System;
using System.Collections.Generic;
@@ -45,5 +47,28 @@ namespace reallife_gamemode.Server.Managers
{
return itemList.Find(i => i.Id == id);
}
public static IItem GetItemByName(string name)
{
return itemList.Find(i => i.Name == name);
}
public static void RemoveUserItem(Entities.User user, UserItem item)
{
using (var dbContext = new DatabaseContext())
{
var userItem = dbContext.UserItems.FirstOrDefault(i => i.Id == item.Id);
userItem.Amount--;
dbContext.SaveChanges();
if(userItem.Amount == 0)
{
dbContext.Remove(userItem);
dbContext.SaveChanges();
}
}
}
}
}