Class: Lich::Gemstone::Group

Inherits:
Object
  • Object
show all
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

Class Method Details

._membersObject



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.

Parameters:

  • members (Array<GameObj, String>)

    the members to add to the group.

Returns:

  • (Array<Hash>)

    results of the add operation for each member.



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.

Returns:

  • (Boolean)

    true if the group is broken, false otherwise.



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

.checkArray<GameObj>

Checks the group status and clears members if necessary.

Returns:

  • (Array<GameObj>)

    the current members of the group after checking.



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.

Parameters:

  • flag (Boolean)

    the new checked status.



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.

Returns:

  • (Boolean)

    true if checked, false otherwise.



27
28
29
# File 'documented/gemstone/group.rb', line 27

def self.checked?
  @@checked
end

.clearvoid

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.

Returns:

  • (Boolean)

    true if the group is closed, false otherwise.



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.

Parameters:

  • members (Array<GameObj>)

    the members to remove from the group.



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

.disksArray<Disk>

Retrieves the disks associated with the group members.

Returns:

  • (Array<Disk>)

    the disks of 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

.idsArray<Integer>

Returns the IDs of the current group members.

Returns:

  • (Array<Integer>)

    the IDs of the 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.

Parameters:

  • members (Array<GameObj>)

    the members to check for inclusion.

Returns:

  • (Boolean)

    true if all specified members are included, false otherwise.



197
198
199
# File 'documented/gemstone/group.rb', line 197

def self.include?(*members)
  members.all? { |m| ids.include?(m.id) }
end

.leaderGameObj?

Returns the current leader of the group.

Returns:

  • (GameObj, nil)

    the current leader of the group or nil if none.



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.

Parameters:

  • char (GameObj)

    the character to set as the leader.



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.

Returns:

  • (Boolean)

    true if this instance is the leader, false otherwise.



147
148
149
# File 'documented/gemstone/group.rb', line 147

def self.leader?
  @@leader.eql?(:self)
end

.maybe_checkObject



122
123
124
# File 'documented/gemstone/group.rb', line 122

def self.maybe_check
  Group.check unless checked?
end

.membersArray<GameObj>

Returns a duplicate of the current group members.

Returns:

  • (Array<GameObj>)

    the current members of the group.



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.

Parameters:

  • method (Symbol)

    the method name being called.

  • args (Array)

    the arguments for the method call.

  • block (Proc)

    an optional block for the method call.

Returns:

  • (Object)

    the result of the delegated method call.



219
220
221
# File 'documented/gemstone/group.rb', line 219

def self.method_missing(method, *args, &block)
  @@members.send(method, *args, &block)
end

.nonmembersArray<GameObj>

Returns a list of characters that are not members of the group.

Returns:

  • (Array<GameObj>)

    the non-member characters.



128
129
130
# File 'documented/gemstone/group.rb', line 128

def self.nonmembers
  GameObj.pcs.to_a.reject { |pc| ids.include?(pc.id) }
end

.nounsArray<String>

Returns the nouns of the current group members.

Returns:

  • (Array<String>)

    the nouns of the 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.

Returns:

  • (Boolean)

    true if the group is open, false otherwise.



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.

Parameters:

  • members (Array<GameObj>)

    the members to add to the group.



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.

Parameters:

  • members (Array<GameObj>)

    the new members to set for the group.



51
52
53
# File 'documented/gemstone/group.rb', line 51

def self.refresh(*members)
  @@members = members.dup
end

.statusSymbol

Returns the current status of the group.

Returns:

  • (Symbol)

    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.

Parameters:

  • state (Symbol)

    the new status of the group.



89
90
91
# File 'documented/gemstone/group.rb', line 89

def self.status=(state)
  @@status = state
end

.to_sObject



75
76
77
# File 'documented/gemstone/group.rb', line 75

def self.to_s
  @@members.to_s
end