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 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 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 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 argList) { throw new UnsupportedOperationException("Unimplemented method 'upgrade'"); } }