mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
|
|
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 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);
|
|
},
|
|
};
|
|
}
|