hestia-rsps / hestia

An open-source Kotlin game server.
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Loot tables #93

Open GregHib opened 4 years ago

GregHib commented 4 years ago

Requirements:

Drop tables are essentially simplified utility-based systems #58 so why not plan them to cover these use cases instead? If containers #76 are made functionally #92 couldn't we pass add functions as the values of a table and then just apply/transform the choice onto the container?

Further reading

GregHib commented 4 years ago

See Apache math Enumerated Distributions

GregHib commented 4 years ago
import org.apache.commons.math3.distribution.EnumeratedDistribution
import org.apache.commons.math3.util.Pair

val nested = EnumeratedDistribution(
    listOf(
        Pair("Third", 0.5),
        Pair("Fourth", 0.5)
    )
)
val list = listOf<Pair<Any, Double>>(
    Pair("First", 0.2),
    Pair("Second", 0.4),
    Pair(
        nested,
        0.5
    ),
    Pair("Fifth", 0.3)
)
val distribution = EnumeratedDistribution<Any>(list)

fun main() {
    repeat(10) {
        var sample = distribution.sample()
        while (sample is EnumeratedDistribution<*>) {
            sample = sample.sample()
        }
        println(sample)
    }
}

Pros:

Cons: