public async Task sellShopItem(IPlayer player, int shopId, int amount, string itemname) { if (player == null || !player.Exists || shopId <= 0 || amount <= 0 || itemname == "") { return; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs()) { HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return; } if (!player.Position.IsInRange(ServerShops.GetShopPosition(shopId), 3f)) { HUDHandler.SendNotification(player, 3, 5000, "Du bist zu weit entfernt."); return; } int charId = User.GetPlayerOnline(player); if (charId == 0) { return; } if (ServerShops.GetShopNeededLicense(shopId) != "None" && !Characters.HasCharacterPermission(charId, ServerShops.GetShopNeededLicense(shopId))) { HUDHandler.SendNotification(player, 3, 5000, "Du hast hier keinen Zugriff drauf."); return; } if (!CharactersInventory.ExistCharacterItem(charId, itemname, "inventory") && !CharactersInventory.ExistCharacterItem(charId, itemname, "backpack")) { HUDHandler.SendNotification(player, 3, 5000, "Diesen Gegenstand besitzt du nicht."); return; } int itemSellPrice = ServerShopsItems.GetShopItemPrice(shopId, itemname); //Verkaufpreis pro Item int invItemAmount = CharactersInventory.GetCharacterItemAmount(charId, itemname, "inventory"); //Anzahl an Items im Inventar int backpackItemAmount = CharactersInventory.GetCharacterItemAmount(charId, itemname, "backpack"); //Anzahl an Items im Rucksack if (invItemAmount + backpackItemAmount < amount) { HUDHandler.SendNotification(player, 3, 5000, "Soviele Gegenstände hast du nicht zum Verkauf dabei."); return; } var removeFromInventory = Math.Min(amount, invItemAmount); if (removeFromInventory > 0) { CharactersInventory.RemoveCharacterItemAmount(charId, itemname, removeFromInventory, "inventory"); } var itemsLeft = amount - removeFromInventory; if (itemsLeft > 0) { CharactersInventory.RemoveCharacterItemAmount(charId, itemname, itemsLeft, "backpack"); } HUDHandler.SendNotification(player, 2, 5000, $"Du hast {amount}x {itemname} für {itemSellPrice * amount}$ verkauft."); CharactersInventory.AddCharacterItem(charId, "Bargeld", amount * itemSellPrice, "inventory"); stopwatch.Stop(); if (stopwatch.Elapsed.Milliseconds > 30) { Alt.Log($"{charId} - sellShopItem benötigte {stopwatch.Elapsed.Milliseconds}ms"); } }
public async Task buyShopItem(IPlayer player, int shopId, int amount, string itemname) { if (player == null || !player.Exists || shopId <= 0 || amount <= 0 || itemname == "") { return; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs()) { HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return; } if (!player.Position.IsInRange(ServerShops.GetShopPosition(shopId), 3f)) { HUDHandler.SendNotification(player, 3, 5000, $"Du bist zu weit vom Shop entfernt."); return; } int charId = User.GetPlayerOnline(player); if (charId == 0) { return; } if (ServerShops.GetShopNeededLicense(shopId) != "None" && !Characters.HasCharacterPermission(charId, ServerShops.GetShopNeededLicense(shopId))) { HUDHandler.SendNotification(player, 3, 5000, $"Du hast hier keinen Zugriff drauf."); return; } float itemWeight = ServerItems.GetItemWeight(itemname) * amount; float invWeight = CharactersInventory.GetCharacterItemWeight(charId, "inventory"); float backpackWeight = CharactersInventory.GetCharacterItemWeight(charId, "backpack"); int itemPrice = ServerShopsItems.GetShopItemPrice(shopId, itemname) * amount; int shopFaction = ServerShops.GetShopFaction(shopId); if (ServerShopsItems.GetShopItemAmount(shopId, itemname) < amount) { HUDHandler.SendNotification(player, 3, 5000, $"Soviele Gegenstände hat der Shop nicht auf Lager."); return; } if (invWeight + itemWeight > 15f && backpackWeight + itemWeight > Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(charId))) { HUDHandler.SendNotification(player, 3, 5000, $"Du hast nicht genug Platz in deinen Taschen."); return; } if (invWeight + itemWeight <= 15f) { if (shopFaction > 0 && shopFaction != 0) { if (!ServerFactions.IsCharacterInAnyFaction(charId)) { HUDHandler.SendNotification(player, 3, 2500, "Du hast hier keinen Zugriff drauf [CODE1-2]."); return; } if (ServerFactions.GetCharacterFactionId(charId) != shopFaction) { HUDHandler.SendNotification(player, 3, 2500, $"Du hast hier keinen Zugriff drauf (Gefordert: {shopFaction} - Deine: {ServerFactions.GetCharacterFactionId(charId)}."); return; } if (ServerFactions.GetFactionBankMoney(shopFaction) < itemPrice) { HUDHandler.SendNotification(player, 3, 2500, "Die Frakton hat nicht genügend Geld auf dem Fraktionskonto."); return; } ServerFactions.SetFactionBankMoney(shopFaction, ServerFactions.GetFactionBankMoney(shopFaction) - itemPrice); LoggingService.NewFactionLog(shopFaction, charId, 0, "shop", $"{Characters.GetCharacterName(charId)} hat {itemname} ({amount}x) für {itemPrice}$ erworben."); } else { if (!CharactersInventory.ExistCharacterItem(charId, "Bargeld", "inventory") || CharactersInventory.GetCharacterItemAmount(charId, "Bargeld", "inventory") < itemPrice) { HUDHandler.SendNotification(player, 3, 2500, "Du hast nicht genügend Geld dabei."); return; } CharactersInventory.RemoveCharacterItemAmount(charId, "Bargeld", itemPrice, "inventory"); } CharactersInventory.AddCharacterItem(charId, itemname, amount, "inventory"); HUDHandler.SendNotification(player, 2, 5000, $"Du hast {itemname} ({amount}x) für {itemPrice} gekauft (Lagerort: Inventar)."); stopwatch.Stop(); if (stopwatch.Elapsed.Milliseconds > 30) { Alt.Log($"{charId} - buyShopItem benötigte {stopwatch.Elapsed.Milliseconds}ms"); } return; } if (Characters.GetCharacterBackpack(charId) != "None" && backpackWeight + itemWeight <= Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(charId))) { if (shopFaction > 0 && shopFaction != 0) { if (!ServerFactions.IsCharacterInAnyFaction(charId)) { HUDHandler.SendNotification(player, 3, 2500, "Du hast hier keinen Zugriff drauf [CODE1]."); return; } if (ServerFactions.GetCharacterFactionId(charId) != shopFaction) { HUDHandler.SendNotification(player, 3, 2500, $"Du hast hier keinen Zugriff drauf (Gefordert: {shopFaction} - Deine: {ServerFactions.GetCharacterFactionId(charId)}."); return; } if (ServerFactions.GetFactionBankMoney(shopFaction) < itemPrice) { HUDHandler.SendNotification(player, 3, 2500, "Die Frakton hat nicht genügend Geld auf dem Fraktionskonto."); return; } ServerFactions.SetFactionBankMoney(shopFaction, ServerFactions.GetFactionBankMoney(shopFaction) - itemPrice); LoggingService.NewFactionLog(shopFaction, charId, 0, "shop", $"{Characters.GetCharacterName(charId)} hat {itemname} ({amount}x) für {itemPrice}$ erworben."); } else { if (!CharactersInventory.ExistCharacterItem(charId, "Bargeld", "inventory") || CharactersInventory.GetCharacterItemAmount(charId, "Bargeld", "inventory") < itemPrice) { HUDHandler.SendNotification(player, 3, 2500, "Du hast nicht genügend Geld dabei."); return; } CharactersInventory.RemoveCharacterItemAmount(charId, "Bargeld", itemPrice, "inventory"); } CharactersInventory.AddCharacterItem(charId, itemname, amount, "backpack"); HUDHandler.SendNotification(player, 2, 5000, $"Du hast {itemname} ({amount}x) für {itemPrice} gekauft (Lagerort: Rucksack / Tasche)."); stopwatch.Stop(); if (stopwatch.Elapsed.Milliseconds > 30) { Alt.Log($"{charId} - buyShopItem benötigte {stopwatch.Elapsed.Milliseconds}ms"); } return; } }