Finish interaction on items

This commit is contained in:
VegaZ
2018-12-18 23:22:27 +01:00
parent 0fa58ca680
commit f9e488b329
2 changed files with 62 additions and 21 deletions

View File

@@ -107,16 +107,10 @@ mp.events.add("removeItem", (userItemId, amount) => {
arrIndex = i; arrIndex = i;
} }
} }
if (amount === "stack") { inventoryWeight -= parseInt(items[arrIndex][2]) * parseInt(items[arrIndex][3]);
items[arrIndex][4] = "-1"; items[arrIndex][3] -= amount;
inventoryWeight -= parseInt(items[arrIndex][2]) * parseInt(items[arrIndex][3]); if (items[arrIndex][3] === 0) {
items.splice(arrIndex, 1); items.splice(arrIndex, 1);
} else if (amount === "one") {
items[arrIndex][3]--;
inventoryWeight -= items[arrIndex][2];
if (items[arrIndex][3] === 0) {
items.splice(arrIndex, 1);
}
} }
} }
}); });
@@ -479,7 +473,7 @@ function ifMouseSelectRadial(cX2, cY2) {
// radialSelect = "right"; // radialSelect = "right";
// rightRColor = 255; // rightRColor = 255;
// return true; // return true;
//} else { else {
upRColor = 222; upRColor = 222;
downRColor = 222; downRColor = 222;
leftRColor = 222; leftRColor = 222;
@@ -496,7 +490,7 @@ mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, world
if (show) { if (show) {
//LINKE MAUSTASTE //LINKE MAUSTASTE
//RUNTER //RUNTER
if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false && itemRadial === false) { if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) {
mouseLDown = true; mouseLDown = true;
@@ -504,26 +498,24 @@ mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, world
dragItem = hoverItem; dragItem = hoverItem;
oldDragSlot = items[dragItem][4]; oldDragSlot = items[dragItem][4];
items[dragItem][4] = "-1"; items[dragItem][4] = "-1";
} else if (ifMouseSelectRadial(x, y) && dragItem === null) { } else if (ifMouseSelectRadial(x, y)) {
switch (radialSelect) { switch (radialSelect) {
case "up": case "up":
var dropInput = new InputHelper("Wie viel Items möchtest du wegwerfen?"); var dropInput = new InputHelper("Wie viel Items möchtest du wegwerfen?");
dropInput.show(); dropInput.show();
dropInput.getValue((data) => { dropInput.getValue((data) => {
var amount = parseInt(data); var amount = parseInt(data);
if (isNaN(amount)) { if (isNaN(amount) || amount < 1) {
mp.game.graphics.notify('~r~Du musst eine Nummer eingeben!'); mp.game.graphics.notify('~r~Du musst eine Zahl größer als 0 eingeben!');
return; return;
} }
mp.events.callRemote('itemInteract', "drop", items[clickedItem][5], amount); mp.events.callRemote('itemInteract', "drop", items[clickedItem][5], amount);
items[clickedItem][3] -= amount;
}); });
itemRadial = false; itemRadial = false;
break; break;
case "down": case "down":
mp.events.callRemote('itemInteract', "use", items[clickedItem][5], 1); mp.events.callRemote('itemInteract', "use", items[clickedItem][5], 1);
items[clickedItem][3]--;
itemRadial = false; itemRadial = false;
break; break;
case "left": case "left":

View File

@@ -223,12 +223,61 @@ namespace reallife_gamemode.Server.Managers
[RemoteEvent("itemInteract")] [RemoteEvent("itemInteract")]
public void ItemInteract(Client player, string type, string itemId, int amount) public void ItemInteract(Client player, string type, string itemId, int amount)
{ {
switch (type) using (var context = new DatabaseContext())
{ {
case "use": UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(itemId));
break; IItem iItem = InventoryManager.GetItemById(fItem.ItemId);
case "drop":
break; 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();
} }
} }
} }