SHARE
TWEET

Untitled

a guest Jan 21st, 2020 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct PetLevel
  2. {
  3.     static std::map<BYTE, DWORD> levelBoundaries;
  4.     BYTE curLevel, curSkillLevel;
  5.     FLOAT progressPercentage;
  6.     DWORD curExperience, expBoundaries[2];
  7.  
  8.     PetLevel(BYTE lvl, DWORD exp, bool masterSkillLvl = FALSE)
  9.     {
  10.         computeBoundaries(lvl);
  11.  
  12.         curLevel = lvl > PET_MAX_LEVEL ? PET_MAX_LEVEL : lvl;
  13.         curExperience = (exp >= expBoundaries[TRUE] && curLevel < PET_MAX_LEVEL) ? LevelUp(exp) : exp;
  14.         curSkillLevel = masterSkillLvl ? PET_MAX_SKILLVL : BYTE(curLevel / PET_FACTOR_INCREASESKILLLVL);
  15.  
  16.         computeProgress();
  17.     }
  18.  
  19.     void Gain(DWORD exp)
  20.     {
  21.         exp = (exp * PET_FACTOR_EXPSHARE) / 100;
  22.  
  23.         DWORD newValue = curExperience + exp;
  24.         curExperience = newValue;
  25.        
  26.         while (newValue >= expBoundaries[TRUE])
  27.         {
  28.             if (curLevel >= PET_MAX_LEVEL)
  29.                 break;
  30.  
  31.             LevelUp(newValue);
  32.  
  33.             if (newValue == expBoundaries[FALSE]) //to prevent endless loop when the curExperience == expBoundaries[FALSE]
  34.                 break;
  35.         }
  36.  
  37.         computeProgress();
  38.     }
  39.  
  40.     DWORD LevelUp(DWORD newValue)
  41.     {
  42.         if (curLevel >= PET_MAX_LEVEL)
  43.             return expBoundaries[TRUE];
  44.  
  45.         curLevel++;
  46.  
  47.         computeBoundaries(curLevel);       
  48.  
  49.         return newValue;
  50.     }
  51.  
  52.     void computeBoundaries(BYTE lvl)
  53.     {
  54.         for (BYTE i = 0; i < 2; i++)
  55.         {
  56.             if (lvl == 1 && !i)
  57.             {
  58.                 expBoundaries[i] = 0;
  59.                 continue;
  60.             }
  61.            
  62.             std::map<BYTE, DWORD>::iterator iterLowerBound = levelBoundaries.find(i ? lvl : lvl -1);
  63.  
  64.             if (iterLowerBound != levelBoundaries.end())
  65.                 expBoundaries[i] = iterLowerBound->second;
  66.             else
  67.             {
  68.                 fprintf(stderr, "Pet Level %d does not exist in pet_levelchart", i ? lvl: lvl -1);
  69.                 exit(1);
  70.             }
  71.         }
  72.     }
  73.  
  74.     void computeProgress() { progressPercentage = (((FLOAT)(curExperience - expBoundaries[FALSE]) / (expBoundaries[TRUE] - expBoundaries[FALSE])) * 100);}
  75. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top