refactor: consolidate duplicate functions (calculateDesignTime, calculateDesignCapacityCost, generateSwarmEnemies)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m21s

This commit is contained in:
2026-05-20 17:46:43 +02:00
parent 742a992d59
commit 53b3a94725
5 changed files with 27 additions and 57 deletions
+16 -3
View File
@@ -1,10 +1,24 @@
// ─── Enemy Naming System ───────────────────────────────────────────────
// ─── Enemy Naming & Swarm Generation ──────────────────────────────────
// Moved from store-modules/enemy-utils.ts to eliminate legacy dependencies
import type { EnemyState } from '../types';
import { SWARM_CONFIG } from '../constants';
import { getFloorMaxHP, getFloorElement } from './floor-utils';
// Barrier elements more likely to have barrier
const BARRIER_ELEMENTS = ['light', 'water', 'earth'];
// Get barrier for an enemy (0-1 as percentage of max HP)
function getEnemyBarrier(floor: number, element: string): number {
if (floor < 20) return 0;
const baseChance = BARRIER_ELEMENTS.includes(element) ? 0.15 : 0.08;
const floorBonus = Math.min(0.25, (floor - 20) * 0.003);
const barrierChance = Math.min(0.4, baseChance + floorBonus);
if (Math.random() > barrierChance) return 0;
const floorProgress = Math.min(1, (floor - 20) / 80);
return 0.1 + floorProgress * 0.2;
}
// Enemy names by element and floor tier
const ENEMY_NAMES_BY_ELEMENT: Record<string, string[]> = {
fire: ['Fire Imp', 'Flame Sprite', 'Emberling', 'Scorchling', 'Inferno Whelp'],
@@ -49,8 +63,7 @@ export function generateSwarmEnemies(floor: number): EnemyState[] {
maxHP: Math.floor(baseHP * SWARM_CONFIG.hpMultiplier),
armor: SWARM_CONFIG.armorBase + Math.floor(floor / 10) * SWARM_CONFIG.armorPerFloor,
dodgeChance: 0,
healthRegen: 0, // Will be set by caller if needed
barrier: 0, // Will be set by caller if needed
barrier: getEnemyBarrier(floor, element),
element,
});
}