The Rule Engine provides a flexible system for creating conditional automation rules that can trigger actions based on game state conditions.
The Rule Engine enables:
The engine is designed with modularity in mind:
Main rule processing and management.
Each rule consists of conditions and actions.
Rule := {
Id: 1,
Name: "Health Low Rule",
Enabled: true,
Priority: 1,
CooldownMs: 1000,
LastTrigger: 0,
Conditions: [
{
Type: "Pixel",
X: 500,
Y: 300,
Color: "0xFF0000",
Tolerance: 10,
Operator: "Equals"
}
],
Actions: [
{
Type: "Skill",
SkillId: 5,
DelayMs: 0
}
]
}
Supports various condition types for flexible rule creation.
PixelCondition := {
Type: "Pixel",
X: 100,
Y: 200,
Color: "0xRRGGBB",
Tolerance: 5,
Operator: "Equals" | "NotEquals" | "GreaterThan" | "LessThan"
}
TimerCondition := {
Type: "Timer",
IntervalMs: 5000,
LastTrigger: 0,
OneShot: false
}
SkillCondition := {
Type: "Skill",
SkillId: 1,
CheckType: "Ready" | "Cooldown" | "Active",
Value: 0 ; Cooldown remaining or threshold
}
CompositeCondition := {
Type: "Composite",
Operator: "AND" | "OR" | "NOT",
Conditions: [
{ ... }, // Sub-condition 1
{ ... } // Sub-condition 2
]
}
Defines what happens when rule conditions are met.
SkillAction := {
Type: "Skill",
SkillId: 1,
DelayMs: 0,
ThreadId: 1
}
KeyAction := {
Type: "Key",
Key: "F1",
DelayMs: 0
}
ScriptAction := {
Type: "Script",
Script: "MyFunction()",
DelayMs: 0
}
Initializes the rule engine.
Parameters: None
Returns: Boolean indicating success
Adds a new rule to the engine.
Parameters:
ruleConfig (Map): Rule configurationReturns: Rule ID
Removes a rule from the engine.
Parameters:
ruleId (Integer): Rule identifierReturns: Boolean indicating success
Evaluates all rules and executes triggered actions.
Parameters: None
Returns: Number of rules triggered
Registers a new condition type.
Parameters:
typeName (String): Condition type identifierevalFunc (Function): Evaluation functionReturns: Boolean indicating success
Evaluates a single condition.
Parameters:
condition (Map): Condition configurationReturns: Boolean evaluation result
Registers a new action type.
Parameters:
typeName (String): Action type identifierexecFunc (Function): Execution functionReturns: Boolean indicating success
Executes a single action.
Parameters:
action (Map): Action configurationReturns: Boolean indicating success
; Create a rule that uses a health potion when health is low
healthRule := {
Id: 1,
Name: "Use Health Potion",
Enabled: true,
Priority: 10,
CooldownMs: 30000,
Conditions: [
{
Type: "Pixel",
X: 400,
Y: 250,
Color: "0xFF0000",
Tolerance: 5,
Operator: "Equals"
}
],
Actions: [
{
Type: "Key",
Key: "5", ; Health potion hotkey
DelayMs: 100
}
]
}
RuleEngine_AddRule(healthRule)
; Rule that triggers only when multiple conditions are met
compositeRule := {
Id: 2,
Name: "Boss Phase Change",
Enabled: true,
Priority: 5,
Conditions: [
{
Type: "Composite",
Operator: "AND",
Conditions: [
{
Type: "Pixel",
X: 600,
Y: 300,
Color: "0x00FF00",
Tolerance: 10
},
{
Type: "Timer",
IntervalMs: 10000,
OneShot: true
}
]
}
],
Actions: [
{
Type: "Skill",
SkillId: 8,
DelayMs: 0
}
]
}
; Register a custom condition type for buff detection
RuleEngine_RegisterConditionType("Buff", BuffCondition_Evaluate)
BuffCondition_Evaluate(condition) {
; Custom buff detection logic
buffActive := CheckBuff(condition["BuffId"])
return buffActive
}
; Use the custom condition
buffRule := {
Conditions: [
{
Type: "Buff",
BuffId: 123
}
],
Actions: [ ... ]
}
Rules are stored in profile data and loaded with profiles:
profile := App["ProfileData"]
profile["Rules"] := [rule1, rule2, rule3]
Rules are automatically saved with profile data and restored on load.
The rule engine includes comprehensive error handling:
The engine is designed for easy extension:
RuleEngine_RegisterConditionType()RuleEngine_RegisterActionType()