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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | 37x 37x 37x 37x 39x 39x 1x 38x 38x 38x 38x 38x 38x 37x 1x 38x 38x 7x 7x 7x 7x 13x 13x 13x 13x 7x 7x 7x 1x 6x 3x 3x 3x 2x 1x 1x 1x 1x 1x 1x 38x 28x 4x 2x | /**
* Bone Impact Audio System for Black Trigram (흑괘)
*
* Provides realistic bone contact sounds, fracture audio, and anatomically-accurate
* impact feedback for Korean martial arts combat.
*
* **Korean**: 골절음 시스템 (骨折音 - Bone Fracture Sound System)
*
* @module BoneImpactAudioSystem
*
* Features:
* - 5 body region categories (head, torso, arms, legs, soft tissue)
* - Impact intensity scaling (light 70% → fracture 130% volume)
* - Fracture detection when health < 30%
* - Spatial audio positioning (planned feature, not yet implemented in AudioManager)
* - Korean-English bilingual audio cues
*/
import {
calculateImpactIntensity,
detectAudioBodyRegion,
getBoneImpactSoundId,
getImpactVolumeMultiplier,
} from "../../audio/BoneImpactAudioMap";
import {
AudioBodyRegion,
BoneImpactEvent,
ImpactIntensity,
} from "../../audio/types";
import { VitalPoint } from "../vitalpoint/types";
/**
* 3D Position for spatial audio
*/
export interface Vector3 {
readonly x: number;
readonly y: number;
readonly z: number;
}
/**
* Audio manager interface (minimal subset needed)
*
* Note: Spatial audio parameters (position) are not currently supported by the
* actual IAudioManager interface. This interface documents the intended API
* for future spatial audio integration with Howler.js.
*/
export interface AudioManagerInterface {
playSFX(soundId: string, volume?: number): Promise<void>;
}
/**
* Configuration for BoneImpactAudioSystem
*/
export interface BoneImpactAudioConfig {
/**
* Enable spatial audio positioning (default: true).
*
* NOTE: Spatial/positional audio is a planned future feature. The current
* AudioManager implementation does not support 3D positions, so this flag
* is effectively a no-op until the core audio layer is extended.
*/
readonly enableSpatialAudio?: boolean;
/** Master volume multiplier for bone impacts (default: 1.0) */
readonly masterVolume?: number;
/** Minimum interval between bone impact sounds in ms (default: 50) */
readonly minPlayInterval?: number;
/** Character height for body region detection (default: 2.0) */
readonly characterHeight?: number;
/** Enable Korean-English audio cues (default: false - not implemented yet) */
readonly enableBilingualCues?: boolean;
}
/**
* Statistics for BoneImpactAudioSystem monitoring
*/
export interface BoneImpactAudioStats {
readonly totalImpactsPlayed: number;
readonly impactsByRegion: Record<AudioBodyRegion, number>;
readonly impactsByIntensity: Record<ImpactIntensity, number>;
readonly fracturesTriggered: number;
readonly vitalPointStrikes: number;
readonly lastImpactTime: number;
}
/**
* Bone Impact Audio System
*
* Centralized system for playing anatomically-accurate bone and flesh impact sounds
* based on strike location, intensity, and target health.
*/
export class BoneImpactAudioSystem {
private readonly audioManager: AudioManagerInterface;
private readonly config: Required<BoneImpactAudioConfig>;
private lastPlayTime: number = 0;
// Statistics tracking
private stats: BoneImpactAudioStats = {
totalImpactsPlayed: 0,
impactsByRegion: {
head: 0,
torso: 0,
arms: 0,
legs: 0,
soft_tissue: 0,
},
impactsByIntensity: {
light: 0,
medium: 0,
heavy: 0,
critical: 0,
fracture: 0,
},
fracturesTriggered: 0,
vitalPointStrikes: 0,
lastImpactTime: 0,
};
/**
* Create a new BoneImpactAudioSystem
*
* @param audioManager - Audio manager for playing sounds
* @param config - Optional configuration
*/
constructor(
audioManager: AudioManagerInterface,
config?: BoneImpactAudioConfig
) {
this.audioManager = audioManager;
this.config = {
enableSpatialAudio: config?.enableSpatialAudio ?? true,
masterVolume: config?.masterVolume ?? 1.0,
minPlayInterval: config?.minPlayInterval ?? 50,
characterHeight: config?.characterHeight ?? 2.0,
enableBilingualCues: config?.enableBilingualCues ?? false,
};
}
/**
* Play bone impact sound based on event parameters
*
* **Korean**: 골절음 재생
*
* @param event - Bone impact event with region, intensity, and health info
* @param _position - Optional 3D position for spatial audio (future feature, not yet implemented)
* @returns Promise that resolves when sound starts playing
*
* @example
* ```typescript
* await system.playBoneImpact(
* { region: 'head', intensity: 'heavy', vitalPoint: false },
* { x: 0, y: 1.8, z: 0 }
* );
* ```
*/
async playBoneImpact(
event: BoneImpactEvent,
_position?: Vector3 // Prefixed with _ to indicate unused (spatial audio not yet implemented)
): Promise<void> {
// Rate limiting check
const now = Date.now();
if (now - this.lastPlayTime < this.config.minPlayInterval) {
return;
}
const { region, intensity, vitalPoint } = event;
// Get sound ID with random variant
const soundId = getBoneImpactSoundId(region, intensity, true);
// Calculate volume based on intensity and master volume
const volumeMultiplier = getImpactVolumeMultiplier(intensity);
const finalVolume = Math.min(
1.0,
0.8 * volumeMultiplier * this.config.masterVolume
);
// NOTE: Spatial audio (position) is not yet implemented in the actual AudioManager.
// The position parameter is accepted for API compatibility but not currently used.
// Future implementation will pass position to Howler.js for 3D audio positioning.
try {
// Play the sound (without spatial audio for now)
await this.audioManager.playSFX(soundId, finalVolume);
// Play Korean-English audio cue if enabled (future feature)
Iif (this.config.enableBilingualCues && intensity === "fracture") {
await this.playBilingualCue("bone_fracture");
}
} catch (error) {
console.warn(
`Failed to play bone impact sound: ${soundId}`,
error
);
} finally {
// Update statistics regardless of playback success/failure
this.updateStats(region, intensity, vitalPoint);
this.lastPlayTime = now;
}
}
/**
* Play bone impact from vital point strike
*
* @param vitalPoint - Vital point that was struck
* @param impactForce - Force of impact (damage amount)
* @param remainingHealth - Target's remaining health
* @param position - 3D position of strike
*
* @example
* ```typescript
* await system.playBoneImpactFromVitalPoint(
* ribVitalPoint,
* 35,
* 25,
* { x: 0.2, y: 1.2, z: 0 }
* );
* ```
*/
async playBoneImpactFromVitalPoint(
vitalPoint: VitalPoint,
impactForce: number,
remainingHealth: number,
position: Vector3
): Promise<void> {
// Determine body region from vital point
const region = this.getBoneTypeFromVitalPoint(vitalPoint);
// Calculate intensity from impact force and health
const intensity = calculateImpactIntensity(
impactForce,
remainingHealth,
true // Vital point strikes are always critical
);
// Create bone impact event
const event: BoneImpactEvent = {
region,
intensity,
vitalPoint: true,
remainingHealth,
};
await this.playBoneImpact(event, position);
}
/**
* Play bone impact from damage and position
* Auto-detects body region and calculates intensity
*
* @param damage - Damage amount
* @param remainingHealth - Target's remaining health
* @param hitPosition - 3D position where strike landed
* @param isVitalPoint - Whether strike hit a vital point
*
* @example
* ```typescript
* await system.playBoneImpactFromDamage(
* 40,
* 60,
* { x: 0, y: 1.8, z: 0 },
* false
* );
* ```
*/
async playBoneImpactFromDamage(
damage: number,
remainingHealth: number,
hitPosition: Vector3,
isVitalPoint: boolean = false
): Promise<void> {
// Auto-detect body region from hit position
const region = detectAudioBodyRegion(
hitPosition,
this.config.characterHeight
);
// Calculate intensity from damage and health
const intensity = calculateImpactIntensity(
damage,
remainingHealth,
isVitalPoint
);
// Create bone impact event
const event: BoneImpactEvent = {
region,
intensity,
vitalPoint: isVitalPoint,
remainingHealth,
};
await this.playBoneImpact(event, hitPosition);
}
/**
* Determine bone type from vital point category
* Maps vital point data to audio body regions
*
* @param vitalPoint - Vital point that was struck
* @returns Audio body region
*/
private getBoneTypeFromVitalPoint(vitalPoint: VitalPoint): AudioBodyRegion {
const name = vitalPoint.names.korean.toLowerCase();
const category = vitalPoint.category?.toLowerCase() ?? "";
// Head region detection
if (
name.includes("머리") ||
name.includes("두부") ||
name.includes("관자놀이") ||
name.includes("턱") ||
name.includes("목")
) {
return "head";
}
// Skeletal (bone) regions
if (category.includes("skeletal") || category.includes("골격")) {
Eif (name.includes("갈비") || name.includes("늑골")) {
return "torso";
}
if (name.includes("척추") || name.includes("등뼈")) {
return "torso";
}
}
// Joint regions
if (category.includes("joint") || category.includes("관절")) {
if (
name.includes("어깨") ||
name.includes("팔꿈치") ||
name.includes("손목")
) {
return "arms";
}
Eif (
name.includes("무릎") ||
name.includes("발목") ||
name.includes("고관절")
) {
return "legs";
}
}
// Arm detection
Iif (name.includes("팔") || name.includes("완")) {
return "arms";
}
// Leg detection
Iif (name.includes("다리") || name.includes("각") || name.includes("발")) {
return "legs";
}
// Default to torso for center mass
return "torso";
}
/**
* Update statistics for monitoring
*/
private updateStats(
region: AudioBodyRegion,
intensity: ImpactIntensity,
vitalPoint: boolean = false
): void {
this.stats = {
totalImpactsPlayed: this.stats.totalImpactsPlayed + 1,
impactsByRegion: {
...this.stats.impactsByRegion,
[region]: this.stats.impactsByRegion[region] + 1,
},
impactsByIntensity: {
...this.stats.impactsByIntensity,
[intensity]: this.stats.impactsByIntensity[intensity] + 1,
},
fracturesTriggered:
this.stats.fracturesTriggered + (intensity === "fracture" ? 1 : 0),
vitalPointStrikes:
this.stats.vitalPointStrikes + (vitalPoint ? 1 : 0),
lastImpactTime: Date.now(),
};
}
/**
* Play Korean-English bilingual audio cue
* (Future feature - placeholder for now)
*
* @param cueId - Audio cue ID (e.g., "bone_fracture")
*/
private async playBilingualCue(_cueId: string): Promise<void> {
// TODO: Implement Korean-English audio cues
// Example: "뼈 골절 | Bone Fracture"
// This would require voice line assets
}
/**
* Get current statistics
*
* @returns Current statistics object
*/
getStats(): Readonly<BoneImpactAudioStats> {
return { ...this.stats };
}
/**
* Reset statistics
*/
resetStats(): void {
this.stats = {
totalImpactsPlayed: 0,
impactsByRegion: {
head: 0,
torso: 0,
arms: 0,
legs: 0,
soft_tissue: 0,
},
impactsByIntensity: {
light: 0,
medium: 0,
heavy: 0,
critical: 0,
fracture: 0,
},
fracturesTriggered: 0,
vitalPointStrikes: 0,
lastImpactTime: 0,
};
}
/**
* Get configuration
*
* @returns Current configuration object
*/
getConfig(): Readonly<Required<BoneImpactAudioConfig>> {
return { ...this.config };
}
}
export default BoneImpactAudioSystem;
|