Class: Lich::Gemstone::Injured
- Inherits:
-
Gemstone::CharacterStatus
- Object
- Gemstone::CharacterStatus
- Lich::Gemstone::Injured
- Defined in:
- documented/gemstone/injured.rb
Overview
Injured class for checking ability to perform actions based on wounds and scars
Constant Summary collapse
- BODY_PART_GROUPS =
Maps injury group names to their constituent body parts as symbols.
Used to check multiple related body parts at once when evaluating injury effects on character abilities (e.g., both eyes as a group, both arms and hands per side).
{ eyes: %i[leftEye rightEye], arms: %i[leftArm rightArm], hands: %i[leftHand rightHand], legs: %i[leftLeg rightLeg], feet: %i[leftFoot rightFoot], head_and_nerves: %i[head nsys] }.freeze
Class Method Summary collapse
-
.able_to_cast? ⇒ Boolean
Check if character is able to cast spells.
-
.able_to_search? ⇒ Boolean
Check if character is able to search.
-
.able_to_sneak? ⇒ Boolean
Check if character is able to sneak.
-
.able_to_use_ranged? ⇒ Boolean
Check if character is able to use ranged weapons.
-
.bypasses_injuries? ⇒ Boolean
Check for the presence of a buff that bypasses rank 2 or lower injuries.
-
.effective_injury_from_hashes(body_part, wounds_hash, scars_hash) ⇒ Object
Helper method to calculate effective injury level from hash data Rank 1 scars are ignored, and wounds take precedence over scars.
-
.get_injury_data ⇒ Object
Get cached or fresh injury data.
-
.injuries_at_or_above_rank?(rank, wounds_hash, scars_hash, *parts) ⇒ Boolean
Check if any of the given body parts have an injury of a specific rank or higher.
-
.injuries_at_rank?(rank, wounds_hash, scars_hash, *parts) ⇒ Boolean
Check if any of the given body parts have an injury at exactly a specific rank.
-
.injury_fingerprint ⇒ Object
Build an immutable fingerprint of the current injury state.
Class Method Details
.able_to_cast? ⇒ Boolean
Check if character is able to cast spells
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'documented/gemstone/injured.rb', line 113 def able_to_cast? fix_injury_mode("both") # Fetch cached or fresh injury data wounds, scars = get_injury_data # Rank 3 critical injuries prevent casting (Sigil cannot bypass) return false if injuries_at_rank?(3, wounds, scars, :head, :nsys, *BODY_PART_GROUPS[:eyes]) # Check for rank 3 in arms/hands (worst of arm vs hand per side) left_arm = effective_injury_from_hashes(:leftArm, wounds, scars) left_hand = effective_injury_from_hashes(:leftHand, wounds, scars) right_arm = effective_injury_from_hashes(:rightArm, wounds, scars) right_hand = effective_injury_from_hashes(:rightHand, wounds, scars) left_side = [left_arm, left_hand].max right_side = [right_arm, right_hand].max return false if left_side == 3 || right_side == 3 # Sigil of Determination bypasses rank 2 or lower injuries return true if bypasses_injuries? # Head or nerve injuries > rank 1 prevent casting return false if injuries_at_or_above_rank?(2, wounds, scars, *BODY_PART_GROUPS[:head_and_nerves]) # Cumulative injuries >= 3 prevent casting eyes_total = BODY_PART_GROUPS[:eyes].sum { |part| effective_injury_from_hashes(part, wounds, scars) } return false if eyes_total >= 3 arms_total = left_side + right_side return false if arms_total >= 3 true end |
.able_to_search? ⇒ Boolean
Check if character is able to search
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'documented/gemstone/injured.rb', line 169 def able_to_search? fix_injury_mode("both") wounds, scars = get_injury_data # Rank 3 critical injuries prevent searching (Sigil cannot bypass) return false if injuries_at_rank?(3, wounds, scars, :head, :nsys, *BODY_PART_GROUPS[:eyes]) # Sigil of Determination bypasses rank 2 or lower injuries return true if bypasses_injuries? # Rank 2+ head or nerve injury prevents searching return false if injuries_at_or_above_rank?(2, wounds, scars, *BODY_PART_GROUPS[:head_and_nerves]) true end |
.able_to_sneak? ⇒ Boolean
Check if character is able to sneak
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'documented/gemstone/injured.rb', line 150 def able_to_sneak? fix_injury_mode("both") wounds, scars = get_injury_data # Rank 3 leg/foot injuries always prevent sneaking, but these are NOT critical # (Sigil cannot bypass, but they're not in the critical list for other actions) return false if injuries_at_rank?(3, wounds, scars, *BODY_PART_GROUPS[:legs], *BODY_PART_GROUPS[:feet]) # Sigil of Determination bypasses rank 2 or lower injuries return true if bypasses_injuries? # Any leg or foot injury > rank 1 prevents sneaking return false if injuries_at_or_above_rank?(2, wounds, scars, *BODY_PART_GROUPS[:legs], *BODY_PART_GROUPS[:feet]) true end |
.able_to_use_ranged? ⇒ Boolean
Check if character is able to use ranged weapons
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'documented/gemstone/injured.rb', line 187 def able_to_use_ranged? fix_injury_mode("both") wounds, scars = get_injury_data # Rank 3 critical injuries prevent ranged weapon use (Sigil cannot bypass) return false if injuries_at_rank?(3, wounds, scars, :head, :nsys, *BODY_PART_GROUPS[:eyes], *BODY_PART_GROUPS[:arms], *BODY_PART_GROUPS[:hands]) # Sigil of Determination bypasses rank 2 or lower injuries return true if bypasses_injuries? # Any single arm or hand injury >= rank 2 prevents ranged weapon use return false if injuries_at_or_above_rank?(2, wounds, scars, *BODY_PART_GROUPS[:arms], *BODY_PART_GROUPS[:hands], :nsys) true end |
.bypasses_injuries? ⇒ Boolean
Check for the presence of a buff that bypasses rank 2 or lower injuries
101 102 103 |
# File 'documented/gemstone/injured.rb', line 101 def bypasses_injuries? Effects::Buffs.active?("Sigil of Determination") end |
.effective_injury_from_hashes(body_part, wounds_hash, scars_hash) ⇒ Object
Helper method to calculate effective injury level from hash data Rank 1 scars are ignored, and wounds take precedence over scars
78 79 80 81 82 83 84 |
# File 'documented/gemstone/injured.rb', line 78 def effective_injury_from_hashes(body_part, wounds_hash, scars_hash) scar = scars_hash[body_part.to_s] || 0 wound = wounds_hash[body_part.to_s] || 0 effective_scar = (scar == 1) ? 0 : scar [wound, effective_scar].max end |
.get_injury_data ⇒ Object
Get cached or fresh injury data
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'documented/gemstone/injured.rb', line 48 def get_injury_data current_key = injury_fingerprint # Fast path: return cached data if key hasn't changed if @injury_cache_key == current_key && @wounds_cache && @scars_cache return [@wounds_cache, @scars_cache] end # Slow path: fetch new data with mutex protection @cache_mutex.synchronize do # Double-check after acquiring lock (another thread may have updated) if @injury_cache_key == current_key && @wounds_cache && @scars_cache return [@wounds_cache, @scars_cache] end # Fetch fresh data wounds = Wounds.all_wounds scars = Scars.all_scars # Update cache @wounds_cache = wounds @scars_cache = scars @injury_cache_key = current_key [wounds, scars] end end |
.injuries_at_or_above_rank?(rank, wounds_hash, scars_hash, *parts) ⇒ Boolean
Check if any of the given body parts have an injury of a specific rank or higher
94 95 96 97 98 |
# File 'documented/gemstone/injured.rb', line 94 def injuries_at_or_above_rank?(rank, wounds_hash, scars_hash, *parts) parts.flatten.any? do |part| effective_injury_from_hashes(part, wounds_hash, scars_hash) >= rank end end |
.injuries_at_rank?(rank, wounds_hash, scars_hash, *parts) ⇒ Boolean
Check if any of the given body parts have an injury at exactly a specific rank
87 88 89 90 91 |
# File 'documented/gemstone/injured.rb', line 87 def injuries_at_rank?(rank, wounds_hash, scars_hash, *parts) parts.flatten.any? do |part| effective_injury_from_hashes(part, wounds_hash, scars_hash) == rank end end |
.injury_fingerprint ⇒ Object
Build an immutable fingerprint of the current injury state. XMLData.injuries is mutated in place by the parser, so the hash itself cannot serve as a cache key: it would always compare equal to itself. Note: this runs in injury mode 2 ('both'), where a scar underneath an active wound is not visible, so such a scar changing will not invalidate the cache. That is a narrow case and acceptable given each cache miss costs two _injury round trips in Scars.all_scars.
43 44 45 |
# File 'documented/gemstone/injured.rb', line 43 def injury_fingerprint XMLData.injuries.map { |part, v| [part, v['wound'], v['scar']] }.freeze end |