42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import {
|
|
upgradeMaxLevel,
|
|
upgradePercentPerLevel,
|
|
type GameConfig,
|
|
type ShipModel,
|
|
type Upgrade,
|
|
} from "@deadhead/content";
|
|
|
|
/** Installed upgrade levels by upgrade id; a missing upgrade is level 0. */
|
|
export type UpgradeLevels = Readonly<Record<string, number>>;
|
|
|
|
/**
|
|
* A ship's stats after upgrades (decision 0.5.63): its model with the four
|
|
* upgradable model stats adjusted, plus its own handling time per tonne.
|
|
*/
|
|
export interface EffectiveStats extends ShipModel {
|
|
handlingGameHoursPerTonne: number;
|
|
}
|
|
|
|
/**
|
|
* Applies installed upgrades to a model's base stats: each level adds the
|
|
* upgrade's percent (after model overrides) of the base stat, linearly.
|
|
* Levels above the model's max for an upgrade are clamped.
|
|
*/
|
|
export function effectiveStats(
|
|
model: ShipModel,
|
|
levels: UpgradeLevels,
|
|
content: { upgrades: readonly Upgrade[]; config: GameConfig },
|
|
): EffectiveStats {
|
|
const stats: EffectiveStats = {
|
|
...model,
|
|
handlingGameHoursPerTonne: content.config.handlingGameHoursPerTonne,
|
|
};
|
|
for (const upgrade of content.upgrades) {
|
|
const level = Math.min(levels[upgrade.id] ?? 0, upgradeMaxLevel(upgrade, model.id));
|
|
if (level <= 0) continue;
|
|
const base = stats[upgrade.stat];
|
|
stats[upgrade.stat] = base * (1 + (upgradePercentPerLevel(upgrade, model.id) * level) / 100);
|
|
}
|
|
return stats;
|
|
}
|