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 | /**
* Fall Integration Utilities
*
* Helper functions to check for fall conditions and determine fall animations
* based on balance and consciousness systems.
*
* @module systems/combat/FallIntegration
* @category Combat System
* @korean 낙법통합
*/
import type { PlayerState } from "../player";
import type { AnimationState, FallType } from "../animation/types";
import { FALL_TYPE_TO_ANIMATION } from "../animation/types";
import type { CombatSystem } from "../CombatSystem";
/**
* Result of fall check with animation state
* @korean 낙법확인결과
*/
export interface FallCheckResult {
/** Whether a fall should be triggered */
readonly shouldFall: boolean;
/** Fall type if falling */
readonly fallType?: FallType;
/** Animation state to transition to */
readonly animationState?: AnimationState;
/** Reason for fall */
readonly reason?: "balance" | "consciousness";
}
/**
* Checks if player should fall and determines fall animation.
*
* Integrates BalanceSystem and ConsciousnessSystem to check fall conditions.
* Returns animation state to transition to if fall is triggered.
*
* Korean terminology:
* - 균형상실 (Gyunhyeong Sangsil): Balance loss
* - 의식상실 (Uisik Sangsil): Consciousness loss
*
* @param player - Player state to check
* @param combatSystem - Combat system with balance and consciousness systems
* @param lastImpactAngle - Optional angle of last impact (for consciousness falls)
* @param attackAngle - Optional angle of current attack (for balance falls)
* @returns Fall check result with animation state
*
* @example
* ```typescript
* const fallCheck = checkForFall(player, combatSystem, undefined, attackAngle);
* if (fallCheck.shouldFall && fallCheck.animationState) {
* animationMachine.transitionTo(fallCheck.animationState);
* console.log(`Player falling: ${fallCheck.reason}`);
* }
* ```
*
* @public
* @korean 낙법확인
*/
export function checkForFall(
player: PlayerState,
combatSystem: CombatSystem,
lastImpactAngle?: number,
attackAngle?: number
): FallCheckResult {
const balanceSystem = combatSystem.getBalanceSystem();
const consciousnessSystem = combatSystem.getConsciousnessSystem();
// Check consciousness first (higher priority - complete loss of control)
if (consciousnessSystem.shouldTriggerFall(player)) {
const fallType = consciousnessSystem.determineFallType(player, lastImpactAngle);
return {
shouldFall: true,
fallType,
animationState: FALL_TYPE_TO_ANIMATION[fallType],
reason: "consciousness",
};
}
// Check balance (lower priority - still some control)
if (balanceSystem.shouldTriggerFall(player)) {
// Use attack angle if available, otherwise use stance-based fall
const fallType = attackAngle !== undefined
? balanceSystem.determineFallType(player, attackAngle, "mid")
: balanceSystem.determineFallTypeFromStance(player.currentStance);
return {
shouldFall: true,
fallType,
animationState: FALL_TYPE_TO_ANIMATION[fallType],
reason: "balance",
};
}
// No fall condition met
return {
shouldFall: false,
};
}
/**
* Checks if player is currently in a fall or ground animation state.
*
* Used to prevent other actions during falls and ground states.
*
* @param animationState - Current animation state
* @returns True if player is falling or on ground
*
* @public
* @korean 낙법중확인
*/
export function isInFallOrGroundState(animationState: AnimationState): boolean {
return (
animationState === "fall_forward" ||
animationState === "fall_backward" ||
animationState === "fall_side_left" ||
animationState === "fall_side_right" ||
animationState === "ground_prone" ||
animationState === "ground_supine" ||
animationState === "ground_side_left" ||
animationState === "ground_side_right"
);
}
/**
* Gets Korean description for fall type.
*
* @param fallType - Type of fall
* @returns Korean and English names
*
* @public
* @korean 낙법이름
*/
export function getFallTypeName(fallType: FallType): {
korean: string;
english: string;
} {
const names: Record<FallType, { korean: string; english: string }> = {
forward: { korean: "전방낙법", english: "Forward Fall" },
backward: { korean: "후방낙법", english: "Backward Fall" },
side_left: { korean: "좌측낙법", english: "Left Side Fall" },
side_right: { korean: "우측낙법", english: "Right Side Fall" },
};
return names[fallType];
}
|