Module: Group

Defined in:
lib/Olib/character/group.rb

Defined Under Namespace

Classes: Member, Members

Constant Summary collapse

MEMBERS =
Members.new
OPEN =
:open
CLOSED =
:closed
CHECK_HOOK =
self.name.to_s
NO_GROUP =
/You are not currently in a group/
MEMBER =
/<a exist="(?<id>.*?)" noun="(?<name>.*?)">(.*?)<\/a> is (?<type>(the leader|also a member) of your group|following you)\./
STATE =
/^Your group status is currently (?<state>open|closed)\./
END_GROUP =
/list of other options\./
PARSER =
Proc.new do |line|
  
  if line.strip.empty? || line =~ NO_GROUP
    nil
  elsif line =~ STATE
    nil
  elsif line =~ END_GROUP
    Group.checked!
    DownstreamHook.remove(CHECK_HOOK)
    nil
  elsif line =~ MEMBER
    begin
      pc = line.match(MEMBER).to_struct
      Group::MEMBERS.add GameObj[pc.name], (line =~ /leader/ ? true : false)
      if line =~ /following/
        Group::MEMBERS.leader = OpenStruct.new(name: Char.name, leader: true)
      end
      nil 
    rescue Exception => e
      respond e
      respond e.backtrace
    end
  else
    line
  end
end
@@checked =
false

Class Method Summary collapse

Class Method Details

.checkObject

ran at the initialization of a script


182
183
184
185
186
187
188
189
# File 'lib/Olib/character/group.rb', line 182

def Group.check
  @@checked = false
  MEMBERS.clear!
  DownstreamHook.add(CHECK_HOOK, PARSER)
  Game._puts "<c>group\r\n"
  wait_until { Group.checked? }
  MEMBERS
end

.checked!Object


159
160
161
162
# File 'lib/Olib/character/group.rb', line 159

def Group.checked!
  @@checked = true
  self
end

.checked?Boolean


155
156
157
# File 'lib/Olib/character/group.rb', line 155

def Group.checked?
  @@checked
end

.empty?Boolean


164
165
166
# File 'lib/Olib/character/group.rb', line 164

def Group.empty?
  MEMBERS.empty?
end

.exists?Boolean


168
169
170
# File 'lib/Olib/character/group.rb', line 168

def Group.exists?
  !empty?
end

.leaderObject


199
200
201
# File 'lib/Olib/character/group.rb', line 199

def Group.leader
  members.leader
end

.leader?Boolean


203
204
205
# File 'lib/Olib/character/group.rb', line 203

def Group.leader?
  leader && leader.name == Char.name
end

.maybe_checkObject


191
192
193
# File 'lib/Olib/character/group.rb', line 191

def Group.maybe_check
  Group.check unless checked?
end

.membersObject


172
173
174
175
# File 'lib/Olib/character/group.rb', line 172

def Group.members
  maybe_check
  MEMBERS
end

.nonmembersObject


195
196
197
# File 'lib/Olib/character/group.rb', line 195

def Group.nonmembers
  members.nonmembers
end

.to_sObject


177
178
179
# File 'lib/Olib/character/group.rb', line 177

def Group.to_s
  MEMBERS.to_s
end