The Poltergeist's State
Let your automation spirit morph its behavior based on whether it is dormant, actively haunting, or enraged.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Spectral Phasing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class HauntingState {
Handle(spirit) {
throw Error("Not implemented")
}
}
class DormantState extends HauntingState {
Handle(spirit) {
ToolTip("Spirit is sleeping...")
Sleep(500)
spirit.ChangeState(ActiveHauntingState())
}
}
class ActiveHauntingState extends HauntingState {
Handle(spirit) {
ToolTip("Spirit is haunting!")
Send("Wooo")
Sleep(500)
spirit.ChangeState(DormantState())
}
}
class PhasingSpirit {
__New() {
this.state := DormantState()
}
ChangeState(new_state) {
this.state := new_state
}
Tick() {
this.state.Handle(this)
}
}
ghost := PhasingSpirit()
ghost.Tick() ; Sleeps, then changes to active
ghost.Tick() ; Haunts, then changes to dormant
Runic Tags:
#autohotkey
#state
#automation
#poltergeist