onilink_

Untitled

Feb 8th, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1.  
  2. bool PetHouseAttribute::generateEgg()
  3. {
  4.     Expects(_pets.size() >= 2);
  5.    
  6.     if(!_pets[0].pet || !_pets[1].pet) {
  7.         return false;
  8.     }
  9.     const MonsterAttributesCore& m1 = _pets[0].pet->attribs;
  10.     const MonsterAttributesCore& m2 = _pets[1].pet->attribs;
  11.    
  12.     // 1. Check compatibility
  13.     if(!monstersAreInLove()) {
  14.         return false;
  15.     }
  16.    
  17.     MonsterAttributesCore child(m1.ind);
  18.    
  19.     // 2. Generate rarity
  20.     {
  21.         const bool can_be_shiny = m1.rarity.shiny() && m2.rarity.shiny();
  22.         const unsigned rarity_max =
  23.                 std::min(m1.rarity.rarity(), m2.rarity.rarity());
  24.        
  25.         unsigned rarity = Rand()(0u, rarity_max);
  26.         bool shiny = can_be_shiny && Rand()(1.f) < 0.25f;
  27.         if(shiny && rarity >= 3) {
  28.             child.rarity = MonsterRarity(MonsterRarity::Color(rarity-2));
  29.         }
  30.         else {
  31.             child.rarity = MonsterRarity(uint8_t(rarity));
  32.         }
  33.     }
  34.    
  35.    
  36.     // 3. Generate effect table
  37.     using Effect = MonsterEffectTable::Effect;
  38.     std::vector<Effect> effects_pool;
  39.    
  40.     auto add = [&effects_pool](const Effect& effect){
  41.         if(effect.type == SuffixType::None) {
  42.             return;
  43.         }
  44.         // check if effect not already exists
  45.         for(Effect& eff: effects_pool) {
  46.             if(eff.type == effect.type) {
  47.                 if(eff.level < effect.level) {
  48.                     eff.level = effect.level;
  49.                 }
  50.                 return;
  51.             }
  52.         }
  53.         // add effect to the pool
  54.         effects_pool.push_back(effect);
  55.     };
  56.    
  57.     for(const Effect& effect: m1.effects.table) {
  58.         add(effect);
  59.     }
  60.     for(const Effect& effect: m2.effects.table) {
  61.         add(effect);
  62.     }
  63.    
  64.     // select random effects from the pool
  65.     std::shuffle(begin(effects_pool), end(effects_pool), Rand().engine());
  66.     effects_pool.resize(child.effects.table.size());
  67.     std::copy(begin(effects_pool), end(effects_pool), begin(child.effects.table));
  68.    
  69.     // 4. Generate IVs
  70.     for(unsigned i=0; i<m1.ivs.size(); ++i) {
  71.         unsigned max = std::max<unsigned>(m1.ivs[i] & 0x7F, m2.ivs[i] & 0x7F);
  72.         child.ivs[i] = uint8_t(Rand()(0, max)) | 0x80;
  73.     }
  74.    
  75.     // generate gem
  76.     const auto& info = MonsterInfo::get(m1.ind);
  77.     const ItemIndex egg = info.attribs().egg;
  78.     if(egg.unknown_entry()) {
  79.         return false;
  80.     }
  81.    
  82.     ItemSlot out(egg, 1);
  83.     auto attr = std::make_shared<ItemMonsterAttribute>();
  84.     attr->attribs = child;
  85.     attr->egg = true;
  86.     attr->hatching_duration = 30+uint16_t(info.experienceFactor())*10;
  87.     attr->hatching_duration_max = attr->hatching_duration;
  88.     out.setMonster(attr);
  89.    
  90.     setEggSlot(std::move(out));
  91.    
  92.     return true;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment