@zerospacegg/iolin
Version:
Pure TypeScript implementation of ZeroSpace game data processing (PKL-free)
234 lines • 10.2 kB
JavaScript
/**
* Emperor Calculator - Legion Ritual Sacrifice Optimization System
* Calculates optimal unit sacrifices for maximizing Emperor Projection power
*
* The Emperor ritual is Legion's ultimate ability - sacrifice thralls to summon
* a powerful Emperor Projection with scaling stats based on sacrificed supply.
*/
import { all } from "../meta/all.js";
// Helper function to find entities by slug
function bySlug(slug) {
return all.find((entity) => entity.slug === slug);
}
/**
* Emperor Calculator Class - Handles all sacrifice optimization logic
*/
export class EmperorCalculator {
/**
* Get unit data from the entity system
*/
static getUnitData() {
const thrall = bySlug("thrall");
const steelsworn = bySlug("steelsworn");
const darkDisciple = bySlug("dark-disciple");
const emperor = bySlug("emperor-projection");
if (!thrall || !steelsworn || !darkDisciple) {
throw new Error("Missing Legion unit data - ensure thrall, steelsworn, and dark-disciple entities exist");
}
return {
thrall: {
supply: thrall.supply || 1,
hexiteCost: thrall.hexiteCost || 50,
fluxCost: thrall.fluxCost || 0,
},
steelsworn: {
supply: steelsworn.supply || 2,
hexiteCost: steelsworn.hexiteCost || 100,
fluxCost: steelsworn.fluxCost || 0,
},
darkDisciple: {
supply: darkDisciple.supply || 3,
hexiteCost: darkDisciple.hexiteCost || 0,
fluxCost: darkDisciple.fluxCost || 75,
},
emperor: {
hp: emperor?.hp || this.EMPEROR_BASE_HP,
damage: emperor?.attacks?.Attack?.damage || this.EMPEROR_BASE_DAMAGE,
},
};
}
/**
* Calculate Emperor ritual results with sacrifice optimization
*/
static calculateSacrifice(input) {
const { thralls, steelsworn, darkDisciples } = input;
const unitData = this.getUnitData();
// Calculate total supply from sacrifices
const totalSupply = thralls * unitData.thrall.supply +
steelsworn * unitData.steelsworn.supply +
darkDisciples * unitData.darkDisciple.supply;
// Cap at maximum sacrifices
const effectiveSupply = Math.min(totalSupply, this.EMPEROR_MAX_SACRIFICES);
const wastedSupply = totalSupply - effectiveSupply;
// Calculate resource costs
const totalHexiteCost = thralls * unitData.thrall.hexiteCost +
steelsworn * unitData.steelsworn.hexiteCost +
darkDisciples * unitData.darkDisciple.hexiteCost;
const totalFluxCost = thralls * unitData.thrall.fluxCost +
steelsworn * unitData.steelsworn.fluxCost +
darkDisciples * unitData.darkDisciple.fluxCost;
const totalResourceCost = totalHexiteCost + totalFluxCost;
// Calculate Emperor final stats
const finalHp = this.EMPEROR_BASE_HP + effectiveSupply * this.HP_BONUS_PER_SUPPLY;
const finalDamage = this.EMPEROR_BASE_DAMAGE + effectiveSupply * this.DAMAGE_BONUS_PER_SUPPLY;
const finalDps = Math.floor((finalDamage / this.EMPEROR_COOLDOWN) * 100) / 100;
// Calculate efficiency metrics
const hpGained = finalHp - this.EMPEROR_BASE_HP;
const damageGained = finalDamage - this.EMPEROR_BASE_DAMAGE;
const costPerHp = hpGained > 0 ? Math.floor((totalResourceCost / hpGained) * 100) / 100 : "infinite";
const costPerDamage = damageGained > 0 ? Math.floor((totalResourceCost / damageGained) * 100) / 100 : "infinite";
// Calculate sacrifice ratios
const thrallSupplyContribution = thralls * unitData.thrall.supply;
const steelswornSupplyContribution = steelsworn * unitData.steelsworn.supply;
const darkDiscipleSupplyContribution = darkDisciples * unitData.darkDisciple.supply;
const thrallPercent = effectiveSupply > 0 ? Math.floor((thrallSupplyContribution / effectiveSupply) * 100) : 0;
const steelswornPercent = effectiveSupply > 0 ? Math.floor((steelswornSupplyContribution / effectiveSupply) * 100) : 0;
const darkDisciplePercent = effectiveSupply > 0 ? Math.floor((darkDiscipleSupplyContribution / effectiveSupply) * 100) : 0;
// Generate recommendations
const isOptimal = effectiveSupply === this.EMPEROR_MAX_SACRIFICES && wastedSupply === 0;
const canSacrificeMore = effectiveSupply < this.EMPEROR_MAX_SACRIFICES;
const isWasteful = wastedSupply > 0;
return {
input: { thralls, steelsworn, darkDisciples },
sacrifice: {
totalUnits: thralls + steelsworn + darkDisciples,
totalSupplyCalculated: totalSupply,
effectiveSupplyUsed: effectiveSupply,
wastedSupply,
maxEfficiency: effectiveSupply === this.EMPEROR_MAX_SACRIFICES,
},
costs: {
hexite: totalHexiteCost,
flux: totalFluxCost,
totalValue: totalResourceCost,
},
emperor: {
baseStats: {
hp: this.EMPEROR_BASE_HP,
damage: this.EMPEROR_BASE_DAMAGE,
},
finalStats: {
hp: finalHp,
damage: finalDamage,
armor: this.EMPEROR_ARMOR,
armorType: "medium",
range: this.EMPEROR_RANGE,
cooldown: this.EMPEROR_COOLDOWN,
dps: finalDps,
},
bonuses: {
hpGained,
damageGained,
},
},
efficiency: {
resourcesPerHp: costPerHp,
resourcesPerDamage: costPerDamage,
powerLevel: Math.floor((effectiveSupply / this.EMPEROR_MAX_SACRIFICES) * 100),
sacrificeRatio: {
thrallPercent,
steelswornPercent,
darkDisciplePercent,
},
},
recommendations: {
isOptimal,
canSacrificeMore,
isWasteful,
optimalMix: "15 Thralls (15 supply) + 7 Steelsworn (14 supply) + 1 Dark Disciple (3 supply) = 30 supply maximum",
economicalMix: "30 Thralls (30 supply) - lowest total resource cost at 1500 hexite + 0 flux",
fluxEfficientMix: "Any combination without Dark Disciples to preserve flux for other Legion abilities",
},
};
}
/**
* Generate optimal sacrifice combinations for different strategies
*/
static generateOptimalCombinations() {
const strategies = [
{
strategy: "Maximum Power",
combination: { thralls: 15, steelsworn: 7, darkDisciples: 1 }, // Exactly 30 supply
},
{
strategy: "Economical",
combination: { thralls: 30, steelsworn: 0, darkDisciples: 0 }, // Cheapest at 30 supply
},
{
strategy: "Flux Efficient",
combination: { thralls: 15, steelsworn: 15, darkDisciples: 0 }, // No flux cost
},
{
strategy: "Balanced",
combination: { thralls: 10, steelsworn: 10, darkDisciples: 0 }, // Moderate cost, 30 supply
},
{
strategy: "Elite Heavy",
combination: { thralls: 0, steelsworn: 15, darkDisciples: 0 }, // Only elite units
},
];
return strategies.map(({ strategy, combination }) => ({
strategy,
combination,
result: this.calculateSacrifice(combination),
}));
}
/**
* Calculate metadata for the Emperor calculation system
*/
static getCalculationMetadata() {
return {
timestamp: new Date().toISOString(),
version: "1.0-emperor-sacrifice-calculator-typescript",
inputUnits: { thralls: 0, steelsworn: 0, darkDisciples: 0 },
gameBalance: {
maxSacrifices: this.EMPEROR_MAX_SACRIFICES,
hpPerSupply: this.HP_BONUS_PER_SUPPLY,
damagePerSupply: this.DAMAGE_BONUS_PER_SUPPLY,
emperorTier: "T4 Ultimate",
},
features: {
sacrificeCalculation: true,
costAnalysis: true,
efficiencyMetrics: true,
recommendations: true,
powerScaling: true,
},
success: true,
};
}
}
// Game balance constants
EmperorCalculator.EMPEROR_MAX_SACRIFICES = 30;
EmperorCalculator.HP_BONUS_PER_SUPPLY = 50;
EmperorCalculator.DAMAGE_BONUS_PER_SUPPLY = 5;
// Emperor base stats
EmperorCalculator.EMPEROR_BASE_HP = 400;
EmperorCalculator.EMPEROR_BASE_DAMAGE = 100;
EmperorCalculator.EMPEROR_ARMOR = 2;
EmperorCalculator.EMPEROR_RANGE = 300;
EmperorCalculator.EMPEROR_COOLDOWN = 1.4;
// Export default calculation function for easy use
export function calculateEmperorSacrifice(thralls = 10, steelsworn = 5, darkDisciples = 3) {
const result = EmperorCalculator.calculateSacrifice({ thralls, steelsworn, darkDisciples });
const metadata = EmperorCalculator.getCalculationMetadata();
metadata.inputUnits = { thralls, steelsworn, darkDisciples };
return { result, metadata };
}
// Export for JSON output configuration
export const output = {
files: {
"api/emperor-calculator.json": {
renderer: { indent: " " },
value: {
// Default calculation example
example: calculateEmperorSacrifice(),
// Optimal combinations showcase
strategies: EmperorCalculator.generateOptimalCombinations(),
// System metadata
metadata: EmperorCalculator.getCalculationMetadata(),
},
},
},
};
//# sourceMappingURL=emperor-calculator.js.map