This commit is contained in:
cay 2026-04-10 12:34:43 +01:00
parent a3d4dc9ce8
commit f3d0b8dc90

View File

@ -110,29 +110,26 @@ router.post("/cards/combine", requireLogin, async (req, res) => {
});
}
/* ── 8. Ausgabe-Karte bestimmen ── */
/* ── 8. Gleiche Karte mit Rarity+1 suchen ── */
const targetRarity = parseInt(inputCard.rarity) + 1;
const maxRarity = getMaxRarity(playerLevel);
const outputRarity = Math.min(targetRarity, maxRarity);
// Karte mit outputRarity suchen (nicht dieselbe Karte)
const [pool] = await db.query(
"SELECT id, name, image, rarity, attack, defends, cooldown FROM cards WHERE rarity = ? AND id != ?",
[outputRarity, card_id]
);
// Fallback: gleiche Rarity falls keine höhere vorhanden
const [fallbackPool] = await db.query(
"SELECT id, name, image, rarity, attack, defends, cooldown FROM cards WHERE rarity = ?",
[parseInt(inputCard.rarity)]
);
const finalPool = pool.length ? pool : fallbackPool;
if (!finalPool.length) {
return res.status(500).json({ error: "Keine passende Karte gefunden." });
if (targetRarity > maxRarity) {
return res.status(400).json({
error: `Dein Spielerlevel erlaubt keine Karten über Rarity ${maxRarity}.`,
});
}
const reward = finalPool[Math.floor(Math.random() * finalPool.length)];
const [[reward]] = await db.query(
"SELECT id, name, image, rarity, attack, defends, cooldown FROM cards WHERE name = ? AND rarity = ?",
[inputCard.name, targetRarity]
);
if (!reward) {
return res.status(400).json({
error: `Keine höhere Version von "${inputCard.name}" (Rarity ${targetRarity}) in der Datenbank gefunden.`,
});
}
/* ── 9. Belohnungskarte gutschreiben ── */
await db.query(