From b8ad248fcb88ccde5fe8195a1487143db270f22f Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Wed, 25 Mar 2020 01:45:09 +0000 Subject: [PATCH] runenergy: update graceful recovery rate logic Updates the energy recovery rate calculation to reflect the changes made in the 9th January 2020 game update. Each individual piece of graceful now boosts your recovery rate by 3%, with an extra 1% for the top and legs. With the full set, an extra boost of 10% is added, totalling 30%. Previously, there was no boost for individual pieces, instead the full set was required for a flat boost of 30%. --- .../plugins/runenergy/RunEnergyPlugin.java | 69 ++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runenergy/RunEnergyPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runenergy/RunEnergyPlugin.java index 4fb960b748..bf911c2f35 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runenergy/RunEnergyPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runenergy/RunEnergyPlugin.java @@ -26,7 +26,10 @@ package net.runelite.client.plugins.runenergy; import com.google.common.collect.ImmutableSet; import com.google.inject.Provides; +import java.util.Arrays; import javax.inject.Inject; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import net.runelite.api.Client; import net.runelite.api.Constants; import net.runelite.api.EquipmentInventorySlot; @@ -94,6 +97,27 @@ public class RunEnergyPlugin extends Plugin AGILITY_CAPE, AGILITY_CAPET, MAX_CAPE ); + @RequiredArgsConstructor + @Getter + private enum GracefulEquipmentSlot + { + HEAD(EquipmentInventorySlot.HEAD.getSlotIdx(), ALL_GRACEFUL_HOODS, 3), + BODY(EquipmentInventorySlot.BODY.getSlotIdx(), ALL_GRACEFUL_TOPS, 4), + LEGS(EquipmentInventorySlot.LEGS.getSlotIdx(), ALL_GRACEFUL_LEGS, 4), + GLOVES(EquipmentInventorySlot.GLOVES.getSlotIdx(), ALL_GRACEFUL_GLOVES, 3), + BOOTS(EquipmentInventorySlot.BOOTS.getSlotIdx(), ALL_GRACEFUL_BOOTS, 3), + CAPE(EquipmentInventorySlot.CAPE.getSlotIdx(), ALL_GRACEFUL_CAPES, 3); + + private final int index; + private final ImmutableSet items; + private final int boost; + + private static final int TOTAL_BOOSTS = Arrays.stream(values()).mapToInt(GracefulEquipmentSlot::getBoost).sum(); + } + + // Full set grants an extra 10% boost to recovery rate + private static final int GRACEFUL_FULL_SET_BOOST_BONUS = 10; + @Inject private Client client; @@ -199,30 +223,45 @@ public class RunEnergyPlugin extends Plugin } } - private boolean isLocalPlayerWearingFullGraceful() + private int getGracefulRecoveryBoost() { final ItemContainer equipment = client.getItemContainer(InventoryID.EQUIPMENT); if (equipment == null) { - return false; + return 0; } final Item[] items = equipment.getItems(); - // Check that the local player is wearing enough items to be using full Graceful - // (the Graceful boots will have the highest slot index in the worn set). - if (items == null || items.length <= EquipmentInventorySlot.BOOTS.getSlotIdx()) + if (items == null) { - return false; + return 0; } - return (ALL_GRACEFUL_HOODS.contains(items[EquipmentInventorySlot.HEAD.getSlotIdx()].getId()) && - ALL_GRACEFUL_TOPS.contains(items[EquipmentInventorySlot.BODY.getSlotIdx()].getId()) && - ALL_GRACEFUL_LEGS.contains(items[EquipmentInventorySlot.LEGS.getSlotIdx()].getId()) && - ALL_GRACEFUL_GLOVES.contains(items[EquipmentInventorySlot.GLOVES.getSlotIdx()].getId()) && - ALL_GRACEFUL_BOOTS.contains(items[EquipmentInventorySlot.BOOTS.getSlotIdx()].getId()) && - ALL_GRACEFUL_CAPES.contains(items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId())); + int boost = 0; + + for (final GracefulEquipmentSlot slot : GracefulEquipmentSlot.values()) + { + if (items.length <= slot.getIndex()) + { + continue; + } + + final Item wornItem = items[slot.getIndex()]; + + if (wornItem != null && slot.getItems().contains(wornItem.getId())) + { + boost += slot.getBoost(); + } + } + + if (boost == GracefulEquipmentSlot.TOTAL_BOOSTS) + { + boost += GRACEFUL_FULL_SET_BOOST_BONUS; + } + + return boost; } int getEstimatedRecoverTimeRemaining() @@ -234,11 +273,7 @@ public class RunEnergyPlugin extends Plugin // Calculate the amount of energy recovered every second double recoverRate = (48 + client.getBoostedSkillLevel(Skill.AGILITY)) / 360.0; - - if (isLocalPlayerWearingFullGraceful()) - { - recoverRate *= 1.3; // 30% recover rate increase from Graceful set effect - } + recoverRate *= 1.0 + getGracefulRecoveryBoost() / 100.0; // Calculate the number of seconds left final double secondsLeft = (100 - client.getEnergy()) / recoverRate;