Module: Lich::Claim

Defined in:
documented/gemstone/claim.rb

Constant Summary collapse

Lock =
Mutex.new

Class Method Summary collapse

Class Method Details

.checked?(room = nil) ⇒ Boolean

Checks if the specified room has been checked.

Parameters:

  • room (Integer, nil) (defaults to: nil)

    the room ID to check; defaults to the last room

Returns:

  • (Boolean)

    true if the room has been checked, false otherwise



58
59
60
# File 'documented/gemstone/claim.rb', line 58

def self.checked?(room = nil)
  Lock.synchronize { XMLData.room_id == (room || @last_room) }
end

.claim_room(id) ⇒ void

This method returns an undefined value.

Claims a room by its ID.

Examples:

Claim a room

Lich::Claim.claim_room(5)

Parameters:

  • id (Integer)

    the ID of the room to claim



17
18
19
20
21
22
# File 'documented/gemstone/claim.rb', line 17

def self.claim_room(id)
  @claimed_room = id.to_i
  @timestamp    = Time.now
  Log.out("claimed #{@claimed_room}", label: %i(claim room)) if defined?(Log)
  Lock.unlock
end

.claimed_roomInteger?

Returns the ID of the currently claimed room.

Returns:

  • (Integer, nil)

    the ID of the claimed room or nil if none



26
27
28
# File 'documented/gemstone/claim.rb', line 26

def self.claimed_room
  @claimed_room
end

.clusteredArray

Returns a list of connected clusters if defined.

Returns:

  • (Array)

    an array of connected clusters or an empty array if not defined



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

def self.clustered
  begin
    return [] unless defined? Cluster
    Cluster.connected
  rescue
    return []
  end
end

.current?Boolean

Checks if the current instance is the one that claimed the room.

Returns:

  • (Boolean)

    true if this instance claimed the room, false otherwise



50
51
52
# File 'documented/gemstone/claim.rb', line 50

def self.current?
  Lock.synchronize { @mine.eql?(true) }
end

.infoString

Provides information about the current claim status and room details.

Returns:

  • (String)

    a formatted string containing the claim information



64
65
66
67
68
69
70
71
72
73
74
75
# File 'documented/gemstone/claim.rb', line 64

def self.info
  rows = [['XMLData.room_id', XMLData.room_id, 'Current room according to the XMLData'],
          ['Claim.mine?', Claim.mine?, 'Claim status on the current room'],
          ['Claim.claimed_room', Claim.claimed_room, 'Room id of the last claimed room'],
          ['Claim.checked?', Claim.checked?, "Has Claim finished parsing ROOMID\ndefault: the current room"],
          ['Claim.last_room', Claim.last_room, 'The last room checked by Claim, regardless of status'],
          ['Claim.others', Claim.others.join("\n"), "Other characters in the room\npotentially less grouped characters"]]
  info_table = Terminal::Table.new :headings => ['Property', 'Value', 'Description'],
                                   :rows     => rows,
                                   :style    => { :all_separators => true }
  Lich::Messaging.mono(info_table.to_s)
end

.last_roomInteger?

Returns the ID of the last room checked.

Returns:

  • (Integer, nil)

    the ID of the last room or nil if none



32
33
34
# File 'documented/gemstone/claim.rb', line 32

def self.last_room
  @last_room
end

.lockvoid

This method returns an undefined value.

Acquires the lock if it is not already owned.



38
39
40
# File 'documented/gemstone/claim.rb', line 38

def self.lock
  Lock.lock if !Lock.owned?
end

.membersArray<String>

Returns a list of members in the group if defined.

Returns:

  • (Array<String>)

    an array of member nouns or an empty array if not defined



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'documented/gemstone/claim.rb', line 91

def self.members
  return [] unless defined? Group

  begin
    if Group.checked?
      return Group.members.map(&:noun)
    else
      return []
    end
  rescue
    return []
  end
end

.mine?Boolean

Checks if this instance is the one that currently owns the claim.

Returns:

  • (Boolean)

    true if this instance owns the claim, false otherwise



79
80
81
# File 'documented/gemstone/claim.rb', line 79

def self.mine?
  self.current?
end

.othersArray<String>

Returns a list of other characters in the room.

Returns:

  • (Array<String>)

    an array of character names



85
86
87
# File 'documented/gemstone/claim.rb', line 85

def self.others
  @others
end

.parser_handle(nav_rm, pcs) ⇒ void

This method returns an undefined value.

Handles the claim parsing for a given room and character list.

Parameters:

  • nav_rm (Integer)

    the room ID being navigated to

  • pcs (Array<String>)

    the list of character names present

Raises:

  • StandardError if an error occurs during parsing



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'documented/gemstone/claim.rb', line 122

def self.parser_handle(nav_rm, pcs)
  echo "Claim handled #{nav_rm} with xmlparser" if $claim_debug
  begin
    @others = pcs - self.clustered - self.members
    @last_room = nav_rm
    unless @others.empty?
      @mine = false
      return
    end
    @mine = true
    self.claim_room nav_rm unless nav_rm.nil?
  rescue StandardError => e
    if defined?(Log)
      Log.out(e)
    else
      respond("Claim Parser Error: #{e}")
    end
  ensure
    Lock.unlock if Lock.owned?
  end
end

.unlockvoid

This method returns an undefined value.

Releases the lock if it is owned.



44
45
46
# File 'documented/gemstone/claim.rb', line 44

def self.unlock
  Lock.unlock if Lock.owned?
end