Class: Lich::DragonRealms::CreatureInstance Private
- Inherits:
-
Object
- Object
- Lich::DragonRealms::CreatureInstance
- Includes:
- Common::CreatureBase
- Defined in:
- documented/dragonrealms/creature.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A single DragonRealms creature, keyed by its server exist id.
Shares its registry, room roster and <crtrStatus> flag handling with
GemStone through Common::CreatureBase; the DragonRealms-specific
layer adds the assess-stream backfill (name, assess number, relation,
range) and a DragonRealms valid_target? rule.
Constant Summary
Constants included from Common::CreatureBase
Common::CreatureBase::ALL_CRTR_FLAGS, Common::CreatureBase::CRTR_CLASSIFICATION_FLAGS, Common::CreatureBase::CRTR_STATUS_FLAGS, Common::CreatureBase::KNOWN_FLAG_NAMES, Common::CreatureBase::STATUS_DURATIONS
Instance Attribute Summary collapse
-
#assess_number ⇒ Integer?
readonly
private
The
assesslist number (1-based), if seen. -
#assess_status ⇒ String?
readonly
private
The
assessparenthetical status, e.g. -
#balance ⇒ String?
readonly
private
Balance descriptor parsed from the
assessparenthetical, one of DR_BALANCE_VALUES (e.g. "solidly", "off"). -
#conditions ⇒ Array<String>
readonly
private
Assess-only condition/classification words parsed from the
assessparenthetical that crtrStatus does NOT carry (e.g. ["cursed"], ["friendly", "cursed"]); [] when none/unseen. -
#created_at ⇒ Time
readonly
private
When this instance was first registered.
-
#enriched_at ⇒ Time?
readonly
private
When assess enrichment last landed for this id; nil until first assess.
-
#id ⇒ Integer
readonly
private
Server creature id.
-
#name ⇒ String?
private
Display name; nil until a room-objs backfill or an
assesstie-in supplies one. -
#noun ⇒ String?
readonly
private
Attack noun (the trailing word of the name), derived whenever a name is set; nil until then.
-
#range ⇒ Symbol?
readonly
private
assessrange bucket::melee,:poleor:missile. -
#relation ⇒ String?
readonly
private
The
assessrelation phrase, e.g. -
#target ⇒ String?
readonly
private
Name of the creature/PC this one is engaging, from
assess(e.g. "you", "Holdigor", "a plague spawn"). -
#target_id ⇒ String?
readonly
private
Id of the creature/PC this one is engaging, from
assess. -
#target_number ⇒ Integer?
readonly
private
The engaged target's
assesslist number, if any.
Class Method Summary collapse
-
.balance_pattern ⇒ Regexp
private
Matches a DR_BALANCE_VALUES descriptor followed by the balance word in an assess parenthetical, e.g.
Instance Method Summary collapse
-
#apply_room_name(name) ⇒ void
private
Applies a name learned from the room-objs stream, and derives the attack noun from it.
-
#condition?(name) ⇒ Boolean
private
Whether a given assess affliction is present (e.g. "cursed", "poisoned").
-
#cursed? ⇒ Boolean
private
Convenience for the "cursed" affliction; use #condition? for others.
-
#enriched? ⇒ Boolean
private
Whether any
assessenrichment (range/balance/conditions/relation/target) has landed for this id. -
#feed_assess(entry) ⇒ void
private
Backfills name and positional data from a parsed
assessentry. -
#friendly? ⇒ Boolean
private
True while assess reports this creature as "friendly" - i.e.
-
#initialize(id, noun, name) ⇒ CreatureInstance
constructor
private
A new instance of CreatureInstance.
-
#off_balance? ⇒ Boolean
private
Whether the creature is below "solidly balanced" per the last
assess(a softer target). -
#valid_target? ⇒ Boolean
private
Whether this creature should be considered attackable.
Methods included from Common::CreatureBase
Constructor Details
#initialize(id, noun, name) ⇒ CreatureInstance
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 new instance of CreatureInstance.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'documented/dragonrealms/creature.rb', line 95 def initialize(id, noun, name) @id = id.to_i @noun = noun @name = name @created_at = Time.now @assess_number = nil @relation = nil @assess_status = nil @range = nil @target_id = nil @target = nil @target_number = nil @balance = nil @conditions = [] @enriched_at = nil # The assess stream is the authoritative id<->name tie; once it names a # creature, the room-objs backfill must not overwrite it (see # #apply_room_name). Room-objs may still supply a name first, before any # assess has run. @name_from_assess = false initialize_status_tracking end |
Instance Attribute Details
#assess_number ⇒ Integer? (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.
Returns the assess list number (1-based), if seen.
61 62 63 |
# File 'documented/dragonrealms/creature.rb', line 61 def assess_number @assess_number end |
#assess_status ⇒ String? (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.
Returns the assess parenthetical status, e.g.
"cursed and solidly balanced".
66 67 68 |
# File 'documented/dragonrealms/creature.rb', line 66 def assess_status @assess_status end |
#balance ⇒ String? (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.
Returns balance descriptor parsed from the assess
parenthetical, one of DR_BALANCE_VALUES (e.g. "solidly", "off"). nil
until an assess with a balance phrase arrives. See #off_balance?.
79 80 81 |
# File 'documented/dragonrealms/creature.rb', line 79 def balance @balance end |
#conditions ⇒ Array<String> (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.
Returns assess-only condition/classification words parsed
from the assess parenthetical that crtrStatus does NOT carry (e.g.
["cursed"], ["friendly", "cursed"]); [] when none/unseen. crtrStatus
states (prone/sleeping/stunned/immobile/hidden/...) live in crtr_flag?/
has_status?, not here. See #cursed? and #friendly?.
85 86 87 |
# File 'documented/dragonrealms/creature.rb', line 85 def conditions @conditions end |
#created_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.
Returns when this instance was first registered.
59 60 61 |
# File 'documented/dragonrealms/creature.rb', line 59 def created_at @created_at end |
#enriched_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.
Returns when assess enrichment last landed for this id; nil until first assess. See #enriched?. Assess fields (range/balance/ conditions/relation/target) are "pull" snapshots and can go stale - poll assess before relying on one.
90 91 92 |
# File 'documented/dragonrealms/creature.rb', line 90 def enriched_at @enriched_at end |
#id ⇒ Integer (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.
Returns server creature id.
51 52 53 |
# File 'documented/dragonrealms/creature.rb', line 51 def id @id end |
#name ⇒ 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 display name; nil until a room-objs backfill or an
assess tie-in supplies one.
57 58 59 |
# File 'documented/dragonrealms/creature.rb', line 57 def name @name end |
#noun ⇒ String? (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.
Returns attack noun (the trailing word of the name), derived whenever a name is set; nil until then.
54 55 56 |
# File 'documented/dragonrealms/creature.rb', line 54 def noun @noun end |
#range ⇒ Symbol? (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.
Returns assess range bucket: :melee, :pole or :missile.
68 69 70 |
# File 'documented/dragonrealms/creature.rb', line 68 def range @range end |
#relation ⇒ String? (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.
Returns the assess relation phrase, e.g. "behind you".
63 64 65 |
# File 'documented/dragonrealms/creature.rb', line 63 def relation @relation end |
#target ⇒ String? (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.
Returns name of the creature/PC this one is engaging, from
assess (e.g. "you", "Holdigor", "a plague spawn").
73 74 75 |
# File 'documented/dragonrealms/creature.rb', line 73 def target @target end |
#target_id ⇒ String? (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.
Returns id of the creature/PC this one is engaging, from assess.
70 71 72 |
# File 'documented/dragonrealms/creature.rb', line 70 def target_id @target_id end |
#target_number ⇒ Integer? (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.
Returns the engaged target's assess list number, if any.
75 76 77 |
# File 'documented/dragonrealms/creature.rb', line 75 def target_number @target_number end |
Class Method Details
.balance_pattern ⇒ Regexp
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.
Matches a DR_BALANCE_VALUES descriptor followed by the balance word in an assess parenthetical, e.g. "solidly balanced", "off balance", and the worst levels' "imbalanced" phrasing ("extremely imbalanced"). Built lazily so DR_BALANCE_VALUES (loaded with drvariables) is present by first use; union order (longest multi-word values first in the array) resolves "somewhat off" ahead of "off".
237 238 239 |
# File 'documented/dragonrealms/creature.rb', line 237 def self.balance_pattern @balance_pattern ||= /\b(#{Regexp.union(DR_BALANCE_VALUES)})\s+(?:im)?balanced?\b/i end |
Instance Method Details
#apply_room_name(name) ⇒ 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.
Applies a name learned from the room-objs stream, and derives the attack noun from it.
Two producers call this, both via the XML parser: the stream-order
backfill that pairs the Nth bold room-objs name with the Nth
<crtrStatus> id, and (future-proofing) a GemStone-style
<a exist noun> room-objs tag if DragonRealms ever emits one. The
assess stream is the authoritative id<->name tie, so once #feed_assess
has named the creature this is a no-op. A nil name (e.g. an out-of-range
positional lookup, the count-guard) is ignored, leaving any existing name
intact.
160 161 162 163 164 165 |
# File 'documented/dragonrealms/creature.rb', line 160 def apply_room_name(name) return if name.nil? || @name_from_assess @name = name @noun = derive_noun(name) end |
#condition?(name) ⇒ 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 a given assess affliction is present (e.g. "cursed", "poisoned").
201 202 203 |
# File 'documented/dragonrealms/creature.rb', line 201 def condition?(name) @conditions.include?(name.to_s) end |
#cursed? ⇒ 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.
Convenience for the "cursed" affliction; use #condition? for others.
208 209 210 |
# File 'documented/dragonrealms/creature.rb', line 208 def cursed? condition?('cursed') end |
#enriched? ⇒ 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 assess enrichment (range/balance/conditions/relation/target)
has landed for this id. These are "pull" snapshots -- poll assess before
relying on them, and see #enriched_at for staleness.
182 183 184 |
# File 'documented/dragonrealms/creature.rb', line 182 def enriched? !@enriched_at.nil? end |
#feed_assess(entry) ⇒ 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.
Backfills name and positional data from a parsed assess entry.
<crtrStatus> registers a creature id-first with no name, so this is how
DragonRealms learns which name/relation/range belongs to that id. The
assess feed capitalizes the subject ("A jeol moradu"); the name is
downcased to match the room-objs vocabulary DragonRealms scripts expect.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'documented/dragonrealms/creature.rb', line 128 def feed_assess(entry) if entry[:name] @name = entry[:name].to_s.downcase @noun = derive_noun(@name) # Authoritative from here on: subsequent room-objs backfills no-op. @name_from_assess = true end @assess_number = entry[:number] @assess_status = entry[:status] @balance, @conditions = parse_assess_status(entry[:status]) @relation = entry[:relation] @range = entry[:range] @target_id = entry[:target_id] @target = entry[:target] @target_number = entry[:target_number] @enriched_at = Time.now end |
#friendly? ⇒ 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.
True while assess reports this creature as "friendly" - i.e. it has been empathically manipulated (an Empath ability: "manipulate ... to consider you friend, not foe") into treating you as a friend.
This is a TEMPORARY, manipulated state, NOT a permanent classification: crtrStatus keeps reporting hostile="1" throughout, and it wears off. Confirmed from logs - one jeol moradu (exist 105829093) went hostile/flanking-you -> manipulated "friendly" (and turned on its own kind) while crtrStatus stayed hostile the whole time. Assess-only, so it is a staleable pull field: re-assess before relying on it, and do not treat it as a durable friend/foe flag (a summon/pet is a different thing).
225 226 227 |
# File 'documented/dragonrealms/creature.rb', line 225 def friendly? condition?('friendly') end |
#off_balance? ⇒ 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 the creature is below "solidly balanced" per the last assess
(a softer target). False when balance is unknown.
190 191 192 193 194 195 |
# File 'documented/dragonrealms/creature.rb', line 190 def off_balance? return false unless @balance idx = DR_BALANCE_VALUES.index(@balance) !idx.nil? && idx < DR_BALANCE_VALUES.index('solidly') end |
#valid_target? ⇒ 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 this creature should be considered attackable.
DragonRealms has no UCS or appendage decoys to exclude, so the rule is
simply "not confirmed dead by <crtrStatus>".
173 174 175 |
# File 'documented/dragonrealms/creature.rb', line 173 def valid_target? !crtr_flag?(:dead) end |