GameAchievements 1.0.2.1
dotnet add package GameAchievements --version 1.0.2.1
NuGet\Install-Package GameAchievements -Version 1.0.2.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="GameAchievements" Version="1.0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GameAchievements" Version="1.0.2.1" />
<PackageReference Include="GameAchievements" />
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 GameAchievements --version 1.0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GameAchievements, 1.0.2.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 GameAchievements@1.0.2.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=GameAchievements&version=1.0.2.1
#tool nuget:?package=GameAchievements&version=1.0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Achievements Library (Stateless Root Pattern)
A composable achievements framework using a stateless root criteria pattern:
- Central singleton root criteria (e.g. Criteria.Kills / Score / Deaths) expose Create(condition) which returns per-achievement handles.
- Runtime events (kills, score changes, deaths) are pushed once into the root (root.Evaluate(context)), which fans out to every handle.
- Achievement trees are composed from handles (no direct game state snapshot passing, no per-achievement polling logic).
Core Concepts
- AbstractCriterion<TCondition,TContext,TProgress>: Public base for creating a root criterion. You implement creation of initial progress and mutation logic; framework manages handles & fan-out.
- Condition record/class: Immutable requirement data (EnemyType, Required, etc.).
- Progress (TProgress): Arbitrary mutable state tracked per handle (e.g. int count, struct with multiple counters).
- Handle (IUpdatableCriterion): Internal per-achievement progress state (framework-generated; not user implemented).
- Criteria registry: Static singleton instances (Criteria.Kills, Criteria.Score, Criteria.Deaths).
- AchievementBuilder: Fluent AllOf / AnyOf composition of handles.
- AchievementTracker: Evaluates unlock transitions and persists via IAchievementStore.
Why This Pattern?
- Single authoritative event stream per context type.
- Many achievements share same events with distinct conditions.
- No duplicated event dispatch logic per instance.
- Simple persistence (usually only unlocked names).
Example: Defining Achievements
var kill10Zombies = Criteria.Kills.Create("Kill 10 Zombies", new KillTypeCountRoot.Condition("Zombie", 10));
var score25 = Criteria.Score.Create("Score 25", new ScoreRoot.Condition(25));
var dieTwice = Criteria.Deaths.Create("Die Twice", new DeathRoot.Condition(2));
var achievement = AchievementBuilder
.CreateNew("Pressure", "Kill 10 zombies AND (Score 25 OR Die Twice)")
.AllOf("Root", all =>
{
all.Criterion("10 Zombies", kill10Zombies);
all.AnyOf("Branch", any =>
{
any.Criterion("Score 25", score25);
any.Criterion("Die Twice", dieTwice);
});
})
.Build();
Pushing Events
Criteria.Kills.Evaluate("Zombie");
Criteria.Score.Evaluate(5);
Criteria.Deaths.Evaluate(1);
Tracking Unlocks
var tracker = new AchievementTracker();
tracker.Register(achievement);
tracker.EvaluateAll();
Built-in Root Criteria
- KillTypeCountRoot (string enemyType)
- ScoreRoot (int deltaScore)
- DeathRoot (int deltaDeaths)
Creating a Custom Criterion
Implement a condition + criterion class only.
public sealed class DistanceRoot : AbstractCriterion<DistanceRoot.Condition, double, double>
{
public sealed record Condition(double RequiredMeters);
protected override double CreateInitialProgress(Condition c) => 0d;
protected override bool UpdateProgress(ref double progress, Condition c, double deltaMeters)
{
progress += deltaMeters;
return progress >= c.RequiredMeters;
}
}
// Register
public static class Criteria
{
public static readonly DistanceRoot Distance = new();
}
// Use
var run100 = Criteria.Distance.Create("Run 100m", new DistanceRoot.Condition(100));
Optional DSL Extensions
public static class AchievementBuilderExtensions
{
public static AchievementBuilder Kill(this AchievementBuilder b, string label, string enemy, int count)
=> b.Criterion(label, Criteria.Kills.Create(label, new KillTypeCountRoot.Condition(enemy, count)));
}
Persistence
Store unlocked achievement names (IAchievementStore). Mid-progress serialization optional; expose Handles() if needed.
Migration Notes
Legacy root base replaced by AbstractCriterion<TCondition,TContext,TProgress>.
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.