Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cctype>
- #include <sstream>
- #include <typeinfo>
- #include <iomanip>
- #include <limits>
- struct Character {
- float skillPercent, skillDelay;
- int hits, mobs, weaponSpeed;
- bool isHurricaneSkill;
- bool hasFinalAttack;
- float faRate, faDamage;
- float minRange, maxRange;
- float critRate, critMin, critMax;
- std::vector<float> ignoreDEF;
- float mobPDR;
- float bossDamage;
- std::pair<float,float> dps;
- float criticalDamage() {
- return (1 + (critRate/100) * (critMin/100 + critMax/100)/2);
- }
- float skillPerSecond() {
- if(!isHurricaneSkill && weaponSpeed != 6) {
- float adjustDelay = (10+weaponSpeed)/6 * skillDelay;
- skillDelay = adjustDelay - (static_cast<int>(skillDelay) % 30);
- }
- return (1000/skillDelay) * skillPercent * hits * mobs;
- }
- float faCalculation() {
- if(!hasFinalAttack)
- return 1;
- else
- return (faRate/100)*faDamage;
- }
- float physicalDEF() {
- float k = 1.0f;
- if(ignoreDEF.empty())
- return mobPDR;
- else {
- for(auto& i : ignoreDEF)
- k *= (i/100);
- return mobPDR*k;
- }
- }
- void calculateDPS() {
- float critDmg = criticalDamage();
- float sPS = skillPerSecond();
- float fa = faCalculation();
- float pdr = physicalDEF();
- dps.first = sPS * fa* critDmg * pdr * minRange * ((bossDamage/100)+1);
- dps.second = sPS * fa * critDmg * pdr * maxRange * ((bossDamage/100)+1);
- }
- friend std::ostream& operator<<(std::ostream& out, Character& player) {
- player.calculateDPS();
- out << "Minimum Damage: " << player.dps.first << "\nMaximum Damage: " << player.dps.second;
- return out;
- }
- };
- template<typename T>
- T lexical_cast(const std::string& str) {
- std::stringstream ss(str);
- T result;
- try {
- if((ss >> result).fail() || !(ss >> std::ws).eof())
- throw std::bad_cast();
- }
- catch(std::bad_cast& e) {
- std::cerr << "Lexical Cast Failed: " << e.what();
- }
- return result;
- }
- bool isValid(const std::string& str) {
- for(auto& i : str) {
- if(!std::isdigit(i))
- return false;
- }
- return true;
- }
- void validateInput(std::string& input) {
- while(std::getline(std::cin,input) && (!isValid(input))) {
- std::cout << "Please enter a valid numerical value: ";
- }
- }
- void validateConfirmation(char& confirmation, bool& value) {
- while((std::cin >> confirmation) && (confirmation != 'n' || confirmation != 'Y')) {
- std::cout << "Please enter a valid input: ";
- }
- if(confirmation == 'Y')
- value = true;
- else
- value = false;
- }
- int main() {
- Character player;
- std::string input;
- char confirmation;
- std::cout << "Enter your minimum range in numbers only: ";
- validateInput(input);
- player.minRange = lexical_cast<float>(input);
- std::cout << "Enter your maximum range in numbers only: ";
- validateInput(input);
- player.maxRange = lexical_cast<float>(input);
- std::cout << "Enter your skill's percent damage\nFor example a 600% skill would be typed as 600: ";
- validateInput(input);
- player.skillPercent = lexical_cast<float>(input);
- std::cout << "Enter your skill's delay\nFor example, 690ms would be input as 690: ";
- validateInput(input);
- player.skillDelay = lexical_cast<float>(input);
- std::cout << "How many mobs are you hitting?: ";
- validateInput(input);
- player.mobs = lexical_cast<int>(input);
- std::cout << "How many hits does your skill do?: ";
- validateInput(input);
- player.hits = lexical_cast<int>(input);
- std::cout << "Is this a hurricane-type skill?\nThink Ultimate Drive, Rapid Fire, etc\nUse \"Y\" for Yes and \"N\" for No: ";
- validateConfirmation(confirmation,player.isHurricaneSkill);
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
- std::cout << "Do you have final attack?\nUse \"Y\" for Yes and \"N\" for No: ";
- validateConfirmation(confirmation,player.hasFinalAttack);
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
- if(player.hasFinalAttack) {
- std::cout<< "What is your final attack rate?\nFor example, 75% final attack rate would be input as 75: ";
- validateInput(input);
- player.faRate = lexical_cast<float>(input);
- std::cout << "What is your final attack damage?\nFor example, 300% final attack damage would be input as 300: ";
- validateInput(input);
- player.faDamage = lexical_cast<float>(input);
- }
- else {
- player.faRate = 0.0f;
- player.faDamage = 0.0f;
- }
- std::cout << "What is your critical rate?\nFor example, 65% critical rate should be input as 65: ";
- validateInput(input);
- player.critRate = lexical_cast<float>(input);
- std::cout << "What is your critical minimum damage?\nThe default is 120% which would be input as 120: ";
- validateInput(input);
- player.critMin = lexical_cast<float>(input);
- std::cout << "What is your critical maximum damage?\nThe default is 150% which would be input as 150: ";
- validateInput(input);
- player.critMax = lexical_cast<float>(input);
- std::cout << "What is the monster's PDR?\nFor example, 25% monster would be input as 25: ";
- validateInput(input);
- player.mobPDR = lexical_cast<float>(input);
- std::cout << "How much percent PDR ignore do you have?\nInput your percent PDR without the % line by line\nType \"N\" to stop";
- while(std::getline(std::cin,input)) {
- if(input.find("N") != std::string::npos)
- break;
- else if(isValid(input)) {
- player.ignoreDEF.push_back(lexical_cast<float>(input));
- }
- }
- std::cout << "How much boss damage do you have?\nFor example, 300% boss damage would be input as 300: ";
- validateInput(input);
- player.bossDamage = lexical_cast<float>(input);
- std::cout << std::fixed << player;
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
- std::cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement