Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 2207x 169x 2038x 2020x 18x 7x 11x 1023x 1023x 1023x 1023x 1016x 7x 7x 7x 7x 6x 3x 3x 2x 1x 1x 1x 4x 2x 2x 2x 2x 3x 3x 3x 1018x 1018x 1018x 24x | /**
* Movement Penalty System
*
* **Korean**: 이동 패널티 시스템
*
* Implements injury-based movement penalties where leg and body damage reduces
* movement speed, stance changes, and mobility capabilities. This system applies
* realistic combat trauma effects based on Korean martial arts principles.
*
* ## System Features
*
* - Progressive speed reduction based on leg health
* - Asymmetric damage (left/right leg affects directional movement)
* - Instant penalties from knee/ankle strikes (5 seconds)
* - Stance change duration penalties
* - Advanced stance restrictions when critically injured
* - Balance integration for VULNERABLE/HELPLESS states
*
* ## Movement Speed Penalties
*
* | Leg Health | State | Speed | Can Run |
* |------------|-------|-------|---------|
* | 100-70% | Normal | 100% | Yes |
* | 69-50% | Limping | 80% | Yes |
* | 49-30% | Severe Limp | 60% | Yes |
* | <30% | Hobbled | 40% | No |
*
* ## Stance Change Penalties
*
* - Legs <50% health: Stance change takes 2x longer
* - Legs <30% health: Cannot change to advanced stances (only basic)
*
* @module systems/bodypart/MovementPenaltySystem
* @category Body Part System
* @korean 이동패널티시스템
*/
import {
BodyPart,
BodyPartHealth,
BodyPartMaxHealth,
LegInjuryState,
MovementPenalty,
InstantMovementPenalty,
MOVEMENT_PENALTY_CONSTANTS,
} from "./types";
/**
* Movement Penalty System class.
*
* **Korean**: 이동 패널티 시스템 클래스
*
* Calculates movement penalties from leg injuries, manages instant penalties
* from knee/ankle strikes, and integrates with balance system.
*
* @example
* ```typescript
* const system = new MovementPenaltySystem();
*
* // Calculate current movement penalty
* const penalty = system.calculateMovementPenalty(
* bodyPartHealth,
* maxHealth,
* activeInstantPenalty
* );
*
* // Apply to movement speed
* const actualSpeed = baseSpeed * penalty.speedMultiplier;
* ```
*
* @public
* @category Body Part System
*/
export class MovementPenaltySystem {
/**
* Calculate movement penalty from body part health.
*
* **Korean**: 이동 패널티 계산
*
* Analyzes leg health and returns comprehensive movement penalty including
* speed multiplier, stance change penalties, and balance effects.
*
* @param health - Current body part health
* @param maxHealth - Maximum health values
* @param instantPenalty - Optional active instant penalty
* @param currentTime - Current timestamp for instant penalty expiry check
* @returns Movement penalty with all modifiers
*
* @public
*/
calculateMovementPenalty(
health: BodyPartHealth,
maxHealth: BodyPartMaxHealth,
instantPenalty?: InstantMovementPenalty,
currentTime: number = Date.now()
): MovementPenalty {
// Calculate average leg health percentage
const leftLegPercent = health.legLeft / maxHealth.legLeft;
const rightLegPercent = health.legRight / maxHealth.legRight;
const avgLegHealth = (leftLegPercent + rightLegPercent) / 2;
// Determine injury state and base speed multiplier
const { injuryState, speedMultiplier } = this.getInjuryStateFromHealth(avgLegHealth);
// Check if instant penalty is active
const hasActiveInstantPenalty =
instantPenalty !== undefined &&
instantPenalty.appliedAt + instantPenalty.duration > currentTime;
// Apply instant penalty if active, otherwise use base multiplier
const finalSpeedMultiplier = hasActiveInstantPenalty && instantPenalty
? Math.min(speedMultiplier, instantPenalty.speedMultiplier)
: speedMultiplier;
// Calculate stance change penalty
const stanceChangePenalty =
avgLegHealth < MOVEMENT_PENALTY_CONSTANTS.STANCE_CHANGE.CRITICAL_THRESHOLD
? MOVEMENT_PENALTY_CONSTANTS.STANCE_CHANGE.INJURED
: MOVEMENT_PENALTY_CONSTANTS.STANCE_CHANGE.NORMAL;
// Determine if advanced stances are restricted
const advancedStancesRestricted =
avgLegHealth < MOVEMENT_PENALTY_CONSTANTS.STANCE_CHANGE.RESTRICTION_THRESHOLD;
// Calculate balance modifier (lower leg health = worse balance)
const balanceModifier = Math.max(0.3, avgLegHealth);
// Determine if player can run
const canRun = injuryState !== LegInjuryState.HOBBLED;
return {
speedMultiplier: finalSpeedMultiplier,
canRun,
injuryState,
stanceChangePenalty,
advancedStancesRestricted,
balanceModifier,
hasInstantPenalty: hasActiveInstantPenalty,
instantPenaltyExpiry: hasActiveInstantPenalty && instantPenalty
? instantPenalty.appliedAt + instantPenalty.duration
: 0,
};
}
/**
* Get injury state and speed multiplier from leg health percentage.
*
* **Korean**: 부상 상태 및 속도 배율 조회
*
* @param legHealthPercent - Average leg health as percentage (0.0-1.0)
* @returns Injury state and corresponding speed multiplier
*
* @private
*/
private getInjuryStateFromHealth(legHealthPercent: number): {
injuryState: LegInjuryState;
speedMultiplier: number;
} {
const { THRESHOLDS, SPEED_MULTIPLIERS } = MOVEMENT_PENALTY_CONSTANTS;
if (legHealthPercent >= THRESHOLDS.NORMAL) {
return {
injuryState: LegInjuryState.NORMAL,
speedMultiplier: SPEED_MULTIPLIERS.NORMAL,
};
} else if (legHealthPercent >= THRESHOLDS.LIMPING) {
return {
injuryState: LegInjuryState.LIMPING,
speedMultiplier: SPEED_MULTIPLIERS.LIMPING,
};
} else if (legHealthPercent >= THRESHOLDS.SEVERE_LIMP) {
return {
injuryState: LegInjuryState.SEVERE_LIMP,
speedMultiplier: SPEED_MULTIPLIERS.SEVERE_LIMP,
};
} else {
return {
injuryState: LegInjuryState.HOBBLED,
speedMultiplier: SPEED_MULTIPLIERS.HOBBLED,
};
}
}
/**
* Calculate asymmetric movement penalty based on movement direction and injured leg.
*
* **Korean**: 비대칭 이동 패널티 계산
*
* Left leg damage affects left-side movements more, and vice versa.
* This creates realistic limping behavior where movement toward the injured
* side is more impaired.
*
* @param health - Current body part health
* @param maxHealth - Maximum health values
* @param movementDirection - Direction of movement (positive = right, negative = left)
* @returns Additional speed multiplier for asymmetric penalty
*
* @public
*/
calculateAsymmetricPenalty(
health: BodyPartHealth,
maxHealth: BodyPartMaxHealth,
movementDirection: { x: number; y: number }
): number {
const leftLegPercent = health.legLeft / maxHealth.legLeft;
const rightLegPercent = health.legRight / maxHealth.legRight;
// Only apply asymmetric penalty if one leg is significantly more damaged
const legHealthDifference = Math.abs(leftLegPercent - rightLegPercent);
if (legHealthDifference < 0.15) {
// Both legs similarly damaged - no asymmetric penalty
return 1.0;
}
// Determine which leg is more injured
const leftLegMoreInjured = leftLegPercent < rightLegPercent;
// Horizontal movement direction (x-axis)
const movingLeft = movementDirection.x < -0.1;
const movingRight = movementDirection.x > 0.1;
if (leftLegMoreInjured) {
// Left leg injured - left movement more impaired
if (movingLeft) {
return MOVEMENT_PENALTY_CONSTANTS.ASYMMETRIC.SAME_SIDE_PENALTY;
} else if (movingRight) {
return MOVEMENT_PENALTY_CONSTANTS.ASYMMETRIC.OPPOSITE_SIDE_PENALTY;
}
} else {
// Right leg injured - right movement more impaired
if (movingRight) {
return MOVEMENT_PENALTY_CONSTANTS.ASYMMETRIC.SAME_SIDE_PENALTY;
E} else if (movingLeft) {
return MOVEMENT_PENALTY_CONSTANTS.ASYMMETRIC.OPPOSITE_SIDE_PENALTY;
}
}
return 1.0; // No horizontal movement
}
/**
* Create instant movement penalty from knee/ankle strike.
*
* **Korean**: 순간 이동 패널티 생성
*
* Applied when knee or ankle vital points are struck, causing immediate
* severe movement impairment for 5 seconds.
*
* @param affectedPart - Body part that was struck (LEG_LEFT or LEG_RIGHT)
* @param currentTime - Timestamp when strike occurred
* @returns Instant movement penalty configuration
*
* @public
*/
createInstantPenalty(
affectedPart: BodyPart.LEG_LEFT | BodyPart.LEG_RIGHT,
currentTime: number = Date.now()
): InstantMovementPenalty {
return {
speedMultiplier: MOVEMENT_PENALTY_CONSTANTS.INSTANT_PENALTY.SPEED_MULTIPLIER,
duration: MOVEMENT_PENALTY_CONSTANTS.INSTANT_PENALTY.DURATION,
appliedAt: currentTime,
affectedPart,
};
}
/**
* Check if player should enter VULNERABLE state from leg damage.
*
* **Korean**: 취약 상태 확인
*
* Low leg health increases chance of entering vulnerable state,
* making player more susceptible to follow-up attacks.
*
* @param health - Current body part health
* @param maxHealth - Maximum health values
* @returns True if player should enter vulnerable state
*
* @public
*/
shouldEnterVulnerableState(
health: BodyPartHealth,
maxHealth: BodyPartMaxHealth
): boolean {
const leftLegPercent = health.legLeft / maxHealth.legLeft;
const rightLegPercent = health.legRight / maxHealth.legRight;
const avgLegHealth = (leftLegPercent + rightLegPercent) / 2;
// Enter vulnerable state when legs are critically damaged
return avgLegHealth < MOVEMENT_PENALTY_CONSTANTS.THRESHOLDS.SEVERE_LIMP;
}
/**
* Check if player should enter HELPLESS state from leg damage.
*
* **Korean**: 무력 상태 확인
*
* Both legs critically damaged or hobbled - player cannot maintain
* effective combat stance and is highly vulnerable.
*
* @param health - Current body part health
* @param maxHealth - Maximum health values
* @returns True if player should enter helpless state
*
* @public
*/
shouldEnterHelplessState(
health: BodyPartHealth,
maxHealth: BodyPartMaxHealth
): boolean {
const leftLegPercent = health.legLeft / maxHealth.legLeft;
const rightLegPercent = health.legRight / maxHealth.legRight;
// Enter helpless state when both legs are hobbled
return (
leftLegPercent < MOVEMENT_PENALTY_CONSTANTS.THRESHOLDS.SEVERE_LIMP &&
rightLegPercent < MOVEMENT_PENALTY_CONSTANTS.THRESHOLDS.SEVERE_LIMP
);
}
/**
* Calculate modified movement speed with all penalties applied.
*
* **Korean**: 수정된 이동 속도 계산
*
* Applies base movement penalty, asymmetric penalties, and instant penalties
* to calculate the final movement speed.
*
* @param baseSpeed - Base movement speed (pixels per frame)
* @param health - Current body part health
* @param maxHealth - Maximum health values
* @param movementDirection - Direction vector of movement
* @param instantPenalty - Optional active instant penalty
* @param currentTime - Current timestamp
* @returns Final movement speed with all penalties applied
*
* @public
*/
calculateModifiedSpeed(
baseSpeed: number,
health: BodyPartHealth,
maxHealth: BodyPartMaxHealth,
movementDirection: { x: number; y: number },
instantPenalty?: InstantMovementPenalty,
currentTime: number = Date.now()
): number {
// Get base movement penalty
const penalty = this.calculateMovementPenalty(
health,
maxHealth,
instantPenalty,
currentTime
);
// Calculate asymmetric penalty
const asymmetricMultiplier = this.calculateAsymmetricPenalty(
health,
maxHealth,
movementDirection
);
// Apply all multipliers
return baseSpeed * penalty.speedMultiplier * asymmetricMultiplier;
}
}
/**
* Singleton instance of Movement Penalty System.
*
* **Korean**: 이동 패널티 시스템 싱글톤
*
* Provides global access to the movement penalty system throughout the game.
*
* @public
*/
export const movementPenaltySystem = new MovementPenaltySystem();
|