generated from nhcarrigan/template
fix: return authoritative materials from craft API to prevent client desync
Closes #128
This commit is contained in:
@@ -148,11 +148,22 @@ craftRouter.post("/", async(context) => {
|
|||||||
|
|
||||||
const bonusType = recipe.bonus.type;
|
const bonusType = recipe.bonus.type;
|
||||||
const bonusValue = recipe.bonus.value;
|
const bonusValue = recipe.bonus.value;
|
||||||
|
const { materials } = state.exploration;
|
||||||
|
const {
|
||||||
|
craftedGoldMultiplier,
|
||||||
|
craftedEssenceMultiplier,
|
||||||
|
craftedClickMultiplier,
|
||||||
|
craftedCombatMultiplier,
|
||||||
|
} = updatedMultipliers;
|
||||||
const response: CraftRecipeResponse = {
|
const response: CraftRecipeResponse = {
|
||||||
bonusType,
|
bonusType,
|
||||||
bonusValue,
|
bonusValue,
|
||||||
|
craftedClickMultiplier,
|
||||||
|
craftedCombatMultiplier,
|
||||||
|
craftedEssenceMultiplier,
|
||||||
|
craftedGoldMultiplier,
|
||||||
|
materials,
|
||||||
recipeId,
|
recipeId,
|
||||||
...updatedMultipliers,
|
|
||||||
};
|
};
|
||||||
return context.json(response);
|
return context.json(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1864,14 +1864,6 @@ export const GameProvider = ({
|
|||||||
if (previous?.exploration === undefined) {
|
if (previous?.exploration === undefined) {
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
let materials = [ ...previous.exploration.materials ];
|
|
||||||
for (const request of recipe.requiredMaterials) {
|
|
||||||
materials = materials.map((mat) => {
|
|
||||||
return mat.materialId === request.materialId
|
|
||||||
? { ...mat, quantity: mat.quantity - request.quantity }
|
|
||||||
: mat;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...previous,
|
...previous,
|
||||||
exploration: {
|
exploration: {
|
||||||
@@ -1884,7 +1876,7 @@ export const GameProvider = ({
|
|||||||
...previous.exploration.craftedRecipeIds,
|
...previous.exploration.craftedRecipeIds,
|
||||||
recipeId,
|
recipeId,
|
||||||
],
|
],
|
||||||
materials: materials,
|
materials: result.materials,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ interface CraftRecipeResponse {
|
|||||||
craftedEssenceMultiplier: number;
|
craftedEssenceMultiplier: number;
|
||||||
craftedClickMultiplier: number;
|
craftedClickMultiplier: number;
|
||||||
craftedCombatMultiplier: number;
|
craftedCombatMultiplier: number;
|
||||||
|
materials: Array<{ materialId: string; quantity: number }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ForceUnlocksResponse {
|
interface ForceUnlocksResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user