예제 #1
0
        public static MapleShop Create(int id, bool isShopId)
        {
            MapleShop ret = null;
            var       ii  = MapleItemInformationProvider.Instance;

            try
            {
                var shopMappings = JsonConvert.DeserializeObject <List <ShopMapping> >(File.ReadAllText($"{Environment.CurrentDirectory}\\Json\\Shops.json"));
                var shopQuery    = shopMappings.Where(x => id == (isShopId ? x.ShopId : x.NpcId)).Select(x => x).FirstOrDefault();

                int shopId;
                if (shopQuery != null)
                {
                    shopId = shopQuery.ShopId;
                }
                else
                {
                    return(null);
                }

                ret = new MapleShop(shopId, shopQuery.NpcId);

                List <int> recharges = new List <int>(MRechargeableItems);

                var items = JsonConvert.DeserializeObject <List <OriginalShopItem> >(File.ReadAllText($"{Environment.CurrentDirectory}\\Json\\ShopItems.json"));

                foreach (var item in items.Where(x => x.ShopId == shopId))
                {
                    int itemId = item.ItemId;
                    if (ii.IsThrowingStar(itemId) || ii.IsBullet(itemId))
                    {
                        MapleShopItem starItem = new MapleShopItem(1, itemId, item.Price);
                        ret.AddItem(starItem);
                        if (MRechargeableItems.Contains(starItem.ItemId))
                        {
                            recharges.Remove(starItem.ItemId);
                        }
                    }
                    else
                    {
                        ret.AddItem(new MapleShopItem(1000, itemId, item.Price));
                    }
                }

                foreach (var itemId in recharges)
                {
                    ret.AddItem(new MapleShopItem(1000, itemId, 0));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not load shop" + e);
            }

            return(ret);
        }
예제 #2
0
        public void Buy(MapleClient c, int itemId, short quantity)
        {
            if (quantity <= 0)
            {
                Console.WriteLine($"{c.Player.Name} is buying an invalid amount: { quantity } of itemid: { itemId}");
                c.Close();
                return;
            }
            MapleShopItem item = FindByItemId(itemId);
            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;

            if (item != null && item.Price > 0 && c.Player.Meso.Value >= item.Price * quantity)
            {
                if (MapleInventoryManipulator.CheckSpace(c, itemId, quantity, ""))
                {
                    if (itemId >= 5000000 && itemId <= 5000100)
                    {
                        if (quantity > 1)
                        {
                            quantity = 1;
                        }
                        int petId = MaplePet.Create(itemId);
                        MapleInventoryManipulator.AddById(c, itemId, quantity, "Pet was purchased.", null, petId);
                    }
                    else if (ii.IsRechargable(itemId))
                    {
                        short rechquantity = ii.GetSlotMax(c, item.ItemId);
                        MapleInventoryManipulator.AddById(c, itemId, rechquantity, "Rechargable item purchased.", null, -1);
                    }
                    else
                    {
                        MapleInventoryManipulator.AddById(c, itemId, quantity, c.Player.Name + " bought " + quantity + " for " + item.Price * quantity + " from shop " + ShopId);
                    }
                    c.Player.GainMeso(-(item.Price * quantity), false);
                    c.Send(PacketCreator.ConfirmShopTransaction(0));
                }
                else
                {
                    c.Send(PacketCreator.ConfirmShopTransaction(3));
                }
            }
        }
예제 #3
0
 public void AddItem(MapleShopItem item) => m_mItems.Add(item);