2017-09-19 20:45:28 +00:00
|
|
|
|
|
|
|
|
function getText (textOrFunction) {
|
|
|
|
|
if (textOrFunction instanceof Function) {
|
|
|
|
|
return textOrFunction();
|
|
|
|
|
} else {
|
|
|
|
|
return textOrFunction;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-08 01:04:46 +00:00
|
|
|
export default 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,
|
2017-09-19 20:45:28 +00:00
|
|
|
eggName: getText(egg.text),
|
2017-08-08 01:04:46 +00:00
|
|
|
potionKey: potion.key,
|
2017-09-19 20:45:28 +00:00
|
|
|
potionName: getText(potion.text),
|
2017-08-08 01:04:46 +00:00
|
|
|
name: content[`${type}Info`][animalKey].text(),
|
|
|
|
|
isOwned () {
|
|
|
|
|
return userItems[`${type}s`][animalKey] > 0;
|
|
|
|
|
},
|
|
|
|
|
mountOwned () {
|
|
|
|
|
return userItems.mounts[this.key] > 0;
|
|
|
|
|
},
|
|
|
|
|
isAllowedToFeed () {
|
|
|
|
|
return type === 'pet' && this.isOwned() && !this.mountOwned();
|
|
|
|
|
},
|
|
|
|
|
isHatchable () {
|
2017-08-16 22:34:25 +00:00
|
|
|
return !this.isOwned() & userItems.eggs[egg.key] > 0 && userItems.hatchingPotions[potion.key] > 0;
|
2017-08-08 01:04:46 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|