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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package net.uomc.mineshaft.blacksmith;
import java.awt.Color;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
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.util.PeelingUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.uomc.mineshaft.Mineshaft;
import net.uomc.mineshaft.MineshaftItem;
public class BlacksmithCommand extends DetailedCommand {
private static final Color COMMAND_COLOUR = PeelingUtils.hex2Rgb("#252525");
private static final String COMMAND_TITLE = "Blacksmith";
private static final String COMMAND_IMAGE = "https://minecraft.wiki/images/Plains_Armorer.png?0dee1";
Mineshaft bot;
Blacksmith blacksmith;
public BlacksmithCommand(Mineshaft bot) {
setCommandDetails(CommandDetails.from("blacksmith", "upgrade your tools", "blacksmith upgrade"));
this.bot = bot;
blacksmith = new Blacksmith(bot);
bot.getCommandController().addCommand("upgrade", (e, b, args) -> {
// allow also upgrading pickaxe
if (Arrays.stream(args).filter(a -> a.equalsIgnoreCase("pick") || a.equalsIgnoreCase("pickaxe")).findFirst().isPresent()) {
bot.getCommandController().getCommand("pickaxe").execute(e, bot, new String[]{"upgrade"});
return;
}
execute(e, bot, Stream.concat(Stream.of("upgrade"), Arrays.stream(args)).toArray(String[]::new));
});
}
@Override
public void execute(MessageReceivedEvent e, CustomBot b, String[] args) throws CommandFail {
Member m = e.getMember();
List<String> argList = Arrays.asList(args);
long blacksmiths = bot.getItem(m, MineshaftItem.BLACKSMITH);
if (blacksmiths < 1) {
b.sendErrorMessage(e, ":x: You need to have at least **"
+ bot.getItem(MineshaftItem.BLACKSMITH).prettyValue(1)
+ "** to use this!");
return;
}
long forges = bot.getItem(m, MineshaftItem.FORGE);
EmbedBuilder em = new EmbedBuilder();
em.setTitle(COMMAND_TITLE);
em.setThumbnail(COMMAND_IMAGE);
em.setColor(COMMAND_COLOUR);
blacksmith.update(m);
if (blacksmith.isWorking(m)) {
if (blacksmith.isReady(m)) {
// do get new sword
return;
}
em.setDescription(blacksmith.getWorkingString(m));
blacksmith.incrementQuestions(m);
e.getMessage().replyEmbeds(em.build()).queue();
return;
}
if (args.length > 1 && "upgrade".equalsIgnoreCase(args[0])) {
if (forges < 1) {
em.setDescription(String.format("Sorry, I can't work without a forge %s!", bot.getItem(MineshaftItem.FORGE).getSymbol()));
return;
}
if (!upgrade(e, argList))
bot.sendErrorMessage(e, String.format(":x: Usage `%supgrade [sword|armour]`", bot.getPrefixManager().getPrefix(e.getGuild())));
return;
}
em.appendDescription(String.format("Hello, I am your blacksmith. I can upgrade your tools and armour for you `%supgrade [sword|armour]`\n\n",
bot.getPrefixManager().getPrefix(e.getGuild())
));
String swordName = "You have a **" + bot.getSword(m).getName() + " Sword**";
Map<MineshaftItem, Long> swordUpgradeCost = blacksmith.getSwordUpgradeCost(m);
if (bot.getSword(m).getLevel() == 0) {
swordName = "**You have no sword**";
}
String armourName = "You have a **" + bot.getArmour(m).getName() + " Armour**";
Map<MineshaftItem, Long> armourUpgradeCost = blacksmith.getArmourUpgradeCost(m);
if (bot.getArmour(m).getLevel() == 0) {
armourName = "**You have no armour**";
}
em.appendDescription(String.format("%s\n", swordName));
if (blacksmith.canUpgradeSword(m))
em.appendDescription(String.format("Upgrade to **%s** for **%s**\n",
blacksmith.getNextSwordName(m),
String.join(",", bot.createItemList(swordUpgradeCost).split("\n"))));
em.appendDescription("\n");
em.appendDescription(String.format("**%s**\n", armourName));
if (blacksmith.canUpgradeArmour(m))
em.appendDescription(String.format("Upgrade to **%s** for **%s**\n",
blacksmith.getNextArmourName(m),
String.join(",", bot.createItemList(armourUpgradeCost).split("\n"))));
em.appendDescription("\n");
if (blacksmiths > 1) {
long forgeCount = blacksmith.getValidForgeCount(m);
String total = bot.prettyValue(MineshaftItem.BLACKSMITH, blacksmiths);
if (forgeCount < blacksmiths) {
em.appendDescription("**" + forgeCount + "/" + total + "** are able to work.\n");
em.appendDescription("Get more " + bot.getItem(MineshaftItem.FORGE).getSymbol() + " so they can work!");
} else {
em.appendDescription("Your **" + total + "** are all able to work!");
}
} else if (blacksmiths == 1) {
em.appendDescription("I am currently working alone. Hire more **" + bot.getItem(MineshaftItem.BLACKSMITH).getSymbol() + "** to speed up progress!");
} else {
em.appendDescription("I need a " + bot.getItem(MineshaftItem.FORGE).getSymbol() + " so I can get to work!");
}
e.getMessage().replyEmbeds(em.build()).queue();
}
private boolean upgrade(MessageReceivedEvent e, List<String> argList) {
throw new UnsupportedOperationException("Unimplemented method 'upgrade'");
}
}
|