🌙 LUA GLYPH DIFFICULTY: Adept Behavioral

The State of the Shapeshifter

Altering an entity's behavior entirely by swapping its internal magical state table.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Polymorph
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LUA PATTERN //
local BearState = { attack = function() return "Maul!" end }
local EagleState = { attack = function() return "Dive!" end }

local Druid = { state = BearState }
function Druid:shift(newState)
  self.state = newState
end
function Druid:strike()
  return self.state.attack()
end

print(Druid:strike())
Druid:shift(EagleState)
print(Druid:strike())

State

A shapeshifter’s essence fundamentally alters depending on their current form. In Lua, the State pattern is trivially elegant: simply replace the internal state reference with a different table of Fae Moon Glyphs. The druid’s strike() command dynamically delegates to the active spirit form.

Runic Tags: #fae #state #polymorphism