Add support for custom formulas.

This commit re-frames the formula concept used by the wave growth, swarm
amount, and boss health wave configuration properties. It fundamentally
changes how these values are calculated, from a static, compile-time set
of enum values and hardcoded expressions, to a powerful math expression
feature that supports constants, variables, operators, and functions.

In part to remain backwards compatible with existing MobArena setups,
and in part for a better user experience, the old enum-based expressions
are relocated into a new file, `formulas.yml`, as _macros_. The file is
written to the plugin folder if missing, and it contains a formula for
each of the legacy values for each of the enums. Additionally, it has a
global section with some predefined macros for inspiration's sake. The
goal of this file is to allow people to define new formulas and reuse
them in their wave configurations instead of having to duplicate the
same formulas again and again.

Parts of the system are extensible. It is possible for other plugins to
register additional constants, variables, operators, and functions.

Closes #460
Closes #461
This commit is contained in:
Andreas Troelsen
2021-04-07 22:13:03 +02:00
parent 0da90f3963
commit 9081ec8055
45 changed files with 2940 additions and 72 deletions
+34
View File
@@ -0,0 +1,34 @@
# These formulas work for all properties. If a global formula has the
# same name as a property-specific formula, it is the property-specific
# formula that will be used when parsing the given property.
global:
wave-squared: <current-wave> ^ 2
wave-inverted: max(1, <final-wave> - <current-wave>)
five-each: <live-players> * 5
double-team: <live-players> / 2
top-up: max(1, 10 - <live-monsters>)
dead-man-walking: max(1, <dead-players>)
# These formulas only work in the "growth" property of Default Waves.
wave-growth:
old: <current-wave> + <initial-players>
slow: min(ceil(<initial-players> / 2) + 1, 13) * <current-wave> ^ 0.5
medium: min(ceil(<initial-players> / 2) + 1, 13) * <current-wave> ^ 0.65
fast: min(ceil(<initial-players> / 2) + 1, 13) * <current-wave> ^ 0.8
psycho: min(ceil(<initial-players> / 2) + 1, 13) * <current-wave> ^ 1.2
# These formulas only work in the "amount" property of Swarm Waves.
swarm-amount:
low: max(1, floor(<initial-players> / 2)) * 10
medium: max(1, floor(<initial-players> / 2)) * 20
high: max(1, floor(<initial-players> / 2)) * 30
psycho: max(1, floor(<initial-players> / 2)) * 60
# These formulas only work in the "health" property of Boss Waves.
boss-health:
verylow: (<initial-players> + 1) * 20 * 4
low: (<initial-players> + 1) * 20 * 8
medium: (<initial-players> + 1) * 20 * 15
high: (<initial-players> + 1) * 20 * 25
veryhigh: (<initial-players> + 1) * 20 * 40
psycho: (<initial-players> + 1) * 20 * 60