コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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");
            }
        }
コード例 #3
0
        internal static void openShop(IPlayer player, Server_Shops shopPos)
        {
            try
            {
                if (player == null || !player.Exists)
                {
                    return;
                }
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                int charId = User.GetPlayerOnline(player);
                if (charId <= 0)
                {
                    return;
                }

                if (shopPos.faction > 0 && shopPos.faction != 0)
                {
                    if (!ServerFactions.IsCharacterInAnyFaction(charId))
                    {
                        HUDHandler.SendNotification(player, 3, 2500, "Kein Zugriff [1]"); return;
                    }
                    if (ServerFactions.GetCharacterFactionId(charId) != shopPos.faction)
                    {
                        HUDHandler.SendNotification(player, 3, 2500, $"Kein Zugriff [{shopPos.faction} - {ServerFactions.GetCharacterFactionId(charId)}]"); return;
                    }
                }

                if (shopPos.neededLicense != "None" && !Characters.HasCharacterPermission(charId, shopPos.neededLicense))
                {
                    HUDHandler.SendNotification(player, 3, 5000, $"Du hast hier keinen Zugriff drauf.");
                    stopwatch.Stop();
                    if (stopwatch.Elapsed.Milliseconds > 30)
                    {
                        Alt.Log($"{charId} - openShop benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    }
                    return;
                }

                if (shopPos.isOnlySelling == false)
                {
                    Global.mGlobal.VirtualAPI.TriggerClientEventSafe(player, "Client:Shop:shopCEFCreateCEF", ServerShopsItems.GetShopShopItems(shopPos.shopId), shopPos.shopId, shopPos.isOnlySelling);
                    stopwatch.Stop();
                    if (stopwatch.Elapsed.Milliseconds > 30)
                    {
                        Alt.Log($"{charId} - openShop benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    }
                    return;
                }
                else if (shopPos.isOnlySelling == true)
                {
                    Global.mGlobal.VirtualAPI.TriggerClientEventSafe(player, "Client:Shop:shopCEFCreateCEF", ServerShopsItems.GetShopSellItems(charId, shopPos.shopId), shopPos.shopId, shopPos.isOnlySelling);
                    stopwatch.Stop();
                    if (stopwatch.Elapsed.Milliseconds > 30)
                    {
                        Alt.Log($"{charId} - openShop benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    }
                    return;
                }
                stopwatch.Stop();
                if (stopwatch.Elapsed.Milliseconds > 30)
                {
                    Alt.Log($"{charId} - openShop benötigte {stopwatch.Elapsed.Milliseconds}ms");
                }
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }