Module: Lich::Common::CreatureBase::InstanceMethods Private
- Defined in:
- documented/common/creature/creature_base.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.
Per-instance transient status and classification tracking driven by the
<crtrStatus> feed. The host class must call
#initialize_status_tracking from its own initialize and expose
@name/@id (used only for debug headers).
Instance Attribute Summary collapse
-
#last_seen_at ⇒ Time
readonly
private
When the feed last showed this creature (registration, room-object refresh, or a
<crtrStatus>update).
Instance Method Summary collapse
-
#add_status(status, duration = nil) ⇒ void
private
Adds a status to the creature.
-
#cleanup_expired_statuses ⇒ void
private
Drops any timed statuses whose expiry has passed.
-
#crtr_flag?(key) ⇒ Boolean
private
Checks a classification flag captured from
<crtrStatus>, or, until the first real tag arrives, one inferred by the parser (see #infer_crtr_flags). -
#crtr_flags? ⇒ Boolean
private
Whether any
<crtrStatus>classification has been seen for this creature yet. -
#ever_hostile? ⇒ Boolean
private
Whether
<crtrStatus>has ever asserted this creature hostile. -
#flag_active?(key) ⇒ Boolean
private
Checks whether a status or classification flag is active.
-
#has_status?(status) ⇒ Boolean
private
Checks whether a specific status is active (after expiring stale ones).
-
#health ⇒ Integer?
private
Exact current health from the latest
<crtrStatus health="...">snapshot. -
#infer_crtr_flags(flags) ⇒ void
private
Stands in classification flags for a creature the feed has not reported on yet (see #crtr_flags?), e.g.
-
#initialize_status_tracking ⇒ void
private
Initializes the tracking ivars.
-
#max_health ⇒ Integer?
private
Exact maximum health from the latest
<crtrStatus maxhealth="...">snapshot. -
#remove_status(status) ⇒ void
private
Removes a status from the creature.
-
#statuses ⇒ Array<String>
private
Returns a copy of the currently-active statuses (after expiry).
-
#sync_crtr_status(attrs) ⇒ void
private
Reconciles status and classification from a
<crtrStatus>tag. -
#touch_seen ⇒ Time
private
Stamps the creature as just seen.
Instance Attribute Details
#last_seen_at ⇒ Time (readonly)
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.
When the feed last showed this creature (registration, room-object
refresh, or a <crtrStatus> update). Registry housekeeping ages
against this rather than creation time.
620 621 622 |
# File 'documented/common/creature/creature_base.rb', line 620 def last_seen_at @last_seen_at end |
Instance Method Details
#add_status(status, duration = nil) ⇒ 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.
Adds a status to the creature.
Normalizes to String so callers can pass symbols from message-based
status parsing or strings from <crtrStatus>; both sources then land
in the same status entries and match #has_status?.
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 |
# File 'documented/common/creature/creature_base.rb', line 639 def add_status(status, duration = nil) # Canonicalize case at the boundary, not per producer: the crit # tables report position as "PRONE"/"KNEELING"/"SITTING" while # messaging and <crtrStatus> use lowercase, and @status membership # is exact - an uppercase add could never be removed or matched. status = status.to_s.downcase if @status.include?(status) # Re-adding with an explicit duration extends the lock: without # this, a 3s roundtime followed by an overlapping 20s one kept # the 3s expiry and reported the creature free ~19s early. # Never shorten - the longest known source wins. if duration expires = Time.now + duration current = @status_timestamps[status] @status_timestamps[status] = expires if current.nil? || expires > current end return end @status << status duration ||= STATUS_DURATIONS[status] if duration @status_timestamps[status] = Time.now + duration debug_log("+status: #{status} (expires in #{duration}s)") else debug_log("+status: #{status} (no auto-expiry)") end end |
#cleanup_expired_statuses ⇒ 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.
Drops any timed statuses whose expiry has passed.
687 688 689 690 691 692 693 694 695 696 |
# File 'documented/common/creature/creature_base.rb', line 687 def cleanup_expired_statuses return unless @status_timestamps && !@status_timestamps.empty? now = Time.now @status_timestamps.select { |_status, expires_at| expires_at <= now }.keys.each do |expired_status| @status.delete(expired_status) @status_timestamps.delete(expired_status) debug_log("~status: #{expired_status} (auto-expired)") end end |
#crtr_flag?(key) ⇒ 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 a classification flag captured from <crtrStatus>, or, until
the first real tag arrives, one inferred by the parser (see
#infer_crtr_flags). Callers that need the server's own word should
check #crtr_flags? first.
Unlike template tri-state facts, live XML flags are always-sent booleans, so an unknown or unseen flag is false, not nil.
768 769 770 771 |
# File 'documented/common/creature/creature_base.rb', line 768 def crtr_flag?(key) flags = crtr_flags? ? @crtr_flags : @inferred_crtr_flags flags[key.to_sym] || false end |
#crtr_flags? ⇒ 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.
Whether any <crtrStatus> classification has been seen for this
creature yet.
Callers filtering on a flag need to tell "the feed said this is not
hostile" apart from "the feed has not told us anything" - an absent
flag is unknown, not false. A ridden mount, for instance, carries a
bold creature link but never a <crtrStatus> of its own.
813 814 815 |
# File 'documented/common/creature/creature_base.rb', line 813 def crtr_flags? !@crtr_flags.empty? end |
#ever_hostile? ⇒ 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.
Whether <crtrStatus> has ever asserted this creature hostile.
Sympathy (1120) replaces hostile with sympathetic in the next
snapshot even though the creature is still in the fight, so
crtr_flag?(:hostile) - the literal live value - drops it. This
remembers the earlier assertion for the life of the registry entry.
It never un-latches, so it is not an attack gate by itself: pair it
with a live crtr_flag?(:sympathetic), as ClassMethods#targets
does. Only the Sympathy (1120) hostile -> sympathetic path has been
observed in a capture.
800 801 802 |
# File 'documented/common/creature/creature_base.rb', line 800 def ever_hostile? @ever_hostile || false end |
#flag_active?(key) ⇒ 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 whether a status or classification flag is active.
The two vocabularies are intentionally disjoint, so callers can filter on any known flag name without caring which bucket stores it.
824 825 826 |
# File 'documented/common/creature/creature_base.rb', line 824 def flag_active?(key) has_status?(key) || crtr_flag?(key) end |
#has_status?(status) ⇒ 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 whether a specific status is active (after expiring stale ones).
702 703 704 705 |
# File 'documented/common/creature/creature_base.rb', line 702 def has_status?(status) cleanup_expired_statuses @status.include?(status.to_s.downcase) end |
#health ⇒ Integer?
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.
Exact current health from the latest <crtrStatus health="...">
snapshot. It may be negative when damage carries a creature below
zero. It is nil until reported, and becomes nil again when a complete
snapshot omits or malforms the attribute.
600 601 602 |
# File 'documented/common/creature/creature_base.rb', line 600 def health @health end |
#infer_crtr_flags(flags) ⇒ 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.
Stands in classification flags for a creature the feed has not
reported on yet (see #crtr_flags?), e.g. a mount inferred from its
rider's rider="1" tag. Consulted by #crtr_flag? only until the
first real <crtrStatus> arrives, which then wins outright.
#crtr_flags? stays false, so callers can still tell the two apart.
Replaces, not merges: each call is the full current inference.
783 784 785 |
# File 'documented/common/creature/creature_base.rb', line 783 def infer_crtr_flags(flags) @inferred_crtr_flags = flags.dup end |
#initialize_status_tracking ⇒ 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.
Initializes the tracking ivars. Call from the host class initialize.
583 584 585 586 587 588 589 590 591 592 |
# File 'documented/common/creature/creature_base.rb', line 583 def initialize_status_tracking @status = [] @status_timestamps = {} @crtr_flags = {} @inferred_crtr_flags = {} @ever_hostile = false @health = nil @max_health = nil @last_seen_at = Time.now end |
#max_health ⇒ Integer?
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.
Exact maximum health from the latest
<crtrStatus maxhealth="..."> snapshot. It may be zero for entities
that do not participate in combat. It is nil until reported, and
becomes nil again when a complete snapshot omits or malforms the
attribute.
611 612 613 |
# File 'documented/common/creature/creature_base.rb', line 611 def max_health @max_health end |
#remove_status(status) ⇒ 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.
Removes a status from the creature.
673 674 675 676 677 678 679 680 681 682 |
# File 'documented/common/creature/creature_base.rb', line 673 def remove_status(status) status = status.to_s.downcase @status.delete(status) @status_timestamps.delete(status) # A stun removal (message or <crtrStatus> snapshot) is authoritative # and retires any crit-table duration estimate with it, however much # time that estimate had left. GemStone-only hook. clear_stun_estimate if status == 'stunned' && respond_to?(:clear_stun_estimate) debug_log("-status: #{status}") end |
#statuses ⇒ Array<String>
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.
Returns a copy of the currently-active statuses (after expiry).
710 711 712 713 |
# File 'documented/common/creature/creature_base.rb', line 710 def statuses cleanup_expired_statuses @status.dup end |
#sync_crtr_status(attrs) ⇒ 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.
Reconciles status and classification from a <crtrStatus> tag.
The tag is a full snapshot of what is currently active, not a delta. A missing flag, or a flag set to "0", means inactive even if it was active a moment ago, so absent known flags are cleared rather than ignored.
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
# File 'documented/common/creature/creature_base.rb', line 724 def sync_crtr_status(attrs) touch_seen # crtrStatus is a complete snapshot. Missing (or malformed) exact HP # attributes clear the previous values instead of leaving stale data. @health = strict_crtr_integer(attrs['health']) @max_health = strict_crtr_integer(attrs['maxhealth']) # Scoped to CRTR_STATUS_FLAGS on purpose: @status has two writers, # this feed and the combat parser reading messaging. The feed is a # full snapshot only of the states it reports, so it owns removal # for exactly those - and must not touch the rest. blind, # poisoned, natures_decay and the other message-only effects never # appear in the tag; reconciling them here would clear them on the # next one and make them impossible to model. CRTR_STATUS_FLAGS.each do |xml_name, status| if attrs[xml_name] == '1' add_status(status) elsif @status.include?(status) remove_status(status) end end CRTR_CLASSIFICATION_FLAGS.each do |xml_name, key| new_value = (attrs[xml_name] == '1') debug_log("~flag: #{key}=#{new_value}") if debug_level == :changes && @crtr_flags[key] != new_value @crtr_flags[key] = new_value end # Sticky: Sympathy (1120) swaps hostile for sympathetic in the next # snapshot while the creature is still in the fight. See #ever_hostile?. @ever_hostile = true if @crtr_flags[:hostile] report_crtr_snapshot(attrs) if %i[all active].include?(debug_level) end |
#touch_seen ⇒ Time
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.
Stamps the creature as just seen.
625 626 627 |
# File 'documented/common/creature/creature_base.rb', line 625 def touch_seen @last_seen_at = Time.now end |