Verbessere die Behandlung von Charaktereigenschaften beim Versenden von Geschenken: Füge eine Überprüfung hinzu, um sicherzustellen, dass characterTraits ein Array ist, und behandle fehlende Traits als neutralen Wert.
This commit is contained in:
@@ -3258,12 +3258,14 @@ class FalukantService extends BaseService {
|
|||||||
if (user.money < cost) {
|
if (user.money < cost) {
|
||||||
throw new PreconditionError('insufficientFunds');
|
throw new PreconditionError('insufficientFunds');
|
||||||
}
|
}
|
||||||
const traits = gift.characterTraits;
|
const traits = Array.isArray(gift.characterTraits) ? gift.characterTraits : [];
|
||||||
|
// Wenn keine passenden characterTraits gefunden wurden, behandeln wir das als neutralen Wert (0)
|
||||||
|
// statt einen Fehler zu werfen. Das erlaubt das Versenden, auch wenn keine Trait-Übereinstimmung vorliegt.
|
||||||
if (!traits.length) {
|
if (!traits.length) {
|
||||||
throw new Error('noTraits');
|
console.warn(`sendGift: no matching characterTraits for user id=${user.id} giftId=${giftId}`);
|
||||||
}
|
}
|
||||||
// Finde den höchsten Charakterwert (wie im Frontend)
|
// Finde den höchsten Charakterwert (wie im Frontend). Falls keine Traits vorhanden, 0.
|
||||||
const highestCharacterValue = Math.max(...traits.map(ct => ct.suitability));
|
const highestCharacterValue = traits.length ? Math.max(...traits.map(ct => ct.suitability)) : 0;
|
||||||
const moodRecord = gift.promotionalgiftmoods[0];
|
const moodRecord = gift.promotionalgiftmoods[0];
|
||||||
if (!moodRecord) {
|
if (!moodRecord) {
|
||||||
throw new Error('noMoodData');
|
throw new Error('noMoodData');
|
||||||
|
|||||||
Reference in New Issue
Block a user