Module: Lich::Claim
- Defined in:
- documented/gemstone/claim.rb
Overview
module Gemstone # test this? Provides functionality for claiming rooms in the game. This module manages the state of claimed rooms and handles related operations.
Constant Summary collapse
- Lock =
Mutex for synchronizing access to claimed room data.
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 with the given ID.
-
.claimed_room ⇒ Integer?
Returns the ID of the currently claimed room.
-
.clustered ⇒ Array
Returns a list of connected clusters if defined.
-
.current? ⇒ Boolean
Checks if the current instance is the one that claimed the room.
-
.info ⇒ String
Provides information about the current claim status and related data.
-
.last_room ⇒ Integer?
Returns the ID of the last room that was checked.
-
.lock ⇒ void
Acquires the lock for the claiming process if not already owned.
-
.members ⇒ Array<String>
Returns a list of members in the group if defined.
-
.mine? ⇒ Boolean
Checks if the current instance is the owner of the claimed room.
-
.others ⇒ Array<String>
Returns a list of other characters in the room.
-
.parser_handle(nav_rm, pcs) ⇒ void
Handles the parsing of room claims and updates the state accordingly.
-
.unlock ⇒ void
Releases the lock for the claiming process if owned.
Class Method Details
.checked?(room = nil) ⇒ Boolean
Checks if the specified room has been checked.
63 64 65 |
# File 'documented/gemstone/claim.rb', line 63 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 with the given ID.
23 24 25 26 27 28 |
# File 'documented/gemstone/claim.rb', line 23 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.
32 33 34 |
# File 'documented/gemstone/claim.rb', line 32 def self.claimed_room @claimed_room end |
.clustered ⇒ Array
Returns a list of connected clusters if defined.
114 115 116 117 118 119 120 121 |
# File 'documented/gemstone/claim.rb', line 114 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.
56 57 58 |
# File 'documented/gemstone/claim.rb', line 56 def self.current? Lock.synchronize { @mine.eql?(true) } end |
.info ⇒ String
Provides information about the current claim status and related data.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'documented/gemstone/claim.rb', line 71 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 that was checked.
38 39 40 |
# File 'documented/gemstone/claim.rb', line 38 def self.last_room @last_room end |
.lock ⇒ void
This method returns an undefined value.
Acquires the lock for the claiming process if not already owned.
44 45 46 |
# File 'documented/gemstone/claim.rb', line 44 def self.lock Lock.lock if !Lock.owned? end |
.members ⇒ Array<String>
Returns a list of members in the group if defined.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'documented/gemstone/claim.rb', line 98 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.
86 87 88 |
# File 'documented/gemstone/claim.rb', line 86 def self.mine? self.current? end |
.others ⇒ Array<String>
Returns a list of other characters in the room.
92 93 94 |
# File 'documented/gemstone/claim.rb', line 92 def self.others @others end |
.parser_handle(nav_rm, pcs) ⇒ void
This method returns an undefined value.
Handles the parsing of room claims and updates the state accordingly.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'documented/gemstone/claim.rb', line 130 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 |