mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
|
|
import content from 'common/script/content';
|
|
|
|
const specialPets = Object.keys(content.specialPets);
|
|
|
|
function getText (textOrFunction) {
|
|
if (textOrFunction instanceof Function) {
|
|
return textOrFunction();
|
|
} else {
|
|
return textOrFunction;
|
|
}
|
|
}
|
|
|
|
export function isOwned (type, animal, userItems) {
|
|
return userItems[`${type}s`][animal.key] > 0;
|
|
}
|
|
|
|
export function isHatchable (animal, userItems) {
|
|
return !isOwned('pet', animal, userItems) &&
|
|
userItems.eggs[animal.eggKey] &&
|
|
userItems.hatchingPotions[animal.potionKey];
|
|
}
|
|
|
|
export function isAllowedToFeed (animal, userItems) {
|
|
return !specialPets.includes(animal.key) &&
|
|
isOwned('pet', animal, userItems) &&
|
|
!isOwned('mount', animal, userItems);
|
|
}
|
|
|
|
export function createAnimal (egg, potion, type, _content, userItems) {
|
|
let animalKey = `${egg.key}-${potion.key}`;
|
|
|
|
return {
|
|
key: animalKey,
|
|
class: type === 'pet' ? `Pet Pet-${animalKey}` : `Mount_Icon_${animalKey}`,
|
|
eggKey: egg.key,
|
|
eggName: getText(egg.text),
|
|
potionKey: potion.key,
|
|
potionName: getText(potion.text),
|
|
name: _content[`${type}Info`][animalKey].text(),
|
|
isOwned () {
|
|
return isOwned(type, this, userItems);
|
|
},
|
|
mountOwned () {
|
|
return isOwned('mount', this, userItems);
|
|
},
|
|
isAllowedToFeed () {
|
|
return isAllowedToFeed(this, userItems);
|
|
},
|
|
isHatchable () {
|
|
return isHatchable(this, userItems);
|
|
},
|
|
};
|
|
}
|
|
|