fsrjnsrt
This commit is contained in:
parent
a3d4dc9ce8
commit
f3d0b8dc90
@ -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 targetRarity = parseInt(inputCard.rarity) + 1;
|
||||||
const maxRarity = getMaxRarity(playerLevel);
|
const maxRarity = getMaxRarity(playerLevel);
|
||||||
const outputRarity = Math.min(targetRarity, maxRarity);
|
|
||||||
|
|
||||||
// Karte mit outputRarity suchen (nicht dieselbe Karte)
|
if (targetRarity > maxRarity) {
|
||||||
const [pool] = await db.query(
|
return res.status(400).json({
|
||||||
"SELECT id, name, image, rarity, attack, defends, cooldown FROM cards WHERE rarity = ? AND id != ?",
|
error: `Dein Spielerlevel erlaubt keine Karten über Rarity ${maxRarity}.`,
|
||||||
[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." });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ── */
|
/* ── 9. Belohnungskarte gutschreiben ── */
|
||||||
await db.query(
|
await db.query(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user