Abaci
Statistics with Context

Introduction

Streaks are a way to tracking unbroken chain of actions without another action happening, popularized by Call of Duty: Modern Warface with killstreaks (kills without deaths). Streaks Tutorial, Space Shooter section Streaks and Platformer section Challenge Streaks are all examples of streaks in action.

Component

Streak can be added as a component (or game object) and requires a bundle, what increments the streak and what zeros to the streak to be filled out.

streak_component.png

Streaks aren't symetrical, if you want to track win streaks as well as losing streaks, you'll need two streak components.

streak_symetrical.png

Code

To query the current value of a streak using Abaci.Streak.GetStat passed into Abaci.Bundle.Get.

int winStreak = bundle.Get(streak.GetStat());

Streaks can also be added (and removed) in code through the Abaci.Streak class.

Streak streak = new Streak();
streak.Register(bundle, "win", "lose");
bundle.Increment("win");
Assert.AreEqual(bundle.Get(streak.GetStat()), 1);
bundle.Increment("win");
bundle.Increment("win");
Assert.AreEqual(bundle.Get(streak.GetStat()), 3);
bundle.Increment("lose");
Assert.AreEqual(bundle.Get(streak.GetStat()), 0);
bundle.Increment("win");
Assert.AreEqual(bundle.Get(streak.GetStat()), 1);

Context

Of course contexts are supported for streaks, both as parameters for streaks and to query streak.

Streak streak = new Streak();
streak.Register(bundle, "pickup&triangle", "pickup&square");
bundle.IncrementWithContexts("pickup", "triangle");
Assert.AreEqual(bundle.Get(streak.GetStat()), 1);
bundle.IncrementWithContexts("pickup", "triangle");
bundle.IncrementWithContexts("pickup", "triangle");
Assert.AreEqual(bundle.Get(streak.GetStat()), 3);
bundle.IncrementWithContexts("pickup", "square");
Assert.AreEqual(bundle.Get(streak.GetStat()), 0);

Similarly for quering

Streak streak = new Streak();
streak.Register(bundle, "win", "lose");
bundle.Increment("win");
bundle.AddContext("tournament");
bundle.Increment("win");
bundle.Increment("win");
Assert.AreEqual(bundle.Get(streak.GetStat()), 3);
Assert.AreEqual(bundle.Get(streak.GetStat() + "&tournament"), 2);

Best Streaks

Obviously streaks reset when they're zeroed, so if you want to store the Best Streak you should add a MaxStat of the streak and it'll be saved (as shown in the Space Shooter example - MaxStat).


API

The full API for the bundle is available Abaci.Streak