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 | 1x 1x 1x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /** * Player state utilities and helper functions */ import { PLAYER_ARCHETYPES_DATA, PlayerState, StatusEffect } from "../systems"; import { PlayerArchetype, Position, TrigramStance } from "../types"; import { CombatState } from "../types/common"; /** * Create a complete PlayerState from archetype and player index */ export function createPlayerFromArchetype( archetype: PlayerArchetype, playerIndex: number ): PlayerState { const archetypeData = PLAYER_ARCHETYPES_DATA[archetype]; const basePosition: Position = { x: playerIndex === 0 ? 300 : 500, y: 400, }; return { id: `player_${playerIndex + 1}`, name: archetypeData.name, archetype, // Combat stats health: archetypeData.baseHealth, maxHealth: archetypeData.baseHealth, ki: archetypeData.baseKi, maxKi: archetypeData.baseKi, stamina: archetypeData.baseStamina, maxStamina: archetypeData.baseStamina, energy: 100, maxEnergy: 100, // Combat attributes attackPower: archetypeData.stats.attackPower, defense: archetypeData.stats.defense, speed: archetypeData.stats.speed, technique: archetypeData.stats.technique, pain: 0, consciousness: 100, balance: 100, momentum: 0, // Combat state currentStance: archetypeData.coreStance, combatState: CombatState.IDLE, position: basePosition, isBlocking: false, isStunned: false, isCountering: false, lastActionTime: 0, recoveryTime: 0, lastStanceChangeTime: 0, // Status and effects statusEffects: [], activeEffects: [], // Vital points state vitalPoints: [], // Match statistics totalDamageReceived: 0, totalDamageDealt: 0, hitsTaken: 0, hitsLanded: 0, perfectStrikes: 0, vitalPointHits: 0, }; } /** * Update player state with partial updates */ export function updatePlayerState( player: PlayerState, updates: Partial<PlayerState> ): PlayerState { return { ...player, ...updates, // Ensure vital constraints health: Math.max( 0, Math.min(updates.health ?? player.health, player.maxHealth) ), ki: Math.max(0, Math.min(updates.ki ?? player.ki, player.maxKi)), stamina: Math.max( 0, Math.min(updates.stamina ?? player.stamina, player.maxStamina) ), consciousness: Math.max( 0, Math.min(updates.consciousness ?? player.consciousness, 100) ), balance: Math.max(0, Math.min(updates.balance ?? player.balance, 100)), }; } /** * Apply damage to player */ export function applyDamage( player: PlayerState, damage: number, _damageType?: string // Fix: Add underscore for unused parameter ): PlayerState { const newHealth = Math.max(0, player.health - damage); const isKnockedOut = newHealth <= 0; return updatePlayerState(player, { health: newHealth, totalDamageReceived: player.totalDamageReceived + damage, hitsTaken: player.hitsTaken + 1, combatState: isKnockedOut ? CombatState.STUNNED : player.combatState, consciousness: isKnockedOut ? 0 : player.consciousness, }); } /** * Apply status effect to player */ export function applyStatusEffect( player: PlayerState, effect: StatusEffect ): PlayerState { const existingEffectIndex = player.statusEffects.findIndex( (e) => e.type === effect.type && !e.stackable ); let newEffects: StatusEffect[]; if (existingEffectIndex >= 0 && !effect.stackable) { // Replace existing non-stackable effect newEffects = [...player.statusEffects]; newEffects[existingEffectIndex] = effect; } else { // Add new effect newEffects = [...player.statusEffects, effect]; } return updatePlayerState(player, { statusEffects: newEffects, activeEffects: [...player.activeEffects, effect.type], }); } /** * Get vital point by ID (fix return type) */ export function getVitalPointByOnPlayerId( player: PlayerState, vitalPointId: string ): { readonly id: string; readonly isHit: boolean; readonly damage: number; readonly lastHitTime: number; } | null { return player.vitalPoints.find((vp) => vp.id === vitalPointId) || null; } /** * Check if player can act */ export function canPlayerAct(player: PlayerState): boolean { if (player.health <= 0) return false; if (player.consciousness <= 0) return false; if (player.combatState === CombatState.STUNNED) return false; if (player.isStunned) return false; return true; } /** * Get player's current stance effectiveness against opponent */ export function getStanceEffectiveness( _playerStance: TrigramStance, // Fix: Add underscore to unused parameter _opponentStance: TrigramStance // Fix: Add underscore to unused parameter ): number { // Basic implementation - could be enhanced with stance matrix return 1.0; } /** * Check if player has enough resources for action */ export function hasEnoughResources( player: PlayerState, kiCost: number, staminaCost: number ): boolean { return player.ki >= kiCost && player.stamina >= staminaCost; } /** * Get player archetype bonuses */ export function getArchetypeBonuses(archetype: PlayerArchetype): { attackBonus: number; defenseBonus: number; speedBonus: number; techniqueBonus: number; } { const data = PLAYER_ARCHETYPES_DATA[archetype]; return { attackBonus: data.stats.attackPower * 0.1, defenseBonus: data.stats.defense * 0.1, speedBonus: data.stats.speed * 0.1, techniqueBonus: data.stats.technique * 0.1, }; } /** * Calculate player's current combat effectiveness */ export function calculateCombatEffectiveness(player: PlayerState): number { const healthFactor = player.health / player.maxHealth; const staminaFactor = player.stamina / player.maxStamina; const consciousnessFactor = player.consciousness / 100; const balanceFactor = player.balance / 100; return ( (healthFactor + staminaFactor + consciousnessFactor + balanceFactor) / 4 ); } /** * Remove expired status effects */ export function updateStatusEffects( player: PlayerState, currentTime: number ): PlayerState { const activeEffects = player.statusEffects.filter( (effect) => effect.endTime > currentTime ); return updatePlayerState(player, { statusEffects: activeEffects, activeEffects: activeEffects.map((e) => e.type), }); } /** * Reset player to starting state */ export function resetPlayerState( archetype: PlayerArchetype, playerIndex: number ): PlayerState { return createPlayerFromArchetype(archetype, playerIndex); } |