lore;
private int costToOpen = -1;
private String name;
private int slot;
private boolean shouldHighlight;
private double profit;
public double getProfit() {
return profit;
}
public void calculateProfitAndBuildLore() {
profit = 0d;
lore = new ArrayList<>();
lore.add(name);
for (SkyblockItem item : items) {
double cost = item.calculateCost();
profit += cost;
lore.add(
EnumChatFormatting.AQUA + " - " + item.getDisplayName() + EnumChatFormatting.RESET + " " +
EnumChatFormatting.GREEN +
Utils.shortNumberFormat(cost, 0));
}
lore.add("");
profit -= costToOpen;
lore.add(
EnumChatFormatting.AQUA + "Cost to open: " + EnumChatFormatting.RED + Utils.shortNumberFormat(costToOpen, 0));
lore.add(
EnumChatFormatting.AQUA + "Total profit: " +
(profit > 0 ? EnumChatFormatting.GREEN + Utils.shortNumberFormat(profit, 0)
: EnumChatFormatting.RED + "-" + Utils.shortNumberFormat(
-profit,
0
)));
}
}
/**
* Dataclass holding info on a single skyblock item which is part of a DungeonChest
*
* This includes:
*
* - The internal name of the item
* - The amount
*
*
* @see DungeonChest
*/
private static class SkyblockItem {
private final String internalName;
private final int amount;
private SkyblockItem(String internalName, int amount) {
this.internalName = internalName;
this.amount = amount;
}
/**
* Try to create a SkyblockItem from the given lore line.
*
* This involves checking for:
*
* - Enchanted books
* - Dungeon essence
* - Normal items that can appear in dungeon chests
*
*
* @param line the line to be parsed
* @return a new SkyblockItem if possible, otherwise null
*/
public static @Nullable SkyblockItem createFromLoreEntry(String line) {
Matcher essenceMatcher = essencePattern.matcher(line);
Matcher enchantedBookMatcher = enchantedBookPattern.matcher(line);
if (enchantedBookMatcher.matches()) {
String enchant = StringUtils.cleanColour(enchantedBookMatcher.group("enchantName"));
for (Map.Entry entry : NotEnoughUpdates.INSTANCE.manager
.getItemInformation()
.entrySet()) {
String displayName = StringUtils.cleanColour(entry.getValue().get("displayname").getAsString());
if (displayName.equals("Enchanted Book")) {
JsonArray lore = entry.getValue().get("lore").getAsJsonArray();
String enchantName = StringUtils.cleanColour(lore.get(0).getAsString());
if (enchant.equals(enchantName)) {
return new SkyblockItem(entry.getKey(), 1);
}
}
}
} else if (essenceMatcher.matches() && NotEnoughUpdates.INSTANCE.config.dungeons.useEssenceCostFromBazaar) {
String essenceType = essenceMatcher.group("essenceType");
String essenceAmount = essenceMatcher.group("essenceAmount");
if (essenceType == null || essenceAmount == null) {
return null;
}
String internalName = "ESSENCE_" + essenceType.toUpperCase(Locale.ROOT);
if (!NotEnoughUpdates.INSTANCE.manager.isValidInternalName(internalName)) {
return null;
}
//this can only be an integer if the regex matches
int amount = Integer.parseInt(essenceAmount);
return new SkyblockItem(internalName, amount);
} else {
String s = StringUtils.cleanColour(line.trim());
for (Map.Entry entries : NotEnoughUpdates.INSTANCE.manager
.getItemInformation()
.entrySet()) {
String displayName = entries.getValue().get("displayname").getAsString();
String cleanDisplayName = StringUtils.cleanColour(displayName);
if (s.equals(cleanDisplayName)) {
return new SkyblockItem(entries.getKey(), 1);
}
}
}
return null;
}
/**
* Calculate the price of this item, factoring in the amount
*
* @return total price
*/
public double calculateCost() {
double price = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarOrBin(internalName, true);
if (price != -1) {
return price * amount;
}
return 0d;
}
public String getDisplayName() {
JsonObject entry = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withKnownInternalName(
internalName).resolveToItemListJson();
if (entry != null) {
String displayName = entry.get("displayname").getAsString();
String cleanedDisplayName = StringUtils.cleanColour(displayName);
if ("Enchanted Book".equals(cleanedDisplayName)) {
return entry.get("lore").getAsJsonArray().get(0).getAsString();
} else {
return entry.get("displayname").getAsString();
}
}
return "ERROR";
}
}
}