Class: Lich::Common::GameObj

Inherits:
Object
  • Object
show all
Defined in:
documented/common/gameobj.rb

Overview

Represents a game object in the Lich game system. This class manages various attributes and behaviors of game objects.

Examples:

Creating a game object

obj = GameObj.new("1", "sword", "Sword of Destiny")

Direct Known Subclasses

RoomObj

Constant Summary collapse

@@loot =
Array.new
@@npcs =
Array.new
@@npc_status =
Hash.new
@@pcs =
Array.new
@@pc_status =
Hash.new
@@inv =
Array.new
@@contents =
Hash.new
@@right_hand =
nil
@@left_hand =
nil
@@room_desc =
Array.new
@@fam_loot =
Array.new
@@fam_npcs =
Array.new
@@fam_pcs =
Array.new
@@fam_room_desc =
Array.new
@@type_data =
Hash.new
@@type_cache =
Hash.new
@@sellable_data =
Hash.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, noun, name, before = nil, after = nil) ⇒ GameObj

Initializes a new game object.

Parameters:

  • id (String)

    The object ID.

  • noun (String)

    The object noun.

  • name (String)

    The object name.

  • before (String, nil) (defaults to: nil)

    Optional prefix for the name.

  • after (String, nil) (defaults to: nil)

    Optional suffix for the name.



36
37
38
39
40
41
42
43
44
45
46
# File 'documented/common/gameobj.rb', line 36

def initialize(id, noun, name, before = nil, after = nil)
  @id = id
  @noun = noun
  @noun = 'lapis' if @noun == 'lapis lazuli'
  @noun = 'hammer' if @noun == "Hammer of Kai"
  @noun = 'ball' if @noun == "ball and chain" # DR item 'ball and chain' doesn't work.
  @noun = 'mother-of-pearl' if (@noun == 'pearl') and (@name =~ /mother\-of\-pearl/)
  @name = name
  @before_name = before
  @after_name = after
end

Instance Attribute Details

#after_nameObject

Returns the value of attribute after_name.



27
28
29
# File 'documented/common/gameobj.rb', line 27

def after_name
  @after_name
end

#before_nameObject

Returns the value of attribute before_name.



27
28
29
# File 'documented/common/gameobj.rb', line 27

def before_name
  @before_name
end

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'documented/common/gameobj.rb', line 26

def id
  @id
end

#nameObject

Returns the value of attribute name.



27
28
29
# File 'documented/common/gameobj.rb', line 27

def name
  @name
end

#nounObject

Returns the value of attribute noun.



27
28
29
# File 'documented/common/gameobj.rb', line 27

def noun
  @noun
end

Class Method Details

.[](val) ⇒ GameObj?

Retrieves a game object by ID, noun, or name.

Parameters:

  • val (String, Regexp)

    The identifier to search for.

Returns:

  • (GameObj, nil)

    The found game object or nil if not found.

Raises:

  • (ArgumentError)

    If val is not a String or Regexp.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'documented/common/gameobj.rb', line 132

def self.[](val)
  unless val.is_a?(String) || val.is_a?(Regexp)
    respond "--- Lich: error: GameObj[] passed with #{val.class} #{val} via caller: #{caller[0]}"
    respond "--- Lich: error: GameObj[] supports String or Regexp only"
    Lich.log "--- Lich: error: GameObj[] passed with #{val.class} #{val} via caller: #{caller[0]}\n\t"
    Lich.log "--- Lich: error: GameObj[] supports String or Regexp only\n\t"
    if val.is_a?(Integer)
      respond "--- Lich: error: GameObj[] converted Integer #{val} to String to continue"
      val = val.to_s
    else
      return
    end
  end
  if val.is_a?(String)
    if val =~ /^\-?[0-9]+$/ # ID lookup
      # excludes @@room_desc ID lookup due to minimal use case, but could be added in future if desired
      @@inv.find { |o| o.id == val } || @@loot.find { |o| o.id == val } || @@npcs.find { |o| o.id == val } || @@pcs.find { |o| o.id == val } || [@@right_hand, @@left_hand].find { |o| o.id == val } || @@room_desc.find { |o| o.id == val } || @@contents.values.flatten.find { |o| o.id == val }
    elsif val.split(' ').length == 1 # noun lookup
      @@inv.find { |o| o.noun == val } || @@loot.find { |o| o.noun == val } || @@npcs.find { |o| o.noun == val } || @@pcs.find { |o| o.noun == val } || [@@right_hand, @@left_hand].find { |o| o.noun == val } || @@room_desc.find { |o| o.noun == val }
    else # name lookup
      @@inv.find { |o| o.name == val } || @@loot.find { |o| o.name == val } || @@npcs.find { |o| o.name == val } || @@pcs.find { |o| o.name == val } || [@@right_hand, @@left_hand].find { |o| o.name == val } || @@room_desc.find { |o| o.name == val } || @@inv.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@loot.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@npcs.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@pcs.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || [@@right_hand, @@left_hand].find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@room_desc.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@inv.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@loot.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@npcs.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@pcs.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || [@@right_hand, @@left_hand].find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@room_desc.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i }
    end
  elsif val.is_a?(Regexp) # name only lookup when passed a Regexp
    @@inv.find { |o| o.name =~ val } || @@loot.find { |o| o.name =~ val } || @@npcs.find { |o| o.name =~ val } || @@pcs.find { |o| o.name =~ val } || [@@right_hand, @@left_hand].find { |o| o.name =~ val } || @@room_desc.find { |o| o.name =~ val }
  end
