Module: Lich::Gemstone::Combat::Definitions::Messages Private

Defined in:
documented/gemstone/combat/defs/messages.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defines non-combat game line patterns and the event families scripts subscribe to.

Events cover hunting script concerns: disarmed weapons, curses, traps, ambushers, blessings, archery state, spell marks, and weapon reactions. Patterns are pinned to messaging in the wild and gated by PatternGate; each Family scans only while something subscribes to it.

Defined Under Namespace

Classes: Family, MessageDef, MessageTable

Constant Summary collapse

CONTRACTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The payload contract of every shipped event: the family it belongs to and the keys (with types) its consumers rely on. This is what a player supplement (defs/supplements.rb) that reuses a shipped event name is validated against - the same name is only useful if subscribers still get the payload they expect - and it is also how a supplement is kept from moving an event to another family. A key absent here is optional (rooted's id, for one); nil is accepted for any key. Types: :string, :integer, :boolean, :symbol. Keep in step with the defs below - the spec checks that every shipped event has an entry naming its family.

{
  disarm_seen: { family: :disarm, keys: { kind: :symbol, noun: :string } },
  sanctum_transform: { family: :disarm, keys: { noun: :string } },
  itchy_curse: { family: :hazard, keys: {} },
  infected_wound: { family: :hazard, keys: {} },
  hive_trap: { family: :hazard, keys: { kind: :symbol } },
  entangled: { family: :hazard, keys: {} },
  ambusher: { family: :ambush, keys: { noun: :string } },
  bolted: { family: :ambush, keys: {} },
  rooted: { family: :hold, keys: {} },
  unrooted: { family: :hold, keys: { id: :string } },
  item_limit: { family: :hold, keys: {} },
  bless_shrugged: { family: :bless, keys: { id: :string, noun: :string } },
  bless_expired: { family: :bless, keys: { id: :string, noun: :string } },
  arrow_stuck: { family: :archery, keys: { id: :string, where: :string } },
  aiming: { family: :archery, keys: { where: :string } },
  bond_return: { family: :archery, keys: { what: :string } },
  haze_703: { family: :marks, keys: { id: :string, on: :boolean } },
  rebuke_1614: { family: :marks, keys: { id: :string, on: :boolean } },
  swift_justice: { family: :marks, keys: { charges: :integer } },
  arcane_reflex: { family: :marks, keys: { active: :boolean } },
  weapon_reaction: { family: :reaction, keys: { reaction: :string } }
}.freeze
NONE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A data block that yields no event payload from a matched line.

Used by defs where the pattern match itself is the only fact of interest, with no captures to extract. Subscribers receive only the :raw key.

Returns:

  • (Proc) —

    a lambda accepting a MatchData and returning an empty Hash

->(_m) { {} }
SHIPPED_FAMILIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Families of message patterns that ship with Lich.

Defines patterns for disarm, hazard, ambush, hold, bless, archery, marks, and reaction events. Player supplements can extend these with the same family name or add new families with the user_ prefix.

Returns:

  • (Array<Family>) —

    the frozen list of shipped families

[
  # ecleanse set_hooks 1618: the line-driven recoveries. The disarm
  # lines carry the weapon's noun; what hand it was in and where
  # we stood is the subscriber's to read at the moment.
  family(:disarm, [
           [:disarm_seen, %r{Your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a> is knocked from your grasp}, ->(m) { { kind: :recover, noun: m[:noun] } }],
           [:disarm_seen, %r{your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a> at .+?\.  The weapon rebounds off of the hardened .+? and is wrenched from your hand\.  It slides along the ground and disappears into the shadows!}, ->(m) { { kind: :recover, noun: m[:noun] } }],
           [:disarm_seen, %r{^Your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a> strikes one of the bony protrusions on <pushBold/>an? <a exist="\d+" noun="[^"]+">[^<]+</a><popBold/> \w+ and it is wrenched out of your grasp!}, ->(m) { { kind: :recover, noun: m[:noun] } }],
           [:disarm_seen, %r{^You swing your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a> at <pushBold/>(?:an?|the) <a exist="[^"]+" noun="[^"]+">[^<]+</a><popBold/>\.  The weapon strikes one of the bony protrusions on the <pushBold/><a exist="[^"]+" noun="[^"]+">[^<]+</a><popBold/> \w+ and it is wrenched out of your grasp!}, ->(m) { { kind: :recover, noun: m[:noun] } }],
           [:disarm_seen, %r{Your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a> tears free from your hands and floats}, ->(m) { { kind: :telekinetic_recover, noun: m[:noun] } }],
           [:disarm_seen, %r{The webbing entangles your <a exist="[^"]+" noun="(?<noun>[^"]+)">[^<]+</a>, rendering it useless}, ->(m) { { kind: :recover_weapon_webbing, noun: m[:noun] } }],
           [:sanctum_transform, %r{Striking with a serpent's unsettling quickness, .*\.  Vile .*, kindling it into an unholy semblance of life\.  The .* form twists and mutates, sprouting scales and cold eyes as it transforms into a <a exist="\d+" noun="(?<noun>[^"]+)">[^<]+</a>!}, ->(m) { { noun: m[:noun] } }]
         ]),

  # ecleanse: afflictions and traps that take a trip to clear.
  family(:hazard, [
           [:itchy_curse, /You shiver slightly as an invisible rash covers your body/, NONE],
           [:infected_wound, /The flesh around the wound feels hot and cold at the same time, heavy with infection\./, NONE],
           [:hive_trap, /You notice a flickering glint in the shadows/, ->(_m) { { kind: :apparatus } }],
           [:hive_trap, /The apparatus flickers with deadly radiance/, ->(_m) { { kind: :apparatus } }],
           [:hive_trap, /The ground churns violently as flashes of chitin jut from its depths/, ->(_m) { { kind: :ground } }],
           [:hive_trap, /The ground underfoot churns violently and huge chitinous mandibles flash as the insectoid monstrosity below goes into a feeding frenzy!/, ->(_m) { { kind: :ground } }],
           [:hive_trap, /Hindered by the churning terrain, you are helpless as the concealed assailant's mandibles snap at you from the safety of its pit trap!/, ->(_m) { { kind: :ground } }],
           [:entangled, /^An unseen force entangles you, restricting your movement!/, NONE]
         ]),

  # bigshot hunt_monitor 2322-2383: the flee rules' lines.
  family(:ambush, [
           [:ambusher, %r{<a exist="-?\d+" noun="(?<noun>[a-zA-Z]*?)">[a-zA-Z]*?</a> leaps from hiding to attack!}i, ->(m) { { noun: m[:noun] } }],
           [:ambusher, /flies out of the shadows toward/i, ->(_m) { { noun: nil } }],
           [:ambusher, /A shadowy figure leaps from hiding to attack/i, ->(_m) { { noun: nil } }],
           [:bolted, /^You bolt/i, NONE]
         ]),

  # bigshot hunt_monitor 2406-2416: held in place, freed, the item
  # limit.
  family(:hold, [
           [:rooted, /You don't seem to be able to move(?: your legs)? to do that\./, NONE],
           [:rooted, %r{You are unable to get out of the way as <pushBold/>the <a exist="(?<id>\d+)" noun="snake">snake</a><popBold/> coils tightly around you, holding you in place!}, ->(m) { { id: m[:id] } }],
           [:unrooted, %r{You're finally able to break free of <pushBold/>the <a exist="(?<id>\d+)" noun="snake">snake's</a><popBold/> coils!}, ->(m) { { id: m[:id] } }],
           [:item_limit, /^You are unable to hold the number of items /, NONE],
           [:item_limit, /^You note some treasure of interest but are unable to pick any up\./, NONE],
           [:item_limit, /^At your touch, the lit sigils marking your .+ ignite, then quickly sputter out again\./, NONE]
         ]),

  # bigshot hunt_monitor 2359-2367: a blessing shrugged off or gone.
  family(:bless, [
           [:bless_shrugged, %r{The <a exist="(?<id>[^"]+)" noun="(?<noun>[^"]+)">[^<]+</a> strikes? true.* shrugs off some of the damage!}i, ->(m) { { id: m[:id], noun: m[:noun] } }],
           [:bless_expired, %r{Your <a exist="(?<id>[^"]+)" noun="(?<noun>[^"]+)">[^<]+</a> returns? to normal\.}i, ->(m) { { id: m[:id], noun: m[:noun] } }]
         ]),

  # bigshot's archery state (cmd_dislodge, archery aiming, the
  # bonded weapon's return).
  family(:archery, [
           [:arrow_stuck, %r{The .* sticks in <pushBold/>an? <a exist="(?<id>\d+)" noun="[^"]+">[^<]+</a><popBold/>'s (?:left |right )?(?<where>.*)!}i, ->(m) { { id: m[:id], where: m[:where] } }],
           [:aiming, /You're now aiming at the (?<where>.*) of/i, ->(m) { { where: m[:where] } }],
           [:aiming, /You're now no longer aiming at anything in particular/i, ->(_m) { { where: nil } }],
           [:bond_return, /^An? (?<what>.*) rises out of the shadows and flies back to your waiting hand!/i, ->(m) { { what: m[:what] } }]
         ]),

  # Marks a spell leaves on a creature, and counters on us
  # (bigshot hunt_monitor 2387-2405).
  family(:marks, [
           [:haze_703, %r{<pushBold/>.*?<a exist="(?<id>[^"]+)" noun="[^"]+">[^<]+</a><popBold/>.*?is suddenly surrounded by a blood red haze\.}i, ->(m) { { id: m[:id], on: true } }],
           [:haze_703, %r{The blood red haze dissipates from around.*?<pushBold/>.*?<a exist="(?<id>[^"]+)" noun="[^"]+">[^<]+</a><popBold/>}i, ->(m) { { id: m[:id], on: false } }],
           [:rebuke_1614, %r{<pushBold/>.*?<a exist="(?<id>[^"]+)" noun="[^"]+">[^<]+</a><popBold/>.*?visibly struggling against your radiant aura!}i, ->(m) { { id: m[:id], on: true } }],
           [:rebuke_1614, %r{<pushBold/>.*?<a exist="(?<id>[^"]+)" noun="[^"]+">[^<]+</a><popBold/>.*?in awe of your radiant aura!}i, ->(m) { { id: m[:id], on: true } }],
           [:rebuke_1614, %r{<pushBold/>.*?<a exist="(?<id>[^"]+)" noun="[^"]+">[^<]+</a><popBold/>.*?recovers from being rebuked}i, ->(m) { { id: m[:id], on: false } }],
           [:swift_justice, /Your Swift Justice charges are increased to (?<n>\d+)\./i, ->(m) { { charges: m[:n].to_i } }],
           [:swift_justice, /Your Swift Justice surges through you! Its charges are reduced to (?<n>\d+)\./i, ->(m) { { charges: m[:n].to_i } }],
           [:arcane_reflex, /^Vital energy infuses you, hastening your arcane reflexes!/i, ->(_m) { { active: true } }],
           [:arcane_reflex, /^Nature's blessing of vitality departs as your arcane prowess returns to normal\./i, ->(_m) { { active: false } }]
         ]),

  # The weapon reaction prompt (bigshot perform_reaction).
  family(:reaction, [
           [:weapon_reaction, %r{^You could use this opportunity to <d cmd='WEAPON (?<reaction>\w+\s#\d+)'>.*</d>!}i, ->(m) { { reaction: m[:reaction] } }]
         ])
].freeze
USER_FAMILIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Families the player's file declares that are not shipped ones (their names carry the user_ prefix; see Supplements). Rows come in through family()'s splice, so pass none here.

Supplements.message_families
.reject { |n| SHIPPED_FAMILIES.any? { |f| f.name == n } }
.map { |n| family(n, []) }.freeze
FAMILIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

All available message families: shipped and user-defined.

This is the authoritative list of families scanned by the messaging system.

Returns:

  • (Array<Family>) —

    the frozen combined list

(SHIPPED_FAMILIES + USER_FAMILIES).freeze
BY_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Index of families by name for O(1) lookup.

Returns:

  • (Hash{Symbol => Family}) —

    family name to Family struct mapping

FAMILIES.to_h { |f| [f.name, f] }.freeze
FAMILY_OF =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

event -> family, for subscription gating

FAMILIES.each_with_object({}) { |f, h| f.events.each { |e| h[e] = f } }.freeze
EVENTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

All event names the messaging system can emit.

Returns:

  • (Array<Symbol>) —

    the frozen list of event names

FAMILY_OF.keys.freeze
TABLE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The current frozen message definitions table, bound at load time.

Holds families, family index, event-to-family map, and all known events. Subscribers read this table once per scan call. Hot reloads rebind this constant atomically to ensure all parts stay in sync.

Returns:

See Also:

MessageTable.new(FAMILIES, BY_NAME, FAMILY_OF, EVENTS).freeze

Class Method Summary collapse

Class Method Details

.family(name, rows) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a family from [event, pattern, data] rows, with the player's supplement rows for that family name appended (empty when there is no file), before the gate is derived.



97
98
99
100
101
# File 'documented/gemstone/combat/defs/messages.rb', line 97

def self.family(name, rows)
  defs = (rows + Supplements.messages(name)).map { |event, pattern, data| MessageDef.new(event, pattern, data) }
  gate, always = PatternGate.build(defs.map(&:pattern))
  Family.new(name, defs.freeze, gate, always)
end

.scan(line, families = TABLE.families) ⇒ Array<Array(Symbol, Hash)>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Every event a line yields across families, as [event, data]. A def whose data block returns nil emits nothing: that is how a supplement def reports a capture it could not convert instead of publishing a misleading fact (shipped data blocks never return nil).

Parameters:

  • families (Array<Family>) (defaults to: TABLE.families) —

    the ones to scan (all by default)

Returns:

  • (Array<Array(Symbol, Hash)>)


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'documented/gemstone/combat/defs/messages.rb', line 274

def self.scan(line, families = TABLE.families)
  found = []
  families.each do |family|
    # Both the gate and the match below are timeout-guarded in
    # PatternGate: one pathological pattern must not cost the
    # facts this line already yielded, nor the defs after it.
    next if family.rejects?(line)

    family.defs.each do |d|
      m = PatternGate.safe_match(d.pattern, line)
      next unless m

      payload = d.data.call(m)
      next if payload.nil?

      found << [d.event, payload.merge(raw: line)]
    end
  end
  found
end

.table ⇒ MessageTable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current message table.

Returns:



264
# File 'documented/gemstone/combat/defs/messages.rb', line 264

def self.table = TABLE