Custom conditions
What this page is for
Section titled “What this page is for”A condition asks one question about the game and answers yes, no, or “I cannot tell”. Schemes, requirements and a character’s decisions are full of them. This page shows three ways to add a question of your own, from the lightest to the heaviest. Pick the lightest that works.
When you come here
Section titled “When you come here”- A rule only your code can answer: “has the player’s army reached the pass?”
- You want that rule as a row inside a condition list, next to the built-in rows.
- You want a check node of your own, with a True and a False output.
Way 1: a bool method as a row
Section titled “Way 1: a bool method as a row”Mark a method of your code with [IntrigueMethod] and let it return bool. The Studio lists it under Method Returns True, a row kind in the Code group of the menu that + Add condition (or + Add another check on a check node) opens. The same method also works in the Run Code node. How to write the method is on Code methods.
The method returns bool, bool? or void: true and false answer the row, null leaves it without an answer, and a void method that returns without throwing answers true. The method takes nothing, (Actor conspirator), (Actor conspirator, Actor target), (Scheme scheme) (it then needs a running scheme) or (IntrigueCall call). The row’s For actor defaults to the Conspirator and Against to the Target; they show only when the method takes those actors. (sources: IntrigueMethodAttribute.cs, ConditionKinds.cs)
The demo has methods of this shape. This one is from MapPlace.cs; its description text is cut here:
[IntrigueMethod(Description = "Whether the target holds a province the conspirator can raid: ...")]public static bool? HasRaidPlace(Actor conspirator, Actor target) => HasPlace(Kind.Raid, conspirator, target);The row is not called when the conditions above it already settle the answer. A method that throws, an unknown name, or a call that cannot be made leaves the row without an answer. The row’s summary reads “MethodName(…) returns True”. (source: ConditionKinds.cs, MethodCondition)
Way 2: a row kind of your own
Section titled “Way 2: a row kind of your own”When your question needs its own settings in the inspector, write a ConditionData class.
A row kind is a [Serializable] sealed class with a public constructor with no parameters, plain public fields, and a [Condition] attribute. Its class name and field names are stored in the database, so keep them once the kind is used. (source: ConditionData.cs)
[Condition(title)] takes:
| Setting | Default | Meaning |
|---|---|---|
Title |
required | The name in the Add Condition menu. |
Order |
0 | Position in the menu; lower comes first. |
Group |
none | The sub-menu: Actor, Family, Clan, AI, Scheme, Variables or Code. It is display only. A kind without a group is listed at the top; a group name the picker does not know sorts last. |
Graphs |
Scheme and Check |
Where the row can be used. |
Description |
none | One sentence, the tooltip of the menu entry. |
The members of ConditionData:
| Member | What it does |
|---|---|
abstract ConditionResult Test(NodeInfo flow) |
Checks the row. Must not allocate, must not change the game, and must not call flow.Stop or flow.Next. |
abstract string Summary(NodeDescription d) |
One short text in the author’s words, for example “Gold ≥ 800”. Add errors and warnings to d. |
virtual string Explain(NodeInfo flow) |
Why the row has no answer. Called only when the flow stops because of it. Default: “A condition could not be checked.” |
Join, Negate |
How the row joins the ones above (And or Or) and NOT. The Studio sets them; they are hidden in the inspector. |
static Answer(bool), static Apply(result, negate) |
Helpers: bool to result, and NOT. |
ConditionResult has three values: False, True and Unknown. Return Unknown exactly where a single check node would stop the flow: the actor, clan or variable the row reads is not there. A row never changes the game.
One row object belongs to one node. Copy a row only through JSON, never by sharing the reference. (source: ConditionData.cs)
Example. Compiled against the package’s runtime assembly; not run in Unity. A row that checks the first letters of an actor’s name. Built from the signatures above.
using System;using MrW.Intrigues.Graph;
[Serializable][Condition("Name Starts With", Order = 100, Group = "Actor", Description = "Checks the first letters of an actor's name.")]public sealed class NameStartsWithCondition : ConditionData{ public ActorRef Who = ActorRef.Target; public string Letters;
public override ConditionResult Test(NodeInfo flow) => Check(flow, Who, Letters);
public override string Summary(NodeDescription d) => Text(d, Who, Letters);
public override string Explain(NodeInfo flow) => $"{Who} is not available.";
public static ConditionResult Check(NodeInfo flow, ActorRef who, string letters) { var actor = who.Resolve(flow); if (actor == null) return ConditionResult.Unknown; return Answer(actor.Name != null && actor.Name.StartsWith(letters ?? string.Empty, StringComparison.Ordinal)); }
public static string Text(NodeDescription d, ActorRef who, string letters) => $"{who.Describe(d)} has a name that starts with {letters}";}The Check and Text methods are static on purpose. The package writes each of its own rows this way, so a node and its row answer and read alike.
A class without [Condition] is logged as an error and cannot be added: “Intrigues: condition class X has no [Condition] attribute and cannot be added in the Studio.” A class without a public constructor without parameters gets its own error: “Intrigues: condition class X needs a public parameterless constructor.” (source: ConditionListInspector.cs, ConditionKindRegistry)
In an Edit-mode preview a row of your own has no answer. The base class returns Unknown there, and only a running game knows. (source: ConditionData.cs)
A row whose Graphs includes Check is also asked outside a running scheme. There flow.IsCheck is true and flow.Schemer is null, so Test must not depend on a scheme run.
Way 3: a check node
Section titled “Way 3: a check node”A check node is a node whose settings are its first condition. Derive from ConditionNodeData. It already has the outputs True (output 0) and False (output 1), joins extra rows with And and Or, and runs them. Run and Describe are sealed. You supply:
| Member | What it does |
|---|---|
abstract Type ConditionType |
The row kind with the same fields as the node. The editor moves values between them. |
abstract ConditionResult Test(NodeInfo flow) |
Checks the node’s own settings, without NOT. |
abstract string Summary(NodeDescription d) |
The text of the first condition. It is protected. |
virtual string Explain(NodeInfo flow) |
Why there is no answer. Protected. |
virtual string RowSummary(NodeDescription d) |
The one-line text when the node holds several conditions. Defaults to Summary. |
virtual void Details(NodeDescription d) |
More body lines, shown only while the node has one condition. |
When a condition has no answer and the others do not settle the result, the flow stops. With Verbose logging on in the Studio settings, the Console says why; for an added row the line starts with “Condition 2: …”.
Example. Compiled against the package’s runtime assembly; not run in Unity. The node that pairs with the row above. The field names and types are the same as the row’s.
using System;using MrW.Intrigues.Graph;
[Serializable][GraphNode("Check Name", "Conditions/Actor/Check Name", NodeCategory.Condition, Description = "Checks the first letters of an actor's name.", Color = NodeColor.Check)]public sealed class CheckNameData : ConditionNodeData{ public ActorRef Who = ActorRef.Target; public string Letters;
public override Type ConditionType => typeof(NameStartsWithCondition);
public override ConditionResult Test(NodeInfo flow) => NameStartsWithCondition.Check(flow, Who, Letters);
protected override string Summary(NodeDescription d) => NameStartsWithCondition.Text(d, Who, Letters);
protected override string Explain(NodeInfo flow) => $"{Who} is not available.";}This is how the package writes CheckGenderData: the same shape, in Runtime/Graph/Nodes/Conditions.cs.
In an Edit-mode preview a check node of your own answers Unknown: only the package’s own check nodes have a preview answer.
How it connects
Section titled “How it connects”- Writing a custom node covers
NodeData,[GraphNode], outputs andRun. - Requirements shows where rows are asked outside a running scheme.
- Who a node acts on explains
ActorRef.
Mistakes and messages
Section titled “Mistakes and messages”| What you see | Why | What to do |
|---|---|---|
The Console says a condition class has no [Condition] attribute. |
The attribute is missing. | Add it. |
| The row’s field values are gone after you rename a field. | Class and field names are stored. | Keep them once the kind is used. |
| The flow stops at the node; with Verbose logging on, the Console says “… is not available.” | Test returned Unknown. |
Link the case in the scheme, or make the actor available. |
| A method row never answers. | The method returned null, threw, or is not found by that name. |
Return bool, and check the name. |