SHARE
TWEET

Elysium Resistance DR calculator

Kujalla Oct 12th, 2017 294 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
  3.  * Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
  4.  *
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  */
  20.  
  21. /********************************************************************
  22. *    From Unit.cpp of https://github.com/elysium-project/server/    *
  23. *                                                                   *
  24. *    Line numbers commented for each part for reference             *
  25. ********************************************************************/
  26.  
  27. #include <iostream>
  28. #include <string>
  29. #include <sstream>
  30. #include <fstream>
  31. #include <sys/stat.h>
  32.  
  33. using namespace std;
  34.  
  35. int main()
  36. {
  37.     // Lines 2060 - 2103
  38.     struct ResistanceValues
  39.     {
  40.         int resist100;
  41.         int resist75;
  42.         int resist50;
  43.         int resist25;
  44.         int resist0;
  45.         int chanceResist;
  46.     };
  47.     static ResistanceValues resistValues[] =
  48.     {
  49.         {0, 0, 0, 0, 100, 0},    // 0
  50.         {0, 0, 2, 6, 92, 3},     // 10
  51.         {0, 1, 4, 12, 84, 5},    // 20
  52.         {0, 1, 5, 18, 76, 8},    // 30
  53.         {0, 1, 7, 23, 69, 10},   // 40
  54.         {0, 2, 9, 28, 61, 13},   // 50
  55.         {0, 2, 11, 33, 54, 15},  // 60
  56.         {0, 2, 13, 37, 37, 18},  // 70
  57.         {0, 3, 15, 41, 41, 20},  // 80
  58.         {1, 3, 17, 46, 36, 23},  // 90
  59.         {1, 4, 19, 47, 29, 25},  // 100
  60.         {1, 5, 21, 48, 24, 28},  // 110
  61.         {1, 6, 24, 49, 20, 30},  // 120
  62.         {1, 8, 28, 47, 17, 33},  // 130
  63.         {1, 9, 33, 43, 14, 35},  // 140
  64.         {1, 11, 37, 39, 12, 38}, // 150
  65.         {1, 13, 41, 35, 10, 40}, // 160
  66.         {1, 16, 45, 30, 8, 43},  // 170
  67.         {1, 18, 48, 26, 7, 45},  // 180
  68.         {2, 20, 48, 24, 6, 48},  // 190
  69.         {4, 23, 48, 21, 4, 50},  // 200
  70.         {5, 25, 47, 19, 3, 53},  // 210
  71.         {7, 28, 45, 17, 2, 55},  // 220
  72.         {9, 31, 43, 16, 2, 58},  // 230
  73.         {11, 34, 40, 14, 1, 60}, // 240
  74.         {13, 37, 37, 12, 1, 62}, // 250
  75.         {15, 41, 33, 10, 1, 65}, // 260
  76.         {18, 44, 29, 8, 1, 68},  // 270
  77.         {20, 48, 25, 7, 1, 70},  // 280
  78.         {23, 51, 20, 5, 1, 73},  // 290
  79.         {25, 55, 16, 3, 1, 75}   // 300
  80.     };
  81.  
  82.     int casterLevel;
  83.     ofstream outputFile;
  84.  
  85.     cout << "Caster Level: " << endl;
  86.     cin >> casterLevel;
  87.     int lastResistance = casterLevel * 5;
  88.     string fileName = to_string(casterLevel);
  89.     struct stat buf;
  90.  
  91.     stringstream fileNameStream;
  92.     int i = 0;
  93.     do {
  94.         fileNameStream.str(string());
  95.         if(i > 0)
  96.             fileNameStream << fileName << "(" << i << ").txt";
  97.         else
  98.             fileNameStream << fileName << ".txt";
  99.  
  100.         if (stat(fileNameStream.str().c_str(), &buf) != -1)
  101.             i++;
  102.         else
  103.             outputFile.open(fileNameStream.str());
  104.     } while (!outputFile.is_open() && i < 10000);
  105.  
  106.     if (!outputFile.is_open()) {
  107.         cout << "File not open. Closing.";
  108.         system("pause");
  109.         return 0;
  110.     }
  111.  
  112.     for (int currentResistance = 0; currentResistance <= lastResistance; currentResistance++) {
  113.  
  114.         // Lines 2949 - 2954
  115.         float resistModHitChance = currentResistance * (0.15f / casterLevel);
  116.         if (resistModHitChance < 0.0f)
  117.             resistModHitChance = 0.0f;
  118.         if (resistModHitChance > 0.75f)
  119.             resistModHitChance = 0.75f;
  120.  
  121.         // Line 2139
  122.         float resistanceChance = resistModHitChance * 100.0f;
  123.  
  124.         // Lines 2161 - 2179
  125.         ResistanceValues* prev = nullptr;
  126.         ResistanceValues* next = nullptr;
  127.  
  128.         for (int i = 1; i < 31; ++i)
  129.         {
  130.             if (resistValues[i].chanceResist >= resistanceChance)
  131.             {
  132.                 prev = &resistValues[i - 1];
  133.                 next = &resistValues[i];
  134.                 break;
  135.             }
  136.         }
  137.  
  138.         float coeff = float(resistanceChance - prev->chanceResist) / float(next->chanceResist - prev->chanceResist);
  139.         float resist0 = prev->resist0 + (next->resist0 - prev->resist0) * coeff;
  140.         float resist25 = prev->resist25 + (next->resist25 - prev->resist25) * coeff;
  141.         float resist50 = prev->resist50 + (next->resist50 - prev->resist50) * coeff;
  142.         float resist75 = prev->resist75 + (next->resist75 - prev->resist75) * coeff;
  143.         float resist100 = prev->resist100 + (next->resist100 - prev->resist100) * coeff;
  144.  
  145.         int count75 = 0;
  146.         int count50 = 0;
  147.         int count25 = 0;
  148.         int count0 = 0;
  149.  
  150.         // Lines 2185 - 2190
  151.         for (int ran = 0; ran < 100; ran++){
  152.             if (ran < resist100 + resist75)
  153.                 count75++;
  154.             else if (ran < resist100 + resist75 + resist50)
  155.                 count50++;
  156.             else if (ran < resist100 + resist75 + resist50 + resist25)
  157.                 count25++;
  158.         }
  159.  
  160.         float averageDamageReduction = count75 * 0.75f + count50 * 0.50f + count25 * 0.25f;
  161.         if (count75+count50+count25 < 101)
  162.             count0 = 100 - count75 - count50 - count25;
  163.  
  164.         outputFile << currentResistance << '\t' << currentResistance * (0.15f / casterLevel) * 100 << '\t' << averageDamageReduction << '\t' << count75 << '\t' << count50 << '\t' << count25 << '\t' << count0 << '\r' << '\n';
  165.     }
  166.  
  167.     outputFile.close();
  168.     cout << "Completed. File name: " << fileNameStream.str() << '\n';
  169.     system("pause");
  170.     return 0;
  171. }
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