Module: Lich::DragonRealms::XMLDelta

Extended by:
Common::XMLParserDelta::Base
Defined in:
documented/dragonrealms/xml_delta.rb

Overview

DragonRealms' semantic deltas for the shared server-stream parser. See Lich::Common::XMLParserDelta for the composition and the hook contracts.

Constant Summary collapse

SUBTITLE_ROOM =

Pattern to extract the room title and optional UID marker from a DragonRealms subtitle.

Matches "[Room Name]" and an optional trailing UID marker " (230008)" or " (**)". Named captures: :roomtitle for the bracketed room name, :uid for the numeric ID or asterisks, or nil if the marker is absent.

Examples:

"[Bosque Deriel, Hermit's Shacks] (230008)".match(SUBTITLE_ROOM)
# => #<MatchData "[Bosque Deriel, Hermit's Shacks] (230008)" roomtitle="[Bosque Deriel, Hermit's Shacks]" uid="230008">

See Also:

%r{(?<roomtitle>\[.*?\])(?:\s\((?<uid>\d+|\*+)\))?}.freeze

Class Method Summary collapse

Methods included from Common::XMLParserDelta::Base

apply_crtr_status, main_subtitle

Class Method Details

.apply_crtr_status(id, flags, in_room_objs: false) ⇒ Object

DragonRealms' batch carries its own id and arrives after the room-objs component, so it is applied at once, id-first: Creature.sync registers the creature and marks it in the room even when no link names it (the legacy stream has none). Names come from the room-objs link, the stream-order pairing (legacy) or the assess backfill. Because sync registers by id, this works whichever order the tag and the link arrive.



62
63
64
65
66
67
# File 'documented/dragonrealms/xml_delta.rb', line 62

def self.apply_crtr_status(id, flags, in_room_objs: false) # rubocop:disable Lint/UnusedMethodArgument
  return false unless defined?(Lich::DragonRealms::Creature)

  Lich::DragonRealms::Creature.sync(id, flags)
  true
end

.main_subtitle(subtitle, nav_uid_pending:) ⇒ Object

DragonRealms subtitles read " - [Bosque Deriel, Hermit's Shacks]", with a trailing UID marker only when the game's ShowRoomID flag is ON: " (230008)" for a room with a UID, " ()" for one without.



47
48
49
50
51
52
53
54
# File 'documented/dragonrealms/xml_delta.rb', line 47

def self.main_subtitle(subtitle, nav_uid_pending:)
  room = subtitle.match(SUBTITLE_ROOM)
  return {} unless room

  update = { room_title: "[#{room[:roomtitle]}]", nav_uid_pending: false, show_room_id: !room[:uid].nil? }
  update[:room_id] = (room[:uid] =~ /\A\d+\z/ ? room[:uid].to_i : 0) if room[:uid] && !nav_uid_pending
  update
end