Class: Lich::DragonRealms::CreatureInstance Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::CreatureBase

included

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.

Parameters:

  • id (Integer, String)

    server creature id.

  • noun (String, nil)

    noun, when available.

  • name (String, nil)

    display name, when already known.



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_numberInteger? (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.

Returns:

  • (Integer, nil)

    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_statusString? (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".

Returns:

  • (String, nil)

    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

#balanceString? (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?.

Returns:

  • (String, nil)

    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

#conditionsArray<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?.

Returns:

  • (Array<String>)

    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_atTime (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.

Returns:

  • (Time)

    when this instance was first registered.



59
60
61
# File 'documented/dragonrealms/creature.rb', line 59

def created_at
  @created_at
end

#enriched_atTime? (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.

Returns:

  • (Time, nil)

    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

#idInteger (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.

Returns:

  • (Integer)

    server creature id.



51
52
53
# File 'documented/dragonrealms/creature.rb', line 51

def id
  @id
end

#nameString?

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.

Returns:

  • (String, nil)

    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

#nounString? (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.

Returns:

  • (String, nil)

    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

#rangeSymbol? (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.

Returns:

  • (Symbol, nil)

    assess range bucket: :melee, :pole or :missile.



68
69
70
# File 'documented/dragonrealms/creature.rb', line 68

def range
  @range
end

#relationString? (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".

Returns:

  • (String, nil)

    the assess relation phrase, e.g. "behind you".



63
64
65
# File 'documented/dragonrealms/creature.rb', line 63

def relation
  @relation
end

#targetString? (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").

Returns:

  • (String, nil)

    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_idString? (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.

Returns:

  • (String, nil)

    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_numberInteger? (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.

Returns:

  • (Integer, nil)

    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_patternRegexp

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".

Returns:

  • (Regexp)


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.

Parameters:

  • name (String, nil)

    display name from the room-objs stream.



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").

Parameters:

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Parameters:

  • entry (Hash)

    an entry from XMLData.parse_assess_line, with keys :name, :number, :status, :relation, :range, :target_id.



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).

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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>".

Returns:

  • (Boolean)


173
174
175
# File 'documented/dragonrealms/creature.rb', line 173

def valid_target?
  !crtr_flag?(:dead)
end