Class: Lich::Gemstone::Disk

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

Overview

Represents a disk item in the game.

This class provides methods to identify, find, and manage disk objects.

See Also:

  • #find_by_name
  • #all

Constant Summary collapse

NOUNS =
%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) ⇒ void

Initializes a new Disk object with the given game object.

Parameters:

  • obj (Object)

    the game object representing the disk



53
54
55
56
57
58
# File 'documented/gemstone/disk.rb', line 53

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



74
75
76
# File 'documented/gemstone/disk.rb', line 74

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



48
49
50
# File 'documented/gemstone/disk.rb', line 48

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'documented/gemstone/disk.rb', line 48

def name
  @name
end

Class Method Details

.allArray<Lich::Gemstone::Disk>

Retrieves all disk objects from the loot.

Returns:



40
41
42
43
44
45
46
# File 'documented/gemstone/disk.rb', line 40

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

.find_by_name(name) ⇒ Lich::Gemstone::Disk?

Finds a disk by its name.

Examples:

Find a disk by name

disk = Lich::Gemstone::Disk.find_by_name("golden disk")

Parameters:

  • name (String)

    the name of the disk to find

Returns:



24
25
26
27
28
29
30
# File 'documented/gemstone/disk.rb', line 24

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.

Parameters:

  • thing (Object)

    the object to check

Returns:

  • (Boolean)

    true if the object is a disk, false otherwise



15
16
17
# File 'documented/gemstone/disk.rb', line 15

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

.mineLich::Gemstone::Disk?

Mines for a disk based on the character's name.

Returns:



34
35
36
# File 'documented/gemstone/disk.rb', line 34

def self.mine
  find_by_name(Char.name)
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this disk with another disk for equality.

Parameters:

  • other (Object)

    the object to compare

Returns:

  • (Boolean)

    true if the disks are equal, false otherwise



63
64
65
# File 'documented/gemstone/disk.rb', line 63

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

Returns:

  • (Boolean)

    true if the disks are equal, false otherwise



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

def eql?(other)
  self == other
end

#to_containerContainer, GameObj

Converts this disk to a container object.

Returns:

  • (Container, GameObj)

    the corresponding container object or game object



80
81
82
83
84
85
86
# File 'documented/gemstone/disk.rb', line 80

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