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 | 21x 21x 21x 21x 21x 21x 21x 46x 46x 46x 46x 46x 46x 46x 29x 46x 38x 38x 38x 38x 38x 38x 33x 33x 33x 11x 8x 11x 21x 4x 1x 21x 11x 2x 14x 11x 5x 5x 6x | /**
* Effect calculation system for vital point strikes.
*
* **Korean**: 효과 계산 시스템 (Effect Calculation System)
*
* This module provides comprehensive calculations for status effect duration,
* intensity, and application based on vital point strikes, accuracy, severity,
* and archetype-specific modifiers.
*
* ## Key Features
*
* - **Duration Calculation**: Based on severity, accuracy, and archetype
* - **Intensity Scaling**: Scales with hit accuracy (0.5-1.5x)
* - **Archetype Modifiers**: Resistance and vulnerability factors
* - **Critical Hit Enhancement**: 2x duration for accuracy > 0.9
* - **Effect Stacking**: Manages multiple concurrent effects
*
* @module systems/EffectCalculator
* @category Combat Effects
* @korean 효과계산기
*/
import { PlayerArchetype, VitalPointSeverity } from "../types/common";
import { EffectIntensity } from "./effects";
import { StatusEffect } from "./types";
import { VitalPointEffect } from "./vitalpoint/types";
/**
* Severity multipliers for effect duration calculation.
*
* **Korean**: 심각도 배율 (Severity Multipliers)
*/
const SEVERITY_MULTIPLIERS: Record<VitalPointSeverity, number> = {
[VitalPointSeverity.MINOR]: 0.5,
[VitalPointSeverity.MODERATE]: 1.0,
[VitalPointSeverity.MAJOR]: 1.5,
[VitalPointSeverity.CRITICAL]: 2.0,
[VitalPointSeverity.LETHAL]: 3.0,
};
/**
* Critical hit accuracy threshold.
* Strikes with accuracy >= 0.9 are considered critical.
*
* **Korean**: 크리티컬 정확도 기준점
*/
const CRITICAL_HIT_THRESHOLD = 0.9;
/**
* Critical hit duration multiplier.
*
* **Korean**: 크리티컬 타격 지속시간 배율
*/
const CRITICAL_DURATION_MULTIPLIER = 2.0;
/**
* Maximum number of concurrent status effects allowed per player.
*
* **Korean**: 최대 동시 효과 개수
*/
export const MAX_CONCURRENT_EFFECTS = 5;
/**
* Archetype resistance modifiers.
* Positive values = resistance (effects last shorter)
* Negative values = vulnerability (effects last longer)
*
* **Korean**: 원형별 저항력 배율 (Archetype Resistance Modifiers)
*/
const ARCHETYPE_RESISTANCE: Record<PlayerArchetype, number> = {
[PlayerArchetype.MUSA]: 0.2, // +20% resistance (traditional warrior discipline)
[PlayerArchetype.AMSALJA]: -0.1, // -10% resistance (glass cannon)
[PlayerArchetype.HACKER]: 0.0, // Neutral resistance
[PlayerArchetype.JEONGBO_YOWON]: 0.1, // +10% resistance (mental fortitude)
[PlayerArchetype.JOJIK_POKRYEOKBAE]: 0.15, // +15% resistance (street-hardened)
};
/**
* Archetype offensive effect modifiers.
* Applied when archetype deals vital point strike.
*
* **Korean**: 원형별 공격 효과 배율 (Archetype Offensive Modifiers)
*/
const ARCHETYPE_OFFENSIVE: Record<PlayerArchetype, number> = {
[PlayerArchetype.MUSA]: 1.0, // Standard effects
[PlayerArchetype.AMSALJA]: 1.3, // +30% effect potency (assassination mastery)
[PlayerArchetype.HACKER]: 1.15, // +15% effect potency (precision targeting)
[PlayerArchetype.JEONGBO_YOWON]: 1.25, // +25% effect potency (anatomical knowledge)
[PlayerArchetype.JOJIK_POKRYEOKBAE]: 1.2, // +20% effect potency (brutal efficiency)
};
/**
* Default effect duration in milliseconds if not specified.
*
* **Korean**: 기본 효과 지속시간 (Default Effect Duration)
*/
const DEFAULT_EFFECT_DURATION = 2000;
/**
* Calculates the duration of a status effect based on multiple factors.
*
* **Korean**: 효과 지속시간 계산 (Calculate Effect Duration)
*
* Formula:
* ```
* duration = baseDuration * (1 + (accuracy - 0.5) * 0.5) * severityMultiplier * archetypeModifier
* ```
*
* For critical hits (accuracy >= 0.9):
* ```
* duration = duration * 2.0
* ```
*
* @param effect - Vital point effect with base duration
* @param accuracy - Hit accuracy (0-1)
* @param severity - Vital point severity level
* @param attackerArchetype - Attacking player's archetype
* @param defenderArchetype - Defending player's archetype
* @returns Calculated duration in milliseconds
*
* @example
* ```typescript
* const duration = calculateEffectDuration(
* { id: "paralysis", duration: 2000, ... },
* 0.95, // High accuracy
* VitalPointSeverity.MAJOR,
* PlayerArchetype.AMSALJA, // Assassin attacker (+30%)
* PlayerArchetype.MUSA // Warrior defender (+20% resistance)
* );
* // Result: 2000 * 1.225 * 1.5 * 1.3 * 0.8 * 2.0 = ~9,568ms
* ```
*
* @public
* @korean 효과지속시간계산
*/
export function calculateEffectDuration(
effect: VitalPointEffect,
accuracy: number,
severity: VitalPointSeverity,
attackerArchetype: PlayerArchetype,
defenderArchetype: PlayerArchetype
): number {
const baseDuration = effect.duration || DEFAULT_EFFECT_DURATION;
// Accuracy bonus: 0.75x at 0 accuracy, 1.0x at 0.5, 1.25x at 1.0
const accuracyBonus = 1 + (accuracy - 0.5) * 0.5;
// Severity multiplier
const severityMult = SEVERITY_MULTIPLIERS[severity] || 1.0;
// Attacker offensive modifier
const offensiveModifier = ARCHETYPE_OFFENSIVE[attackerArchetype] || 1.0;
// Defender resistance modifier (inverted: resistance reduces duration)
const resistanceModifier =
1 - (ARCHETYPE_RESISTANCE[defenderArchetype] || 0);
// Calculate base duration
let finalDuration =
baseDuration * accuracyBonus * severityMult * offensiveModifier * resistanceModifier;
// Critical hit bonus for high accuracy
if (accuracy >= CRITICAL_HIT_THRESHOLD) {
finalDuration *= CRITICAL_DURATION_MULTIPLIER;
}
return Math.floor(finalDuration);
}
/**
* Calculates the intensity of a status effect based on hit accuracy.
*
* **Korean**: 효과 강도 계산 (Calculate Effect Intensity)
*
* Scales effect intensity from 0.5x (poor accuracy) to 1.5x (perfect accuracy).
*
* @param baseIntensity - Base effect intensity
* @param accuracy - Hit accuracy (0-1)
* @returns Scaled intensity value
*
* @example
* ```typescript
* const intensity = calculateEffectIntensity(
* EffectIntensity.MEDIUM,
* 0.9 // High accuracy
* );
* // Returns scaled intensity for 90% accuracy hit
* ```
*
* @public
* @korean 효과강도계산
*/
export function calculateEffectIntensity(
baseIntensity: EffectIntensity,
accuracy: number
): EffectIntensity {
// Map intensities to numeric scale
const intensityMap: Record<EffectIntensity, number> = {
[EffectIntensity.WEAK]: 1,
[EffectIntensity.MINOR]: 2,
[EffectIntensity.LOW]: 3,
[EffectIntensity.MEDIUM]: 4,
[EffectIntensity.MODERATE]: 5,
[EffectIntensity.HIGH]: 6,
[EffectIntensity.SEVERE]: 7,
[EffectIntensity.CRITICAL]: 8,
[EffectIntensity.EXTREME]: 9,
};
// Reverse map for lookup
const reverseMap: EffectIntensity[] = [
EffectIntensity.WEAK,
EffectIntensity.MINOR,
EffectIntensity.LOW,
EffectIntensity.MEDIUM,
EffectIntensity.MODERATE,
EffectIntensity.HIGH,
EffectIntensity.SEVERE,
EffectIntensity.CRITICAL,
EffectIntensity.EXTREME,
];
const baseLevel = intensityMap[baseIntensity] || 4;
// Accuracy modifier: 0.5x at 0 accuracy, 1.0x at 0.5, 1.5x at 1.0
const accuracyModifier = 0.5 + accuracy;
// Calculate scaled level
const scaledLevel = Math.max(
1,
Math.min(9, Math.round(baseLevel * accuracyModifier))
);
return reverseMap[scaledLevel - 1];
}
/**
* Converts a VitalPointEffect to a StatusEffect with calculated properties.
*
* **Korean**: 급소 효과를 상태 효과로 변환 (Convert Vital Point Effect to Status Effect)
*
* @param effect - Vital point effect to convert
* @param accuracy - Hit accuracy
* @param severity - Vital point severity
* @param attackerArchetype - Attacker's archetype
* @param defenderArchetype - Defender's archetype
* @param vitalPointId - Source vital point ID
* @param timestamp - Current timestamp (for startTime/endTime)
* @returns StatusEffect with calculated duration and intensity
*
* @public
* @korean 상태효과변환
*/
export function convertToStatusEffect(
effect: VitalPointEffect,
accuracy: number,
severity: VitalPointSeverity,
attackerArchetype: PlayerArchetype,
defenderArchetype: PlayerArchetype,
vitalPointId: string,
timestamp: number
): StatusEffect {
const duration = calculateEffectDuration(
effect,
accuracy,
severity,
attackerArchetype,
defenderArchetype
);
const intensity = calculateEffectIntensity(effect.intensity, accuracy);
return {
id: `${effect.id}_${timestamp}`,
type: effect.type,
intensity,
duration,
description: effect.description,
stackable: effect.stackable,
source: vitalPointId,
startTime: timestamp,
endTime: timestamp + duration,
};
}
/**
* Applies effect stacking logic to a list of status effects.
*
* **Korean**: 효과 중첩 관리 (Manage Effect Stacking)
*
* Rules:
* - Non-stackable effects: Keep only the most recent
* - Stackable effects: Allow up to MAX_CONCURRENT_EFFECTS
* - Expired effects: Remove automatically
*
* @param currentEffects - Existing active effects
* @param newEffects - New effects to add
* @param currentTime - Current timestamp
* @returns Updated effect list with stacking applied
*
* @example
* ```typescript
* const updated = applyEffectStacking(
* player.statusEffects,
* newVitalPointEffects,
* Date.now()
* );
* ```
*
* @public
* @korean 효과중첩적용
*/
export function applyEffectStacking(
currentEffects: readonly StatusEffect[],
newEffects: readonly StatusEffect[],
currentTime: number
): StatusEffect[] {
// Remove expired effects
let activeEffects = currentEffects.filter(
(effect) => effect.endTime > currentTime
);
// Process each new effect
for (const newEffect of newEffects) {
if (!newEffect.stackable) {
// Remove existing effects of same type (non-stackable)
activeEffects = activeEffects.filter(
(effect) => effect.type !== newEffect.type
);
}
// Add new effect
activeEffects = [...activeEffects, newEffect];
}
// Limit to MAX_CONCURRENT_EFFECTS (keep most recent)
if (activeEffects.length > MAX_CONCURRENT_EFFECTS) {
activeEffects = activeEffects
.sort((a, b) => b.startTime - a.startTime)
.slice(0, MAX_CONCURRENT_EFFECTS);
}
return activeEffects;
}
/**
* Gets the offensive effect modifier for an archetype.
*
* **Korean**: 원형 공격 배율 조회 (Get Archetype Offensive Modifier)
*
* @param archetype - Player archetype
* @returns Offensive effect multiplier (1.0 - 1.3)
*
* @public
* @korean 원형공격배율조회
*/
export function getArchetypeOffensiveModifier(
archetype: PlayerArchetype
): number {
return ARCHETYPE_OFFENSIVE[archetype] || 1.0;
}
/**
* Gets the defensive resistance modifier for an archetype.
*
* **Korean**: 원형 방어 배율 조회 (Get Archetype Defensive Modifier)
*
* @param archetype - Player archetype
* @returns Resistance modifier (-0.1 to 0.2)
*
* @public
* @korean 원형방어배율조회
*/
export function getArchetypeDefensiveModifier(
archetype: PlayerArchetype
): number {
return ARCHETYPE_RESISTANCE[archetype] || 0;
}
/**
* Checks if a hit qualifies as a critical hit based on accuracy.
*
* **Korean**: 크리티컬 타격 판정 (Check Critical Hit)
*
* @param accuracy - Hit accuracy (0-1)
* @returns True if accuracy >= 0.9 (critical hit)
*
* @public
* @korean 크리티컬판정
*/
export function isCriticalHit(accuracy: number): boolean {
return accuracy >= CRITICAL_HIT_THRESHOLD;
}
|