Search in sources :

Example 1 with ConsumableContainer

use of com.wynntils.modules.utilities.instances.ConsumableContainer in project Wynntils by Wynntils.

the class ConsumableTimerOverlay method updateActiveEffects.

private static void updateActiveEffects() {
    Map<String, IdentificationHolder> effects = new HashMap<>();
    for (ConsumableContainer consumable : activeConsumables) {
        for (String cEf : consumable.getEffects().keySet()) {
            IdentificationHolder holder = consumable.getEffects().get(cEf);
            if (effects.containsKey(cEf)) {
                effects.get(cEf).sumAmount(holder.getCurrentAmount());
                continue;
            }
            effects.put(cEf, new IdentificationHolder(holder.getCurrentAmount(), holder.getModifier()));
        }
    }
    activeEffects = effects;
}
Also used : IdentificationHolder(com.wynntils.modules.utilities.instances.IdentificationHolder) ConsumableContainer(com.wynntils.modules.utilities.instances.ConsumableContainer)

Example 2 with ConsumableContainer

use of com.wynntils.modules.utilities.instances.ConsumableContainer in project Wynntils by Wynntils.

the class ConsumableTimerOverlay method addConsumable.

public static void addConsumable(ItemStack stack) {
    // display name also checks for the nbt data
    if (stack.isEmpty() || !stack.hasDisplayName())
        return;
    // foods and scrolls have DIAMOND_AXE as their items
    if (stack.getItem() != Items.DIAMOND_AXE && stack.getItem() != Items.POTIONITEM && stack.getItem() != Items.SPLASH_POTION)
        return;
    // vanilla potions needs a special verification, they DON'T start with dark aqua
    if (!stack.getDisplayName().startsWith(DARK_AQUA.toString())) {
        String displayName = TextFormatting.getTextWithoutFormattingCodes(stack.getDisplayName());
        SkillPoint sp = SkillPoint.findSkillPoint(displayName);
        ConsumableContainer consumable;
        if (sp == null) {
            if (displayName.contains("Potion of Mana")) {
                consumable = new ConsumableContainer(AQUA + "✺ Mana");
            } else {
                return;
            }
        } else {
            consumable = new ConsumableContainer(sp.getAsName());
        }
        List<String> itemLore = ItemUtils.getLore(stack);
        for (String line : itemLore) {
            line = TextFormatting.getTextWithoutFormattingCodes(line);
            // duration | - Duration: <group1> Seconds
            Matcher m = DURATION_PATTERN.matcher(line);
            if (m.matches() && m.group(1) != null) {
                consumable.setExpirationTime(McIf.getSystemTime() + (Integer.parseInt(m.group(1)) * 1000));
                // currentMillis + (seconds * 1000)
                continue;
            }
            // effects | - Effect: <id>
            m = EFFECT_PATTERN.matcher(line);
            if (m.matches()) {
                String id = m.group(1);
                // continues if id is null or empty
                if (id == null || id.isEmpty())
                    continue;
                // removing skill point symbols
                for (SkillPoint skillPoint : SkillPoint.values()) {
                    id = id.replace(skillPoint.getSymbol() + " ", "");
                }
                m = ItemIdentificationOverlay.ID_PATTERN.matcher(id);
                // continues if the effect is not a valid id
                if (!m.matches())
                    continue;
                verifyIdentification(m, consumable);
                continue;
            }
            // mana | - Mana: <group1> <mana symbol>
            m = MANA_PATTERN.matcher(line);
            if (m.matches() && m.group(1) != null) {
                consumable.addEffect("Mana", Integer.parseInt(m.group(1)), IdentificationModifier.INTEGER);
            }
        }
        activeConsumables.add(consumable);
        updateActiveEffects();
        return;
    }
    // crafted items
    String name;
    if (stack.getItem() == Items.POTIONITEM || stack.getItem() == Items.SPLASH_POTION)
        name = LIGHT_PURPLE + "Ⓛ Potion";
    else if (// food, 69 <= damage <= 75
    stack.getItemDamage() >= 69 && stack.getItemDamage() <= 75)
        name = GOLD + "Ⓐ Food";
    else if (// scrolls, 42 <= damage <= 44
    stack.getItemDamage() >= 42 && stack.getItemDamage() <= 44)
        name = YELLOW + "Ⓔ Scroll";
    else
        // breaks if not valid
        return;
    ConsumableContainer consumable = new ConsumableContainer(name);
    List<String> itemLore = ItemUtils.getLore(stack);
    for (String line : itemLore) {
        // remove colors
        line = TextFormatting.getTextWithoutFormattingCodes(line);
        // duration | - Duration: <group1> Seconds
        Matcher m = DURATION_PATTERN.matcher(line);
        if (m.matches() && m.group(1) != null) {
            consumable.setExpirationTime(McIf.getSystemTime() + (Integer.parseInt(m.group(1)) * 1000));
            // currentMillis + (seconds * 1000)
            continue;
        }
        // effects | <Value><Suffix> <ID>
        m = ItemIdentificationOverlay.ID_PATTERN.matcher(line);
        // continues if not a valid effect
        if (!m.matches())
            continue;
        verifyIdentification(m, consumable);
    }
    if (!consumable.isValid())
        return;
    // check for duplicates to avoid doubling timers
    for (ConsumableContainer c : activeConsumables) {
        if (Math.abs(consumable.getExpirationTime() - c.getExpirationTime()) <= 1000) {
            // check within a second
            for (String cEf : c.getEffects().keySet()) {
                if (consumable.getEffects().containsKey(cEf) && c.getEffects().get(cEf).getCurrentAmount() == consumable.getEffects().get(cEf).getCurrentAmount()) {
                    // consumable has already been added, ignore this one
                    return;
                }
            }
        }
    }
    activeConsumables.add(consumable);
    updateActiveEffects();
}
Also used : SkillPoint(com.wynntils.core.framework.enums.SkillPoint) Matcher(java.util.regex.Matcher) ConsumableContainer(com.wynntils.modules.utilities.instances.ConsumableContainer)

