chlutk
This commit is contained in:
parent
bd9b96d70e
commit
c149ec785c
@ -52,11 +52,9 @@ async function loadAiDeck(station, playerLevel) {
|
||||
: station <= 6 ? 3
|
||||
: 4;
|
||||
|
||||
// KI darf maximal 1 Rarity über dem Spieler liegen
|
||||
const playerMaxRarity = getMaxRarity(playerLevel || 1);
|
||||
const maxRarity = Math.min(stationRarity, playerMaxRarity + 1);
|
||||
|
||||
// Kartenanzahl nach Station (3–15)
|
||||
// Kartenanzahl nach Station (5–15)
|
||||
const deckSize = station === 1 ? 5
|
||||
: station === 2 ? 7
|
||||
: station === 3 ? 9
|
||||
@ -65,32 +63,44 @@ async function loadAiDeck(station, playerLevel) {
|
||||
: station === 6 ? 14
|
||||
: 15;
|
||||
|
||||
// Stationen 1–6: alle Karten ≤ playerMaxRarity
|
||||
// Station 7: 14 Karten ≤ playerMaxRarity + 1 starke Karte (exakt playerMaxRarity+1)
|
||||
const baseRarity = Math.min(stationRarity, playerMaxRarity);
|
||||
const bonusRarity = Math.min(playerMaxRarity + 1, 6);
|
||||
const bonusCount = station >= 7 ? 1 : 0; // nur Station 7 bekommt 1 stärkere Karte
|
||||
const baseCount = deckSize - bonusCount;
|
||||
|
||||
try {
|
||||
// Zuerst passende Karten mit korrekter Rarity holen
|
||||
const [cards] = await db.query(
|
||||
// Basis-Karten laden (Rarity ≤ baseRarity)
|
||||
const [baseCards] = await db.query(
|
||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||
FROM cards
|
||||
WHERE rarity <= ?
|
||||
ORDER BY RAND()
|
||||
LIMIT ?`,
|
||||
[maxRarity, deckSize]
|
||||
FROM cards WHERE rarity <= ? ORDER BY RAND() LIMIT ?`,
|
||||
[baseRarity, baseCount]
|
||||
);
|
||||
|
||||
// Wenn nicht genug Karten → Rarity schrittweise erhöhen
|
||||
let result = [...cards];
|
||||
|
||||
if (result.length < deckSize) {
|
||||
for (let r = maxRarity + 1; r <= 6 && result.length < deckSize; r++) {
|
||||
const [more] = await db.query(
|
||||
// Bonus-Karte für Station 7 (exakt Rarity = bonusRarity)
|
||||
let bonusCards = [];
|
||||
if (bonusCount > 0) {
|
||||
const [bonus] = await db.query(
|
||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||
FROM cards WHERE rarity = ? ORDER BY RAND() LIMIT ?`,
|
||||
[r, deckSize - result.length]
|
||||
[bonusRarity, bonusCount]
|
||||
);
|
||||
result = [...result, ...more];
|
||||
bonusCards = bonus;
|
||||
// Fallback: falls keine Karte dieser Rarity vorhanden
|
||||
if (bonusCards.length === 0) {
|
||||
const [fallback] = await db.query(
|
||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||
FROM cards WHERE rarity <= ? ORDER BY RAND() LIMIT ?`,
|
||||
[bonusRarity, bonusCount]
|
||||
);
|
||||
bonusCards = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
// Letzter Fallback: alle Karten ohne Rarity-Filter
|
||||
let result = [...baseCards, ...bonusCards];
|
||||
|
||||
// Fallback: alle Karten ohne Filter wenn zu wenig
|
||||
if (result.length === 0) {
|
||||
const [all] = await db.query(
|
||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||
@ -100,16 +110,16 @@ async function loadAiDeck(station, playerLevel) {
|
||||
result = all;
|
||||
}
|
||||
|
||||
// Noch immer zu wenig? → vorhandene Karten so oft wiederholen bis deckSize erreicht
|
||||
// Zu wenig Karten → vorhandene wiederholen bis deckSize erreicht
|
||||
if (result.length > 0 && result.length < deckSize) {
|
||||
const base = [...result];
|
||||
while (result.length < deckSize) {
|
||||
result.push({ ...base[result.length % base.length] });
|
||||
}
|
||||
console.log(`[HT] KI-Deck aufgefüllt durch Wiederholung: ${base.length} unique → ${result.length} Karten`);
|
||||
console.log(`[HT] KI-Deck aufgefüllt: ${base.length} unique → ${result.length} Karten`);
|
||||
}
|
||||
|
||||
console.log(`[HT] KI-Deck Station ${station}: ${result.length} Karten, max. Rarity ${maxRarity}`);
|
||||
console.log(`[HT] KI-Deck Station ${station}: ${result.length} Karten (${baseCount}x ≤ Rarity ${baseRarity}${bonusCount ? `, 1x Rarity ${bonusRarity}` : ''})`);
|
||||
return result.map(c => ({ ...c, currentCd: 0 }));
|
||||
|
||||
} catch (err) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user