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
152
153
154
155
156
157
158
|
package net.uomc.mineshaft;
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 com.vdurmont.emoji.EmojiParser;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class EnchantCommand extends DetailedCommand {
private static final String COMMAND_IMAGE = "https://minecraft.wiki/images/Enchanting_Table.gif";
private static final double MIN_DISCOUNT = 0.4;
private static final long MAX_BOOKSHELVES = 24;
private static final String COMMAND_TITLE = "Enchanting Table";
Mineshaft bot;
public EnchantCommand(Mineshaft bot) {
setCommandDetails(CommandDetails.from("enchant,enchanting,ench,etable,enchantingtable", "", "enchant"));
this.bot = bot;
}
@Override
public void execute(MessageReceivedEvent e, CustomBot b, String[] args) throws CommandFail {
long ench_tables = bot.getItem(e.getMember(), MineshaftItem.ENCHANTING_TABLE);
if (ench_tables < 1) {
b.sendErrorMessage(e, ":x: You need to have at least **"
+ bot.getItem(MineshaftItem.ENCHANTING_TABLE).prettyValue(1)
+ "** to use this!");
return;
}
if (args.length > 0) {
enchant(e, args);
return;
}
int fortune = bot.getPickaxes().getPickaxeFortune(e.getMember());
int efficiency = bot.getPickaxes().getPickaxeEfficiency(e.getMember());
long bookshelves = bot.getItem(e.getMember(), MineshaftItem.BOOKSHELF);
String bookshelfDiscountPercent = "-" + (int) Math.ceil((1 -bookshelfDiscount(bookshelves))*100) + "%";
long xpLevel = getXpLevel(fortune+efficiency, bookshelves);
long lapisLevel = getLapisLevel(fortune+efficiency, bookshelves);
long xpLevelNormal = getXpLevel(fortune+efficiency, 0);
long lapisLevelNormal = getLapisLevel(fortune+efficiency, 0);
String curr = "Your pickaxe " + getPickaxeEnchantmentsString(fortune, efficiency);
curr += "\n\n";
String description = curr + "Enchant your pickaxe with `" + b.getPrefixManager().getPrefix(e.getGuild()) + "enchant pickaxe`\n\n";
description += "**Cost:**\n";
if (bookshelves > 0)
description += "~~" + PeelingUtils.amountToString(lapisLevelNormal) + "~~ ";
description += "**" + bot.getItem(MineshaftItem.LAPIS).prettyValue(lapisLevel) + "**";
description += "\n";
if (bookshelves > 0)
description += "~~" + PeelingUtils.amountToString(xpLevelNormal) + "~~ ";
description += "**" + bot.getItem(MineshaftItem.XP).prettyValue(xpLevel) + "**";
if (bookshelves > 0) {
description += "\n\nYour ";
description += bot.getItem(MineshaftItem.BOOKSHELF).prettyValue(bookshelves);
description += " are giving you a **" + bookshelfDiscountPercent + "** discount!";
}
EmbedBuilder em = new EmbedBuilder();
em.setTitle(COMMAND_TITLE);
em.setDescription(description);
em.setThumbnail(COMMAND_IMAGE);
em.setColor(PeelingUtils.hex2Rgb("#0a0711"));
if (bookshelves == 0) {
em.setFooter(EmojiParser.parseToUnicode(":bulb:") + "Bookshelves give you a discount on your enchantments");
}
e.getMessage().replyEmbeds(em.build()).queue();
}
public String getPickaxeEnchantmentsString(int fortune, int efficiency) {
String curr = "";
if (fortune > 0 || efficiency > 0) {
curr = "is enchanted with ";
if (fortune > 0)
curr += "**Fortune " + Pickaxes.getRomanNumber(fortune) + "** ";
if (efficiency > 0)
curr += "**Efficiency " + Pickaxes.getRomanNumber(efficiency) + "** ";
} else {
curr = "has no enchantments";
}
return curr;
}
private long getLapisLevel(int fortune, long bookshelves) {
return (long) (Math.pow(2, fortune + 4) * bookshelfDiscount(bookshelves));
}
private long getXpLevel(int fortune, long bookshelves) {
return (long) (15000l * Math.pow(fortune + 1, 2) * bookshelfDiscount(bookshelves));
}
private double bookshelfDiscount(long bookshelves) {
double b = Math.min(bookshelves, MAX_BOOKSHELVES);
return MIN_DISCOUNT + Math.log(
1.0 + ( (Math.E - 1) * (
(double) (MAX_BOOKSHELVES - b) / (double) MAX_BOOKSHELVES))
) * (double) (1-MIN_DISCOUNT);
}
private void enchant(MessageReceivedEvent e, String[] args) {
int fortune = bot.getPickaxes().getPickaxeFortune(e.getMember());
int efficiency = bot.getPickaxes().getPickaxeEfficiency(e.getMember());
long bookshelves = bot.getItem(e.getMember(), MineshaftItem.BOOKSHELF);
long xpLevel = getXpLevel(fortune + efficiency, bookshelves);
long lapisLevel = getLapisLevel(fortune + efficiency, bookshelves);
long memberLapis = bot.getItem(e.getMember(), MineshaftItem.LAPIS);
long memberXp = bot.getItem(e.getMember(), MineshaftItem.XP);
if (memberLapis < lapisLevel) {
bot.sendErrorMessage(e, ":x: You need " + bot.getItem(MineshaftItem.LAPIS).prettyValue(lapisLevel - memberLapis) + " more lapis!" );
return;
}
if (memberXp < xpLevel) {
bot.sendErrorMessage(e, ":x: You need " + bot.getItem(MineshaftItem.XP).prettyValue(xpLevel - memberXp) + " more xp!" );
return;
}
bot.removeItem(e.getMember(), MineshaftItem.LAPIS, lapisLevel);
bot.removeItem(e.getMember(), MineshaftItem.XP, xpLevel);
String newEnch = "";
if (Math.random() > 0.5) {
int level = bot.getPickaxes().incrementFortune(e.getMember());
newEnch = "**Fortune " + Pickaxes.getRomanNumber(level) + "**";
} else {
int level = bot.getPickaxes().incrementEfficiency(e.getMember());
newEnch = "**Efficiency " + Pickaxes.getRomanNumber(level) + "**";
}
bot.sendSuccessMessage(e, ":white_check_mark: You enchanted your pickaxe. You now have " + newEnch);
}
}
|