Class: Lich::Gemstone::Disk

Inherits:
Object
  • Object
show all
Defined in:
documented/gemstone/disk.rb

Overview

Represents a disk object in the game. This class provides methods to identify, find, and manage disk objects.

Examples:

Finding a disk by name

disk = Disk.find_by_name("golden disk")

Constant Summary collapse

NOUNS =

A list of nouns that represent different types of disks.

%w{cassone chest coffer coffin coffret disk hamper saucer sphere trunk tureen}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Disk

Initializes a new Disk object with the given game object.

Examples:

disk = Disk.new(game_object)
# => #<Disk:0x00007f...>

Parameters:

  • obj (Object)

    The game object representing the disk.



67
68
69
70
71
72
# File 'documented/gemstone/disk.rb', line 67

def initialize(obj)
  @id   = obj.id
  @name = obj.name.split(" ").find do |word|
    word[0].upcase.eql?(word[0])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Handles calls to methods that are not defined in this class.

Examples:

disk.some_method
# => result of GameObj[@id].some_method

Parameters:

  • method (Symbol)

    The name of the method being called.

  • args (Array)

    The arguments passed to the method.

Returns:

  • (Object)

    Returns the result of the method call on the underlying game object.



98
99
100
# File 'documented/gemstone/disk.rb', line 98

def method_missing(method, *args)
  GameObj[@id].send(method, *args)
end

Instance Attribute Details

#idObject (readonly)

Provides read access to the disk’s ID and name.



59
60
61
# File 'documented/gemstone/disk.rb', line 59

def id
  @id
end

#nameObject (readonly)

Provides read access to the disk’s ID and name.



59
60
61
# File 'documented/gemstone/disk.rb', line 59

def name
  @name
end

Class Method Details

.allArray<Disk>

Retrieves all disk objects from the game’s loot.

Examples:

disks = Disk.all()
# => [#<Disk:0x00007f...>, #<Disk:0x00007f...>]

Returns:

  • (Array<Disk>)

    An array of Disk objects.



50
51
52
53
54
55
56
# File 'documented/gemstone/disk.rb', line 50

def self.all()
  (GameObj.loot || []).select do |item|
    is_disk?(item)
  end.map do |i|
    Disk.new(i)
  end
end

.find_by_name(name) ⇒ Disk?

Note:

This method searches through the game’s loot.

Finds a disk by its name in the game’s loot.

Examples:

disk = Disk.find_by_name("golden disk")
# => #<Disk:0x00007f...>

Parameters:

  • name (String)

    The name of the disk to find.

Returns:

  • (Disk, nil)

    Returns a Disk object if found, nil otherwise.



28
29
30
31
32
33
34
# File 'documented/gemstone/disk.rb', line 28

def self.find_by_name(name)
  disk = GameObj.loot.find do |item|
    is_disk?(item) && item.name.include?(name)
  end
  return nil if disk.nil?
  Disk.new(disk)
end

.is_disk?(thing) ⇒ Boolean

Checks if the given object is a disk based on its name.

Examples:

Disk.is_disk?(some_object)
# => true or false

Parameters:

  • thing (Object)

    The object to check.

Returns:

  • (Boolean)

    Returns true if the object is a disk, false otherwise.



17
18
19
# File 'documented/gemstone/disk.rb', line 17

def self.is_disk?(thing)
  thing.name =~ /\b([A-Z][a-z]+) #{Regexp.union(NOUNS)}\b/
end

.mineDisk?

Mines the disk associated with the current character.

Examples:

disk = Disk.mine()
# => #<Disk:0x00007f...>

Returns:

  • (Disk, nil)

    Returns the Disk object for the character, nil if not found.



41
42
43
# File 'documented/gemstone/disk.rb', line 41

def self.mine
  find_by_name(Char.name)
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this disk with another disk for equality.

Examples:

disk1 == disk2
# => true or false

Parameters:

  • other (Object)

    The object to compare with.

Returns:

  • (Boolean)

    Returns true if both disks are equal, false otherwise.



80
81
82
# File 'documented/gemstone/disk.rb', line 80

def ==(other)
  other.is_a?(Disk) && other.id == self.id
end

#eql?(other) ⇒ Boolean

Checks if this disk is equal to another disk.

Parameters:

  • other (Object)

    The object to compare with.

Returns:

  • (Boolean)

    Returns true if both disks are equal, false otherwise.



87
88
89
# File 'documented/gemstone/disk.rb', line 87

def eql?(other)
  self == other
end

#to_containerContainer, GameObj

Converts this disk into a container object.

Examples:

container = disk.to_container()
# => #<Container:0x00007f...> or #<GameObj:0x00007f...>

Returns:

  • (Container, GameObj)

    Returns a Container object if defined, otherwise returns the GameObj.



107
108
109
110
111
112
113
# File 'documented/gemstone/disk.rb', line 107

def to_container
  if defined?(Container)
    Container.new(@id)
  else
    GameObj["#{@id}"]
  end
end