chlutk
This commit is contained in:
parent
bd9b96d70e
commit
c149ec785c
@ -52,45 +52,55 @@ async function loadAiDeck(station, playerLevel) {
|
|||||||
: station <= 6 ? 3
|
: station <= 6 ? 3
|
||||||
: 4;
|
: 4;
|
||||||
|
|
||||||
// KI darf maximal 1 Rarity über dem Spieler liegen
|
|
||||||
const playerMaxRarity = getMaxRarity(playerLevel || 1);
|
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
|
const deckSize = station === 1 ? 5
|
||||||
: station === 2 ? 7
|
: station === 2 ? 7
|
||||||
: station === 3 ? 9
|
: station === 3 ? 9
|
||||||
: station === 4 ? 11
|
: station === 4 ? 11
|
||||||
: station === 5 ? 12
|
: station === 5 ? 12
|
||||||
: station === 6 ? 14
|
: station === 6 ? 14
|
||||||
: 15;
|
: 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 {
|
try {
|
||||||
// Zuerst passende Karten mit korrekter Rarity holen
|
// Basis-Karten laden (Rarity ≤ baseRarity)
|
||||||
const [cards] = await db.query(
|
const [baseCards] = await db.query(
|
||||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||||
FROM cards
|
FROM cards WHERE rarity <= ? ORDER BY RAND() LIMIT ?`,
|
||||||
WHERE rarity <= ?
|
[baseRarity, baseCount]
|
||||||
ORDER BY RAND()
|
|
||||||
LIMIT ?`,
|
|
||||||
[maxRarity, deckSize]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wenn nicht genug Karten → Rarity schrittweise erhöhen
|
// Bonus-Karte für Station 7 (exakt Rarity = bonusRarity)
|
||||||
let result = [...cards];
|
let bonusCards = [];
|
||||||
|
if (bonusCount > 0) {
|
||||||
if (result.length < deckSize) {
|
const [bonus] = await db.query(
|
||||||
for (let r = maxRarity + 1; r <= 6 && result.length < deckSize; r++) {
|
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||||
const [more] = await db.query(
|
FROM cards WHERE rarity = ? ORDER BY RAND() LIMIT ?`,
|
||||||
|
[bonusRarity, bonusCount]
|
||||||
|
);
|
||||||
|
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
|
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||||
FROM cards WHERE rarity = ? ORDER BY RAND() LIMIT ?`,
|
FROM cards WHERE rarity <= ? ORDER BY RAND() LIMIT ?`,
|
||||||
[r, deckSize - result.length]
|
[bonusRarity, bonusCount]
|
||||||
);
|
);
|
||||||
result = [...result, ...more];
|
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) {
|
if (result.length === 0) {
|
||||||
const [all] = await db.query(
|
const [all] = await db.query(
|
||||||
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
`SELECT id, name, image, attack, defends, cooldown, \`range\`, \`race\`, rarity
|
||||||
@ -100,16 +110,16 @@ async function loadAiDeck(station, playerLevel) {
|
|||||||
result = all;
|
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) {
|
if (result.length > 0 && result.length < deckSize) {
|
||||||
const base = [...result];
|
const base = [...result];
|
||||||
while (result.length < deckSize) {
|
while (result.length < deckSize) {
|
||||||
result.push({ ...base[result.length % base.length] });
|
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 }));
|
return result.map(c => ({ ...c, currentCd: 0 }));
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user