Weighted gacha system.
Create an item using GachaMachine.createItem
More weight = more common
const items = [
GachaMachine.createItem("SSR cool character", 1),
GachaMachine.createItem("Kinda rare character", 3),
GachaMachine.createItem("Mob character", 5),
GachaMachine.createItem("Mob character", 5),
GachaMachine.createItem("Mob character", 5),
}
]
const machine = new GachaMachine(items)
machine.get(10) // Rolls 10x
/*
My result:
[
"Kinda rare character",
"Mob character",
"Mob character",
"Mob character",
"Mob character",
"Kinda rare character",
"Mob character",
"Mob character",
"Mob character",
"Mob character"
]
*/
You probably don't need all complicated stuff. Here's a quick way to just create a simple weight-based gacha system: (Only works on v1.1.0 and above)
import fortuna from 'xxx' // wherever you are importing from.
const items = [
GachaMachine.createRollChoice("SSR cool character", 1),
GachaMachine.createRollChoice("Kinda rare character", 3),
GachaMachine.createRollChoice("Mob character", 5),
GachaMachine.createRollChoice("Mob character", 5),
GachaMachine.createRollChoice("Mob character", 5),
]
GachaMachine._roll(items) // Rolls one item from the list of items
GachaMachine.createRollChoice
just returns an object with result
and chance
.
import { GachaMachine } from 'xxx' // wherever you are importing from.
const items = [
{result: "SSR cool character", chance: 1},
{result: "Kinda rare character", chance: 3},
{result: "Mob character", chance: 5},
{result: "Mob character", chance: 5},
{result: "Mob character", chance: 5},
]
GachaMachine._roll(items) // Rolls one item from the list of items
Documentation for the latest version can be found in https://doc.deno.land/https://deno.land/x/fortuna/mod.ts
A guide for usage can be found in docs.nekooftheabyss.moe