Applies balance effects to player state.
Modifies player stats based on current balance level.
Current player state
Modified player state with balance effects
Applies balance recovery over time.
Balance recovers quickly when not being disrupted, allowing fighters to regain stable footing between exchanges.
Recovery is affected by:
Current player state
Time elapsed in milliseconds
Updated player state with recovered balance
Apply stamina cost for recovery animation.
Deducts stamina cost from player state for recovery animations that require stamina (like roll recovery).
Current player state
Type of recovery animation
Updated player state with stamina deducted
Calculate balance modifier based on body part damage.
Leg damage significantly reduces balance. The leg-specific modifier scales linearly from 0.7x at 0% leg health to 1.0x at 100% leg health:
Torso damage also affects balance but to a lesser degree, and the combined leg/torso modifier is clamped so the final balance modifier stays within the range 0.5x to 1.0x.
Current player state with body part health
Balance modifier (0.5 to 1.0)
Check if player can execute recovery based on stamina.
Some recovery animations (like roll recovery) require stamina. This checks if player has sufficient stamina for the recovery type.
Current player state
Type of recovery animation
True if player has enough stamina
// Roll recovery costs 20 stamina
const canRoll = balanceSystem.canRecoverWithType(player, "roll_recovery");
// Returns: true if player.stamina >= 20
// Normal recoveries have no cost
const canStand = balanceSystem.canRecoverWithType(player, "prone_standup");
// Returns: true (no stamina requirement)
Determines which fall animation to play based on attack and stance.
Calculates fall direction using:
Korean falling techniques (낙법):
Angle of attack in radians (0 = from front)
Attack height: 'high', 'mid', or 'low'
Fall type to use for animation
// Player facing forward (0°), attacked from behind (π)
const fallType = balanceSystem.determineFallType(
player,
Math.PI,
'mid'
);
// Returns: 'forward' (pushed forward by rear attack)
// Low sweep from right side
const fallType = balanceSystem.determineFallType(
player,
Math.PI/2,
'low'
);
// Returns: 'side_right' (swept to the side)
Determines fall type based on player stance when no attack direction available.
Uses stance bias to determine likely fall direction when balance is lost without a specific attack (e.g., from fatigue, leg damage accumulation).
Current trigram stance
Fall type based on stance characteristics
Disrupts balance from combat impact.
Calculates balance loss based on damage amount and body region hit. Leg strikes cause maximum balance disruption.
Now also considers:
Current player state
Impact force amount
Optionalregion: BodyRegionBody region affected
OptionalcurrentTime: numberCurrent game time for penalty checks (optional)
Updated player state with reduced balance
Determines balance level from balance value.
Balance value (0-100)
Current balance level
Gets effects for a specific balance level.
Balance level
Effects applied at that level
Get ground state from animation state.
Extracts the ground position type from animation state name. Returns null if not in a ground state.
Current animation state from AnimationStateMachine
Ground state or null if not grounded
Calculate knockback resistance based on current stance.
Different stances provide varying levels of knockback resistance:
Current trigram stance
Knockback resistance multiplier (0.7 to 1.5)
Gets color indicator for balance level (for UI).
Balance level
Hex color code
Gets bilingual name for balance level.
Balance level
Korean and English level names
Get damage multiplier during recovery animation.
Some recovery animations (like defensive getup) provide damage reduction. This returns the multiplier to apply to incoming damage.
Type of recovery animation
Current frame in the animation
Damage multiplier (1.0 = normal, 0.5 = 50% reduction)
// Defensive getup has 50% damage reduction
const multiplier = balanceSystem.getRecoveryDamageMultiplier("defensive_getup", 20);
// Returns: 0.5 (50% damage reduction)
// Normal recoveries have no reduction
const normal = balanceSystem.getRecoveryDamageMultiplier("prone_standup", 15);
// Returns: 1.0 (full damage)
Get total vulnerability multiplier considering all factors.
Combines:
Current player state
Combined vulnerability multiplier
Calculates damage multiplier for vulnerable balance state.
Current player state
Damage multiplier (1.0 = normal, >1.0 = increased damage)
Check if player is in a grounded state based on animation state.
Player is considered grounded when in any ground_* animation state (ground_prone, ground_supine, ground_side_left, ground_side_right).
Current animation state from AnimationStateMachine
True if player is on the ground
Check if rapid stance change penalty is active.
Penalty applies when player changes stances >2 times in 3 seconds.
Lasts for 2 seconds after the last rapid change.
The penalty increases balance loss by 20% in disruptBalance().
Current player state
Current game time in milliseconds
True if penalty is active
Checks if player is vulnerable due to balance.
Current player state
True if off-balance or falling
Checks if knockdown should occur, using a provided random function for determinism.
Current player state
Optional random number generator (returns number in [0,1)), defaults to Math.random
True if knockdown should occur
Checks if balance is low enough to trigger fall animation.
Falls occur when balance drops below 20% (FALLING state). This creates realistic knockdown conditions from balance loss.
Current player state
True if fall animation should trigger
Start a stance transition, creating vulnerability window.
When a player changes stance, they become vulnerable for 0.5s with a 1.5x damage multiplier. This creates tactical depth around stance changes.
Current player state
Target stance to transition to
Current game time in milliseconds
Updated player state with transition tracking
Update stance transition state based on time elapsed.
Transitions last 0.5s. After that, vulnerability window closes. Called each frame to manage transition timing.
Current player state
Current game time in milliseconds
Updated player state
Private ReadonlybalanceBalance level effects and thresholds.
Private ReadonlybaseBase balance recovery rate per second.
Private ReadonlymaxMaximum balance value.
Private ReadonlyrapidPrivate ReadonlyrapidPrivate ReadonlyrapidPrivate ReadonlyrapidRapid stance change penalty constants.
Private ReadonlyregionBalance disruption multipliers by body region.
Private ReadonlystancePrivate ReadonlytransitionStance transition constants.
Private Readonlytransition
Balance System managing stability and vulnerability.
Balance represents physical stability and center of gravity control. Low balance creates vulnerability windows where opponents can capitalize with increased damage and reduced defensive options.
Example
Korean
균형시스템