Module: Lich::Gemstone::Group::Observer Private

Defined in:
documented/gemstone/group.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Observes game output and automatically updates Group state. Watches for group-related messages and updates membership, leadership, and status.

Defined Under Namespace

Modules: Term

Class Method Summary collapse

Class Method Details

.consume(line, match_data) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Processes a line of group-related game output and updates Group state. Handles all types of group changes: joins, leaves, leadership changes, etc.

Parameters:

  • line (String) —

    line of game output

  • match_data (MatchData) —

    regex match data from the line



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'documented/gemstone/group.rb', line 609

def self.consume(line, match_data)
  if line.include?(Term::GIVEN_LEADERSHIP)
    return Group.leader = :self
  end

  ## Group indicator changed!
  if line.include?(Term::GROUP_EMPTIED)
    Group.leader = :self
    return Group._members.clear
  end

  people = exist(line)

  if line.include?("You are leading")
    Group.leader = :self
  elsif line.include?("You are grouped with")
    Group.leader = people.first
  end

  case line
  when Term::NO_GROUP, Term::DISBAND
    Group.leader = :self
    return Group._members.clear
  when Term::NO_GROUP_TO_DISBAND
    return Group.checked = false
  when Term::STATUS
    Group.status = match_data[:status].to_sym
    return Group.checked = true
  when Term::GAVE_LEADER_AWAY
    Group.push(people.first)
    return Group.leader = people.first
  when Term::ADDED_TO_NEW_GROUP, Term::JOINED_NEW_GROUP
    Group.checked = false
    Group.push(people.first)
    return Group.leader = people.first
  when Term::SWAP_LEADER
    (old_leader, new_leader) = people
    Group.push(*people) if Group.include?(old_leader) or Group.include?(new_leader)
    return Group.leader = new_leader
  when Term::LEADER_ADDED_MEMBER
    (leader, added) = people
    Group.push(added) if Group.include?(leader)
  when Term::LEADER_REMOVED_MEMBER
    (leader, removed) = people
    return Group.delete(removed) if Group.include?(leader)
  when Term::JOIN, Term::ADD, Term::NOOP
    return Group.push(*people)
  when Term::MEMBER
    return Group.refresh(*people)
  when Term::HOLD_FRIENDLY_FIRST, Term::HOLD_NEUTRAL_FIRST, Term::HOLD_RESERVED_FIRST, Term::HOLD_WARM_FIRST
    return Group.push(people.first)
  when Term::HOLD_FRIENDLY_SECOND, Term::HOLD_NEUTRAL_SECOND, Term::HOLD_RESERVED_SECOND, Term::HOLD_WARM_SECOND
    Group.checked = false
    Group.push(people.first)
    return Group.leader = people.first
  when Term::HOLD_FRIENDLY_THIRD, Term::HOLD_NEUTRAL_THIRD, Term::HOLD_RESERVED_THIRD, Term::HOLD_WARM_THIRD
    (leader, added) = people
    Group.push(added) if Group.include?(leader)
  when Term::OTHER_JOINED_GROUP
    (added, leader) = people
    Group.push(added) if Group.include?(leader)
  when Term::LEAVE, Term::REMOVE
    return Group.delete(*people)
  end
end

.exist(xml) ⇒ Array<GameObj>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extracts GameObj instances from XML character links in game output.

Parameters:

  • xml (String) —

    game output containing character XML tags

Returns:

  • (Array<GameObj>) —

    array of GameObj instances found in the XML



590
591
592
# File 'documented/gemstone/group.rb', line 590

def self.exist(xml)
  xml.scan(Group::Observer::Term::EXIST).map { |id, _noun, _name| GameObj[id] }
end

.wants?(line) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if a line of game output contains group-related information.

Parameters:

  • line (String) —

    line of game output

Returns:

  • (Boolean) —

    true if line contains group information



598
599
600
601
# File 'documented/gemstone/group.rb', line 598

def self.wants?(line)
  line.strip.match(Term::ANY) or
    line.include?(Term::GROUP_EMPTIED)
end