Module: Lich::Claim
- Defined in:
- lib/gemstone/claim.rb
Overview
module Gemstone # test this?
Constant Summary collapse
- Lock =
Mutex.new
Class Method Summary collapse
-
.checked?(room = nil) ⇒ Boolean
Checks if the specified room has been checked.
-
.claim_room(id) ⇒ void
Claims a room by its ID.
-
.claimed_room ⇒ Integer?
Returns the ID of the currently claimed room.
-
.clustered ⇒ Array
Returns the connected clusters if defined.
-
.current? ⇒ Boolean
Checks if the current instance is the owner of the claimed room.
-
.info ⇒ void
Provides information about the current claim status and related data.
-
.last_room ⇒ Integer?
Returns the ID of the last room checked.
-
.lock ⇒ void
Locks the mutex for the Claim module.
-
.members ⇒ Array
Returns the members of the group if checked.
-
.mine? ⇒ Boolean
Checks if the current instance is the owner of the claimed room.
-
.others ⇒ Array
Returns the list of other characters in the room.
-
.parser_handle(nav_rm, pcs) ⇒ void
Handles the claim parsing for a given room and characters.
-
.unlock ⇒ void
Unlocks the mutex for the Claim module.
Class Method Details
.checked?(room = nil) ⇒ Boolean
Checks if the specified room has been checked.
79 80 81 |
# File 'lib/gemstone/claim.rb', line 79 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.
19 20 21 22 23 24 |
# File 'lib/gemstone/claim.rb', line 19 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_room ⇒ Integer?
Returns the ID of the currently claimed room.
31 32 33 |
# File 'lib/gemstone/claim.rb', line 31 def self.claimed_room @claimed_room end |
.clustered ⇒ Array
Returns the connected clusters if defined.
143 144 145 146 147 148 149 150 |
# File 'lib/gemstone/claim.rb', line 143 def self.clustered begin return [] unless defined? Cluster Cluster.connected rescue return [] end end |
.current? ⇒ Boolean
Checks if the current instance is the owner of the claimed room.
69 70 71 |
# File 'lib/gemstone/claim.rb', line 69 def self.current? Lock.synchronize { @mine.eql?(true) } end |
.info ⇒ void
This method returns an undefined value.
Provides information about the current claim status and related data.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gemstone/claim.rb', line 88 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_room ⇒ Integer?
Returns the ID of the last room checked.
40 41 42 |
# File 'lib/gemstone/claim.rb', line 40 def self.last_room @last_room end |
.lock ⇒ void
This method will only lock if the mutex is not already owned.
This method returns an undefined value.
Locks the mutex for the Claim module.
50 51 52 |
# File 'lib/gemstone/claim.rb', line 50 def self.lock Lock.lock if !Lock.owned? end |
.members ⇒ Array
Returns the members of the group if checked.
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/gemstone/claim.rb', line 124 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 the current instance is the owner of the claimed room.
106 107 108 |
# File 'lib/gemstone/claim.rb', line 106 def self.mine? self.current? end |
.others ⇒ Array
Returns the list of other characters in the room.
115 116 117 |
# File 'lib/gemstone/claim.rb', line 115 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 characters.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gemstone/claim.rb', line 160 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 |