Statemachines become much more powerful with predefined conditions which, when satisfied, change to another state. When changing to another state, actions can be performed.
Conditions and actions are classes with a predefined interface that allows them to be added to any state, while a state subclass makes it easy to evaluate the conditions and perform the actions.
This tutorial explains how to setup such a system so that you can write Statemachines without having to write the same boilerplate code (such as checking distance between nodes) over and over again.
Pseudo example use:
AAPLEnemyChaseState *chase = [[AAPLEnemyChaseState alloc] initWithGame:game entity:enemy];
// automatically enter chase when player closer than "50" and own health above 25%
[chase addConditions:@[PlayerInRange(50), OwnerHealthPercent(GreaterThan, 25)]];
AAPLEnemyFleeState *flee = [[AAPLEnemyFleeState alloc] initWithGame:game entity:enemy];
// enter flee state when owner health below 25%, if so, play a sound once
[chase addConditions:@[OwnerHealthPercent(LessThan, 25)]];
[chase addActions:@[PlaySound(@"crybaby.wav")]];
Estimation: 2-3 days