Search in sources :

Example 1 with Tiered

use of net.kodehawa.mantarobot.commands.currency.item.special.helpers.attributes.Tiered in project MantaroBot by Mantaro.

the class ItemHelper method openLootBox.

private static void openLootBox(Context ctx, Player player, SeasonPlayer seasonPlayer, ItemType.LootboxType type, Item crate, EmoteReference typeEmote, int bound, boolean seasonal) {
    List<Item> toAdd = selectItems(random.nextInt(bound) + bound, type);
    ArrayList<ItemStack> ita = new ArrayList<>();
    toAdd.forEach(item -> ita.add(new ItemStack(item, 1)));
    PlayerData data = player.getData();
    if ((type == ItemType.LootboxType.MINE || type == ItemType.LootboxType.MINE_PREMIUM) && toAdd.contains(ItemReference.SPARKLE_PICKAXE)) {
        data.addBadgeIfAbsent(Badge.DESTINY_REACHES);
    }
    if ((type == ItemType.LootboxType.FISH || type == ItemType.LootboxType.FISH_PREMIUM) && toAdd.contains(ItemReference.SHARK)) {
        data.addBadgeIfAbsent(Badge.TOO_BIG);
    }
    var toShow = ItemStack.reduce(ita);
    // Tools must only drop one, if any.
    toShow = toShow.stream().map(stack -> {
        var item = stack.getItem();
        if (stack.getAmount() > 1 && ((item instanceof Pickaxe) || (item instanceof FishRod) || (item instanceof Axe))) {
            return new ItemStack(item, 1);
        }
        return stack;
    }).collect(Collectors.toList());
    boolean overflow = seasonal ? seasonPlayer.getInventory().merge(toShow) : player.getInventory().merge(toShow);
    if (seasonal) {
        seasonPlayer.getInventory().process(new ItemStack(ItemReference.LOOT_CRATE_KEY, -1));
        seasonPlayer.getInventory().process(new ItemStack(crate, -1));
    } else {
        player.getInventory().process(new ItemStack(ItemReference.LOOT_CRATE_KEY, -1));
        player.getInventory().process(new ItemStack(crate, -1));
    }
    data.setCratesOpened(data.getCratesOpened() + 1);
    player.save();
    if (seasonal) {
        seasonPlayer.save();
    }
    I18nContext lang = ctx.getLanguageContext();
    var show = toShow.stream().map(itemStack -> "x%,d \u2009%s".formatted(itemStack.getAmount(), itemStack.getItem().toDisplayString())).collect(Collectors.joining(", "));
    var extra = "";
    if (overflow) {
        extra = ". " + lang.get("general.misc_item_usage.crate.overflow");
    }
    var high = toShow.stream().filter(stack -> stack.getItem() instanceof Tiered).filter(stack -> ((Tiered) stack.getItem()).getTier() >= 4).map(stack -> "%s \u2009(%d \u2b50)".formatted(stack.getItem().getEmoji(), ((Tiered) stack.getItem()).getTier())).collect(Collectors.joining(", "));
    if (high.length() >= 1) {
        extra = ".\n\n" + lang.get("general.misc_item_usage.crate.success_high").formatted(EmoteReference.POPPER, high);
    }
    ctx.sendFormat(lang.get("general.misc_item_usage.crate.success"), typeEmote.getDiscordNotation() + " ", show, extra);
}
Also used : Badge(net.kodehawa.mantarobot.commands.currency.profile.Badge) java.util(java.util) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) LoggerFactory(org.slf4j.LoggerFactory) SeasonPlayer(net.kodehawa.mantarobot.commands.currency.seasons.SeasonPlayer) SecureRandom(java.security.SecureRandom) Pair(org.apache.commons.lang3.tuple.Pair) FishRod(net.kodehawa.mantarobot.commands.currency.item.special.tools.FishRod) DBUser(net.kodehawa.mantarobot.db.entities.DBUser) Inventory(net.kodehawa.mantarobot.db.entities.helpers.Inventory) Context(net.kodehawa.mantarobot.core.modules.commands.base.Context) Tiered(net.kodehawa.mantarobot.commands.currency.item.special.helpers.attributes.Tiered) Broken(net.kodehawa.mantarobot.commands.currency.item.special.Broken) Player(net.kodehawa.mantarobot.db.entities.Player) UserData(net.kodehawa.mantarobot.db.entities.helpers.UserData) Logger(org.slf4j.Logger) Potion(net.kodehawa.mantarobot.commands.currency.item.special.Potion) Predicate(java.util.function.Predicate) IncreasingRateLimiter(net.kodehawa.mantarobot.utils.commands.ratelimit.IncreasingRateLimiter) Collectors(java.util.stream.Collectors) Axe(net.kodehawa.mantarobot.commands.currency.item.special.tools.Axe) TimeUnit(java.util.concurrent.TimeUnit) Breakable(net.kodehawa.mantarobot.commands.currency.item.special.helpers.Breakable) RatelimitUtils(net.kodehawa.mantarobot.utils.commands.ratelimit.RatelimitUtils) Stream(java.util.stream.Stream) I18nContext(net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) RandomCollection(net.kodehawa.mantarobot.utils.RandomCollection) Pickaxe(net.kodehawa.mantarobot.commands.currency.item.special.tools.Pickaxe) Pickaxe(net.kodehawa.mantarobot.commands.currency.item.special.tools.Pickaxe) FishRod(net.kodehawa.mantarobot.commands.currency.item.special.tools.FishRod) Axe(net.kodehawa.mantarobot.commands.currency.item.special.tools.Axe) Tiered(net.kodehawa.mantarobot.commands.currency.item.special.helpers.attributes.Tiered) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) I18nContext(net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)

Aggregations

SecureRandom (java.security.SecureRandom)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Broken (net.kodehawa.mantarobot.commands.currency.item.special.Broken)1 Potion (net.kodehawa.mantarobot.commands.currency.item.special.Potion)1 Breakable (net.kodehawa.mantarobot.commands.currency.item.special.helpers.Breakable)1 Tiered (net.kodehawa.mantarobot.commands.currency.item.special.helpers.attributes.Tiered)1 Axe (net.kodehawa.mantarobot.commands.currency.item.special.tools.Axe)1 FishRod (net.kodehawa.mantarobot.commands.currency.item.special.tools.FishRod)1 Pickaxe (net.kodehawa.mantarobot.commands.currency.item.special.tools.Pickaxe)1 Badge (net.kodehawa.mantarobot.commands.currency.profile.Badge)1 SeasonPlayer (net.kodehawa.mantarobot.commands.currency.seasons.SeasonPlayer)1 Context (net.kodehawa.mantarobot.core.modules.commands.base.Context)1 I18nContext (net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)1 MantaroData (net.kodehawa.mantarobot.data.MantaroData)1 DBUser (net.kodehawa.mantarobot.db.entities.DBUser)1 Player (net.kodehawa.mantarobot.db.entities.Player)1