lore;
private int costToOpen = -1;
private String name;
@Getter
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 enchantName = ItemResolutionQuery.resolveEnchantmentByName(enchantedBookMatcher.group("enchantName"));
if (enchantName == null) return null;
return new SkyblockItem(enchantName, 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 {
// Remove Book (from hot potato book), as a perf optimization since "book" is a very common phrase
String trimmedLine = line.trim();
String id =
ItemResolutionQuery.filterInternalNameCandidates(ItemResolutionQuery.findInternalNameCandidatesForDisplayName(
trimmedLine.replace("Book", "")), trimmedLine, true);
if (id == null) return null;
if (id.equals("DUNGEON_CHEST_KEY")) return null;
return new SkyblockItem(id, 1);
}
}
/**
* 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";
}
}
}