Class AchievementCondition
One node of an authored unlock rule. A condition answers whether the rule it represents is satisfied right now, describes how far along it is, and — when it counts something across sessions — serializes that count into a string the achievement's progress row carries.
Inherited Members
Namespace: Serenity.Achievements.Application.Conditions
Assembly: Serenity.Achievements.Application.dll
Syntax
public abstract class AchievementCondition
Remarks
Deliberately engine-agnostic and stored inline through Unity's [SerializeReference]
polymorphic serialization, the same shape
Serenity.ProceduralAnimator.Infrastructure.Conditions.Condition uses. It lives in
Business rather than beside that one because every leaf reads a ScoreKey, a progress
flag or a signal type name, none of which need the engine — which is what lets the whole
tree be unit-tested headlessly.
IsMet(in AchievementEvaluationContext) is allowed to mutate a node's own counters, because counting IS what a signal or duration leaf does. GetProgress(in AchievementEvaluationContext) must not: the evaluator calls both per evaluation, so a node whose progress re-enters IsMet(in AchievementEvaluationContext) would count twice. The default implementation here is only safe for a leaf that reads state it does not own.
Constructors
AchievementCondition()
Declaration
protected AchievementCondition()
Properties
Children
This node's children, in authoring order. A leaf has none; CompositeAchievementCondition
and SingleChildAchievementCondition override this to expose the child list or
child reference they each hold, which is what lets ChildrenOf(AchievementCondition)
walk any node — including one authored outside this namespace — without testing for a
concrete type.
Declaration
public virtual IReadOnlyList<AchievementCondition> Children { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<AchievementCondition> |
DisplayName
The name this node is listed under in the authoring tree.
Declaration
public abstract string DisplayName { get; }
Property Value
| Type | Description |
|---|---|
| string |
NeedsTick
Whether this node — or anything under it — has to be asked rather than told: it either measures time, or reads state that changes without dispatching anything. The evaluator ticks exactly the trees that say yes, so a purely signal-driven project walks no tree per frame at all.
Declaration
public virtual bool NeedsTick { get; }
Property Value
| Type | Description |
|---|---|
| bool |
PersistsState
Whether this node — or anything under it — counts something that has to survive a relaunch. The evaluator only writes a condition state for a tree that says yes.
Declaration
public virtual bool PersistsState { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
CaptureState()
Serializes this node's counters, or returns null when it has none to keep.
Declaration
public virtual string CaptureState()
Returns
| Type | Description |
|---|---|
| string |
CollectSignalTypeNames(ICollection<string>)
Adds every signal type name this node listens for to sink. Composites
recurse into their children, so the evaluator can index a whole tree in one call.
Declaration
public virtual void CollectSignalTypeNames(ICollection<string> sink)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection<string> | sink | The collection receiving the names. |
Describe(bool)
The one-line phrase this node contributes to AchievementConditionSummary —
what it actually demands, such as "Signal EnemyKilled ×100" rather than the bare
DisplayName an author sees in the tree editor.
Declaration
public virtual string Describe(bool isNested)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isNested | Whether this node sits inside another node's summary. A node that combines several children uses this to bracket itself so the grouping stays unambiguous once nested. |
Returns
| Type | Description |
|---|---|
| string |
Remarks
Defaults to DisplayName, which is exactly what a node with nothing more to say should read as. A node phrasing something a reader would otherwise have to open the tree to find out overrides this instead of teaching AchievementConditionSummary about its own concrete type.
DescribeChild(AchievementCondition, bool)
The seam a subclass uses to describe a nested child inside its own Describe(bool); the guarded entry point for whole trees is Describe(AchievementCondition).
Declaration
protected static string DescribeChild(AchievementCondition child, bool isNested)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementCondition | child | The child node to describe, or null for an empty slot. |
| bool | isNested | Whether the child sits inside this node's summary. |
Returns
| Type | Description |
|---|---|
| string |
GetProgress(in AchievementEvaluationContext)
How far along this node is, for display and for the achievement's progress numerator. Overriding implementations must not mutate anything.
Declaration
public virtual AchievementConditionProgress GetProgress(in AchievementEvaluationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementEvaluationContext | context | What the world looks like at this evaluation. |
Returns
| Type | Description |
|---|---|
| AchievementConditionProgress |
IsMet(in AchievementEvaluationContext)
Whether the rule this node represents is satisfied for the given evaluation.
Declaration
public abstract bool IsMet(in AchievementEvaluationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementEvaluationContext | context | What the world looks like at this evaluation. |
Returns
| Type | Description |
|---|---|
| bool |
Reset()
Forgets every counter this node accumulated, leaving it as freshly authored.
Declaration
public virtual void Reset()
RestoreState(string)
Restores counters previously produced by CaptureState().
Declaration
public virtual void RestoreState(string state)
Parameters
| Type | Name | Description |
|---|---|---|
| string | state | The captured state. Null or malformed input must be ignored. |
Validate()
Describes what is wrong with this node's configuration, or null when it is valid.
Declaration
public virtual string Validate()
Returns
| Type | Description |
|---|---|
| string |
ValidateCustomRule(IAchievementCustomConditionResolver)
Validates this node against a live resolver, which is the only way to tell a renamed or
deleted project-supplied rule type from one that simply is not loaded yet. Returns null
for a node that names no such rule, which is what every node except
CustomCondition is.
Declaration
public virtual string ValidateCustomRule(IAchievementCustomConditionResolver resolver)
Parameters
| Type | Name | Description |
|---|---|---|
| IAchievementCustomConditionResolver | resolver | The resolver to check against. Overrides must tolerate null. |
Returns
| Type | Description |
|---|---|
| string | What is wrong, or null when the node is valid. |
Remarks
Exists on the base so the authoring rules can validate whatever names a project-supplied rule by asking the node itself, rather than testing for that one concrete type.