Example 3 with ConsumableContainer

use of com.wynntils.modules.utilities.instances.ConsumableContainer in project Wynntils by Wynntils.

the class ConsumableTimerOverlay method addExternalScroll.

public static void addExternalScroll(String chatMsg) {
    String[] splitMsg = chatMsg.split(" for ");
    String effect = splitMsg[0].substring(1);
    String duration = splitMsg[1];
    Matcher m = ItemIdentificationOverlay.ID_PATTERN.matcher(effect);
    if (!m.matches())
        return;
    Matcher m2 = CHAT_DURATION_PATTERN.matcher(duration);
    if (!m2.matches() || m2.group(1) == null)
        return;
    long expiration = McIf.getSystemTime() + (Integer.parseInt(m2.group(1)) * 1000);
    int value = Integer.parseInt(m.group("Value"));
    String shortIdName = ItemIdentificationOverlay.toShortIdName(m.group("ID"), m.group("Suffix") == null);
    ConsumableContainer consumable = null;
    for (ConsumableContainer c : activeConsumables) {
        if (Math.abs(expiration - c.getExpirationTime()) <= 1000) {
            // check within a second
            for (String cEf : c.getEffects().keySet()) {
                if (cEf.equals(shortIdName) && c.getEffects().get(cEf).getCurrentAmount() == value) {
                    // consumable was triggered by player, already in list
                    return;
                }
            }
            if (c.getName().contains("Scroll")) {
                // external scroll already created, add effect to it
                consumable = c;
            }
        }
    }
    if (consumable == null) {
        consumable = new ConsumableContainer(YELLOW + "Ⓔ Scroll");
        consumable.setExpirationTime(expiration);
    }
    verifyIdentification(m, consumable);
    if (!consumable.isValid())
        return;
    if (!activeConsumables.contains(consumable))
        activeConsumables.add(consumable);
    updateActiveEffects();
}
Also used : Matcher(java.util.regex.Matcher) ConsumableContainer(com.wynntils.modules.utilities.instances.ConsumableContainer) SkillPoint(com.wynntils.core.framework.enums.SkillPoint)

Example 4 with ConsumableContainer

use of com.wynntils.modules.utilities.instances.ConsumableContainer in project Wynntils by Wynntils.

the class ConsumableTimerOverlay method render.

@Override
public void render(RenderGameOverlayEvent.Pre event) {
    event.setCanceled(false);
    if (activeConsumables.isEmpty())
        return;
    Iterator<ConsumableContainer> it = activeConsumables.iterator();
    // id names
    int extraY = 0;
    while (it.hasNext()) {
        ConsumableContainer consumable = it.next();
        if (consumable.hasExpired()) {
            // remove if expired
            // update active effects
            removeActiveEffect(consumable);
            it.remove();
            continue;
        }
        drawString(consumable.getName() + " (" + StringUtils.timeLeft(consumable.getExpirationTime() - McIf.getSystemTime() + 1000) + ")", 0, extraY, CommonColors.WHITE, OverlayConfig.ConsumableTimer.INSTANCE.textAlignment, OverlayConfig.ConsumableTimer.INSTANCE.textShadow);
        extraY += 10;
    }
    // effects
    if (!OverlayConfig.ConsumableTimer.INSTANCE.showEffects || activeEffects.isEmpty())
        return;
    extraY += 10;
    for (Map.Entry<String, IdentificationHolder> entry : activeEffects.entrySet()) {
        drawString(entry.getValue().getAsLore(entry.getKey()), 0, extraY, CommonColors.WHITE, OverlayConfig.ConsumableTimer.INSTANCE.textAlignment, OverlayConfig.ConsumableTimer.INSTANCE.textShadow);
        extraY += 10;
    }
}
Also used : IdentificationHolder(com.wynntils.modules.utilities.instances.IdentificationHolder) ConsumableContainer(com.wynntils.modules.utilities.instances.ConsumableContainer) SkillPoint(com.wynntils.core.framework.enums.SkillPoint)

Example 5 with ConsumableContainer

use of com.wynntils.modules.utilities.instances.ConsumableContainer in project Wynntils by Wynntils.

the class ConsumableTimerOverlay method addBasicTimer.

/**
 * Create a new generic timer.
 * @param persistent If this timer should persist over class change or player death
 */
public static void addBasicTimer(String name, int timeInSeconds, boolean persistent) {
    String formattedName = GRAY + name;
    // setExpirationTime adds an extra 1000 so compensate for that here
    long expirationTime = McIf.getSystemTime() + timeInSeconds * 1000 - 1000;
    for (ConsumableContainer c : activeConsumables) {
        if (c.getName().equals(formattedName)) {
            c.setExpirationTime(expirationTime);
            return;
        }
    }
    ConsumableContainer consumable = new ConsumableContainer(formattedName, persistent);
    consumable.setExpirationTime(expirationTime);
    activeConsumables.add(consumable);
}
Also used : ConsumableContainer(com.wynntils.modules.utilities.instances.ConsumableContainer)

Aggregations

ConsumableContainer (com.wynntils.modules.utilities.instances.ConsumableContainer)5 SkillPoint (com.wynntils.core.framework.enums.SkillPoint)3 IdentificationHolder (com.wynntils.modules.utilities.instances.IdentificationHolder)2 Matcher (java.util.regex.Matcher)2