Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct PetLevel
- {
- static std::map<BYTE, DWORD> levelBoundaries;
- BYTE curLevel, curSkillLevel;
- FLOAT progressPercentage;
- DWORD curExperience, expBoundaries[2];
- PetLevel(BYTE lvl, DWORD exp, bool masterSkillLvl = FALSE)
- {
- computeBoundaries(lvl);
- curLevel = lvl > PET_MAX_LEVEL ? PET_MAX_LEVEL : lvl;
- curExperience = (exp >= expBoundaries[TRUE] && curLevel < PET_MAX_LEVEL) ? LevelUp(exp) : exp;
- curSkillLevel = masterSkillLvl ? PET_MAX_SKILLVL : BYTE(curLevel / PET_FACTOR_INCREASESKILLLVL);
- computeProgress();
- }
- void Gain(DWORD exp)
- {
- exp = (exp * PET_FACTOR_EXPSHARE) / 100;
- DWORD newValue = curExperience + exp;
- curExperience = newValue;
- while (newValue >= expBoundaries[TRUE])
- {
- if (curLevel >= PET_MAX_LEVEL)
- break;
- LevelUp(newValue);
- if (newValue == expBoundaries[FALSE]) //to prevent endless loop when the curExperience == expBoundaries[FALSE]
- break;
- }
- computeProgress();
- }
- DWORD LevelUp(DWORD newValue)
- {
- if (curLevel >= PET_MAX_LEVEL)
- return expBoundaries[TRUE];
- curLevel++;
- computeBoundaries(curLevel);
- return newValue;
- }
- void computeBoundaries(BYTE lvl)
- {
- for (BYTE i = 0; i < 2; i++)
- {
- if (lvl == 1 && !i)
- {
- expBoundaries[i] = 0;
- continue;
- }
- std::map<BYTE, DWORD>::iterator iterLowerBound = levelBoundaries.find(i ? lvl : lvl -1);
- if (iterLowerBound != levelBoundaries.end())
- expBoundaries[i] = iterLowerBound->second;
- else
- {
- fprintf(stderr, "Pet Level %d does not exist in pet_levelchart", i ? lvl: lvl -1);
- exit(1);
- }
- }
- }
- void computeProgress() { progressPercentage = (((FLOAT)(curExperience - expBoundaries[FALSE]) / (expBoundaries[TRUE] - expBoundaries[FALSE])) * 100);}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement