Class: Lich::DragonRealms::DRRoom

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/drinfomon/drroom.rb

Overview

Tracks the current room state: NPCs, PCs, exits, objects, and player status.

Data is shared across all running scripts and updated by the script engine as room text is received from the game server. Arrays are frozen when appropriate (npcs, dead_npcs) to prevent script-to-script interference; mutable arrays (pcs, room_objs) are live references.

Class Method Summary collapse

Class Method Details

.dead_npcs ⇒ Array<String>

Dead NPC nouns in the room; same shape and rules as npcs.

Returns:



182
183
184
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 182

def self.dead_npcs
  @@dead_npcs
end

.dead_npcs=(val) ⇒ Object

Stores a frozen copy, leaving the caller's array untouched.

Parameters:



188
189
190
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 188

def self.dead_npcs=(val)
  @@dead_npcs = val.dup.freeze
end

.description ⇒ String

Returns the full description of the current room.

Delegates to XMLData for live room data.

Returns:



134
135
136
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 134

def self.description
  XMLData.room_description
end

.exits ⇒ Array<String>

Returns the exits available from the current room.

Delegates to XMLData for live room data.

Returns:



116
117
118
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 116

def self.exits
  XMLData.room_exits
end

.group_members ⇒ Array

Returns the array of group member identifiers in the current room.

Returns:

  • (Array)


141
142
143
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 141

def self.group_members
  @@group_members
end

.group_members=(val) ⇒ Object

Sets the array of group member identifiers in the current room.

Parameters:

  • val (Array)


148
149
150
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 148

def self.group_members=(val)
  @@group_members = val
end

.npcs ⇒ Array<String>

Living NPC nouns in the room, sorted, duplicates repeated (["goblin", "goblin"]). Read-only: every script shares this array, so it is frozen; take a copy (DRRoom.npcs.dup) to edit. Address a particular creature by its Lich::DragonRealms::Creature id, not by position.

Returns:



33
34
35
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 33

def self.npcs
  @@npcs
end

.npcs=(val) ⇒ Object

Stores a frozen copy, leaving the caller's array untouched.

Parameters:



39
40
41
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 39

def self.npcs=(val)
  @@npcs = val.dup.freeze
end

.pcs ⇒ Array<String>

Returns the array of player character nouns currently in the room.

Returns:



100
101
102
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 100

def self.pcs
  @@pcs
end

.pcs=(val) ⇒ Object

Sets the array of player character nouns in the room.

Parameters:



107
108
109
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 107

def self.pcs=(val)
  @@pcs = val
end

.pcs_prone ⇒ Array<String>

Returns the array of player character nouns currently lying prone in the room.

Returns:



155
156
157
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 155

def self.pcs_prone
  @@pcs_prone
end

.pcs_prone=(val) ⇒ Object

Sets the array of player character nouns lying prone in the room.

Parameters:



162
163
164
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 162

def self.pcs_prone=(val)
  @@pcs_prone = val
end

.pcs_sitting ⇒ Array<String>

Returns the array of player character nouns currently sitting in the room.

Returns:



169
170
171
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 169

def self.pcs_sitting
  @@pcs_sitting
end

.pcs_sitting=(val) ⇒ Object

Sets the array of player character nouns sitting in the room.

Parameters:



176
177
178
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 176

def self.pcs_sitting=(val)
  @@pcs_sitting = val
end

.room_objs ⇒ Array

Returns the array of objects present in the current room.

Returns:

  • (Array)


195
196
197
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 195

def self.room_objs
  @@room_objs
end

.room_objs=(val) ⇒ Object

Sets the array of objects in the current room.

Parameters:

  • val (Array)


202
203
204
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 202

def self.room_objs=(val)
  @@room_objs = val
end

.title ⇒ String

Returns the title of the current room.

Delegates to XMLData for live room data.

Returns:



125
126
127
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 125

def self.title
  XMLData.room_title
end

.unignored_npcs(ignored) ⇒ Array<String>

npcs without the creatures an ignore list names. Same shape as npcs (sorted nouns, duplicates repeated), so it replaces the DRRoom.npcs - ignored idiom.

An entry always removes every NPC whose noun equals it, as npcs - ignored does. When the Creature roster lists exactly the living creatures in npcs, an entry also removes the creatures it names by noun or by full name (CreatureInstance#matches?), so "spectral white leopard" skips that pet but not a wild leopard. While the roster and npcs disagree (a refresh in progress, a creature with no name yet, or a name with no noun), only the noun rule applies.

Parameters:

  • ignored (Array<String>, nil) —

    configured entries

Returns:

  • (Array<String>) —

    a new array



57
58
59
60
61
62
63
64
65
66
67
68
# File 'documented/dragonrealms/drinfomon/drroom.rb', line 57

def self.unignored_npcs(ignored)
  ignored = Array(ignored).compact.map(&:to_s)
  by_noun = npcs - ignored
  return by_noun if by_noun.empty?

  pairs = room_creatures_with_nouns
  return by_noun unless pairs

  pairs.reject { |creature, noun| ignored.include?(noun) || ignored.any? { |entry| creature.matches?(entry) } }
       .map(&:last)
       .sort
end