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); }
private MapleShop LoadShop(int id, bool isShopId) { var ret = MapleShop.Create(id, isShopId); if (ret != null) { if (m_mShops.ContainsKey(ret.ShopId)) { m_mShops[ret.ShopId] = ret; } else { m_mShops.Add(id, ret); } if (m_mNpcShops.ContainsKey(ret.ShopId)) { m_mNpcShops[ret.ShopId] = ret; } else { m_mNpcShops.Add(id, ret); } } else if (isShopId) { if (m_mShops.ContainsKey(id)) { m_mShops[id] = null; } else { m_mShops.Add(id, null); } } else { if (m_mNpcShops.ContainsKey(id)) { m_mNpcShops[id] = null; } else { m_mNpcShops.Add(id, null); } } return(ret); }