// sum together all unique tags public static ItemTag GetUniqueTags(ItemCatalog catalog) { ItemTag unique = 0; foreach ((string itemId, int amount) in catalog.ItemIds) { unique |= ItemHelper.GetTag(itemId); } return(unique); }
public static long CostOf(Item item, ItemCatalog catalog) { long value = item.Value; if (catalog.Discounts.ContainsKey(item.Id)) { return(GetCost(value, catalog.Discounts[item.Id])); } return(value); }
// This writes the catalog info public static string WriteCatalog(CatalogGenerator generator, ItemCatalog catalog) { var info = new StringBuilder(); foreach ((string itemId, int amount) in catalog.ItemIds) { int discountUpper = catalog.Discounts.ContainsKey(itemId) ? catalog.Discounts[itemId] : 0; info.AppendLine(WriteCatalogEntry(ItemHelper.GetItem(itemId), amount, generator.Entries.Any(x => x.ItemId == itemId && x.IsSpecial), discountUpper)); } return(info.ToString()); }
/// <summary> /// Initializes a new <see cref="ItemCatalog"/> that contains properties copied from the specified <see cref="ItemCatalog"/>. /// </summary> /// <param name="catalog">The <see cref="ItemCatalog"/> to create an instance of.</param> public ItemCatalog(ItemCatalog catalog) { ItemIds = catalog?.ItemIds.Count > 0 ? new Dictionary <string, int>(catalog.ItemIds) : throw new Exception("Expected catalog to have at least a single item entry but returned empty"); Discounts = catalog.Discounts.Count > 0 ? new Dictionary <string, int>(catalog.Discounts) : new Dictionary <string, int>(); GeneratedAt = catalog.GeneratedAt; }
public ItemCatalog GetOrGenerateCatalog(Shop shop, ArcadeUser user = null) { if (Catalogs.ContainsKey(shop.Id) && DateTime.UtcNow.DayOfYear - Catalogs[shop.Id].GeneratedAt.DayOfYear == 0) { var catalog = new ItemCatalog(Catalogs[shop.Id]); if (user == null || !user.CatalogHistory.ContainsKey(shop.Id)) { return(catalog); } var toRemoveIds = new List <string>(); foreach ((string itemId, int amount) in user.CatalogHistory[shop.Id].PurchasedIds) { if (amount <= 0) { toRemoveIds.Add(itemId); continue; } if (catalog.ItemIds.ContainsKey(itemId)) { catalog.ItemIds[itemId] -= amount; if (catalog.ItemIds[itemId] <= 0) { catalog.ItemIds.Remove(itemId); } } } foreach (string removeId in toRemoveIds) { user.CatalogHistory[shop.Id].PurchasedIds.Remove(removeId); } return(catalog); } Catalogs[shop.Id] = shop.Catalog.Generate(Var.GetOrSet(user, ShopHelper.GetTierId(shop.Id), 1)); if (user != null && user.CatalogHistory.ContainsKey(shop.Id)) { user.CatalogHistory[shop.Id].Clear(); } return(new ItemCatalog(Catalogs[shop.Id])); }