Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
retraigo committed Jul 14, 2023
1 parent e1871a6 commit 94eccd0
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const items = [
{ result: "Mob character #1", chance: 5 },
{ result: "Mob character #2", chance: 5 },
{ result: "Mob character #3", chance: 5 },

]

const machine = new GachaMachine(items)

Expand All @@ -41,6 +41,42 @@ machine.get(10) // Rolls 10x
*/
```

### Rolling distinct elements
You can roll distinct elements using the `LimitedGachaMachine`. It is slower
than `GachaMachine` but there shouldn't be much noticeable difference.

The "distinct" behavior only applies to within a single `.get()` call. It
doesn't affect the pool of items used when initializing `new LimitedGachaMachine()`.

```js

import { LimitedGachaMachine } from "https://deno.land/x/fortuna/mod.ts"
// or
import { LimitedGachaMachine } from "https://deno.land/x/fortuna/dist/limited_machine.js"

const items = [
{ result: "SSR cool character", chance: 1 },
{ result: "Kinda rare character", chance: 3 },
{ result: "Mob character #1", chance: 5 },
{ result: "Mob character #2", chance: 5 },
{ result: "Mob character #3", chance: 5 },
]

const machine = new LimitedGachaMachine(items)

machine.get(4) // Rolls 4x

/*
My result:
[
"Kinda rare character",
"Mob character #1",
"Mob character #3",
"Mob character #2",
]
*/
```

### Plain weighted random selection

You probably don't need all complicated stuff. Here's a quick way to just create a simple weight-based gacha system:
Expand Down

0 comments on commit 94eccd0

Please sign in to comment.