Advertisement
Rapptz

MapleDPS2

Jan 26th, 2013
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5. #include <sstream>
  6. #include <typeinfo>
  7. #include <iomanip>
  8. #include <limits>
  9.  
  10. struct Character {
  11.     float skillPercent, skillDelay;
  12.     int hits, mobs, weaponSpeed;
  13.     bool isHurricaneSkill;
  14.     bool hasFinalAttack;
  15.     float faRate, faDamage;
  16.     float minRange, maxRange;
  17.     float critRate, critMin, critMax;
  18.     std::vector<float> ignoreDEF;
  19.     float mobPDR;
  20.     float bossDamage;
  21.     std::pair<float,float> dps;
  22.     float criticalDamage() {
  23.         return (1 + (critRate/100) * (critMin/100 + critMax/100)/2);
  24.     }
  25.     float skillPerSecond() {
  26.         if(!isHurricaneSkill && weaponSpeed != 6) {
  27.             float adjustDelay = (10+weaponSpeed)/6 * skillDelay;
  28.             skillDelay = adjustDelay - (static_cast<int>(skillDelay) % 30);
  29.         }
  30.         return (1000/skillDelay) * skillPercent * hits * mobs;
  31.     }
  32.     float faCalculation() {
  33.         if(!hasFinalAttack)
  34.             return 1;
  35.         else
  36.             return (faRate/100)*faDamage;
  37.     }
  38.     float physicalDEF() {
  39.         float k = 1.0f;
  40.         if(ignoreDEF.empty())
  41.             return mobPDR;
  42.         else {
  43.             for(auto& i : ignoreDEF)
  44.                 k *= (i/100);
  45.             return mobPDR*k;
  46.         }
  47.     }
  48.     void calculateDPS() {
  49.         float critDmg = criticalDamage();
  50.         float sPS = skillPerSecond();
  51.         float fa = faCalculation();
  52.         float pdr = physicalDEF();
  53.         dps.first = sPS * fa* critDmg * pdr * minRange * ((bossDamage/100)+1);
  54.         dps.second = sPS * fa * critDmg * pdr * maxRange * ((bossDamage/100)+1);
  55.     }
  56.     friend std::ostream& operator<<(std::ostream& out, Character& player) {
  57.         player.calculateDPS();
  58.         out << "Minimum Damage: " << player.dps.first << "\nMaximum Damage: " << player.dps.second;
  59.         return out;
  60.     }
  61. };
  62.  
  63. template<typename T>
  64. T lexical_cast(const std::string& str) {
  65.     std::stringstream ss(str);
  66.     T result;
  67.     try {
  68.         if((ss >> result).fail() || !(ss >> std::ws).eof())
  69.             throw std::bad_cast();
  70.     }
  71.     catch(std::bad_cast& e) {
  72.         std::cerr << "Lexical Cast Failed: " << e.what();
  73.     }
  74.     return result;
  75. }
  76.  
  77. bool isValid(const std::string& str) {
  78.     for(auto& i : str) {
  79.         if(!std::isdigit(i))
  80.             return false;
  81.     }
  82.     return true;
  83. }
  84.  
  85. void validateInput(std::string& input) {
  86.     while(std::getline(std::cin,input) && (!isValid(input))) {
  87.         std::cout << "Please enter a valid numerical value: ";
  88.     }
  89. }
  90.  
  91. void validateConfirmation(char& confirmation, bool& value) {
  92.     while((std::cin >> confirmation) && (confirmation != 'n' || confirmation != 'Y')) {
  93.         std::cout << "Please enter a valid input: ";
  94.     }
  95.     if(confirmation == 'Y')
  96.         value = true;
  97.     else
  98.         value = false;
  99. }
  100. int main() {
  101.     Character player;
  102.     std::string input;
  103.     char confirmation;
  104.    
  105.     std::cout << "Enter your minimum range in numbers only: ";
  106.     validateInput(input);
  107.     player.minRange = lexical_cast<float>(input);
  108.    
  109.     std::cout << "Enter your maximum range in numbers only: ";
  110.     validateInput(input);
  111.     player.maxRange = lexical_cast<float>(input);
  112.    
  113.     std::cout << "Enter your skill's percent damage\nFor example a 600% skill would be typed as 600: ";
  114.     validateInput(input);
  115.     player.skillPercent = lexical_cast<float>(input);
  116.    
  117.     std::cout << "Enter your skill's delay\nFor example, 690ms would be input as 690: ";
  118.     validateInput(input);
  119.     player.skillDelay = lexical_cast<float>(input);
  120.    
  121.     std::cout << "How many mobs are you hitting?: ";
  122.     validateInput(input);
  123.     player.mobs = lexical_cast<int>(input);
  124.    
  125.     std::cout << "How many hits does your skill do?: ";
  126.     validateInput(input);
  127.     player.hits = lexical_cast<int>(input);
  128.    
  129.     std::cout << "Is this a hurricane-type skill?\nThink Ultimate Drive, Rapid Fire, etc\nUse \"Y\" for Yes and \"N\" for No: ";
  130.     validateConfirmation(confirmation,player.isHurricaneSkill);
  131.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
  132.    
  133.     std::cout << "Do you have final attack?\nUse \"Y\" for Yes and \"N\" for No: ";
  134.     validateConfirmation(confirmation,player.hasFinalAttack);
  135.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
  136.    
  137.     if(player.hasFinalAttack) {
  138.         std::cout<< "What is your final attack rate?\nFor example, 75% final attack rate would be input as 75: ";
  139.         validateInput(input);
  140.         player.faRate = lexical_cast<float>(input);
  141.         std::cout << "What is your final attack damage?\nFor example, 300% final attack damage would be input as 300: ";
  142.         validateInput(input);
  143.         player.faDamage = lexical_cast<float>(input);
  144.     }
  145.     else {
  146.         player.faRate = 0.0f;
  147.         player.faDamage = 0.0f;
  148.     }
  149.    
  150.     std::cout << "What is your critical rate?\nFor example, 65% critical rate should be input as 65: ";
  151.     validateInput(input);
  152.     player.critRate = lexical_cast<float>(input);
  153.    
  154.     std::cout << "What is your critical minimum damage?\nThe default is 120% which would be input as 120: ";
  155.     validateInput(input);
  156.     player.critMin = lexical_cast<float>(input);
  157.    
  158.     std::cout << "What is your critical maximum damage?\nThe default is 150% which would be input as 150: ";
  159.     validateInput(input);
  160.     player.critMax = lexical_cast<float>(input);
  161.    
  162.     std::cout << "What is the monster's PDR?\nFor example, 25% monster would be input as 25: ";
  163.     validateInput(input);
  164.     player.mobPDR = lexical_cast<float>(input);
  165.    
  166.     std::cout << "How much percent PDR ignore do you have?\nInput your percent PDR without the % line by line\nType \"N\" to stop";
  167.     while(std::getline(std::cin,input)) {
  168.         if(input.find("N") != std::string::npos)
  169.             break;
  170.         else if(isValid(input)) {
  171.             player.ignoreDEF.push_back(lexical_cast<float>(input));
  172.         }
  173.     }
  174.    
  175.     std::cout << "How much boss damage do you have?\nFor example, 300% boss damage would be input as 300: ";
  176.     validateInput(input);
  177.     player.bossDamage = lexical_cast<float>(input);
  178.  
  179.     std::cout << std::fixed << player;
  180.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
  181.     std::cin.get();
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement