Class: Lich::Gemstone::Group
- Inherits:
-
Object
- Object
- Lich::Gemstone::Group
- Defined in:
- lib/gemstone/group.rb,
lib/gemstone/group.rb
Overview
Represents a group of members in the game.
Defined Under Namespace
Modules: Observer
Class Method Summary collapse
-
._members ⇒ Array
Retrieves the original group members without duplication.
-
.add(*members) ⇒ Array
Adds members to the group, handling various input types.
-
.broken? ⇒ Boolean
Checks if the group is broken based on the current game state.
-
.check ⇒ Array
Initializes the group and checks its status.
-
.checked=(flag) ⇒ void
Sets the checked status of the group.
-
.checked? ⇒ Boolean
Checks if the group has been checked.
-
.clear ⇒ void
Clears the group members and resets the checked status.
-
.closed? ⇒ Boolean
Checks if the group is closed.
-
.delete(*members) ⇒ void
Removes specified members from the group.
-
.disks ⇒ Array
Retrieves the disks associated with the group members.
-
.ids ⇒ Array
Retrieves the IDs of the group members.
-
.include?(*members) ⇒ Boolean
Checks if the specified members are included in the group.
-
.leader ⇒ Object
Retrieves the current leader of the group.
-
.leader=(char) ⇒ void
Sets the leader of the group.
-
.leader? ⇒ Boolean
Checks if the current character is the leader of the group.
-
.maybe_check ⇒ void
Checks the group status if it hasn’t been checked yet.
-
.members ⇒ Array
Retrieves a duplicate of the current group members.
-
.method_missing(method, *args, &block) ⇒ Object
Handles missing methods by delegating to the members array.
-
.nonmembers ⇒ Array
Retrieves non-member characters.
-
.nouns ⇒ Array
Retrieves the nouns of the group members.
-
.open? ⇒ Boolean
Checks if the group is open.
-
.push(*members) ⇒ void
Adds members to the group if they are not already included.
-
.refresh(*members) ⇒ void
Refreshes the group members with the provided members.
-
.status ⇒ Symbol
Retrieves the current status of the group.
-
.status=(state) ⇒ void
Sets the status of the group.
-
.to_s ⇒ String
Returns a string representation of the group members.
Class Method Details
._members ⇒ Array
Retrieves the original group members without duplication.
88 89 90 |
# File 'lib/gemstone/group.rb', line 88 def self._members @@members end |
.add(*members) ⇒ Array
Adds members to the group, handling various input types.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/gemstone/group.rb', line 242 def self.add(*members) members.map do |member| if member.is_a?(Array) Group.add(*member) else member = GameObj.pcs.find { |pc| pc.noun.eql?(member) } if member.is_a?(String) break if member.nil? result = dothistimeout("group ##{member.id}", 3, Regexp.union( %r{You add #{member.noun} to your group}, %r{#{member.noun}'s group status is closed}, %r{But #{member.noun} is already a member of your group} )) case result when %r{You add}, %r{already a member} Group.push(member) { ok: member } when %r{closed} Group.delete(member) { err: member } else end end end end |
.broken? ⇒ Boolean
Checks if the group is broken based on the current game state.
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/gemstone/group.rb', line 307 def self.broken? sleep(0.1) while Lich::Gemstone::Claim::Lock.locked? if Group.leader? return true if (GameObj.pcs.empty? || GameObj.pcs.nil?) && !@@members.empty? return false if (GameObj.pcs.empty? || GameObj.pcs.nil?) && @@members.empty? (GameObj.pcs.map(&:noun) & @@members.map(&:noun)).size < @@members.size else GameObj.pcs.find do |pc| pc.noun.eql?(Group.leader.noun) end.nil? end end |
.check ⇒ Array
This method will block until the group is checked or the time limit is reached.
Initializes the group and checks its status.
176 177 178 179 180 181 182 |
# File 'lib/gemstone/group.rb', line 176 def self.check Group.clear() ttl = Time.now + 3 Game._puts "<c>group\r\n" wait_until { Group.checked? or Time.now > ttl } @@members.dup end |
.checked=(flag) ⇒ void
This method returns an undefined value.
Sets the checked status of the group.
122 123 124 |
# File 'lib/gemstone/group.rb', line 122 def self.checked=(flag) @@checked = flag end |
.checked? ⇒ Boolean
Checks if the group has been checked.
31 32 33 |
# File 'lib/gemstone/group.rb', line 31 def self.checked? @@checked end |
.clear ⇒ void
This method returns an undefined value.
Clears the group members and resets the checked status.
20 21 22 23 |
# File 'lib/gemstone/group.rb', line 20 def self.clear() @@members = [] @@checked = false end |
.closed? ⇒ Boolean
Checks if the group is closed.
164 165 166 |
# File 'lib/gemstone/group.rb', line 164 def self.closed? not open? end |
.delete(*members) ⇒ void
This method returns an undefined value.
Removes specified members from the group.
55 56 57 58 |
# File 'lib/gemstone/group.rb', line 55 def self.delete(*members) gone = members.map(&:id) @@members.reject! do |m| gone.include?(m.id) end end |
.disks ⇒ Array
Retrieves the disks associated with the group members.
98 99 100 101 102 103 |
# File 'lib/gemstone/group.rb', line 98 def self.disks return [Disk.find_by_name(Char.name)].compact if Group.leader? && members.empty? member_disks = members.map(&:noun).map { |noun| Disk.find_by_name(noun) }.compact member_disks.push(Disk.find_by_name(Char.name)) if Disk.find_by_name(Char.name) return member_disks end |
.ids ⇒ Array
Retrieves the IDs of the group members.
276 277 278 |
# File 'lib/gemstone/group.rb', line 276 def self.ids @@members.map(&:id) end |
.include?(*members) ⇒ Boolean
Checks if the specified members are included in the group.
297 298 299 |
# File 'lib/gemstone/group.rb', line 297 def self.include?(*members) members.all? { |m| ids.include?(m.id) } end |
.leader ⇒ Object
Retrieves the current leader of the group.
221 222 223 |
# File 'lib/gemstone/group.rb', line 221 def self.leader @@leader end |
.leader=(char) ⇒ void
This method returns an undefined value.
Sets the leader of the group.
211 212 213 |
# File 'lib/gemstone/group.rb', line 211 def self.leader=(char) @@leader = char end |
.leader? ⇒ Boolean
Checks if the current character is the leader of the group.
231 232 233 |
# File 'lib/gemstone/group.rb', line 231 def self.leader? @@leader.eql?(:self) end |
.maybe_check ⇒ void
This method returns an undefined value.
Checks the group status if it hasn’t been checked yet.
190 191 192 |
# File 'lib/gemstone/group.rb', line 190 def self.maybe_check Group.check unless checked? end |
.members ⇒ Array
Retrieves a duplicate of the current group members.
77 78 79 80 |
# File 'lib/gemstone/group.rb', line 77 def self.members maybe_check @@members.dup end |
.method_missing(method, *args, &block) ⇒ Object
Handles missing methods by delegating to the members array.
327 328 329 |
# File 'lib/gemstone/group.rb', line 327 def self.method_missing(method, *args, &block) @@members.send(method, *args, &block) end |
.nonmembers ⇒ Array
Retrieves non-member characters.
200 201 202 |
# File 'lib/gemstone/group.rb', line 200 def self.nonmembers GameObj.pcs.to_a.reject { |pc| ids.include?(pc.id) } end |
.nouns ⇒ Array
Retrieves the nouns of the group members.
286 287 288 |
# File 'lib/gemstone/group.rb', line 286 def self.nouns @@members.map(&:noun) end |
.open? ⇒ Boolean
Checks if the group is open.
153 154 155 156 |
# File 'lib/gemstone/group.rb', line 153 def self.open? maybe_check @@status.eql?(:open) end |
.push(*members) ⇒ void
This method returns an undefined value.
Adds members to the group if they are not already included.
42 43 44 45 46 |
# File 'lib/gemstone/group.rb', line 42 def self.push(*members) members.each do |member| @@members.push(member) unless include?(member) end end |
.refresh(*members) ⇒ void
This method returns an undefined value.
Refreshes the group members with the provided members.
67 68 69 |
# File 'lib/gemstone/group.rb', line 67 def self.refresh(*members) @@members = members.dup end |
.status ⇒ Symbol
Retrieves the current status of the group.
143 144 145 |
# File 'lib/gemstone/group.rb', line 143 def self.status() @@status end |
.status=(state) ⇒ void
This method returns an undefined value.
Sets the status of the group.
133 134 135 |
# File 'lib/gemstone/group.rb', line 133 def self.status=(state) @@status = state end |
.to_s ⇒ String
Returns a string representation of the group members.
111 112 113 |
# File 'lib/gemstone/group.rb', line 111 def self.to_s @@members.to_s end |