Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
- * Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /********************************************************************
- * From Unit.cpp of https://github.com/elysium-project/server/ *
- * *
- * Line numbers commented for each part for reference *
- ********************************************************************/
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <fstream>
- #include <sys/stat.h>
- using namespace std;
- int main()
- {
- // Lines 2060 - 2103
- struct ResistanceValues
- {
- int resist100;
- int resist75;
- int resist50;
- int resist25;
- int resist0;
- int chanceResist;
- };
- static ResistanceValues resistValues[] =
- {
- {0, 0, 0, 0, 100, 0}, // 0
- {0, 0, 2, 6, 92, 3}, // 10
- {0, 1, 4, 12, 84, 5}, // 20
- {0, 1, 5, 18, 76, 8}, // 30
- {0, 1, 7, 23, 69, 10}, // 40
- {0, 2, 9, 28, 61, 13}, // 50
- {0, 2, 11, 33, 54, 15}, // 60
- {0, 2, 13, 37, 37, 18}, // 70
- {0, 3, 15, 41, 41, 20}, // 80
- {1, 3, 17, 46, 36, 23}, // 90
- {1, 4, 19, 47, 29, 25}, // 100
- {1, 5, 21, 48, 24, 28}, // 110
- {1, 6, 24, 49, 20, 30}, // 120
- {1, 8, 28, 47, 17, 33}, // 130
- {1, 9, 33, 43, 14, 35}, // 140
- {1, 11, 37, 39, 12, 38}, // 150
- {1, 13, 41, 35, 10, 40}, // 160
- {1, 16, 45, 30, 8, 43}, // 170
- {1, 18, 48, 26, 7, 45}, // 180
- {2, 20, 48, 24, 6, 48}, // 190
- {4, 23, 48, 21, 4, 50}, // 200
- {5, 25, 47, 19, 3, 53}, // 210
- {7, 28, 45, 17, 2, 55}, // 220
- {9, 31, 43, 16, 2, 58}, // 230
- {11, 34, 40, 14, 1, 60}, // 240
- {13, 37, 37, 12, 1, 62}, // 250
- {15, 41, 33, 10, 1, 65}, // 260
- {18, 44, 29, 8, 1, 68}, // 270
- {20, 48, 25, 7, 1, 70}, // 280
- {23, 51, 20, 5, 1, 73}, // 290
- {25, 55, 16, 3, 1, 75} // 300
- };
- int casterLevel;
- ofstream outputFile;
- cout << "Caster Level: " << endl;
- cin >> casterLevel;
- int lastResistance = casterLevel * 5;
- string fileName = to_string(casterLevel);
- struct stat buf;
- stringstream fileNameStream;
- int i = 0;
- do {
- fileNameStream.str(string());
- if(i > 0)
- fileNameStream << fileName << "(" << i << ").txt";
- else
- fileNameStream << fileName << ".txt";
- if (stat(fileNameStream.str().c_str(), &buf) != -1)
- i++;
- else
- outputFile.open(fileNameStream.str());
- } while (!outputFile.is_open() && i < 10000);
- if (!outputFile.is_open()) {
- cout << "File not open. Closing.";
- system("pause");
- return 0;
- }
- for (int currentResistance = 0; currentResistance <= lastResistance; currentResistance++) {
- // Lines 2949 - 2954
- float resistModHitChance = currentResistance * (0.15f / casterLevel);
- if (resistModHitChance < 0.0f)
- resistModHitChance = 0.0f;
- if (resistModHitChance > 0.75f)
- resistModHitChance = 0.75f;
- // Line 2139
- float resistanceChance = resistModHitChance * 100.0f;
- // Lines 2161 - 2179
- ResistanceValues* prev = nullptr;
- ResistanceValues* next = nullptr;
- for (int i = 1; i < 31; ++i)
- {
- if (resistValues[i].chanceResist >= resistanceChance)
- {
- prev = &resistValues[i - 1];
- next = &resistValues[i];
- break;
- }
- }
- float coeff = float(resistanceChance - prev->chanceResist) / float(next->chanceResist - prev->chanceResist);
- float resist0 = prev->resist0 + (next->resist0 - prev->resist0) * coeff;
- float resist25 = prev->resist25 + (next->resist25 - prev->resist25) * coeff;
- float resist50 = prev->resist50 + (next->resist50 - prev->resist50) * coeff;
- float resist75 = prev->resist75 + (next->resist75 - prev->resist75) * coeff;
- float resist100 = prev->resist100 + (next->resist100 - prev->resist100) * coeff;
- int count75 = 0;
- int count50 = 0;
- int count25 = 0;
- int count0 = 0;
- // Lines 2185 - 2190
- for (int ran = 0; ran < 100; ran++){
- if (ran < resist100 + resist75)
- count75++;
- else if (ran < resist100 + resist75 + resist50)
- count50++;
- else if (ran < resist100 + resist75 + resist50 + resist25)
- count25++;
- }
- float averageDamageReduction = count75 * 0.75f + count50 * 0.50f + count25 * 0.25f;
- if (count75+count50+count25 < 101)
- count0 = 100 - count75 - count50 - count25;
- outputFile << currentResistance << '\t' << currentResistance * (0.15f / casterLevel) * 100 << '\t' << averageDamageReduction << '\t' << count75 << '\t' << count50 << '\t' << count25 << '\t' << count0 << '\r' << '\n';
- }
- outputFile.close();
- cout << "Completed. File name: " << fileNameStream.str() << '\n';
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement