Class: Lich::Gemstone::Group
- Inherits:
-
Object
- Object
- Lich::Gemstone::Group
- Defined in:
- documented/gemstone/group.rb,
documented/gemstone/group.rb
Overview
Represents a group of members in the game.
This class manages group membership, leader status, and group operations.
Defined Under Namespace
Modules: Observer
Class Method Summary collapse
- ._members ⇒ Object
-
.add(*members) ⇒ Array<Hash>
Adds members to the group with checks for existing membership and status.
-
.broken? ⇒ Boolean
Checks if the group is in a broken state based on member status.
-
.check ⇒ Array<GameObj>
Checks the group status and clears members if necessary.
-
.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 status is closed.
-
.delete(*members) ⇒ void
Removes members from the group based on their IDs.
-
.disks ⇒ Array<Disk>
Retrieves the disks associated with the group members.
-
.ids ⇒ Array<Integer>
Returns the IDs of the current group members.
-
.include?(*members) ⇒ Boolean
Checks if the specified members are included in the group.
-
.leader ⇒ GameObj?
Returns the current leader of the group.
-
.leader=(char) ⇒ void
Sets the leader of the group.
-
.leader? ⇒ Boolean
Checks if the current instance is the leader of the group.
- .maybe_check ⇒ Object
-
.members ⇒ Array<GameObj>
Returns a duplicate of the current group members.
-
.method_missing(method, *args, &block) ⇒ Object
Handles calls to methods that are not defined on the group, delegating to members.
-
.nonmembers ⇒ Array<GameObj>
Returns a list of characters that are not members of the group.
-
.nouns ⇒ Array<String>
Returns the nouns of the current group members.
-
.open? ⇒ Boolean
Checks if the group status is open.
-
.push(*members) ⇒ void
Adds members to the group unless they are already included.
-
.refresh(*members) ⇒ void
Refreshes the group members with a new list.
-
.status ⇒ Symbol
Returns the current status of the group.
-
.status=(state) ⇒ void
Sets the status of the group.
- .to_s ⇒ Object
Class Method Details
._members ⇒ Object
62 63 64 |
# File 'documented/gemstone/group.rb', line 62 def self._members @@members end |
.add(*members) ⇒ Array<Hash>
Adds members to the group with checks for existing membership and status.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'documented/gemstone/group.rb', line 154 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 in a broken state based on member status.
203 204 205 206 207 208 209 210 211 212 |
# File 'documented/gemstone/group.rb', line 203 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<GameObj>
Checks the group status and clears members if necessary.
114 115 116 117 118 119 120 |
# File 'documented/gemstone/group.rb', line 114 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.
82 83 84 |
# File 'documented/gemstone/group.rb', line 82 def self.checked=(flag) @@checked = flag end |
.checked? ⇒ Boolean
Checks if the group has been checked.
27 28 29 |
# File 'documented/gemstone/group.rb', line 27 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 'documented/gemstone/group.rb', line 20 def self.clear() @@members = [] @@checked = false end |
.closed? ⇒ Boolean
Checks if the group status is closed.
108 109 110 |
# File 'documented/gemstone/group.rb', line 108 def self.closed? not open? end |
.delete(*members) ⇒ void
This method returns an undefined value.
Removes members from the group based on their IDs.
43 44 45 46 |
# File 'documented/gemstone/group.rb', line 43 def self.delete(*members) gone = members.map(&:id) @@members.reject! do |m| gone.include?(m.id) end end |
.disks ⇒ Array<Disk>
Retrieves the disks associated with the group members.
68 69 70 71 72 73 |
# File 'documented/gemstone/group.rb', line 68 def self.disks return [Disk.find_by_name(Char.name)].compact if Group.leader? && members.empty? member_disks = members.map(&:noun).compact.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<Integer>
Returns the IDs of the current group members.
184 185 186 |
# File 'documented/gemstone/group.rb', line 184 def self.ids @@members.map(&:id) end |
.include?(*members) ⇒ Boolean
Checks if the specified members are included in the group.
197 198 199 |
# File 'documented/gemstone/group.rb', line 197 def self.include?(*members) members.all? { |m| ids.include?(m.id) } end |
.leader ⇒ GameObj?
Returns the current leader of the group.
141 142 143 |
# File 'documented/gemstone/group.rb', line 141 def self.leader @@leader end |
.leader=(char) ⇒ void
This method returns an undefined value.
Sets the leader of the group.
135 136 137 |
# File 'documented/gemstone/group.rb', line 135 def self.leader=(char) @@leader = char end |
.leader? ⇒ Boolean
Checks if the current instance is the leader of the group.
147 148 149 |
# File 'documented/gemstone/group.rb', line 147 def self.leader? @@leader.eql?(:self) end |
.maybe_check ⇒ Object
122 123 124 |
# File 'documented/gemstone/group.rb', line 122 def self.maybe_check Group.check unless checked? end |
.members ⇒ Array<GameObj>
Returns a duplicate of the current group members.
57 58 59 60 |
# File 'documented/gemstone/group.rb', line 57 def self.members maybe_check @@members.dup end |
.method_missing(method, *args, &block) ⇒ Object
Handles calls to methods that are not defined on the group, delegating to members.
219 220 221 |
# File 'documented/gemstone/group.rb', line 219 def self.method_missing(method, *args, &block) @@members.send(method, *args, &block) end |
.nonmembers ⇒ Array<GameObj>
Returns a list of characters that are not members of the group.
128 129 130 |
# File 'documented/gemstone/group.rb', line 128 def self.nonmembers GameObj.pcs.to_a.reject { |pc| ids.include?(pc.id) } end |
.nouns ⇒ Array<String>
Returns the nouns of the current group members.
190 191 192 |
# File 'documented/gemstone/group.rb', line 190 def self.nouns @@members.map(&:noun) end |
.open? ⇒ Boolean
Checks if the group status is open.
101 102 103 104 |
# File 'documented/gemstone/group.rb', line 101 def self.open? maybe_check @@status.eql?(:open) end |
.push(*members) ⇒ void
This method returns an undefined value.
Adds members to the group unless they are already included.
34 35 36 37 38 |
# File 'documented/gemstone/group.rb', line 34 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 a new list.
51 52 53 |
# File 'documented/gemstone/group.rb', line 51 def self.refresh(*members) @@members = members.dup end |
.status ⇒ Symbol
Returns the current status of the group.
95 96 97 |
# File 'documented/gemstone/group.rb', line 95 def self.status() @@status end |
.status=(state) ⇒ void
This method returns an undefined value.
Sets the status of the group.
89 90 91 |
# File 'documented/gemstone/group.rb', line 89 def self.status=(state) @@status = state end |
.to_s ⇒ Object
75 76 77 |
# File 'documented/gemstone/group.rb', line 75 def self.to_s @@members.to_s end |