MoLibrary.GachaPool 1.0.1

dotnet add package MoLibrary.GachaPool --version 1.0.1
                    
NuGet\Install-Package MoLibrary.GachaPool -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MoLibrary.GachaPool" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MoLibrary.GachaPool" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MoLibrary.GachaPool" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MoLibrary.GachaPool --version 1.0.1
                    
#r "nuget: MoLibrary.GachaPool, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MoLibrary.GachaPool@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MoLibrary.GachaPool&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MoLibrary.GachaPool&version=1.0.1
                    
Install as a Cake Tool

MoLibrary.GachaPool

NuGet NuGet Downloads Tests codecov

MoLibrary.GachaPool is a flexible and efficient .NET library for managing gacha pools with probability-based drawing mechanisms. It provides a robust foundation for implementing gacha systems in games or any application requiring probability-based item selection.

Language

English | 简体中文

Features

  • 🎯 Probability-based gacha drawing system
  • 🔄 Support for multiple gacha pools
  • 🎲 Customizable rarity and probability settings
  • 📊 Built-in draw statistics tracking
  • 🧩 Generic type support for custom item types
  • 🔌 Easy integration with dependency injection
  • 🔒 Thread-safe operations
  • 🚀 High-performance implementation

Installation

Install the package via NuGet:

dotnet add package MoLibrary.GachaPool

Quick Start

  1. First, create your gacha pool loader by inheriting from CardsPoolByMemoryProvider:
public class MyGameGachaPoolLoader : CardsPoolByMemoryProvider
{
    public override void ConfigurePools()
    {
        // Configure a standard pool with integer-based items
        ConfigurePool("standardPool", pool =>
        {
            var standardItems = Card<int>.CreateMultiCards(CardRarity.OneStar, 1, 2, 3, 4, 5);
            pool.AddCards(standardItems);
            pool.BuildPool();
        });

        // Configure probability settings for different rarities
        ConfigurePool("customPool", pool =>
        {
            pool.SetPoolRarityProbability(CardRarity.OneStar, 0.7)
                .SetPoolRarityProbability(CardRarity.TwoStar, 0.3);
            // Add your items...
            pool.BuildPool();
        });
    }
}
  1. Register the services in your application:
services.AddMemoryCardPool<MyGameGachaPoolLoader>();
  1. Use the gacha pool manager in your code:
public class GameService
{
    private readonly ICardPoolManager _poolManager;

    public GameService(ICardPoolManager poolManager)
    {
        _poolManager = poolManager;
    }

    public Card DrawItem(string poolName)
    {
        var drawer = _poolManager.GetDrawer(poolName);
        return drawer?.DrawCard();
    }

    public string GetDrawStatistics(string poolName)
    {
        var drawer = _poolManager.GetDrawer(poolName);
        return drawer?.Statistician.GetReport().GetTableString();
    }
}

Advanced Usage

Custom Item Types

You can create custom item types by inheriting from Card<T>:

public class CharacterItem : Card<CharacterItem>
{
    public string Name { get; set; }
    public int Level { get; set; }

    public CharacterItem(string name, int level, CardRarity rarity) : base(rarity)
    {
        Name = name;
        Level = level;
    }
}

Then use it with the generic drawer:

var drawer = _poolManager.GetDrawer<CharacterItem>("characterPool");
var character = drawer?.DrawCard();

Probability Configuration

You can configure probabilities for different item rarities:

ConfigurePool("myPool", pool =>
{
    pool.SetPoolRarityProbability(CardRarity.OneStar, 0.6)
        .SetPoolRarityProbability(CardRarity.TwoStar, 0.3)
        .SetPoolRarityProbability(CardRarity.ThreeStar, 0.1);
    // Add items...
    pool.BuildPool();
});

Draw Statistics

The library automatically tracks draw statistics:

var drawer = _poolManager.GetDrawer("myPool");
var stats = drawer?.Statistician.GetReport().GetTableString();
Console.WriteLine(stats);

Performance Considerations

  • The library uses thread-safe collections for concurrent access
  • Gacha pools are built once and cached for subsequent draws
  • Drawing operations are optimized using binary search
  • Memory usage is optimized for large pools

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 101 1/12/2025
1.0.0 112 1/10/2025

- Support multiple frameworks and conditional compilation