end

.clear_container(container_id) ⇒ nil

Clears the contents of a specified container.

Parameters:

  • container_id (String)

    The ID of the container to clear.

Returns:

  • (nil)

    Always returns nil.



458
459
460
# File 'documented/common/gameobj.rb', line 458

def self.clear_container(container_id)
  @@contents[container_id] = Array.new
end

.clear_fam_lootnil

Clears all family loot game objects.

Returns:

  • (nil)

    Always returns nil.



349
350
351
# File 'documented/common/gameobj.rb', line 349

def self.clear_fam_loot
  @@fam_loot.clear
end

.clear_fam_npcsnil

Clears all family NPC game objects.

Returns:

  • (nil)

    Always returns nil.



355
356
357
# File 'documented/common/gameobj.rb', line 355

def self.clear_fam_npcs
  @@fam_npcs.clear
end

.clear_fam_pcsnil

Clears all family player character game objects.

Returns:

  • (nil)

    Always returns nil.



361
362
363
# File 'documented/common/gameobj.rb', line 361

def self.clear_fam_pcs
  @@fam_pcs.clear
end

.clear_fam_room_descnil

Clears all family room description game objects.

Returns:

  • (nil)

    Always returns nil.



343
344
345
# File 'documented/common/gameobj.rb', line 343

def self.clear_fam_room_desc
  @@fam_room_desc.clear
end

.clear_invnil

Clears all inventory game objects.

Returns:

  • (nil)

    Always returns nil.



331
332
333
# File 'documented/common/gameobj.rb', line 331

def self.clear_inv
  @@inv.clear
end

.clear_lootnil

Clears all loot game objects.

Returns:

  • (nil)

    Always returns nil.



311
312
313
# File 'documented/common/gameobj.rb', line 311

def self.clear_loot
  @@loot.clear
end

.clear_npcsnil

Clears all NPC game objects and their statuses.

Returns:

  • (nil)

    Always returns nil.



317
318
319
320
# File 'documented/common/gameobj.rb', line 317

def self.clear_npcs
  @@npcs.clear
  @@npc_status.clear
end

.clear_pcsnil

Clears all player character game objects and their statuses.

Returns:

  • (nil)

    Always returns nil.



324
325
326
327
# File 'documented/common/gameobj.rb', line 324

def self.clear_pcs
  @@pcs.clear
  @@pc_status.clear
end

.clear_room_descnil

Clears all room description game objects.

Returns:

  • (nil)

    Always returns nil.



337
338
339
# File 'documented/common/gameobj.rb', line 337

def self.clear_room_desc
  @@room_desc.clear
end

.containersHash

Retrieves all containers in the game.

Returns:

  • (Hash)

    A duplicate of the contents hash.



516
517
518
# File 'documented/common/gameobj.rb', line 516

def self.containers
  @@contents.dup
end

.deadArray?

Retrieves all dead NPCs.

Returns:

  • (Array, nil)

    An array of dead NPCs or nil if none found.



504
505
506
507
508
509
510
511
512
# File 'documented/common/gameobj.rb', line 504

def self.dead
  dead_list = Array.new
  for obj in @@npcs
    dead_list.push(obj) if obj.status == "dead"
  end
  return nil if dead_list.empty?

  return dead_list
