Class: Lich::Common::GameObj
- Inherits:
-
Object
- Object
- Lich::Common::GameObj
- 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.
Direct Known Subclasses
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
-
#after_name ⇒ Object
Returns the value of attribute after_name.
-
#before_name ⇒ Object
Returns the value of attribute before_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#noun ⇒ Object
Returns the value of attribute noun.
Class Method Summary collapse
-
.[](val) ⇒ GameObj?
Retrieves a game object by ID, noun, or name.
-
.clear_container(container_id) ⇒ nil
Clears the contents of a specified container.
-
.clear_fam_loot ⇒ nil
Clears all family loot game objects.
-
.clear_fam_npcs ⇒ nil
Clears all family NPC game objects.
-
.clear_fam_pcs ⇒ nil
Clears all family player character game objects.
-
.clear_fam_room_desc ⇒ nil
Clears all family room description game objects.
-
.clear_inv ⇒ nil
Clears all inventory game objects.
-
.clear_loot ⇒ nil
Clears all loot game objects.
-
.clear_npcs ⇒ nil
Clears all NPC game objects and their statuses.
-
.clear_pcs ⇒ nil
Clears all player character game objects and their statuses.
-
.clear_room_desc ⇒ nil
Clears all room description game objects.
-
.containers ⇒ Hash
Retrieves all containers in the game.
-
.dead ⇒ Array?
Retrieves all dead NPCs.
-
.delete_container(container_id) ⇒ nil
Deletes a specified container from the contents.
-
.fam_loot ⇒ Array?
Retrieves all family loot game objects.
-
.fam_npcs ⇒ Array?
Retrieves all family NPC game objects.
-
.fam_pcs ⇒ Array?
Retrieves all family player character game objects.
-
.fam_room_desc ⇒ Array?
Retrieves all family room description game objects.
-
.hidden_targets ⇒ Array
Retrieves the IDs of hidden targets.
-
.inv ⇒ Array?
Retrieves all inventory game objects.
-
.left_hand ⇒ GameObj
Retrieves the current left-hand game object.
-
.load_data(filename = nil) ⇒ Boolean
Loads game object data from an XML file.
-
.loot ⇒ Array?
Retrieves all loot game objects.
-
.merge_data(data, newData) ⇒ Regexp
Merges two data sets, handling Regexp types.
-
.new_fam_loot(id, noun, name) ⇒ GameObj
Creates a new family loot game object.
-
.new_fam_npc(id, noun, name) ⇒ GameObj
Creates a new family NPC game object.
-
.new_fam_pc(id, noun, name) ⇒ GameObj
Creates a new family player character game object.
-
.new_fam_room_desc(id, noun, name) ⇒ GameObj
Creates a new family room description game object.
-
.new_inv(id, noun, name, container = nil, before = nil, after = nil) ⇒ GameObj
Creates a new inventory item game object.
-
.new_left_hand(id, noun, name) ⇒ GameObj
Creates a new left-hand game object.
-
.new_loot(id, noun, name) ⇒ GameObj
Creates a new loot game object.
-
.new_npc(id, noun, name, status = nil) ⇒ GameObj
Creates a new NPC game object.
-
.new_pc(id, noun, name, status = nil) ⇒ GameObj
Creates a new player character game object.
-
.new_right_hand(id, noun, name) ⇒ GameObj
Creates a new right-hand game object.
-
.new_room_desc(id, noun, name) ⇒ GameObj
Creates a new room description game object.
-
.npcs ⇒ Array?
Retrieves all NPC game objects.
-
.pcs ⇒ Array?
Retrieves all player character game objects.
-
.reload(filename = nil) ⇒ Boolean
Reloads the game object data from a file.
-
.right_hand ⇒ GameObj
Retrieves the current right-hand game object.
-
.room_desc ⇒ Array?
Retrieves all room description game objects.
-
.sellable_data ⇒ Hash
Retrieves the sellable data for game objects.
-
.target ⇒ GameObj?
Retrieves the current target from the game.
-
.targets ⇒ Array
Retrieves the current targets from the game.
-
.type_cache ⇒ Hash
Retrieves the type cache for game objects.
-
.type_data ⇒ Hash
Retrieves the type data for game objects.
Instance Method Summary collapse
-
#contents ⇒ Array
Retrieves the contents of the game object.
-
#empty? ⇒ Boolean
Checks if the game object is empty.
-
#full_name ⇒ String
Constructs the full name of the game object.
- #GameObj ⇒ Object
-
#initialize(id, noun, name, before = nil, after = nil) ⇒ GameObj
constructor
Initializes a new game object.
-
#sellable ⇒ String?
Retrieves the sellable status of the game object.
-
#status ⇒ String?
Retrieves the current status of the game object.
-
#status=(val) ⇒ nil
Sets the status of the game object.
-
#to_s ⇒ String
Returns a string representation of the game object.
-
#type ⇒ String?
Retrieves the type of the game object based on its name and noun.
-
#type?(type_to_check) ⇒ Boolean
Checks if the game object is of a specific type.
Constructor Details
#initialize(id, noun, name, before = nil, after = nil) ⇒ GameObj
Initializes a new game object.
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_name ⇒ Object
Returns the value of attribute after_name.
27 28 29 |
# File 'documented/common/gameobj.rb', line 27 def after_name @after_name end |
#before_name ⇒ Object
Returns the value of attribute before_name.
27 28 29 |
# File 'documented/common/gameobj.rb', line 27 def before_name @before_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'documented/common/gameobj.rb', line 26 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'documented/common/gameobj.rb', line 27 def name @name end |
#noun ⇒ Object
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.
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.
458 459 460 |
# File 'documented/common/gameobj.rb', line 458 def self.clear_container(container_id) @@contents[container_id] = Array.new end |
.clear_fam_loot ⇒ nil
Clears all family loot game objects.
349 350 351 |
# File 'documented/common/gameobj.rb', line 349 def self.clear_fam_loot @@fam_loot.clear end |
.clear_fam_npcs ⇒ nil
Clears all family NPC game objects.
355 356 357 |
# File 'documented/common/gameobj.rb', line 355 def self.clear_fam_npcs @@fam_npcs.clear end |
.clear_fam_pcs ⇒ nil
Clears all family player character game objects.
361 362 363 |
# File 'documented/common/gameobj.rb', line 361 def self.clear_fam_pcs @@fam_pcs.clear end |
.clear_fam_room_desc ⇒ nil
Clears all family room description game objects.
343 344 345 |
# File 'documented/common/gameobj.rb', line 343 def self.clear_fam_room_desc @@fam_room_desc.clear end |
.clear_inv ⇒ nil
Clears all inventory game objects.
331 332 333 |
# File 'documented/common/gameobj.rb', line 331 def self.clear_inv @@inv.clear end |
.clear_loot ⇒ nil
Clears all loot game objects.
311 312 313 |
# File 'documented/common/gameobj.rb', line 311 def self.clear_loot @@loot.clear end |
.clear_npcs ⇒ nil
Clears all NPC game objects and their statuses.
317 318 319 320 |
# File 'documented/common/gameobj.rb', line 317 def self.clear_npcs @@npcs.clear @@npc_status.clear end |
.clear_pcs ⇒ nil
Clears all player character game objects and their statuses.
324 325 326 327 |
# File 'documented/common/gameobj.rb', line 324 def self.clear_pcs @@pcs.clear @@pc_status.clear end |
.clear_room_desc ⇒ nil
Clears all room description game objects.
337 338 339 |
# File 'documented/common/gameobj.rb', line 337 def self.clear_room_desc @@room_desc.clear end |
.containers ⇒ Hash
Retrieves all containers in the game.
516 517 518 |
# File 'documented/common/gameobj.rb', line 516 def self.containers @@contents.dup end |
.dead ⇒ Array?
Retrieves all dead NPCs.
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.
465 466 467 |
# File 'documented/common/gameobj.rb', line 465 def self.delete_container(container_id) @@contents.delete(container_id) end |
.fam_loot ⇒ Array?
Retrieves all family loot game objects.
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_npcs ⇒ Array?
Retrieves all family NPC game objects.
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_pcs ⇒ Array?
Retrieves all family player character game objects.
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_desc ⇒ Array?
Retrieves all family room description game objects.
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_targets ⇒ Array
Retrieves the IDs of hidden targets.
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 |
.inv ⇒ Array?
Retrieves all inventory game objects.
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_hand ⇒ GameObj
Retrieves the current left-hand game 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.
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 |
.loot ⇒ Array?
Retrieves all loot game objects.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 |
.npcs ⇒ Array?
Retrieves all NPC game objects.
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 |
.pcs ⇒ Array?
Retrieves all player character game objects.
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.
523 524 525 |
# File 'documented/common/gameobj.rb', line 523 def self.reload(filename = nil) GameObj.load_data(filename) end |
.right_hand ⇒ GameObj
Retrieves the current right-hand game object.
290 291 292 |
# File 'documented/common/gameobj.rb', line 290 def self.right_hand @@right_hand.dup end |
.room_desc ⇒ Array?
Retrieves all room description game objects.
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_data ⇒ Hash
Retrieves the sellable data for game objects.
623 624 625 |
# File 'documented/common/gameobj.rb', line 623 def self.sellable_data @@sellable_data end |
.target ⇒ GameObj?
Retrieves the current target from the game.
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 |
.targets ⇒ Array
Retrieves the current targets from the game.
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_cache ⇒ Hash
Retrieves the type cache for game objects.
617 618 619 |
# File 'documented/common/gameobj.rb', line 617 def self.type_cache @@type_cache end |
.type_data ⇒ Hash
Retrieves the type data for game objects.
611 612 613 |
# File 'documented/common/gameobj.rb', line 611 def self.type_data @@type_data end |
Instance Method Details
#contents ⇒ Array
Retrieves the contents of the game object.
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.
118 119 120 |
# File 'documented/common/gameobj.rb', line 118 def empty? false end |
#full_name ⇒ String
Constructs the full name of the game object.
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 |
#GameObj ⇒ Object
159 160 161 |
# File 'documented/common/gameobj.rb', line 159 def GameObj @noun end |
#sellable ⇒ String?
Retrieves the sellable status of the game object.
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 |
#status ⇒ String?
Retrieves the current status of the game object.
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.
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_s ⇒ String
Returns a string representation of the game object.
112 113 114 |
# File 'documented/common/gameobj.rb', line 112 def to_s @noun end |
#type ⇒ String?
Retrieves the type of the game object based on its name and noun.
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.
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 |