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 | 1x 1x 8x 1x 1x | /**
* CombatScreen3D Helper Utilities
*
* Extracted helper functions and constants from CombatScreen3D
* for better code organization and maintainability.
*
* @module components/combat/helpers/combatHelpers
* @category Combat Utilities
* @korean 전투화면도우미
*/
import { PlayerState } from "../../../systems";
import { TrigramStance } from "../../../types";
import { TRIGRAM_STANCES_ORDER } from "../../../systems/trigram/types";
/**
* Map of trigram stances to their array indices for fast lookups
*/
export const STANCE_INDEX_MAP = new Map<TrigramStance, number>();
TRIGRAM_STANCES_ORDER.forEach((stance, index) => {
STANCE_INDEX_MAP.set(stance, index);
});
/**
* Round announcement fade-out delay (in milliseconds)
* Wait for previous announcement to fully fade out before showing next one
*/
export const ANNOUNCEMENT_FADE_OUT_DELAY = 300;
/**
* Calculate accuracy percentage for a player
* Uses hits / (hits + misses) when miss tracking is available
* Falls back to 100% if hits exist but no miss tracking, or 0% if no combat activity
*
* @param player - Player state with combat statistics
* @returns Accuracy percentage (0-100)
*
* @example
* ```typescript
* const accuracy = calculateAccuracy(playerState);
* console.log(`Accuracy: ${accuracy}%`);
* ```
*/
export const calculateAccuracy = (player: PlayerState): number => {
const hits = player.hitsLanded ?? 0;
const misses = player.misses ?? 0;
const totalAttempts = hits + misses;
// If we have miss tracking, use proper accuracy formula
if (totalAttempts > 0) {
return (hits / totalAttempts) * 100;
}
// Fallback: if no miss tracking and hits exist, show 100%
// Otherwise 0% (no combat activity)
return hits > 0 ? 100 : 0;
};
|