示例#1
0
        public ShopManager()
        {
            DataTable shopTable = DatabaseUtils.ReturnQuery("SELECT * FROM shop");

            for (int i = 0; i < shopTable.Rows.Count; i++)
            {
                int  npcId = (int)shopTable.Rows[i]["npc_id"];
                byte slot  = (byte)shopTable.Rows[i]["slot"];

                ShopItem data = new ShopItem()
                {
                    itemId = (int)shopTable.Rows[i]["item_base_id"],
                    amount = (int)shopTable.Rows[i]["amount"],
                    price  = (int)shopTable.Rows[i]["price"],
                };

                RecordsHandler <int, ShopItem> items = Shops.GetRecords(npcId);
                if (items == null)
                {
                    Shops.records.Add(npcId, new RecordsHandler <int, ShopItem>());
                }

                Shops.GetRecords(npcId).SetRecord(slot, data);
            }
        }
示例#2
0
        public override void Interact(User user)
        {
            RecordsHandler <ushort, Item> records = CharactersManager.Items.GetRecords(user.Character.id);

            if (records.GetFreeSlot(out dynamic slot))
            {
                records.SetRecord(slot, item);
                user.RefreshItems(RecordType.BACKPACK, CharactersManager.Items.GetRecords(user.Character.id).records);
                CharactersManager.RemoveCharacter(id);
            }
        }
示例#3
0
        public void BuyItem(User user, ushort slot1)
        {
            RecordsHandler <ushort, Item> records = CharactersManager.Items.GetRecords(user.Character.id);

            if (records.GetFreeSlot(out dynamic slot))
            {
                uint gold = CharactersManager.Stats.GetProperty <uint>(user.Character.id, ObjectStats.GOLD);

                Dictionary <ushort, Data.ShopItem> shop = ShopManager.GetVendorShop(this.baseId);
                if (shop.ContainsKey(slot1))
                {
                    if (shop[slot1].price <= gold)
                    {
                        Item item = ItemsManager.Instance.CreateItem(shop[slot1].itemId);
                        CharactersManager.Stats.SetProperty <uint>(user.Character.id, ObjectStats.GOLD, (uint)(gold - shop[slot1].price));

                        records.SetRecord(slot, item);
                        user.RefreshItems(RecordType.BACKPACK, CharactersManager.Items.GetRecords(user.Character.id).records);
                    }
                }
            }
        }