Class BoostDosePolicy

java.lang.Object
privbot.mechanics.BoostDosePolicy

public final class BoostDosePolicy extends Object
Decides when to drink another dose of a stat boost (overload, super combat, and so on) from the boost the account actually shows. There are no client reads and no actions here, and no assumed effect duration. The caller confirms the dose left the inventory before consumed(long), then keeps feeding the observed boost to observe(int, long), which says to stop if the boost never appeared within the settle window.

What it proves: a dose is "due" only when the boost was read, read as expired, no confirmed dose is still awaiting its boost, and the retry throttle has passed. A confirmed dose with no observable boost by its deadline fails closed (observe(int, long) returns false) instead of drinking repeatedly.

Unreadable looks like: a boost of Integer.MIN_VALUE. It is never expired and never due, and maxBoost(int[], int[]) returns it for any incomplete or non-positive stat read.

Thread rule: not thread safe; keep it on the one worker thread that runs the upkeep. No client calls.

  • Constructor Summary

    Constructors
    Constructor
    Description
    BoostDosePolicy(Predicate<String> isDose, int expiredAtOrBelow, long settleMs, int maxFailures)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    attempted(long now)
    A dose was tried but not confirmed consumed: throttle the next try.
    void
    consumed(long now)
    The dose was confirmed gone from the inventory: wait for its boost and clear the failure count.
    boolean
    due(int boost, long now)
     
    boolean
    expired(int boost)
     
    boolean
    Read-only: true when the recorded failures have reached maxFailures.
    boolean
    isDose(String itemName)
    Whether itemName is a dose of this boost.
    static int
    maxBoost(int[] real, int[] current)
    The largest boost over the paired skills, so one drained skill cannot request another dose while others stay boosted.
    boolean
    observe(int boost, long now)
    False means a confirmed dose never produced an observable boost; do not drink repeatedly.
    Overload flasks and potions, doses 1 to 6: expired at +4 or less, 9 s settle, three failures.
    boolean
    Records a failed attempt (this changes state).
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BoostDosePolicy

      public BoostDosePolicy(Predicate<String> isDose, int expiredAtOrBelow, long settleMs, int maxFailures)
      Parameters:
      isDose - item names that are a dose of this boost
      expiredAtOrBelow - the observed boost at or below which the effect counts as gone
      settleMs - wait after an attempt, and the time a confirmed dose gets to show its boost
      maxFailures - recordFailure() and hasFailed() report true at this many failures
      Throws:
      IllegalArgumentException - when maxFailures < 1 or settleMs < 0
  • Method Details

    • overload

      public static BoostDosePolicy overload()
      Overload flasks and potions, doses 1 to 6: expired at +4 or less, 9 s settle, three failures.
    • isDose

      public boolean isDose(String itemName)
      Whether itemName is a dose of this boost. A null name is not.
    • maxBoost

      public static int maxBoost(int[] real, int[] current)
      The largest boost over the paired skills, so one drained skill cannot request another dose while others stay boosted. real and current are matching levels per skill. Any missing, mismatched or non-positive level gives Integer.MIN_VALUE (unreadable), never an expired boost.
    • expired

      public boolean expired(int boost)
    • reset

      public void reset()
    • due

      public boolean due(int boost, long now)
    • attempted

      public void attempted(long now)
      A dose was tried but not confirmed consumed: throttle the next try.
    • consumed

      public void consumed(long now)
      The dose was confirmed gone from the inventory: wait for its boost and clear the failure count.
    • recordFailure

      public boolean recordFailure()
      Records a failed attempt (this changes state). True once maxFailures is reached. Only a confirmed dose (consumed(long)) or reset() clears the count.
    • hasFailed

      public boolean hasFailed()
      Read-only: true when the recorded failures have reached maxFailures. Records nothing.
    • observe

      public boolean observe(int boost, long now)
      False means a confirmed dose never produced an observable boost; do not drink repeatedly.