Interface IScoreService
Service interface for managing dynamic, multi-metric scoring.
Namespace: Serenity.Score.Application.Interfaces
Assembly: Serenity.Score.Application.dll
Syntax
public interface IScoreService : IService, IFoundationSettings
Remarks
Provides operations to manipulate score metrics keyed by ScoreKey. Game-specific scoring rules should translate gameplay events into calls to this service, without changing the score model itself.
Methods
Add(ScoreKey, float)
Adds a delta to the specified metric.
Declaration
void Add(ScoreKey key, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | delta | The amount to add. |
Divide(ScoreKey, float)
Divides the specified metric by a divisor.
Declaration
void Divide(ScoreKey key, float divisor)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | divisor | The divisor. Must not be zero. |
GetSnapshot()
Returns an immutable snapshot of all current metric values.
Declaration
ScoreSnapshot GetSnapshot()
Returns
| Type | Description |
|---|---|
| ScoreSnapshot | A ScoreSnapshot containing all metrics. |
Multiply(ScoreKey, float)
Multiplies the specified metric by a factor.
Declaration
void Multiply(ScoreKey key, float factor)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | factor | The multiplication factor. |
Register(ScoreKey, ScoreMetricKind)
Registers a new metric with the specified key and kind.
Declaration
void Register(ScoreKey key, ScoreMetricKind kind)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| ScoreMetricKind | kind | The metric interpretation kind. |
ResetAll()
Resets all registered metrics to zero.
Declaration
void ResetAll()
ResetKey(ScoreKey)
Resets the specified metric to zero.
Declaration
void ResetKey(ScoreKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
Set(ScoreKey, float)
Sets the specified metric to an explicit value.
Declaration
void Set(ScoreKey key, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | value | The new value. |
Subtract(ScoreKey, float)
Subtracts a delta from the specified metric.
Declaration
void Subtract(ScoreKey key, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | delta | The amount to subtract. |
TryGetValue(ScoreKey, out ScoreValue)
Attempts to get the current value of a specific metric.
Declaration
bool TryGetValue(ScoreKey key, out ScoreValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| ScoreValue | value | The metric value, if found. |
Returns
| Type | Description |
|---|---|
| bool | True if the metric exists; otherwise false. |