Module: Lich::Gemstone::Group::Observer
- Defined in:
- lib/gemstone/group.rb
Defined Under Namespace
Modules: Term
Class Method Summary collapse
-
.consume(line, match_data) ⇒ void
Consumes a line of text and updates the group state based on the message.
-
.exist(xml) ⇒ Array<GameObj>
Scans the provided XML string for existing group members.
-
.wants?(line) ⇒ Boolean
Determines if the provided line contains any group-related messages.
Class Method Details
.consume(line, match_data) ⇒ void
Note:
This method modifies the state of the Group class directly.
This method returns an undefined value.
Consumes a line of text and updates the group state based on the message.
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/gemstone/group.rb', line 451 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::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>
Scans the provided XML string for existing group members.
424 425 426 |
# File 'lib/gemstone/group.rb', line 424 def self.exist(xml) xml.scan(Group::Observer::Term::EXIST).map { |id, _noun, _name| GameObj[id] } end |
.wants?(line) ⇒ Boolean
Determines if the provided line contains any group-related messages.
436 437 438 439 |
# File 'lib/gemstone/group.rb', line 436 def self.wants?(line) line.strip.match(Term::ANY) or line.include?(Term::GROUP_EMPTIED) end |