refactor: cleanup codebase — remove hydration guards, extract constants, fix bugs
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m20s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m20s
This commit is contained in:
@@ -3,26 +3,21 @@
|
||||
|
||||
import type { EquipmentInstance, PreparationProgress } from './types';
|
||||
import { calculatePrepTime, calculatePrepManaCost, calculateManaPerHourForPrep } from './crafting-utils';
|
||||
import { HOURS_PER_TICK } from './constants';
|
||||
|
||||
// ─── Preparation Validation ─────────────────────────────────────────────────
|
||||
|
||||
// Check if an equipment instance can be prepared
|
||||
export function canPrepareEquipment(
|
||||
instance: EquipmentInstance | undefined,
|
||||
currentTags: string[]
|
||||
): { canPrepare: boolean; reason?: string } {
|
||||
if (!instance) {
|
||||
return { canPrepare: false, reason: 'Equipment instance not found' };
|
||||
}
|
||||
|
||||
if (currentTags.includes('Ready for Enchantment')) {
|
||||
return { canPrepare: false, reason: 'Equipment is already prepared for enchanting' };
|
||||
}
|
||||
|
||||
if (!instance) return { canPrepare: false, reason: 'Equipment instance not found' };
|
||||
if (currentTags.includes('Ready for Enchantment')) return { canPrepare: false, reason: 'Equipment is already prepared for enchanting' };
|
||||
return { canPrepare: true };
|
||||
}
|
||||
|
||||
// Calculate preparation resource costs
|
||||
// ─── Preparation Costs ──────────────────────────────────────────────────────
|
||||
|
||||
export interface PreparationCosts {
|
||||
time: number;
|
||||
manaTotal: number;
|
||||
@@ -34,30 +29,20 @@ export function calculatePreparationCosts(totalCapacity: number): PreparationCos
|
||||
const time = calculatePrepTime(totalCapacity);
|
||||
const manaTotal = calculatePrepManaCost(totalCapacity);
|
||||
const manaPerHour = calculateManaPerHourForPrep(totalCapacity, time);
|
||||
const manaPerTick = manaPerHour * 0.04; // HOURS_PER_TICK
|
||||
|
||||
return { time, manaTotal, manaPerHour, manaPerTick };
|
||||
return { time, manaTotal, manaPerHour, manaPerTick: manaPerHour * HOURS_PER_TICK };
|
||||
}
|
||||
|
||||
// ─── Preparation Progress ───────────────────────────────────────────────────
|
||||
|
||||
// Initialize preparation progress
|
||||
export function initializePreparationProgress(
|
||||
equipmentInstanceId: string,
|
||||
totalCapacity: number,
|
||||
manaCostPaid: number = 0
|
||||
): PreparationProgress {
|
||||
const costs = calculatePreparationCosts(totalCapacity);
|
||||
|
||||
return {
|
||||
equipmentInstanceId,
|
||||
progress: 0,
|
||||
required: costs.time,
|
||||
manaCostPaid,
|
||||
};
|
||||
return { equipmentInstanceId, progress: 0, required: costs.time, manaCostPaid };
|
||||
}
|
||||
|
||||
// Calculate updated preparation progress after a tick
|
||||
// ─── Preparation Tick ───────────────────────────────────────────────────────
|
||||
|
||||
export interface PreparationTickResult {
|
||||
progress: number;
|
||||
manaCostPaid: number;
|
||||
@@ -68,15 +53,14 @@ export interface PreparationTickResult {
|
||||
export function calculatePreparationTick(
|
||||
currentProgress: number,
|
||||
required: number,
|
||||
currentManaCostPaid: number,
|
||||
manaPerTick: number
|
||||
): PreparationTickResult {
|
||||
const progress = currentProgress + 0.04; // HOURS_PER_TICK
|
||||
const progress = currentProgress + HOURS_PER_TICK;
|
||||
const manaConsumed = manaPerTick;
|
||||
const manaCostPaid = manaPerTick; // Accumulated
|
||||
|
||||
return {
|
||||
progress,
|
||||
manaCostPaid,
|
||||
manaCostPaid: currentManaCostPaid + manaConsumed,
|
||||
manaConsumed,
|
||||
isComplete: progress >= required,
|
||||
};
|
||||
@@ -84,51 +68,40 @@ export function calculatePreparationTick(
|
||||
|
||||
// ─── Preparation Completion ─────────────────────────────────────────────────
|
||||
|
||||
// Apply preparation completion to equipment instance
|
||||
const BASE_DISENCHANT_RECOVERY_RATE = 0.1;
|
||||
const DISENCHANT_RECOVERY_PER_LEVEL = 0.2;
|
||||
|
||||
export function completePreparation(
|
||||
instance: EquipmentInstance,
|
||||
_manaSpent: number
|
||||
): {
|
||||
updatedInstance: EquipmentInstance;
|
||||
manaRecovered: number;
|
||||
logMessage: string;
|
||||
} {
|
||||
// Calculate mana recovery from disenchanting (disenchanting skill removed - Bug 13)
|
||||
const disenchantLevel = 0;
|
||||
const recoveryRate = 0.1 + disenchantLevel * 0.2; // 10% base + 20% per level
|
||||
|
||||
disenchantLevel: number = 0
|
||||
): { updatedInstance: EquipmentInstance; manaRecovered: number; logMessage: string } {
|
||||
const recoveryRate = BASE_DISENCHANT_RECOVERY_RATE + disenchantLevel * DISENCHANT_RECOVERY_PER_LEVEL;
|
||||
let totalRecovered = 0;
|
||||
for (const ench of instance.enchantments) {
|
||||
totalRecovered += Math.floor(ench.actualCost * recoveryRate);
|
||||
}
|
||||
|
||||
const updatedInstance: EquipmentInstance = {
|
||||
...instance,
|
||||
enchantments: [],
|
||||
usedCapacity: 0,
|
||||
rarity: 'common',
|
||||
tags: [...(instance.tags || []), 'Ready for Enchantment'],
|
||||
};
|
||||
|
||||
return {
|
||||
updatedInstance,
|
||||
updatedInstance: {
|
||||
...instance,
|
||||
enchantments: [],
|
||||
usedCapacity: 0,
|
||||
rarity: 'common',
|
||||
tags: [...(instance.tags || []), 'Ready for Enchantment'],
|
||||
},
|
||||
manaRecovered: totalRecovered,
|
||||
logMessage: `✅ Equipment prepared for enchanting! Recovered ${totalRecovered} mana.`,
|
||||
};
|
||||
}
|
||||
|
||||
// Cancel preparation (no resource recovery for preparation itself)
|
||||
export function cancelPreparation() {
|
||||
return {
|
||||
logMessage: 'Preparation cancelled.',
|
||||
};
|
||||
return { logMessage: 'Preparation cancelled.' };
|
||||
}
|
||||
|
||||
// ─── Preparation State Calculations ─────────────────────────────────────────
|
||||
|
||||
export function getPreparationManaCostForTick(instance: EquipmentInstance): number {
|
||||
const costs = calculatePreparationCosts(instance.totalCapacity);
|
||||
return costs.manaPerTick;
|
||||
return calculatePreparationCosts(instance.totalCapacity).manaPerTick;
|
||||
}
|
||||
|
||||
export function getPreparationRemainingTime(currentProgress: number, required: number): number {
|
||||
|
||||
Reference in New Issue
Block a user