fix: issues #221 #217 #225 #227 #224 #226 - crafting refunds, mana tracking, cancel slot, multi-element guardians, spell kill advance
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m59s

This commit is contained in:
2026-05-31 01:18:01 +02:00
parent e4f4b297e8
commit 6793461a9f
16 changed files with 263 additions and 63 deletions
@@ -3,6 +3,8 @@
import type { CraftingState } from '../stores/craftingStore.types';
import type { GameAction } from '../types';
import * as CraftingApply from '../crafting-apply';
import { useManaStore } from '../stores/manaStore';
import { useUIStore } from '../stores/uiStore';
/**
* Start applying an enchantment design to an equipment instance.
@@ -66,8 +68,25 @@ export function resumeApplication(
}
export function cancelApplication(
get: () => CraftingState,
set: (partial: Partial<CraftingState>) => void
) {
const state = get();
const progress = state.applicationProgress;
if (!progress) return;
// Refund mana proportionally to remaining progress
const remainingFraction = progress.required > 0
? Math.max(0, (progress.required - progress.progress) / progress.required)
: 1;
// Full refund for unspent progress, 50% for spent progress
const refundRate = remainingFraction + (1 - remainingFraction) * 0.5;
const manaRefund = Math.floor(progress.manaSpent * refundRate);
if (manaRefund > 0) {
useManaStore.setState((s) => ({ rawMana: s.rawMana + manaRefund }));
}
useUIStore.getState().addLog(`🚫 Enchantment application cancelled. Refunded ${manaRefund} mana.`);
set({
applicationProgress: null,
});