public Item Next() { int totalWeight = Loot.Entries.Sum(x => x.Weight); int marker = RandomProvider.Instance.Next(0, totalWeight); int weightSum = 0; if (totalWeight == 0) { return(null); } string choice = Loot.Entries.First().ItemId; for (int i = 0; i < Loot.Entries.Count; i++) { weightSum += Loot.Entries[i].Weight; if (marker <= weightSum) { choice = Loot.Entries[i].ItemId; break; } } return(ItemHelper.GetItem(choice)); }
private static string WriteItem(string itemId, int amount) { Item item = ItemHelper.GetItem(itemId); string icon = ItemHelper.IconOf(itemId); string name = Check.NotNull(icon) ? item.Name : item.GetName(); return($"{(Check.NotNull(icon) ? $"{icon} " : "• ")}{name}{(amount > 1 ? $" (x**{amount:##,0}**)" : "")}"); }
public override Task <TypeReaderResult> ReadAsync(ICommandContext ctx, string input, IServiceProvider provider) { if (ItemHelper.Exists(input)) { return(Task.FromResult(TypeReaderResult.FromSuccess(ItemHelper.GetItem(input)))); } return(Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Could not find an Item with the specified ID."))); }
public static bool CanSell(Shop shop, ItemData data) { Item item = ItemHelper.GetItem(data.Id); if (item == null) { throw new Exception("Invalid data instance specified"); } return((item.Tag & shop.SellTags) != 0); }
// 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()); }
private static void RemoveBoosts(ArcadeUser user, ref List <BoostData> toRemove) { foreach (BoostData booster in toRemove) { user.Boosters.Remove(booster); if (!string.IsNullOrWhiteSpace(booster.ParentId)) { continue; } Item parent = ItemHelper.GetItem(booster.ParentId); parent?.Usage?.OnBreak?.Invoke(user); } }
public static string Sell(Shop shop, ItemData data, ArcadeUser user) { if (!CanSell(shop, data)) { return(Format.Warning($"**{shop.Name}** does not accept this item.")); } Item item = ItemHelper.GetItem(data.Id); ItemHelper.TakeItem(user, data); long value = shop.SellDeduction > 0 ? (long)Math.Floor(item.Value * (1 - shop.SellDeduction / (double)100)) : item.Value; user.Give(value, item.Currency); string icon = (Check.NotNull(item.GetIcon()) ? $"{item.GetIcon()} " : ""); string name = $"{icon}**{(Check.NotNull(icon) ? item.Name : item.GetName())}**"; return($"> You have received {Icons.IconOf(item.Currency)} **{value:##,0}** for {name}."); }
public static IEnumerable <Recipe> RecipesFor(string itemId) => RecipesFor(ItemHelper.GetItem(itemId));