end

.delete_container(container_id) ⇒ nil

Deletes a specified container from the contents.

Parameters:

  • container_id (String)

    The ID of the container to delete.

Returns:

  • (nil)

    Always returns nil.



465
466
467
# File 'documented/common/gameobj.rb', line 465

def self.delete_container(container_id)
  @@contents.delete(container_id)
end

.fam_lootArray?

Retrieves all family loot game objects.

Returns:

  • (Array, nil)

    A duplicate of the family loot array or nil if empty.



427
428
429
430
431
432
433
# File 'documented/common/gameobj.rb', line 427

def self.fam_loot
  if @@fam_loot.empty?
    nil
  else
    @@fam_loot.dup
  end
end

.fam_npcsArray?

Retrieves all family NPC game objects.

Returns:

  • (Array, nil)

    A duplicate of the family NPCs array or nil if empty.



437
438
439
440
441
442
443
# File 'documented/common/gameobj.rb', line 437

def self.fam_npcs
  if @@fam_npcs.empty?
    nil
  else
    @@fam_npcs.dup
  end
end

.fam_pcsArray?

Retrieves all family player character game objects.

Returns:

  • (Array, nil)

    A duplicate of the family PCs array or nil if empty.



447
448
449
450
451
452
453
# File 'documented/common/gameobj.rb', line 447

def self.fam_pcs
  if @@fam_pcs.empty?
    nil
  else
    @@fam_pcs.dup
  end
end

.fam_room_descArray?

Retrieves all family room description game objects.

Returns:

  • (Array, nil)

    A duplicate of the family room descriptions array or nil if empty.



417
418
419
420
421
422
423
# File 'documented/common/gameobj.rb', line 417

def self.fam_room_desc
  if @@fam_room_desc.empty?
    nil
  else
    @@fam_room_desc.dup
  end
end

.hidden_targetsArray

Retrieves the IDs of hidden targets.

Returns:

  • (Array)

    An array of hidden target IDs.



486
487
488
489
490
491
492
493
494
# File 'documented/common/gameobj.rb', line 486

def self.hidden_targets
  a = Array.new
  XMLData.current_target_ids.each { |id|
    unless @@npcs.find { |n| n.id == id }
      a.push(id)
    end
  }
  a
end

.invArray?

Retrieves all inventory game objects.

Returns:

  • (Array, nil)

    A duplicate of the inventory array or nil if empty.



397
398
399
400
401
402
403
# File 'documented/common/gameobj.rb', line 397

def self.inv
  if @@inv.empty?
    nil
  else
    @@inv.dup
  end
end

.left_handGameObj

Retrieves the current left-hand game object.

Returns:

  • (GameObj)

    A duplicate of the left-hand object.



305
306
307
# File 'documented/common/gameobj.rb', line 305

def self.left_hand
  @@left_hand.dup
end

.load_data(filename = nil) ⇒ Boolean

Loads game object data from an XML file.

Parameters:

  • filename (String, nil) (defaults to: nil)

    The name of the file to load.

Returns:

  • (Boolean)

    True if the data was successfully loaded, false otherwise.



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'documented/common/gameobj.rb', line 539

