MoLibrary.GachaPool
1.0.1
dotnet add package MoLibrary.GachaPool --version 1.0.1
NuGet\Install-Package MoLibrary.GachaPool -Version 1.0.1
<PackageReference Include="MoLibrary.GachaPool" Version="1.0.1" />
<PackageVersion Include="MoLibrary.GachaPool" Version="1.0.1" />
<PackageReference Include="MoLibrary.GachaPool" />
paket add MoLibrary.GachaPool --version 1.0.1
#r "nuget: MoLibrary.GachaPool, 1.0.1"
#:package MoLibrary.GachaPool@1.0.1
#addin nuget:?package=MoLibrary.GachaPool&version=1.0.1
#tool nuget:?package=MoLibrary.GachaPool&version=1.0.1
MoLibrary.GachaPool
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
- 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();
});
}
}
- Register the services in your application:
services.AddMemoryCardPool<MyGameGachaPoolLoader>();
- 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 | Versions 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. |
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Support multiple frameworks and conditional compilation