npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@garug/gacha

v1.0.0-alpha.2

Published

A versatile gacha system library for managing summons and probabilities in your applications

Downloads

3

Readme

Garug's Gacha

codecov

Description

This repository contains a comprehensive Gacha System designed to simulate the mechanics commonly found in many popular mobile and online games. The system allows users to "pull" for items or characters, which are distributed based on predefined probabilities. This project aims to provide a flexible and extensible framework for developers looking to integrate a gacha mechanic into their applications.

Features

  • Configurable Gacha Pools: Easily define different pools with unique data
  • Rarity Tiers: Support for multitle rarity tiers with customizable drop rates
  • Pity System: Implement a pity system to ensure users receive a high-rarity items after a certain number of pulls
  • Statistics: Generate detailed statistics on pulls, including probabilities and user history

Usage

Basic Example

import { generatePool } from "garug/gacha";

// Define items and their probabilities
const items = [
  { name: "Some item", probability: 0.5 },
  { name: "Another item", probability: 0.5 },
];

// create a pool
const pool = generatePool({ items });

// get a item
const { item } = pool.random();

Defining probabilities

Instead of define a specific probability for each item, you can use rarities

const rarities = [
  { name: "common", probability: 0.5 },
  { name: "rare", probability: 0.3 },
  { name: "epic", probability: 0.15 },
  { name: "legendary", probability: 0.05 },
];

There are two different ways of rarities usage, define them on each item or group items for each rarity

// for each item
const items_a = [
  { name: "Some item", probability: "rare" },
  { name: "Another item", probability: "legendary" },
];

// grouping items
const items_b = {
  rare: [{ name: "Some item" }],
  legendary: [{ name: "Another item" }],
};

// Both are acceptable to create a pool
const pool_a = generatePool({ items: items_a, rarities });
const pool_b = generatePool({ items: items_b, rarities });
const pool_c = generatePool({ items: [...items_a, ...items_b], rarities });

[!TIP] Using rarities, take attention to quantity of items for each rarity to have desired output, for example, if you have two rarities (Lets call them rare and common), rare with 0.1 probability and common with 0.9 probability, rare has just one item and common has ten items

In this scenario, the rare item has 0.1 of probability, while every common item has 0.09 of probability, making a specific common card more difficult to appear than the rare item

Sorting a Item

After a pool is created, just call random function to get a item

const item = pool.random();

How to Contribute

  1. Fork the project
  2. Commit your changes
  3. Push to the branch
  4. Create a new Pull Request

License

This project is licensed under the MIT license