Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dungeons: Apply cooldown to Dungeon Orb #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ public static void put(ItemStack item) {
}
}

/**
* Put an item on cooldown by getting the index of which cooldown value from its lore.
*
* @param item Item to put on cooldown
* @param index Index of the cooldown
*/
public static void put(ItemStack item, int index) {
if(item == null || !item.hasDisplayName()) {
return;
}

int cooldown = getLoreCooldown(item, index);
if(cooldown > 0) {
// cooldown is returned in seconds and required in milliseconds
put(item.getDisplayName(), cooldown * 1000);
}
}


/**
* Put an item on cooldown with provided cooldown, for items that do not show their cooldown
Expand Down Expand Up @@ -151,22 +169,49 @@ public static double getRemainingCooldownPercent(String itemName) {
* @see #ALTERNATE_COOLDOWN_PATTERN
*/
private static int getLoreCooldown(ItemStack item) {
return getLoreCooldown(item, 0);
}

/**
* Read multiple cooldown values of an item from it's lore.
* And, gets the selected value.
* This requires that the lore shows the cooldown either like {@code X Second Cooldown} or
* {@code Cooldown: Xs}. Cooldown is returned in seconds.
*
* @param item Item to read cooldown from
* @param index The index of the cooldown
* @return Read cooldown in seconds or {@code -1} if no cooldown was found
* @see #ITEM_COOLDOWN_PATTERN
* @see #ALTERNATE_COOLDOWN_PATTERN
*/
private static int getLoreCooldown(ItemStack item, int index) {
int result = -1;
for (String loreLine : item.getTooltip(Minecraft.getMinecraft().thePlayer, false)) {
Matcher matcher = ITEM_COOLDOWN_PATTERN.matcher(loreLine);
if (matcher.matches()) {
try {
return Integer.parseInt(matcher.group(1));
result = Integer.parseInt(matcher.group(1));

if (index == 0)
break;
else
index--;
} catch (NumberFormatException ignored) { }
} else {
matcher = ALTERNATE_COOLDOWN_PATTERN.matcher(loreLine);
if (matcher.matches()) {
try {
return Integer.parseInt(matcher.group(1));
result = Integer.parseInt(matcher.group(1));

if (index == 0)
break;
else
index--;
} catch (NumberFormatException ignored) { }
}
}
}
return -1;
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ public void onInteract(PlayerInteractEvent e) {
ItemStack heldItem = e.entityPlayer.getHeldItem();

if (main.getUtils().isOnSkyblock() && heldItem != null) {
// Show cooldown on dungeon orb when the player uses it in dungeons
if (main.getConfigValues().isEnabled(Feature.SHOW_ITEM_COOLDOWNS)
&& main.getUtils().isInDungeon()
&& (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || e.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR)
&& heldItem.getItem().equals(Items.skull)) {
main.getDungeonUtils().useOrb(heldItem);
}

// Change the GUI background color when a backpack is opened to match the backpack's color.
if (heldItem.getItem() == Items.skull) {
Backpack backpack = BackpackManager.getFromItem(heldItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import codes.biscuit.skyblockaddons.core.DungeonMilestone;
import codes.biscuit.skyblockaddons.core.DungeonPlayer;
import codes.biscuit.skyblockaddons.core.EssenceType;
import codes.biscuit.skyblockaddons.features.cooldowns.CooldownManager;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import java.util.EnumMap;
import java.util.HashMap;
Expand Down Expand Up @@ -113,4 +116,23 @@ public void parseBonusEssence(String message) {
collectedEssences.put(essenceType, collectedEssences.getOrDefault(essenceType, 0) + 1);
}
}

/**
* Check if the given item is a dungeon orb. And, notifies the player that it got used.
* It applies the cooldown of the second ability. Since the main ability is showed in the experience bar.
*
* @param orb The dungeon orb item
*/
public void useOrb(ItemStack orb) {
NBTTagCompound extraAttributes = orb.getTagCompound().getCompoundTag("ExtraAttributes");
if (extraAttributes == null)
return;
String id = extraAttributes.getString("id");
if (id == null)
return;
if (!id.equals("DUNGEON_STONE"))
return;

CooldownManager.put(orb, 1);
}
}