All files / blacktrigram/src/systems/trigram KoreanTechniques.ts

76.66% Statements 69/90
75% Branches 6/8
50% Functions 4/8
76.66% Lines 69/90

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  1x   1x   1x         1x       1x                 1x               1x                           1x                       1x   12x 12x   1x 6x 6x 6x     6x 6x   6x 48x 6x 6x   1x 2x 2x 2x 1x     1x 10x 10x   10x 10x 10x 10x     1x     1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { PlayerArchetype, TrigramStance } from "../../types";
import { TrigramStance as TrigramStanceEnum } from "../../types/common";
import { PlayerState } from "../player";
import { PLAYER_ARCHETYPES_DATA } from "../types";
import { KoreanTechnique } from "../vitalpoint";
import { TRIGRAM_TECHNIQUES } from "./techniques";
 
/**
 * Korean martial arts techniques system
 */
export class KoreanTechniquesSystem {
  /**
   * Get available techniques for a trigram stance
   */
  static getAvailableTechniques(
    stance: TrigramStance
  ): readonly KoreanTechnique[] {
    return (TRIGRAM_TECHNIQUES[stance] as readonly KoreanTechnique[]) || [];
  }
 
  /**
   * Get primary technique for stance
   */
  static getPrimaryTechnique(stance: TrigramStance): KoreanTechnique | null {
    const techniques = this.getAvailableTechniques(stance);
    return techniques[0] || null;
  }
 
  /**
   * Check if player can execute technique
   */
  static canExecuteTechnique(
    player: PlayerState,
    technique: KoreanTechnique
  ): boolean {
    return (
      player.ki >= technique.kiCost &&
      player.stamina >= technique.staminaCost &&
      player.currentStance === technique.stance
    );
  }
 
  /**
   * Get technique effectiveness against target stance
   */
  static getTechniqueEffectiveness(
    attackerStance: TrigramStance,
    defenderStance: TrigramStance
  ): number {
    return (
      TECHNIQUE_EFFECTIVENESS_MATRIX[attackerStance]?.[defenderStance] || 1.0
    );
  }
 
  /**
   * Get all techniques
   */
  static getAllTechniques(): KoreanTechnique[] {
    // Fix: Convert readonly array to mutable array using spread operator
    return [...Object.values(TRIGRAM_TECHNIQUES).flat()] as KoreanTechnique[];
  }
 
  static getTechniquesByArchetype(
    archetype: PlayerArchetype
  ): readonly KoreanTechnique[] {
    const allTechniques = this.getAllTechniques();
 
    // Filter techniques based on archetype preferences
    const archetypeData = PLAYER_ARCHETYPES_DATA[archetype]; // Fix: Now properly imported
    const favoredStances = archetypeData.favoredStances || [];
 
    return allTechniques.filter((technique) =>
      favoredStances.includes(technique.stance)
    );
  }
 
  static getTechniqueById(id: string): KoreanTechnique | undefined {
    const allTechniques = this.getAllTechniques();
    return allTechniques.find((technique) => technique.id === id);
  }
}
 
// Export functions for backwards compatibility
export function getTechniquesByStance(
  stance: TrigramStance
): KoreanTechnique[] {
  // Fix: Convert readonly array to mutable array
  return [
    ...((TRIGRAM_TECHNIQUES[stance] as unknown as KoreanTechnique[]) || []),
  ];
}
 
// Export TRIGRAM_TECHNIQUES for tests
export { TRIGRAM_TECHNIQUES } from "./techniques";
 
// Export technique effectiveness matrix
export const TECHNIQUE_EFFECTIVENESS_MATRIX: Record<
  TrigramStance,
  Partial<Record<TrigramStance, number>>
> = {
  [TrigramStanceEnum.GEON]: {
    [TrigramStanceEnum.GON]: 1.2,
    [TrigramStanceEnum.SON]: 0.8,
  },
  [TrigramStanceEnum.TAE]: {
    [TrigramStanceEnum.JIN]: 1.2,
    [TrigramStanceEnum.GAN]: 0.8,
  },
  [TrigramStanceEnum.LI]: {
    [TrigramStanceEnum.GAM]: 1.2,
    [TrigramStanceEnum.TAE]: 0.8,
  },
  [TrigramStanceEnum.JIN]: {
    [TrigramStanceEnum.SON]: 1.2,
    [TrigramStanceEnum.GEON]: 0.8,
  },
  [TrigramStanceEnum.SON]: {
    [TrigramStanceEnum.GON]: 1.2,
    [TrigramStanceEnum.LI]: 0.8,
  },
  [TrigramStanceEnum.GAM]: {
    [TrigramStanceEnum.LI]: 1.2,
    [TrigramStanceEnum.JIN]: 0.8,
  },
  [TrigramStanceEnum.GAN]: {
    [TrigramStanceEnum.TAE]: 1.2,
    [TrigramStanceEnum.GAM]: 0.8,
  },
  [TrigramStanceEnum.GON]: {
    [TrigramStanceEnum.GEON]: 1.2,
    [TrigramStanceEnum.SON]: 0.8,
  },
};