Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool PetHouseAttribute::generateEgg()
- {
- Expects(_pets.size() >= 2);
- if(!_pets[0].pet || !_pets[1].pet) {
- return false;
- }
- const MonsterAttributesCore& m1 = _pets[0].pet->attribs;
- const MonsterAttributesCore& m2 = _pets[1].pet->attribs;
- // 1. Check compatibility
- if(!monstersAreInLove()) {
- return false;
- }
- MonsterAttributesCore child(m1.ind);
- // 2. Generate rarity
- {
- const bool can_be_shiny = m1.rarity.shiny() && m2.rarity.shiny();
- const unsigned rarity_max =
- std::min(m1.rarity.rarity(), m2.rarity.rarity());
- unsigned rarity = Rand()(0u, rarity_max);
- bool shiny = can_be_shiny && Rand()(1.f) < 0.25f;
- if(shiny && rarity >= 3) {
- child.rarity = MonsterRarity(MonsterRarity::Color(rarity-2));
- }
- else {
- child.rarity = MonsterRarity(uint8_t(rarity));
- }
- }
- // 3. Generate effect table
- using Effect = MonsterEffectTable::Effect;
- std::vector<Effect> effects_pool;
- auto add = [&effects_pool](const Effect& effect){
- if(effect.type == SuffixType::None) {
- return;
- }
- // check if effect not already exists
- for(Effect& eff: effects_pool) {
- if(eff.type == effect.type) {
- if(eff.level < effect.level) {
- eff.level = effect.level;
- }
- return;
- }
- }
- // add effect to the pool
- effects_pool.push_back(effect);
- };
- for(const Effect& effect: m1.effects.table) {
- add(effect);
- }
- for(const Effect& effect: m2.effects.table) {
- add(effect);
- }
- // select random effects from the pool
- std::shuffle(begin(effects_pool), end(effects_pool), Rand().engine());
- effects_pool.resize(child.effects.table.size());
- std::copy(begin(effects_pool), end(effects_pool), begin(child.effects.table));
- // 4. Generate IVs
- for(unsigned i=0; i<m1.ivs.size(); ++i) {
- unsigned max = std::max<unsigned>(m1.ivs[i] & 0x7F, m2.ivs[i] & 0x7F);
- child.ivs[i] = uint8_t(Rand()(0, max)) | 0x80;
- }
- // generate gem
- const auto& info = MonsterInfo::get(m1.ind);
- const ItemIndex egg = info.attribs().egg;
- if(egg.unknown_entry()) {
- return false;
- }
- ItemSlot out(egg, 1);
- auto attr = std::make_shared<ItemMonsterAttribute>();
- attr->attribs = child;
- attr->egg = true;
- attr->hatching_duration = 30+uint16_t(info.experienceFactor())*10;
- attr->hatching_duration_max = attr->hatching_duration;
- out.setMonster(attr);
- setEggSlot(std::move(out));
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment