summaryrefslogtreecommitdiff
path: root/src/main/java/net/uomc/mineshaft/FurnaceCommand.java
blob: 9212ac67bde0320751146042d30ab1425ddd2444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package net.uomc.mineshaft;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

import com.mouldycheerio.dbot.CustomBot;
import com.mouldycheerio.dbot.commands.CommandDetails;
import com.mouldycheerio.dbot.commands.CommandFail;
import com.mouldycheerio.dbot.commands.DetailedCommand;
import com.mouldycheerio.dbot.commands.cooldowns.CooldownCommand;
import com.mouldycheerio.dbot.util.PeelingUtils;
import com.vdurmont.emoji.EmojiParser;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

public class FurnaceCommand extends CooldownCommand {

    private static final String COMMAND_IMAGE = "https://minecraft.wiki/images/Lit_Furnace_%28S%29.gif?40e71";
    private static final String COMMAND_TITLE = "Furnace";
    private static final double COPPER_SPAWN_AMOUNT = 16;
    private static final double IRON_SPAWN_AMOUNT = 8;
    private static final double GOLD_SPAWN_AMOUNT = 4;
    private static final double EMERALD_SPAWN_AMOUNT = 1;
    private static final double DIAMOND_SPAWN_AMOUNT = 1;
    private static final double XP_SPAWN_AMOUNT = 1000;
    private static final long FURNACE_ITEMS = 3;
    Mineshaft bot;

    public FurnaceCommand(Mineshaft bot) {
        super(bot);
        setCommandDetails(CommandDetails.from("furnace,furnaces,furn", "get free ingots", "furnace"));
        this.bot = bot;
        setCooldown(30l * 60l * 1000l);
    }

    @Override
    public boolean trigger(MessageReceivedEvent e) {

        long furnaces = bot.getItem(e.getMember(), MineshaftItem.FURNACE);

        if (furnaces < 1) {
            bot.sendErrorMessage(e, ":x: You need to have at least **"
                    + bot.getItem(MineshaftItem.FURNACE).prettyValue(1)
                    + "** to use this!");
            return false;
        }

        Map<MineshaftItem, Long> award = new LinkedHashMap<>();
        for (int i = 0; i < furnaces * FURNACE_ITEMS; ++i) {
            award =bot.sumItems(award, getAwards());
        };

        String description = "You came back to your **" + bot.getItem(MineshaftItem.FURNACE).prettyValue(furnaces) + "** and collected the ingots:\n";

        String awardsList = bot.createItemList(award, "+%s");
        description += awardsList;

        EmbedBuilder em = new EmbedBuilder();
        em.setTitle(COMMAND_TITLE);
        em.setDescription(description);
        em.setThumbnail(COMMAND_IMAGE);
        em.setColor(PeelingUtils.hex2Rgb("#5c5a5a"));

        e.getMessage().addReaction(Emoji.fromUnicode(EmojiParser.parseToUnicode(":fire:")));
        bot.addItems(e.getMember(), award);
        e.getMessage().replyEmbeds(em.build()).queue();
        return true;
    }
    public Map<MineshaftItem, Long> getAwards() {
        Map<MineshaftItem, Long> award = new HashMap<>();
        Random random = new Random();
        switch (random.nextInt(14)) {
            case 0:
            case 1:
            case 2:
            case 3:
                award.put(MineshaftItem.IRON, (long) Math.ceil(Math.random() * IRON_SPAWN_AMOUNT));
                break;
            case 4:
            case 5:
            case 6:
                award.put(MineshaftItem.COPPER, (long) Math.ceil(Math.random() * COPPER_SPAWN_AMOUNT));
                break;
            case 7:
            case 8:
            case 9:
                award.put(MineshaftItem.GOLD, (long) Math.ceil(Math.random() * GOLD_SPAWN_AMOUNT));
                break;
            case 10:
            case 11:
                award.put(MineshaftItem.DIAMOND, (long) Math.ceil(Math.random() * DIAMOND_SPAWN_AMOUNT));
                break;
            case 12:
            case 13:
            default:
                award.put(MineshaftItem.EMERALD, (long) Math.ceil(Math.random() * EMERALD_SPAWN_AMOUNT));
                break;
        }

        award.put(MineshaftItem.XP, (long) Math.ceil(Math.random() * XP_SPAWN_AMOUNT));

        return award;
    }

}