Klasse Formula

java.lang.Object
de.delinkedde.mobarenareborn.util.Formula

public final class Formula extends Object
A compiled arithmetic expression with named variables, used to drive configurable scaling (mob health, wave size, boss health and the experience curve).

An expression is parsed once via compile(String) into an evaluation tree and can then be evaluated repeatedly with different variable bindings. Supported syntax:

  • the operators + - * / with the usual precedence, parentheses and unary minus;
  • decimal number literals;
  • variables written in angle brackets, for example <current-wave>;
  • the functions min(a,b), max(a,b), pow(a,b), ceil(a), floor(a), round(a), sqrt(a) and abs(a).

Example: min(<monster-limit>, ceil(2 + 0.8 * pow(<current-wave>, 0.8))).

  • Methodendetails

    • compile

      @NotNull public static @NotNull Formula compile(@NotNull @NotNull String expression)
      Compiles an expression into a reusable formula.
      Parameter:
      expression - the expression source
      Gibt zurück:
      the compiled formula
      Löst aus:
      Formula.FormulaException - if the expression is malformed
    • evaluate

      public double evaluate(@NotNull @NotNull Map<String,Double> variables)
      Evaluates the formula with the given variable bindings.
      Parameter:
      variables - the variable values, keyed without the surrounding angle brackets
      Gibt zurück:
      the result
      Löst aus:
      Formula.FormulaException - if the expression references an undefined variable
    • source

      @NotNull public @NotNull String source()
      Gibt zurück:
      the original expression source
    • toString

      public String toString()
      Setzt außer Kraft:
      toString in Klasse Object