9
3

classes.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include "classes.h"
  19. #include "../common/MiscFunctions.h"
  20. #include <algorithm>
  21. Classes::Classes(){
  22. class_map["COMMONER"] = 0;
  23. class_map["FIGHTER"] = 1;
  24. class_map["WARRIOR"] = 2;
  25. class_map["GUARDIAN"] = 3;
  26. class_map["BERSERKER"] = 4;
  27. class_map["BRAWLER"] = 5;
  28. class_map["MONK"] = 6;
  29. class_map["BRUISER"] = 7;
  30. class_map["CRUSADER"] = 8;
  31. class_map["SHADOWKNIGHT"] = 9;
  32. class_map["PALADIN"] = 10;
  33. class_map["PRIEST"] = 11;
  34. class_map["CLERIC"] = 12;
  35. class_map["TEMPLAR"] = 13;
  36. class_map["INQUISITOR"] = 14;
  37. class_map["DRUID"] = 15;
  38. class_map["WARDEN"] = 16;
  39. class_map["FURY"] = 17;
  40. class_map["SHAMAN"] = 18;
  41. class_map["MYSTIC"] = 19;
  42. class_map["DEFILER"] = 20;
  43. class_map["MAGE"] = 21;
  44. class_map["SORCERER"] = 22;
  45. class_map["WIZARD"] = 23;
  46. class_map["WARLOCK"] = 24;
  47. class_map["ENCHANTER"] = 25;
  48. class_map["ILLUSIONIST"] = 26;
  49. class_map["COERCER"] = 27;
  50. class_map["SUMMONER"] = 28;
  51. class_map["CONJUROR"] = 29;
  52. class_map["NECROMANCER"] = 30;
  53. class_map["SCOUT"] = 31;
  54. class_map["ROGUE"] = 32;
  55. class_map["SWASHBUCKLER"] = 33;
  56. class_map["BRIGAND"] = 34;
  57. class_map["BARD"] = 35;
  58. class_map["TROUBADOR"] = 36;
  59. class_map["DIRGE"] = 37;
  60. class_map["PREDATOR"] = 38;
  61. class_map["RANGER"] = 39;
  62. class_map["ASSASSIN"] = 40;
  63. class_map["ANIMALIST"] = 41;
  64. class_map["BEASTLORD"] = 42;
  65. class_map["SHAPER"] = 43;
  66. class_map["CHANNELER"] = 44;
  67. class_map["ARTISAN"] = 45;
  68. class_map["CRAFTSMAN"] = 46;
  69. class_map["PROVISIONER"] = 47;
  70. class_map["WOODWORKER"] = 48;
  71. class_map["CARPENTER"] = 49;
  72. class_map["OUTFITTER"] = 50;
  73. class_map["ARMORER"] = 51;
  74. class_map["WEAPONSMITH"] = 52;
  75. class_map["TAILOR"] = 53;
  76. class_map["SCHOLAR"] = 54;
  77. class_map["JEWELER"] = 55;
  78. class_map["SAGE"] = 56;
  79. class_map["ALCHEMIST"] = 57;
  80. }
  81. int8 Classes::GetBaseClass(int8 class_id) {
  82. int8 ret = 0;
  83. if(class_id>=WARRIOR && class_id <= PALADIN)
  84. ret = FIGHTER;
  85. if((class_id>=CLERIC && class_id <= DEFILER) || (class_id == SHAPER || class_id == CHANNELER))
  86. ret = PRIEST;
  87. if(class_id>=SORCERER && class_id <= NECROMANCER)
  88. ret = MAGE;
  89. if(class_id>=ROGUE && class_id <= BEASTLORD)
  90. ret = SCOUT;
  91. LogWrite(WORLD__DEBUG, 5, "World", "%s returning base class ID: %i", __FUNCTION__, ret);
  92. return ret;
  93. }
  94. int8 Classes::GetSecondaryBaseClass(int8 class_id){
  95. int8 ret = 0;
  96. if(class_id==GUARDIAN || class_id == BERSERKER)
  97. ret = WARRIOR;
  98. if(class_id==MONK || class_id == BRUISER)
  99. ret = BRAWLER;
  100. if(class_id==SHADOWKNIGHT || class_id == PALADIN)
  101. ret = CRUSADER;
  102. if(class_id==TEMPLAR || class_id == INQUISITOR)
  103. ret = CLERIC;
  104. if(class_id==WARDEN || class_id == FURY)
  105. ret = DRUID;
  106. if(class_id==MYSTIC || class_id == DEFILER)
  107. ret = SHAMAN;
  108. if(class_id==WIZARD || class_id == WARLOCK)
  109. ret = SORCERER;
  110. if(class_id==ILLUSIONIST || class_id == COERCER)
  111. ret = ENCHANTER;
  112. if(class_id==CONJUROR || class_id == NECROMANCER)
  113. ret = SUMMONER;
  114. if(class_id==SWASHBUCKLER || class_id == BRIGAND)
  115. ret = ROGUE;
  116. if(class_id==TROUBADOR || class_id == DIRGE)
  117. ret = BARD;
  118. if(class_id==RANGER || class_id == ASSASSIN)
  119. ret = PREDATOR;
  120. if(class_id==BEASTLORD)
  121. ret = ANIMALIST;
  122. if(class_id == CHANNELER)
  123. ret = SHAPER;
  124. LogWrite(WORLD__DEBUG, 5, "World", "%s returning secondary class ID: %i", __FUNCTION__, ret);
  125. return ret;
  126. }
  127. int8 Classes::GetTSBaseClass(int8 class_id) {
  128. class_id += 42;
  129. int8 ret = 0;
  130. if(class_id >= ARTISAN)
  131. ret = ARTISAN;
  132. LogWrite(WORLD__DEBUG, 5, "World", "%s returning base tradeskill class ID: %i", __FUNCTION__, ret - 44);
  133. return ret - 44;
  134. }
  135. int8 Classes::GetSecondaryTSBaseClass(int8 class_id) {
  136. class_id += 42;
  137. int8 ret = 0;
  138. if (class_id == ARTISAN)
  139. ret = ARTISAN;
  140. if (class_id >= CRAFTSMAN && class_id < OUTFITTER)
  141. ret = CRAFTSMAN;
  142. if (class_id >= OUTFITTER && class_id < SCHOLAR)
  143. ret = OUTFITTER;
  144. if (class_id >= SCHOLAR)
  145. ret = SCHOLAR;
  146. LogWrite(WORLD__DEBUG, 5, "World", "%s returning secondary tradeskill class ID: %i", __FUNCTION__, ret - 44);
  147. return ret - 44;
  148. }
  149. sint8 Classes::GetClassID(const char* name){
  150. string class_name = string(name);
  151. class_name = ToUpper(class_name);
  152. if(class_map.count(class_name) == 1) {
  153. LogWrite(WORLD__DEBUG, 5, "World", "%s returning class ID: %i for class name %s", __FUNCTION__, class_map[class_name], class_name.c_str());
  154. return class_map[class_name];
  155. }
  156. LogWrite(WORLD__WARNING, 0, "World", "Could not find class_id in function: %s (return -1)", __FUNCTION__);
  157. return -1;
  158. }
  159. const char* Classes::GetClassName(int8 class_id){
  160. map<string, int8>::iterator itr;
  161. for(itr = class_map.begin(); itr != class_map.end(); itr++){
  162. if(itr->second == class_id) {
  163. LogWrite(WORLD__DEBUG, 5, "World", "%s returning class name: %s for class_id %i", __FUNCTION__, itr->first.c_str(), class_id);
  164. return itr->first.c_str();
  165. }
  166. }
  167. LogWrite(WORLD__WARNING, 0, "World", "Could not find class name in function: %s (return 0)", __FUNCTION__);
  168. return 0;
  169. }
  170. string Classes::GetClassNameCase(int8 class_id) {
  171. map<string, int8>::iterator itr;
  172. for (itr = class_map.begin(); itr != class_map.end(); itr++){
  173. if (itr->second == class_id) {
  174. string class_name = itr->first;
  175. class_name[0] = itr->first[0];
  176. transform(itr->first.begin() + 1, itr->first.end(), class_name.begin() + 1, ::tolower);
  177. LogWrite(WORLD__DEBUG, 5, "World", "%s returning class name: %s for class_id %i", __FUNCTION__, class_name.c_str(), class_id);
  178. return class_name;
  179. }
  180. }
  181. LogWrite(WORLD__WARNING, 0, "World", "Could not find class name in function: %s (return blank)", __FUNCTION__);
  182. return "";
  183. }