onilink_

Planet Centauri Breeding source

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