def self.load_data(filename = nil)
  filename = File.join(DATA_DIR, 'gameobj-data.xml') if filename.nil?
  if File.exist?(filename)
    begin
      @@type_data = Hash.new
      @@sellable_data = Hash.new
      @@type_cache = Hash.new
      File.open(filename) { |file|
        doc = REXML::Document.new(file.read)
        doc.elements.each('data/type') { |e|
          if (type = e.attributes['name'])
            @@type_data[type] = Hash.new
            @@type_data[type][:name]    = Regexp.new(e.elements['name'].text) unless e.elements['name'].text.nil? or e.elements['name'].text.empty?
            @@type_data[type][:noun]    = Regexp.new(e.elements['noun'].text) unless e.elements['noun'].text.nil? or e.elements['noun'].text.empty?
            @@type_data[type][:exclude] = Regexp.new(e.elements['exclude'].text) unless e.elements['exclude'].text.nil? or e.elements['exclude'].text.empty?
          end
        }
        doc.elements.each('data/sellable') { |e|
          if (sellable = e.attributes['name'])
            @@sellable_data[sellable] = Hash.new
            @@sellable_data[sellable][:name]    = Regexp.new(e.elements['name'].text) unless e.elements['name'].text.nil? or e.elements['name'].text.empty?
            @@sellable_data[sellable][:noun]    = Regexp.new(e.elements['noun'].text) unless e.elements['noun'].text.nil? or e.elements['noun'].text.empty?
            @@sellable_data[sellable][:exclude] = Regexp.new(e.elements['exclude'].text) unless e.elements['exclude'].text.nil? or e.elements['exclude'].text.empty?
          end
        }
      }
    rescue
      @@type_data = nil
      @@sellable_data = nil
      echo "error: GameObj.load_data: #{$!}"
      respond $!.backtrace[0..1]
      return false
    end
  else
    @@type_data = nil
    @@sellable_data = nil
    echo "error: GameObj.load_data: file does not exist: #{filename}"
    return false
  end
  filename = File.join(DATA_DIR, 'gameobj-custom', 'gameobj-data.xml')
  if (File.exist?(filename))
    begin
      File.open(filename) { |file|
        doc = REXML::Document.new(file.read)
        doc.elements.each('data/type') { |e|
          if (type = e.attributes['name'])
            @@type_data[type] ||= Hash.new
            @@type_data[type][:name]	  = GameObj.merge_data(@@type_data[type][:name], Regexp.new(e.elements['name'].text)) unless e.elements['name'].text.nil? or e.elements['name'].text.empty?
            @@type_data[type][:noun]	  = GameObj.merge_data(@@type_data[type][:noun], Regexp.new(e.elements['noun'].text)) unless e.elements['noun'].text.nil? or e.elements['noun'].text.empty?
            @@type_data[type][:exclude] = GameObj.merge_data(@@type_data[type][:exclude], Regexp.new(e.elements['exclude'].text)) unless e.elements['exclude'].text.nil? or e.elements['exclude'].text.empty?
          end
        }
        doc.elements.each('data/sellable') { |e|
          if (sellable = e.attributes['name'])
            @@sellable_data[sellable] ||= Hash.new
            @@sellable_data[sellable][:name]	  = GameObj.merge_data(@@sellable_data[sellable][:name], Regexp.new(e.elements['name'].text)) unless e.elements['name'].text.nil? or e.elements['name'].text.empty?
            @@sellable_data[sellable][:noun]	  = GameObj.merge_data(@@sellable_data[sellable][:noun], Regexp.new(e.elements['noun'].text)) unless e.elements['noun'].text.nil? or e.elements['noun'].text.empty?
            @@sellable_data[sellable][:exclude] = GameObj.merge_data(@@sellable_data[sellable][:exclude], Regexp.new(e.elements['exclude'].text)) unless e.elements['exclude'].text.nil? or e.elements['exclude'].text.empty?
          end
        }
      }
    rescue
      echo "error: Custom GameObj.load_data: #{$!}"
      respond $!.backtrace[0..1]
      return false
    end
  end
  return true
end

.lootArray?

Retrieves all loot game objects.

Returns:

  • (Array, nil)

    A duplicate of the loot array or nil if empty.



377
378
379
380
381
382
383
# File 'documented/common/gameobj.rb', line 377

def self.loot
  if @@loot.empty?
    nil
  else
    @@loot.dup
  end
end

.merge_data(data, newData) ⇒ Regexp

Merges two data sets, handling Regexp types.

Parameters:

  • data (Regexp, nil)

    The existing data.

  • newData (Regexp)

    The new data to merge.

Returns:

  • (Regexp)

    The merged data.



531
532
533
534
# File 'documented/common/gameobj.rb', line 531

def self.merge_data(data, newData)
  return newData unless data.is_a?(Regexp)
  return Regexp.union(data, newData)
end

.new_fam_loot(id, noun, name) ⇒ GameObj

Creates a new family loot game object.

Parameters:

  • id (String)

    The family loot ID.

  • noun (String)

    The family loot noun.

  • name (String)

    The family loot name.

Returns:

  • (GameObj)

    The newly created family loot object.



251
252
253
254
255
# File 'documented/common/gameobj.rb', line 251

