Black Trigram (흑괘) - Korean Martial Arts Combat Simulator API - v0.6.52
    Preparing search index...

    Class BalanceSystem

    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.

    const balanceSystem = new BalanceSystem();

    // Apply balance disruption from leg strike
    const newPlayer = balanceSystem.disruptBalance(
    player,
    15,
    BodyRegion.LEFT_LEG
    );

    // Check if vulnerable
    const isVulnerable = balanceSystem.isVulnerable(newPlayer);

    // Apply recovery
    const recovered = balanceSystem.applyRecovery(newPlayer, 1000);

    균형시스템

    Index

    Constructors

    Methods

    • Applies balance recovery over time.

      Balance recovers quickly when not being disrupted, allowing fighters to regain stable footing between exchanges.

      Recovery is affected by:

      • Balance level (harder to recover when off-balance)
      • Stamina (low stamina = slow recovery)
      • Body part damage (leg damage reduces recovery rate)

      Parameters

      • player: BalancePlayerState

        Current player state

      • deltaTime: number

        Time elapsed in milliseconds

      Returns BalancePlayerState

      Updated player state with recovered balance

      // In game loop
      player = system.applyRecovery(player, 16); // ~60fps

      균형회복

    • Apply stamina cost for recovery animation.

      Deducts stamina cost from player state for recovery animations that require stamina (like roll recovery).

      Parameters

      • player: PlayerState

        Current player state

      • recoveryType: RecoveryAnimationType

        Type of recovery animation

      Returns PlayerState

      Updated player state with stamina deducted

      // Roll recovery costs 20 stamina
      const recovered = balanceSystem.applyRecoveryCost(player, "roll_recovery");
      // recovered.stamina = player.stamina - 20

      회복비용적용

    • 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:

      • 100% leg health: 1.0x balance (no reduction from legs)
      • 70% leg health: ≈0.91x balance (≈9% reduction from legs)
      • 30% leg health: ≈0.79x balance (≈21% reduction from legs)
      • 0% leg health: 0.7x balance (30% reduction from legs)

      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.

      Parameters

      Returns number

      Balance modifier (0.5 to 1.0)

      const modifier = balanceSystem.calculateBalanceModifier(player);
      const effectiveBalance = player.balance * modifier;

      균형조정계수계산

    • 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.

      Parameters

      • player: PlayerState

        Current player state

      • recoveryType: RecoveryAnimationType

        Type of recovery animation

      Returns boolean

      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:

      • Attack angle relative to player
      • Attack height (high/mid/low)
      • Player's current stance bias

      Korean falling techniques (낙법):

      • 전방낙법 (Jeonbang Nakbeop): Forward fall
      • 후방낙법 (Hubang Nakbeop): Backward fall
      • 측방낙법 (Cheukbang Nakbeop): Side fall

      Parameters

      • _player: PlayerState
      • attackAngle: number

        Angle of attack in radians (0 = from front)

      • attackHeight: "low" | "high" | "mid" = "mid"

        Attack height: 'high', 'mid', or 'low'

      Returns FallType

      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).

      Parameters

      Returns FallType

      Fall type based on stance characteristics

      // Player in Heaven stance (aggressive forward)
      const fallType = balanceSystem.determineFallTypeFromStance(
      TrigramStance.GEON
      );
      // Returns: 'forward' (Heaven stance has forward bias)

      자세낙법결정

    • 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:

      • Body part damage modifier (damaged legs reduce balance more)
      • Rapid stance change penalty (20% additional reduction)

      Parameters

      • player: BalancePlayerState

        Current player state

      • impact: number

        Impact force amount

      • Optionalregion: BodyRegion

        Body region affected

      • OptionalcurrentTime: number

        Current game time for penalty checks (optional)

      Returns BalancePlayerState

      Updated player state with reduced balance

      // Leg sweep causes major balance disruption
      player = system.disruptBalance(
      player,
      20,
      BodyRegion.RIGHT_LEG,
      Date.now()
      );

      균형파괴

    • Get ground state from animation state.

      Extracts the ground position type from animation state name. Returns null if not in a ground state.

      Parameters

      • animationState: string

        Current animation state from AnimationStateMachine

      Returns GroundState | null

      Ground state or null if not grounded

      const state = balanceSystem.getGroundState("ground_prone");
      // Returns: "prone"

      const none = balanceSystem.getGroundState("idle");
      // Returns: null

      지면자세가져오기

    • Calculate knockback resistance based on current stance.

      Different stances provide varying levels of knockback resistance:

      • Defensive stances (Mountain, Earth): +50% resistance
      • Balanced stances (Water, Wind): normal resistance
      • Offensive stances (Heaven, Fire, Thunder): -30% resistance
      • Fluid stance (Lake): normal resistance

      Parameters

      Returns number

      Knockback resistance multiplier (0.7 to 1.5)

      const resistance = balanceSystem.getKnockbackResistance(TrigramStance.GAN);
      const effectiveKnockback = baseKnockback * (1.0 / resistance);

      넉백저항계산

    • Get damage multiplier during recovery animation.

      Some recovery animations (like defensive getup) provide damage reduction. This returns the multiplier to apply to incoming damage.

      Parameters

      • recoveryType: RecoveryAnimationType

        Type of recovery animation

      • currentFrame: number

        Current frame in the animation

      Returns number

      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:

      • Base balance state vulnerability (1.0 to 2.0)
      • Stance transition vulnerability (1.5x during 0.5s window)

      Parameters

      Returns number

      Combined vulnerability multiplier

      const multiplier = balanceSystem.getTotalVulnerabilityMultiplier(player);
      const finalDamage = baseDamage * multiplier;

      총취약성배율

    • Calculates damage multiplier for vulnerable balance state.

      Parameters

      Returns number

      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).

      Parameters

      • animationState: string

        Current animation state from AnimationStateMachine

      Returns boolean

      True if player is on the ground

      const isGrounded = balanceSystem.isGrounded("ground_prone");
      // Returns: true

      const notGrounded = balanceSystem.isGrounded("idle");
      // Returns: false

      지면상태확인

    • 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().

      Parameters

      • player: BalancePlayerState

        Current player state

      • currentTime: number

        Current game time in milliseconds

      Returns boolean

      True if penalty is active

      // The penalty is applied automatically in disruptBalance()
      if (balanceSystem.isRapidChangePenaltyActive(player, Date.now())) {
      // Penalty active: balance loss will be increased by 20%
      cy.log("Rapid change penalty active");
      }

      급속변경벌칙확인

    • Checks if knockdown should occur, using a provided random function for determinism.

      Parameters

      • player: PlayerState

        Current player state

      • randomFn: () => number = Math.random

        Optional random number generator (returns number in [0,1)), defaults to Math.random

      Returns boolean

      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.

      Parameters

      Returns boolean

      True if fall animation should trigger

      if (balanceSystem.shouldTriggerFall(player)) {
      const fallType = balanceSystem.determineFallType(
      player,
      attackAngle,
      attackHeight
      );
      animationMachine.transitionTo(FALL_TYPE_TO_ANIMATION[fallType]);
      }

      낙법발동확인

    • 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.

      Parameters

      • player: BalancePlayerState

        Current player state

      • newStance: TrigramStance

        Target stance to transition to

      • currentTime: number

        Current game time in milliseconds

      Returns BalancePlayerState

      Updated player state with transition tracking

      // Player switches from Heaven to Water stance
      const transitioning = balanceSystem.startStanceTransition(
      player,
      TrigramStance.GAM,
      Date.now()
      );
      // transitioning.transitionState.isTransitioning = true
      // transitioning.transitionState.vulnerabilityMultiplier = 1.5

      자세전환시작

    • Update stance transition state based on time elapsed.

      Transitions last 0.5s. After that, vulnerability window closes. Called each frame to manage transition timing.

      Parameters

      • player: BalancePlayerState

        Current player state

      • currentTime: number

        Current game time in milliseconds

      Returns BalancePlayerState

      Updated player state

      // In game loop
      player = balanceSystem.updateTransition(player, Date.now());

      전환상태갱신

    Properties

    balanceEffects: Record<BalanceLevel, BalanceEffects> = ...

    Balance level effects and thresholds.

    baseRecoveryRate: 8 = 8.0

    Base balance recovery rate per second.

    maxBalance: 100

    Maximum balance value.

    rapidChangePenalty: 0.2
    rapidChangePenaltyDuration: 2000
    rapidChangeThreshold: 2
    rapidChangeWindow: 3000

    Rapid stance change penalty constants.

    regionMultipliers: Record<string, number> = ...

    Balance disruption multipliers by body region.

    stanceChangeHistoryLimit: 5
    transitionDuration: 500

    Stance transition constants.

    transitionVulnerabilityMultiplier: 1.5