summaryrefslogtreecommitdiff
path: root/src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java')
-rw-r--r--src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java106
1 files changed, 93 insertions, 13 deletions
diff --git a/src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java b/src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java
index db57d55..68f7497 100644
--- a/src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java
+++ b/src/main/java/net/uomc/mineshaft/blacksmith/BlacksmithCommand.java
@@ -3,6 +3,7 @@ package net.uomc.mineshaft.blacksmith;
import java.awt.Color;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -12,6 +13,7 @@ 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 com.vdurmont.emoji.EmojiParser;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
@@ -61,16 +63,24 @@ public class BlacksmithCommand extends DetailedCommand {
long forges = bot.getItem(m, MineshaftItem.FORGE);
- EmbedBuilder em = new EmbedBuilder();
- em.setTitle(COMMAND_TITLE);
- em.setThumbnail(COMMAND_IMAGE);
- em.setColor(COMMAND_COLOUR);
+ EmbedBuilder em = createEmbedTemplate();
blacksmith.update(m);
if (blacksmith.isWorking(m)) {
- if (blacksmith.isReady(m)) {
- // do get new sword
+ int collect = blacksmith.collect(m);
+ if (collect != 0) {
+ String itemName = collect > 0 ? "Sword" : "Armour";
+ String levelName = collect > 0 ? bot.getSword(m).getName() : bot.getArmour(m).getName();
+ String fullName = levelName + " " + itemName;
+ em.setDescription("I have finished your **" + fullName + "**, use it well!");
+ if (collect > 0 && bot.getSword(m).getLevel() == 1) {
+ em.setFooter("You equipped " + fullName);
+ } else {
+ em.setFooter(EmojiParser.parseToUnicode(":bulb:") + "You can now fight players with m!pvp");
+ }
+
+ e.getMessage().replyEmbeds(em.build()).queue();
return;
}
@@ -80,30 +90,32 @@ public class BlacksmithCommand extends DetailedCommand {
return;
}
- if (args.length > 1 && "upgrade".equalsIgnoreCase(args[0])) {
+ if (args.length > 0 && "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()));
+ e.getMessage().replyEmbeds(em.build()).queue();
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",
+ 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**";
+ 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**";
+ String armourName = "You have **" + bot.getArmour(m).getName() + "** Armour";
Map<MineshaftItem, Long> armourUpgradeCost = blacksmith.getArmourUpgradeCost(m);
if (bot.getArmour(m).getLevel() == 0) {
@@ -118,7 +130,7 @@ public class BlacksmithCommand extends DetailedCommand {
em.appendDescription("\n");
- em.appendDescription(String.format("**%s**\n", armourName));
+ em.appendDescription(String.format("%s\n", armourName));
if (blacksmith.canUpgradeArmour(m))
em.appendDescription(String.format("Upgrade to **%s** for **%s**\n",
blacksmith.getNextArmourName(m),
@@ -131,7 +143,7 @@ public class BlacksmithCommand extends DetailedCommand {
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!");
+ em.appendDescription("Get more " + bot.getItem(MineshaftItem.FORGE).getSymbol() + " so they can work faster!");
} else {
em.appendDescription("Your **" + total + "** are all able to work!");
}
@@ -145,7 +157,75 @@ public class BlacksmithCommand extends DetailedCommand {
}
+ private EmbedBuilder createEmbedTemplate() {
+ EmbedBuilder em = new EmbedBuilder();
+ em.setTitle(COMMAND_TITLE);
+ em.setThumbnail(COMMAND_IMAGE);
+ em.setColor(COMMAND_COLOUR);
+ return em;
+ }
+
private boolean upgrade(MessageReceivedEvent e, List<String> argList) {
- throw new UnsupportedOperationException("Unimplemented method 'upgrade'");
+ if (argList.size() < 2) {
+ return false;
+ }
+
+ if (!argList.stream().anyMatch(x -> x.equalsIgnoreCase("armor") ||x.equalsIgnoreCase("armour") || x.equalsIgnoreCase("sword"))) {
+ return false;
+ }
+
+ EmbedBuilder em = createEmbedTemplate();
+
+ boolean isSword = argList.get(1).equalsIgnoreCase("sword");
+ String itemName = (isSword ? "sword" : "armour");
+ Map<MineshaftItem, Long> cost = isSword ? getSwordCost(e) : getArmourCost(e);
+
+ if (cost.size() == 0) {
+ em.setDescription(":x: Sorry but I can't upgrade your **" + itemName + "** any more!");
+ e.getMessage().replyEmbeds(em.build()).queue();;
+ return true;
+ }
+
+ if (!bot.hasItems(e.getMember(), cost)) {
+ em.setDescription("I need more materials to do this! \nYou are missing: **");
+
+ Map<MineshaftItem, Long> missing = bot.getMissingIngredients(e.getMember(), cost);
+ em.appendDescription(bot.createItemList(missing, "%s", ", "));
+ em.appendDescription("**");
+ e.getMessage().replyEmbeds(em.build()).queue();
+ return true;
+ }
+
+ bot.removeItems(e.getMember(), cost);
+
+ if (isSword) {
+ blacksmith.upgradeSword(e.getMember());
+ } else {
+ blacksmith.upgradeArmour(e.getMember());
+ }
+
+ em.setDescription("I am now going to be upgrading your **" + blacksmith.getWorkingName(e.getMember()) + "**! Come back later and I will let you know if its finished");
+ em.setFooter("You unequipped your " + itemName);
+ e.getMessage().replyEmbeds(em.build()).queue();;
+
+ return true;
}
+
+
+ private Map<MineshaftItem, Long> getArmourCost(MessageReceivedEvent e) {
+
+ if (!blacksmith.canUpgradeArmour(e.getMember())) {
+ return Collections.emptyMap();
+ }
+
+ return blacksmith.getArmourUpgradeCost(e.getMember());
+ }
+
+ private Map<MineshaftItem, Long> getSwordCost(MessageReceivedEvent e) {
+ if (!blacksmith.canUpgradeSword(e.getMember())) {
+ return Collections.emptyMap();
+ }
+
+ return blacksmith.getSwordUpgradeCost(e.getMember());
+ }
}