Overview
TheGameObj class represents any game object (NPC, loot, inventory item, room description, etc.) within Lich. It provides a powerful tracking system with categorized registries and efficient identity management.
GameObj tracks all in-game entities across specialized registries:
- Loot - Items on the ground
- NPCs - Non-player characters
- PCs - Player characters
- Inventory - Your carried items
- Room descriptions - Objects in room text
- Containers - Items inside containers
- Hands - What you’re holding
Quick Start
Instance Attributes
The unique string ID of this object from the game
Noun used to refer to this object (e.g. “goblin”, “sword”)
Full descriptive name (e.g. “a snarling goblin”, “a silver-edged longsword”)
Text prepended before the name in full display
Text appended after the name in full display
Instance Methods
to_s
Returns the object’s noun as a string.The object’s noun
full_name
Returns the complete display name, assembling before/name/after parts.The full assembled name
status
Returns the current status of this NPC or PC, or “gone” if not found.Status string (“dead”, “stunned”, etc.) or nil if no status, “gone” if not present
type
Returns a comma-separated string of matching type tags for classification.Comma-separated type tags, or nil if no types match
type?(type_to_check)
Checks if the object matches a specific type tag.The type string to check for
True if the object has this type tag
contents
Returns the contents of this container object.Array of GameObj instances inside this container, or nil
Class Methods - Registries
GameObj.npcs
Returns all NPCs currently visible in the room.Array of NPC objects, or nil if none
GameObj.loot
Returns all loot items on the ground.Array of loot objects, or nil if none
GameObj.inv
Returns all items in your inventory (top-level, not inside containers).Array of inventory objects, or nil if none
GameObj.pcs
Returns all player characters visible in the room.Array of PC objects, or nil if none
GameObj.right_hand / GameObj.left_hand
Returns the object in your right or left hand.Object in hand, or nil if empty
GameObj.room_desc
Returns objects mentioned in the room description.Array of room description objects, or nil if none
GameObj.containers
Returns a hash of all containers and their contents.Hash mapping container IDs to arrays of GameObj instances
Class Methods - Lookup
GameObj[val]
Finds a GameObj by ID (numeric string), noun (single word), name, or Regexp.ID string, noun, name, or pattern to search for
First matching object, or nil if not found
Class Methods - Targeting
GameObj.targets
Returns active NPCs currently targeted (from XML target data).Array of targeted NPC objects
GameObj.target
Returns the single NPC or PC matching the current target ID.Current target object, or nil
GameObj.dead
Returns all NPCs with a status of “dead”.Array of dead NPCs, or nil if none
Class Methods - Clearing
GameObj.clear_loot / clear_npcs / clear_pcs / clear_inv
Clears the specified registry. The shared identity index is preserved.Advanced: Identity Index
GameObj uses a shared persistent identity index for efficient object reuse. Objects with the sameid, noun, and name are the same logical entity across all registries.
GameObj.prune_index!
Removes stale entries from the identity index (entries not seen within TTL).Time-to-live in seconds (default 15 minutes)
Print detailed memory report
GameObj.index_stats
Returns diagnostic information about the identity index state.Print formatted report to stdout
