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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | 348x 16x 5x 5x 6x 4x 4x 191x 4x 4x 4x 4x 189x 189x 189x 189x 1512x 1512x 1512x 293x 293x 189x 1524x 190x 1334x 1334x 1334x 1334x 1334x 1334x 11x 11x 11x 11x 11x 1334x 39x 7x 7x 7x 7x 3x 3x 3x 1x 2x 2x | import { KoreanText, TrigramStance } from "../types/common";
import { PlayerState } from "./player";
import { TRIGRAM_STANCES_ORDER, TrigramTransitionCost } from "./trigram";
import { TrigramCalculator } from "./trigram/TrigramCalculator";
import { PLAYER_ARCHETYPES_DATA } from "./types";
/**
* System for managing Eight Trigram (팔괘) stance transitions and combat calculations.
*
* **Korean**: 팔괘 시스템 (Eight Trigram System)
*
* The TrigramSystem implements the core mechanics of the Eight Trigram martial arts system,
* managing stance transitions, calculating effectiveness, and determining resource costs.
* Based on I Ching (易經) philosophy adapted for tactical combat.
*
* ## Key Responsibilities
*
* - Validate stance transitions based on Ki and Stamina costs
* - Calculate transition difficulty between stances
* - Recommend optimal stance choices
* - Determine stance effectiveness in combat matchups
* - Apply archetype-specific modifiers to transitions
*
* @example
* ```typescript
* const trigramSystem = new TrigramSystem();
*
* // Check if transition is possible
* const canTransition = trigramSystem.canTransitionTo(
* TrigramStance.GEON,
* TrigramStance.GAM,
* playerState
* );
*
* // Get recommended stance
* const recommendedStance = trigramSystem.recommendStance(playerState);
* ```
*
* @public
* @category Trigram System
* @korean 팔괘시스템
*/
export class TrigramSystem {
private calculator: TrigramCalculator;
/**
* Creates a new TrigramSystem instance.
*
* Initializes the internal calculator for stance effectiveness and transition difficulty.
*/
constructor() {
this.calculator = new TrigramCalculator();
}
/**
* Gets the defensive/offensive characteristic of a stance.
*
* **Korean**: 자세 특성 조회 (Stance Characteristic Query)
*
* Returns whether a stance is primarily defensive, offensive, or balanced.
* This information is useful for UI display and tactical decision-making.
*
* ## Stance Classifications
*
* - **Defensive**: 간 (GAN/Mountain), 곤 (GON/Earth) - Protect vital areas
* - **Offensive**: 건 (GEON/Heaven), 진 (JIN/Thunder) - Expose for power
* - **Balanced**: 태 (TAE/Lake), 리 (LI/Fire), 손 (SON/Wind), 감 (GAM/Water)
*
* @param stance - Trigram stance to query
* @returns "defensive", "offensive", or "balanced"
*
* @example
* ```typescript
* const characteristic = trigramSystem.getStanceCharacteristic(TrigramStance.GAN);
* console.log(characteristic); // "defensive"
*
* const offensive = trigramSystem.getStanceCharacteristic(TrigramStance.GEON);
* console.log(offensive); // "offensive"
* ```
*
* @public
* @korean 자세특성조회
*/
getStanceCharacteristic(
stance: TrigramStance
): "defensive" | "offensive" | "balanced" {
switch (stance) {
case TrigramStance.GAN: // Mountain - Immovable defense
case TrigramStance.GON: // Earth - Grounding and stability
return "defensive";
case TrigramStance.GEON: // Heaven - Direct force and aggression
case TrigramStance.JIN: // Thunder - Explosive power
return "offensive";
default:
return "balanced";
}
}
/**
* Checks if a stance provides defensive advantages.
*
* **Korean**: 방어 자세 확인 (Check Defensive Stance)
*
* @param stance - Trigram stance to check
* @returns true if stance is defensive, false otherwise
*
* @example
* ```typescript
* if (trigramSystem.isDefensiveStance(player.currentStance)) {
* console.log("Player is in defensive posture");
* }
* ```
*
* @public
* @korean 방어자세확인
*/
isDefensiveStance(stance: TrigramStance): boolean {
return this.getStanceCharacteristic(stance) === "defensive";
}
/**
* Checks if a stance provides offensive advantages.
*
* **Korean**: 공격 자세 확인 (Check Offensive Stance)
*
* @param stance - Trigram stance to check
* @returns true if stance is offensive, false otherwise
*
* @example
* ```typescript
* if (trigramSystem.isOffensiveStance(player.currentStance)) {
* console.log("Player is in offensive posture");
* }
* ```
*
* @public
* @korean 공격자세확인
*/
isOffensiveStance(stance: TrigramStance): boolean {
return this.getStanceCharacteristic(stance) === "offensive";
}
/**
* Checks if a player can transition from one stance to another.
*
* Validates that the player has sufficient Ki (氣) and Stamina resources
* to perform the stance transition. Same-stance transitions are always valid.
*
* @param fromStance - Current stance
* @param toStance - Target stance
* @param player - Player state with current Ki and Stamina
* @returns true if transition is possible, false otherwise
*
* @example
* ```typescript
* const canChange = trigramSystem.canTransitionTo(
* TrigramStance.GEON, // From Heaven
* TrigramStance.GON, // To Earth
* player
* );
* ```
*
* @public
* @korean 자세전환가능확인
*/
canTransitionTo(
fromStance: TrigramStance,
toStance: TrigramStance,
player: PlayerState
): boolean {
if (fromStance === toStance) return true;
const cost = this.getTransitionCost(fromStance, toStance, player);
// Check if player has sufficient resources
const hasEnoughKi = player.ki >= cost.ki;
const hasEnoughStamina = player.stamina >= cost.stamina;
return hasEnoughKi && hasEnoughStamina;
}
/**
* Recommends the optimal stance for current combat situation.
*
* Calculates the least-cost stance transition from the player's current position.
* Uses combined cost of Ki, Stamina, and transition time to determine best option.
*
* **Algorithm**: Evaluates all eight stances and selects the one with minimum
* total cost (Ki + Stamina + Time).
*
* @param player - Player state with current stance
* @returns Recommended stance to transition to
*
* @example
* ```typescript
* const recommended = trigramSystem.recommendStance(player);
* console.log(`Consider switching to ${recommended}`);
* ```
*
* @public
* @korean 최적자세추천
*/
recommendStance(player: PlayerState): TrigramStance {
const from = player.currentStance;
let best = from;
let bestScore = Infinity;
for (const to of TRIGRAM_STANCES_ORDER) {
const costObj: TrigramTransitionCost = this.getTransitionCost(from, to);
const score = costObj.ki + costObj.stamina + costObj.timeMilliseconds;
if (score < bestScore) {
bestScore = score;
best = to;
}
}
return best;
}
/**
* Calculates the resource cost for transitioning between stances.
*
* Determines Ki, Stamina, and time costs based on the I Ching philosophical
* distance between trigrams. Applies archetype-specific modifiers for favored stances.
*
* ## Cost Calculation
*
* - **Base Cost**: 10 Ki, 15 Stamina per difficulty point
* - **Base Time**: 500ms per difficulty point
* - **Archetype Modifier**: 0.8x for favored stances, 1.0x otherwise
* - **Same Stance**: Zero cost
*
* @param from - Starting stance
* @param to - Target stance
* @param player - Optional player for archetype modifiers
* @returns Transition cost breakdown
*
* @example
* ```typescript
* const cost = trigramSystem.getTransitionCost(
* TrigramStance.GEON,
* TrigramStance.TAE,
* player
* );
* console.log(`Cost: ${cost.ki} Ki, ${cost.stamina} Stamina`);
* ```
*
* @public
* @korean 자세전환비용
*/
public getTransitionCost(
from: TrigramStance,
to: TrigramStance,
player?: PlayerState
): TrigramTransitionCost {
if (from === to) {
return {
ki: 0,
stamina: 0,
timeMilliseconds: 0, // neutral
};
}
const difficulty = TrigramCalculator.calculateTransitionDifficulty(
from,
to
);
const baseCost = 10;
const baseTime = 500;
let ki = Math.ceil(baseCost * difficulty);
let stamina = Math.ceil(baseCost * difficulty * 1.5);
// apply archetype stance‐change cost modifier if player provided
if (player) {
const archData = PLAYER_ARCHETYPES_DATA[player.archetype];
const favs = archData.favoredStances || [];
const mod = favs.includes(to) ? 0.8 : 1.0;
ki = Math.ceil(ki * mod);
stamina = Math.ceil(stamina * mod);
}
return {
ki,
stamina,
timeMilliseconds: Math.ceil(baseTime * difficulty),
};
}
/**
* Calculates stance effectiveness in combat matchup.
*
* Determines the multiplier advantage/disadvantage when one stance attacks another.
* Based on I Ching elemental relationships (e.g., Water extinguishes Fire).
*
* @param attackerStance - Attacking player's stance
* @param defenderStance - Defending player's stance
* @returns Effectiveness multiplier (0.5 = disadvantage, 1.0 = neutral, 1.5 = advantage)
*
* @example
* ```typescript
* const effectiveness = trigramSystem.calculateStanceEffectiveness(
* TrigramStance.GAM, // Water
* TrigramStance.LI // Fire
* ); // Returns > 1.0 (Water beats Fire)
* ```
*
* @public
* @korean 자세효과성계산
*/
calculateStanceEffectiveness(
attackerStance: TrigramStance,
defenderStance: TrigramStance
): number {
return this.calculator.calculateStanceEffectiveness(
attackerStance,
defenderStance
);
}
/**
* Gets bilingual name for a stance.
*
* Returns Korean (Hangul) and English names for display purposes.
*
* @param stance - Stance to get name for
* @returns Object with korean and english name properties
*
* @example
* ```typescript
* const name = trigramSystem.getStanceName(TrigramStance.GEON);
* console.log(`${name.korean} (${name.english})`); // "건 (Heaven)"
* ```
*
* @public
* @korean 자세이름조회
*/
getStanceName(stance: TrigramStance): { korean: string; english: string } {
const stanceNames = {
[TrigramStance.GEON]: { korean: "건", english: "Heaven" },
[TrigramStance.TAE]: { korean: "태", english: "Lake" },
[TrigramStance.LI]: { korean: "리", english: "Fire" },
[TrigramStance.JIN]: { korean: "진", english: "Thunder" },
[TrigramStance.SON]: { korean: "손", english: "Wind" },
[TrigramStance.GAM]: { korean: "감", english: "Water" },
[TrigramStance.GAN]: { korean: "간", english: "Mountain" },
[TrigramStance.GON]: { korean: "곤", english: "Earth" },
};
return stanceNames[stance] || { korean: "Unknown", english: "Unknown" };
}
/**
* Gets complete stance data for UI display.
*
* Returns structured data object containing stance ID and bilingual names.
*
* @param stance - Stance to get data for
* @returns Stance data object
*
* @public
* @korean 자세데이터조회
*/
getCurrentStanceData(stance: TrigramStance): {
id: TrigramStance;
name: KoreanText;
korean: string;
english: string;
} {
const stanceName = this.getStanceName(stance);
return {
id: stance,
name: stanceName,
korean: stanceName.korean,
english: stanceName.english,
};
}
/**
* Validates a stance transition with detailed feedback.
*
* Checks if transition is valid and provides reason if not.
* More detailed than {@link canTransitionTo}, includes specific failure reasons.
*
* @param fromStance - Current stance
* @param toStance - Target stance
* @param player - Player state
* @returns Validation result with optional failure reason
*
* @example
* ```typescript
* const validation = trigramSystem.validateTransition(
* TrigramStance.GEON,
* TrigramStance.GON,
* player
* );
* if (!validation.valid) {
* console.error(validation.reason);
* }
* ```
*
* @public
* @korean 자세전환검증
*/
validateTransition(
fromStance: TrigramStance,
toStance: TrigramStance,
player: PlayerState
): { valid: boolean; reason?: string } {
Iif (fromStance === toStance) {
return { valid: true };
}
const cost = this.getTransitionCost(fromStance, toStance, player);
if (player.ki < cost.ki) {
return {
valid: false,
reason: `Insufficient Ki: need ${cost.ki}, have ${player.ki}`,
};
}
Iif (player.stamina < cost.stamina) {
return {
valid: false,
reason: `Insufficient Stamina: need ${cost.stamina}, have ${player.stamina}`,
};
}
return { valid: true };
}
}
export default TrigramSystem;
|