Class: Lich::Gemstone::Group

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

Class Method Details

._membersArray

Retrieves the original group members without duplication.

Examples:

original_members = Group._members

Returns:

  • (Array)

    the original array of group members



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.

Examples:

results = Group.add(member1, member2)

Parameters:

  • members (Array)

    the members to add

Returns:

  • (Array)

    an array of results for each member added



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.

Examples:

is_broken = Group.broken?

Returns:

  • (Boolean)

    true if the group is broken, false otherwise



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

.checkArray

Note:

This method will block until the group is checked or the time limit is reached.

Initializes the group and checks its status.

Examples:

members = Group.check

Returns:

  • (Array)

    a duplicate of the group members



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.

Examples:

Group.checked = true

Parameters:

  • flag (Boolean)

    the new checked status



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.

Examples:

Group.checked? # => false

Returns:

  • (Boolean)

    true if checked, false otherwise



31
32
33
# File 'lib/gemstone/group.rb', line 31

def self.checked?
  @@checked
end

.clearvoid

This method returns an undefined value.

Clears the group members and resets the checked status.

Examples:

Group.clear


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.

Examples:

is_closed = Group.closed?

Returns:

  • (Boolean)

    true if the group is closed, false otherwise



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.

Examples:

Group.delete(member1, member2)

Parameters:

  • members (Array)

    the members to remove



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

.disksArray

Retrieves the disks associated with the group members.

Examples:

disks = Group.disks

Returns:

  • (Array)

    an array of Disk objects associated with the 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

.idsArray

Retrieves the IDs of the group members.

Examples:

member_ids = Group.ids

Returns:

  • (Array)

    an array of member IDs



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.

Examples:

is_included = Group.include?(member1, member2)

Parameters:

  • members (Array)

    the members to check

Returns:

  • (Boolean)

    true if all members are included, false otherwise



297
298
299
# File 'lib/gemstone/group.rb', line 297

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

.leaderObject

Retrieves the current leader of the group.

Examples:

current_leader = Group.leader

Returns:

  • (Object)

    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.

Examples:

Group.leader = character

Parameters:

  • char (Object)

    the character to set as leader



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.

Examples:

is_leader = Group.leader?

Returns:

  • (Boolean)

    true if the current character is the leader, false otherwise



231
232
233
# File 'lib/gemstone/group.rb', line 231

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

.maybe_checkvoid

This method returns an undefined value.

Checks the group status if it hasn’t been checked yet.

Examples:

Group.maybe_check


190
191
192
# File 'lib/gemstone/group.rb', line 190

def self.maybe_check
  Group.check unless checked?
end

.membersArray

Retrieves a duplicate of the current group members.

Examples:

members = Group.members

Returns:

  • (Array)

    a duplicate array of 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.

Examples:

result = Group.some_missing_method(args)

Parameters:

  • method (Symbol)

    the method name

  • args (Array)

    the arguments for the method

  • block (Proc)

    an optional block

Returns:

  • (Object)

    the result of the method call on members



327
328
329
# File 'lib/gemstone/group.rb', line 327

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

.nonmembersArray

Retrieves non-member characters.

Examples:

nonmembers = Group.nonmembers

Returns:

  • (Array)

    an array of 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

.nounsArray

Retrieves the nouns of the group members.

Examples:

member_nouns = Group.nouns

Returns:

  • (Array)

    an array of member nouns



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.

Examples:

is_open = Group.open?

Returns:

  • (Boolean)

    true if the group is open, false otherwise



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.

Examples:

Group.push(member1, member2)

Parameters:

  • members (Array)

    the members to add



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.

Examples:

Group.refresh(new_member1, new_member2)

Parameters:

  • members (Array)

    the new members to set



67
68
69
# File 'lib/gemstone/group.rb', line 67

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

.statusSymbol

Retrieves the current status of the group.

Examples:

current_status = Group.status

Returns:

  • (Symbol)

    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.

Examples:

Group.status = :open

Parameters:

  • state (Symbol)

    the new status (:open or :closed)



133
134
135
# File 'lib/gemstone/group.rb', line 133

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

.to_sString

Returns a string representation of the group members.

Examples:

group_string = Group.to_s

Returns:

  • (String)

    string representation of the group members



111
112
113
# File 'lib/gemstone/group.rb', line 111

def self.to_s
  @@members.to_s
end