def self.new_fam_loot(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@fam_loot.push(obj)
  obj
end

.new_fam_npc(id, noun, name) ⇒ GameObj

Creates a new family NPC game object.

Parameters:

  • id (String)

    The family NPC ID.

  • noun (String)

    The family NPC noun.

  • name (String)

    The family NPC name.

Returns:

  • (GameObj)

    The newly created family NPC object.



262
263
264
265
266
# File 'documented/common/gameobj.rb', line 262

def self.new_fam_npc(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@fam_npcs.push(obj)
  obj
end

.new_fam_pc(id, noun, name) ⇒ GameObj

Creates a new family player character game object.

Parameters:

  • id (String)

    The family PC ID.

  • noun (String)

    The family PC noun.

  • name (String)

    The family PC name.

Returns:

  • (GameObj)

    The newly created family PC object.



273
274
275
276
277
# File 'documented/common/gameobj.rb', line 273

def self.new_fam_pc(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@fam_pcs.push(obj)
  obj
end

.new_fam_room_desc(id, noun, name) ⇒ GameObj

Creates a new family room description game object.

Parameters:

  • id (String)

    The family room description ID.

  • noun (String)

    The family room description noun.

  • name (String)

    The family room description name.

Returns:

  • (GameObj)

    The newly created family room description object.



240
241
242
243
244
# File 'documented/common/gameobj.rb', line 240

def self.new_fam_room_desc(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@fam_room_desc.push(obj)
  obj
end

.new_inv(id, noun, name, container = nil, before = nil, after = nil) ⇒ GameObj

Creates a new inventory item game object.

Parameters:

  • id (String)

    The inventory item ID.

  • noun (String)

    The inventory item noun.

  • name (String)

    The inventory item name.

  • container (String, nil) (defaults to: nil)

    Optional container ID.

  • before (String, nil) (defaults to: nil)

    Optional prefix for the name.

  • after (String, nil) (defaults to: nil)

    Optional suffix for the name.

Returns:

  • (GameObj)

    The newly created inventory object.



214
215
216
217
218
219
220
221
222
# File 'documented/common/gameobj.rb', line 214

def self.new_inv(id, noun, name, container = nil, before = nil, after = nil)
  obj = GameObj.new(id, noun, name, before, after)
  if container
    @@contents[container].push(obj)
  else
    @@inv.push(obj)
  end
  obj
end

.new_left_hand(id, noun, name) ⇒ GameObj

Creates a new left-hand game object.

Parameters:

  • id (String)

    The left-hand object ID.

  • noun (String)

    The left-hand object noun.

  • name (String)

    The left-hand object name.

Returns:

  • (GameObj)

    The newly created left-hand object.



299
300
301
# File 'documented/common/gameobj.rb', line 299

def self.new_left_hand(id, noun, name)
  @@left_hand = GameObj.new(id, noun, name)
end

.new_loot(id, noun, name) ⇒ GameObj

Creates a new loot game object.

Parameters:

  • id (String)

    The loot ID.

  • noun (String)

    The loot noun.

  • name (String)

    The loot name.

Returns:

  • (GameObj)

    The newly created loot object.



187
188
189
190
191
# File 'documented/common/gameobj.rb', line 187

def self.new_loot(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@loot.push(obj)
  obj
end

.new_npc(id, noun, name, status = nil) ⇒ GameObj

Creates a new NPC game object.

Parameters:

  • id (String)

    The NPC ID.

  • noun (String)

    The NPC noun.

  • name (String)

    The NPC name.

  • status (String, nil) (defaults to: nil)

    Optional status for the NPC.

Returns:

  • (GameObj)

    The newly created NPC object.



175
176
177
178
179
180
# File 'documented/common/gameobj.rb', line 175

def self.new_npc(id, noun, name, status = nil)
  obj = GameObj.new(id, noun, name)
  @@npcs.push(obj)
  @@npc_status[id] = status
  obj
end

.new_pc(id, noun, name, status = nil) ⇒ GameObj

Creates a new player character game object.

Parameters:

  • id (String)

    The PC ID.

  • noun (String)

    The PC noun.

  • name (String)

    The PC name.

  • status (String, nil) (defaults to: nil)

    Optional status for the PC.

Returns:

  • (GameObj)

    The newly created PC object.



199
200
201
202
203
204
# File 'documented/common/gameobj.rb', line 199

def self.new_pc(id, noun, name, status = nil)
  obj = GameObj.new(id, noun, name)
  @@pcs.push(obj)
  @@pc_status[id] = status
  obj
end

.new_right_hand(id, noun, name) ⇒ GameObj

Creates a new right-hand game object.

Parameters:

  • id (String)

    The right-hand object ID.

  • noun (String)

    The right-hand object noun.

  • name (String)

    The right-hand object name.

Returns:

  • (GameObj)

    The newly created right-hand object.



284
285
286
# File 'documented/common/gameobj.rb', line 284

def self.new_right_hand(id, noun, name)
  @@right_hand = GameObj.new(id, noun, name)
end

.new_room_desc(id, noun, name) ⇒ GameObj

Creates a new room description game object.

Parameters:

  • id (String)

    The room description ID.

  • noun (String)

    The room description noun.

  • name (String)

    The room description name.

Returns:

  • (GameObj)

    The newly created room description object.



229
230
231
232
233
# File 'documented/common/gameobj.rb', line 229

def self.new_room_desc(id, noun, name)
  obj = GameObj.new(id, noun, name)
  @@room_desc.push(obj)
  obj
end

.npcsArray?

Retrieves all NPC game objects.

Returns:

  • (Array, nil)

    A duplicate of the NPCs array or nil if empty.



367
368
369
370
371
372
373
# File 'documented/common/gameobj.rb', line 367

def self.npcs
  if @@npcs.empty?
    nil
  else
    @@npcs.dup
  end
end

.pcsArray?

Retrieves all player character game objects.

Returns:

  • (Array, nil)

    A duplicate of the PCs array or nil if empty.



387
388
389
390
391
392
393
# File 'documented/common/gameobj.rb', line 387

def self.pcs
  if @@pcs.empty?
    nil
  else
    @@pcs.dup
  end
end

.reload(filename = nil) ⇒ Boolean

Reloads the game object data from a file.

Parameters:

  • filename (String, nil) (defaults to: nil)

    The name of the file to load.

Returns:

  • (Boolean)

    True if the data was successfully reloaded, false otherwise.



523
524
525
# File 'documented/common/gameobj.rb', line 523

def self.reload(filename = nil)
  GameObj.load_data(filename)
end

.right_handGameObj

Retrieves the current right-hand game object.

Returns:

  • (GameObj)

    A duplicate of the right-hand object.



290
291
292
# File 'documented/common/gameobj.rb', line 290

def self.right_hand
  @@right_hand.dup
end

.room_descArray?

Retrieves all room description game objects.

Returns:

  • (Array, nil)

    A duplicate of the room descriptions array or nil if empty.



407
408
409
410
411
412
413
# File 'documented/common/gameobj.rb', line 407

def self.room_desc
  if @@room_desc.empty?
    nil
  else
    @@room_desc.dup
  end
end

.sellable_dataHash

Retrieves the sellable data for game objects.

Returns:

  • (Hash)

    The sellable data hash.



623
624
625
# File 'documented/common/gameobj.rb', line 623

def self.sellable_data
  @@sellable_data
end

.targetGameObj?

Retrieves the current target from the game.

Returns:

  • (GameObj, nil)

    The current target object or nil if not found.



498
499
500
# File 'documented/common/gameobj.rb', line 498

def self.target
  return (@@npcs + @@pcs).find { |n| n.id == XMLData.current_target_id }
end

.targetsArray

Retrieves the current targets from the game.

Returns:

  • (Array)

    An array of current target NPCs.



471
472
473
474
475
476
477
478
479
480
481
482
# File 'documented/common/gameobj.rb', line 471

def self.targets
  a = Array.new
  XMLData.current_target_ids.each { |id|
    if (npc = @@npcs.find { |n| n.id == id })
      next if (npc.status =~ /dead|gone/i)
      next if (npc.name =~ /^animated\b/i && npc.name !~ /^animated slush/i)
      next if (npc.noun =~ /^(?:arm|appendage|claw|limb|pincer|tentacle)s?$|^(?:palpus|palpi)$/i && npc.name !~ /(?:amaranthine|ghostly|grizzled|ancient) kraken tentacle/i)
      a.push(npc)
    end
  }
  a
end

.type_cacheHash

Retrieves the type cache for game objects.

Returns:

  • (Hash)

    The type cache hash.



617
618
619
# File 'documented/common/gameobj.rb', line 617

def self.type_cache
  @@type_cache
end

.type_dataHash

Retrieves the type data for game objects.

Returns:

  • (Hash)

    The type data hash.



611
612
613
# File 'documented/common/gameobj.rb', line 611

def self.type_data
  @@type_data
end

Instance Method Details

#contentsArray

Retrieves the contents of the game object.

Returns:

  • (Array)

    A duplicate of the contents array.



124
125
126
# File 'documented/common/gameobj.rb', line 124

def contents
  @@contents[@id].dup
end

#empty?Boolean

Checks if the game object is empty.

Returns:

  • (Boolean)

    Always returns false.



118
119
120
# File 'documented/common/gameobj.rb', line 118

def empty?
  false
end

#full_nameString

Constructs the full name of the game object.

Returns:

  • (String)

    The full name including before and after names.



165
166
167
# File 'documented/common/gameobj.rb', line 165

def full_name
  "#{@before_name}#{' ' unless @before_name.nil? or @before_name.empty?}#{name}#{' ' unless @after_name.nil? or @after_name.empty?}#{@after_name}"
end

#GameObjObject



159
160
161
# File 'documented/common/gameobj.rb', line 159

def GameObj
  @noun
end

#sellableString?

Retrieves the sellable status of the game object.

Returns:

  • (String, nil)

    A comma-separated string of sellable types or nil if none found.



73
74
75
76
77
78
79
80
81
# File 'documented/common/gameobj.rb', line 73

def sellable
  GameObj.load_data if @@sellable_data.empty?
  list = @@sellable_data.keys.find_all { |t| (@name =~ @@sellable_data[t][:name] or @noun =~ @@sellable_data[t][:noun]) and (@@sellable_data[t][:exclude].nil? or @name !~ @@sellable_data[t][:exclude]) }
  if list.empty?
    nil
  else
    list.join(',')
  end
end

#statusString?

Retrieves the current status of the game object.

Returns:

  • (String, nil)

    The status of the object or ‘gone’ if not found.



85
86
87
88
89
90
91
92
93
94
95
# File 'documented/common/gameobj.rb', line 85

def status
  if @@npc_status.keys.include?(@id)
    @@npc_status[@id]
  elsif @@pc_status.keys.include?(@id)
    @@pc_status[@id]
  elsif @@loot.find { |obj| obj.id == @id } or @@inv.find { |obj| obj.id == @id } or @@room_desc.find { |obj| obj.id == @id } or @@fam_loot.find { |obj| obj.id == @id } or @@fam_npcs.find { |obj| obj.id == @id } or @@fam_pcs.find { |obj| obj.id == @id } or @@fam_room_desc.find { |obj| obj.id == @id } or (@@right_hand.id == @id) or (@@left_hand.id == @id) or @@contents.values.find { |list| list.find { |obj| obj.id == @id } }
    nil
  else
    'gone'
  end
end

#status=(val) ⇒ nil

Sets the status of the game object.

Parameters:

  • val (String)

    The new status value.

Returns:

  • (nil)

    Always returns nil.



100
101
102
103
104
105
106
107
108
# File 'documented/common/gameobj.rb', line 100

def status=(val)
  if @@npcs.any? { |npc| npc.id == @id }
    @@npc_status[@id] = val
  elsif @@pcs.any? { |pc| pc.id == @id }
    @@pc_status[@id] = val
  else
    nil
  end
end

#to_sString

Returns a string representation of the game object.

Returns:

  • (String)

    The noun of the game object.



112
113
114
# File 'documented/common/gameobj.rb', line 112

def to_s
  @noun
end

#typeString?

Retrieves the type of the game object based on its name and noun.

Examples:

obj.type # => "weapon, magical"

Returns:

  • (String, nil)

    A comma-separated string of types or nil if none found.



52
53
54
55
56
57
58
59
60
61
# File 'documented/common/gameobj.rb', line 52

def type
  GameObj.load_data if @@type_data.empty?
  return @@type_cache[@name] if @@type_cache.key?(@name)
  list = @@type_data.keys.find_all { |t| (@name =~ @@type_data[t][:name] or @noun =~ @@type_data[t][:noun]) and (@@type_data[t][:exclude].nil? or @name !~ @@type_data[t][:exclude]) }
  if list.empty?
    return @@type_cache[@name] = nil
  else
    return @@type_cache[@name] = list.join(',')
  end
end

#type?(type_to_check) ⇒ Boolean

Checks if the game object is of a specific type.

Parameters:

  • type_to_check (String)

    The type to check against.

Returns:

  • (Boolean)

    True if the object is of the specified type, false otherwise.



66
67
68
69
# File 'documented/common/gameobj.rb', line 66

def type?(type_to_check)
  # handle nil types
  return self.type.to_s.split(',').any?(type_to_check)
end