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
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m59s
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
deductFabricatorMana,
|
||||
deductMaterials,
|
||||
makeFabricatorProgress,
|
||||
refundFabricatorMana,
|
||||
} from '../../crafting-fabricator';
|
||||
import { useManaStore } from '../manaStore';
|
||||
import { useCombatStore } from '../combatStore';
|
||||
@@ -50,33 +51,71 @@ export function startCraftingEquipment(
|
||||
export function cancelEquipmentCrafting(get: GetFn, set: SetFn): void {
|
||||
const progress = get().equipmentCraftingProgress;
|
||||
if (!progress) return;
|
||||
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
|
||||
progress.blueprintId,
|
||||
progress.manaSpent,
|
||||
progress.progress,
|
||||
progress.required,
|
||||
);
|
||||
// Refund materials proportionally to remaining progress
|
||||
const recipe = CraftingEquipment.getRecipe(progress.blueprintId);
|
||||
if (recipe) {
|
||||
const remainingFraction = progress.required > 0
|
||||
? Math.max(0, (progress.required - progress.progress) / progress.required)
|
||||
: 1;
|
||||
const currentMaterials = get().lootInventory.materials;
|
||||
const refundedMaterials = { ...currentMaterials };
|
||||
for (const [matId, amount] of Object.entries(recipe.materials)) {
|
||||
const refundAmount = Math.floor(amount * remainingFraction);
|
||||
if (refundAmount > 0) {
|
||||
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
|
||||
|
||||
const isFabricator = progress.blueprintId.startsWith('fabricator-');
|
||||
|
||||
if (isFabricator) {
|
||||
// Fabricator recipe cancel: refund elemental/raw mana and materials
|
||||
const recipeId = progress.blueprintId.replace('fabricator-', '');
|
||||
const recipe = getFabricatorRecipe(recipeId);
|
||||
if (recipe) {
|
||||
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);
|
||||
|
||||
// Refund the correct mana type
|
||||
const rawMana = useManaStore.getState().rawMana;
|
||||
const elements = useManaStore.getState().elements;
|
||||
const refunded = refundFabricatorMana(recipe, manaRefund, rawMana, elements);
|
||||
useManaStore.setState({ rawMana: refunded.rawMana, elements: refunded.elements });
|
||||
|
||||
// Refund materials
|
||||
const currentMaterials = get().lootInventory.materials;
|
||||
const refundedMaterials = { ...currentMaterials };
|
||||
for (const [matId, amount] of Object.entries(recipe.materials)) {
|
||||
const refundAmount = Math.floor(amount * remainingFraction);
|
||||
if (refundAmount > 0) {
|
||||
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
|
||||
}
|
||||
}
|
||||
set({ equipmentCraftingProgress: null, lootInventory: { ...get().lootInventory, materials: refundedMaterials } });
|
||||
useUIStore.getState().addLog(`🚫 Fabricator crafting cancelled. Refunded ${manaRefund} ${recipe.manaType} mana.`);
|
||||
} else {
|
||||
set({ equipmentCraftingProgress: null });
|
||||
}
|
||||
set({ equipmentCraftingProgress: null, lootInventory: { ...get().lootInventory, materials: refundedMaterials } });
|
||||
} else {
|
||||
set({ equipmentCraftingProgress: null });
|
||||
// Standard equipment crafting cancel
|
||||
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
|
||||
progress.blueprintId,
|
||||
progress.manaSpent,
|
||||
progress.progress,
|
||||
progress.required,
|
||||
);
|
||||
// Refund materials proportionally to remaining progress
|
||||
const recipe = CraftingEquipment.getRecipe(progress.blueprintId);
|
||||
if (recipe) {
|
||||
const remainingFraction = progress.required > 0
|
||||
? Math.max(0, (progress.required - progress.progress) / progress.required)
|
||||
: 1;
|
||||
const currentMaterials = get().lootInventory.materials;
|
||||
const refundedMaterials = { ...currentMaterials };
|
||||
for (const [matId, amount] of Object.entries(recipe.materials)) {
|
||||
const refundAmount = Math.floor(amount * remainingFraction);
|
||||
if (refundAmount > 0) {
|
||||
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
|
||||
}
|
||||
}
|
||||
set({ equipmentCraftingProgress: null, lootInventory: { ...get().lootInventory, materials: refundedMaterials } });
|
||||
} else {
|
||||
set({ equipmentCraftingProgress: null });
|
||||
}
|
||||
useManaStore.setState((s) => ({ rawMana: s.rawMana + cancelResult.manaRefund }));
|
||||
useUIStore.getState().addLog(cancelResult.logMessage);
|
||||
}
|
||||
useManaStore.setState((s) => ({ rawMana: s.rawMana + cancelResult.manaRefund }));
|
||||
useCombatStore.setState({ currentAction: 'meditate' });
|
||||
useUIStore.getState().addLog(cancelResult.logMessage);
|
||||
}
|
||||
|
||||
export function startFabricatorCrafting(recipeId: string, get: GetFn, set: SetFn): boolean {
|
||||
|
||||
Reference in New Issue
Block a user