Fix: pet tests

This commit is contained in:
Xaz16
2019-12-15 22:00:34 +03:00
parent dec0488b08
commit 8b780eaf0d
2 changed files with 7 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ function evolve (user, pet, req) {
...user.items.pets, ...user.items.pets,
[pet.key]: -1, [pet.key]: -1,
}; };
user.items.mounts = { user.items.mounts = {
...user.items.mounts, ...user.items.mounts,
[pet.key]: true, [pet.key]: true,
@@ -52,9 +53,8 @@ export default function feed (user, req = {}) {
throw new NotFound(errorMessage('invalidFoodName', req.language)); throw new NotFound(errorMessage('invalidFoodName', req.language));
} }
const userPets = user.items.pets;
if (!userPets[pet.key]) { if (!user.items.pets[pet.key]) {
throw new NotFound(i18n.t('messagePetNotFound', req.language)); throw new NotFound(i18n.t('messagePetNotFound', req.language));
} }
@@ -81,16 +81,16 @@ export default function feed (user, req = {}) {
}; };
if (food.target === pet.potion || pet.type === 'premium') { if (food.target === pet.potion || pet.type === 'premium') {
userPets[pet.key] += 5; user.items.pets[pet.key] += 5;
message = i18n.t('messageLikesFood', messageParams, req.language); message = i18n.t('messageLikesFood', messageParams, req.language);
} else { } else {
userPets[pet.key] += 2; user.items.pets[pet.key] += 2;
message = i18n.t('messageDontEnjoyFood', messageParams, req.language); message = i18n.t('messageDontEnjoyFood', messageParams, req.language);
} }
if (user.markModified) user.markModified('items.pets'); if (user.markModified) user.markModified('items.pets');
if (userPets[pet.key] >= 50 && !user.items.mounts[pet.key]) { if (user.items.pets[pet.key] >= 50 && !user.items.mounts[pet.key]) {
message = evolve(user, pet, req); message = evolve(user, pet, req);
} }
} }
@@ -116,7 +116,7 @@ export default function feed (user, req = {}) {
}); });
return [ return [
userPets[pet.key], user.items.pets[pet.key],
message, message,
]; ];
} }

View File

@@ -46,7 +46,7 @@ export default function hatch (user, req = {}) {
}; };
user.items.eggs = { user.items.eggs = {
...user.items.eggs, ...user.items.eggs,
[egg]: user.items.eggs - 1, [egg]: Number.isInteger(user.items.eggs) ? user.items.eggs - 1 : 0,
}; };
user.items.hatchingPotions[hatchingPotion] -= 1; user.items.hatchingPotions[hatchingPotion] -= 1;
if (user.markModified) { if (user.markModified) {