Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. /*
  2. Copyright <SWGEmu>
  3. See file COPYING for copying conditions. */
  4.  
  5. #include "server/zone/managers/crafting/CraftingManager.h"
  6. #include "server/zone/managers/crafting/labratories/SharedLabratory.h"
  7. #include "server/zone/managers/crafting/labratories/ResourceLabratory.h"
  8. #include "server/zone/managers/crafting/labratories/GeneticLabratory.h"
  9. #include "server/zone/managers/crafting/labratories/DroidLabratory.h"
  10.  
  11. void CraftingManagerImplementation::initialize() {
  12. schematicMap = SchematicMap::instance();
  13. schematicMap->initialize(zoneServer.get());
  14. configureLabratories();
  15. }
  16.  
  17. void CraftingManagerImplementation::stop() {
  18. schematicMap = NULL;
  19. }
  20.  
  21. void CraftingManagerImplementation::awardSchematicGroup(PlayerObject* playerObject, Vector<String>& schematicgroups, bool updateClient) {
  22. schematicMap->addSchematics(playerObject, schematicgroups, updateClient);
  23. }
  24.  
  25. void CraftingManagerImplementation::removeSchematicGroup(PlayerObject* playerObject, Vector<String>& schematicgroups, bool updateClient) {
  26. schematicMap->removeSchematics(playerObject, schematicgroups, updateClient);
  27. }
  28.  
  29. void CraftingManagerImplementation::sendDraftSlotsTo(CreatureObject* player, uint32 schematicID) {
  30. schematicMap->sendDraftSlotsTo(player, schematicID);
  31. }
  32.  
  33. void CraftingManagerImplementation::sendResourceWeightsTo(CreatureObject* player, uint32 schematicID) {
  34. schematicMap->sendResourceWeightsTo(player, schematicID);
  35. }
  36.  
  37. int CraftingManagerImplementation::calculateAssemblySuccess(CreatureObject* player, DraftSchematic* draftSchematic, float effectiveness) {
  38. SharedLabratory* lab = labs.get(draftSchematic->getLabratory());
  39. return lab->calculateAssemblySuccess(player,draftSchematic,effectiveness);
  40. }
  41.  
  42.  
  43. int CraftingManagerImplementation::calculateExperimentationFailureRate(CreatureObject* player,
  44. ManufactureSchematic* manufactureSchematic, int pointsUsed) {
  45. SharedLabratory* lab = labs.get(manufactureSchematic->getLabratory());
  46. // Get the Weighted value of MA
  47. float ma = lab->getWeightedValue(manufactureSchematic, MA);
  48.  
  49. // Get Experimentation skill
  50. String expSkill = manufactureSchematic->getDraftSchematic()->getExperimentationSkill();
  51. float expPoints = player->getSkillMod(expSkill) / 10.0f;
  52.  
  53. int failure = int((50.0f + (ma - 500.0f) / 40.0f + expPoints - 5.0f * float(pointsUsed)));
  54.  
  55. return failure;
  56. }
  57.  
  58. int CraftingManagerImplementation::getCreationCount(ManufactureSchematic* manufactureSchematic) {
  59. SharedLabratory* lab = labs.get(manufactureSchematic->getLabratory());
  60. return lab->getCreationCount(manufactureSchematic);
  61. }
  62.  
  63. int CraftingManagerImplementation::calculateExperimentationSuccess(CreatureObject* player,
  64. DraftSchematic* draftSchematic, float effectiveness) {
  65.  
  66. float cityBonus = player->getSkillMod("private_spec_experimentation");
  67.  
  68. int experimentationSkill = player->getSkillMod(draftSchematic->getExperimentationSkill());
  69. int forceSkill = player->getSkillMod("force_experimentation");
  70. experimentationSkill += forceSkill;
  71.  
  72. float experimentingPoints = ((float)experimentationSkill) / 10.0f;
  73.  
  74. int failMitigate = (player->getSkillMod(draftSchematic->getAssemblySkill()) - 100 + cityBonus) / 7;
  75. failMitigate += player->getSkillMod("force_failure_reduction");
  76.  
  77. if(failMitigate < 0)
  78. failMitigate = 0;
  79. if(failMitigate > 5)
  80. failMitigate = 5;
  81.  
  82. // 0.85-1.15
  83. float toolModifier = 1.0f + (effectiveness / 100.0f);
  84.  
  85. //Bespin Port
  86. float expbonus = 0;
  87. if (player->hasBuff(BuffCRC::FOOD_EXPERIMENT_BONUS)) {
  88. Buff* buff = player->getBuff(BuffCRC::FOOD_EXPERIMENT_BONUS);
  89.  
  90. if (buff != NULL) {
  91. expbonus = buff->getSkillModifierValue("experiment_bonus");
  92. toolModifier *= 1.0f + (expbonus / 100.0f);
  93. }
  94. }
  95.  
  96. /// Range 0-100
  97. int luckRoll = System::random(100) + cityBonus;
  98.  
  99. if(luckRoll > ((95 - expbonus) - forceSkill))
  100. return AMAZINGSUCCESS;
  101.  
  102. if(luckRoll < (5 - expbonus - failMitigate))
  103. luckRoll -= System::random(100);
  104.  
  105. //if(luckRoll < 5)
  106. // return CRITICALFAILURE;
  107.  
  108. luckRoll += System::random(player->getSkillMod("luck") + player->getSkillMod("force_luck"));
  109.  
  110. ///
  111. int experimentRoll = (toolModifier * (luckRoll + (experimentingPoints * 4)));
  112.  
  113. if (experimentRoll > 70)
  114. return GREATSUCCESS;
  115.  
  116. if (experimentRoll > 60)
  117. return GOODSUCCESS;
  118.  
  119. if (experimentRoll > 50)
  120. return MODERATESUCCESS;
  121.  
  122. if (experimentRoll > 40)
  123. return SUCCESS;
  124.  
  125. if (experimentRoll > 30)
  126. return MARGINALSUCCESS;
  127.  
  128. if (experimentRoll > 20)
  129. return OK;
  130.  
  131. return BARELYSUCCESSFUL;
  132. }
  133.  
  134. String CraftingManagerImplementation::generateSerial() {
  135.  
  136. StringBuffer ss;
  137.  
  138. char a;
  139.  
  140. ss << "(";
  141.  
  142. for (int i = 0; i < 8; ++i) {
  143.  
  144. a = (System::random(34));
  145. if (a < 9) {
  146. a = a + 48;
  147. } else {
  148. a -= 9;
  149. a = a + 97;
  150. }
  151. ss << a;
  152. }
  153.  
  154. ss << ")";
  155.  
  156.  
  157. return ss.toString();
  158. }
  159.  
  160. void CraftingManagerImplementation::experimentRow(ManufactureSchematic* schematic, CraftingValues* craftingValues,
  161. int rowEffected, int pointsAttempted, float failure, int experimentationResult) {
  162. int labratory = schematic->getLabratory();
  163. SharedLabratory* lab = labs.get(labratory);
  164. lab->experimentRow(craftingValues,rowEffected,pointsAttempted,failure,experimentationResult);
  165. }
  166.  
  167. void CraftingManagerImplementation::configureLabratories() {
  168. ResourceLabratory* resLab = new ResourceLabratory();
  169. resLab->initialize(zoneServer.get());
  170.  
  171. labs.put(static_cast<int>(DraftSchematicObjectTemplate::RESOURCE_LAB),resLab); //RESOURCE_LAB
  172.  
  173. GeneticLabratory* genLab = new GeneticLabratory();
  174. genLab->initialize(zoneServer.get());
  175. labs.put(static_cast<int>(DraftSchematicObjectTemplate::GENETIC_LAB), genLab); //GENETIC_LAB
  176.  
  177. DroidLabratory* droidLab = new DroidLabratory();
  178. droidLab->initialize(zoneServer.get());
  179. labs.put(static_cast<int>(DraftSchematicObjectTemplate::DROID_LAB), droidLab); //DROID_LAB
  180.  
  181. }
  182. void CraftingManagerImplementation::setInitialCraftingValues(TangibleObject* prototype, ManufactureSchematic* manufactureSchematic, int assemblySuccess) {
  183. if(manufactureSchematic == NULL || manufactureSchematic->getDraftSchematic() == NULL)
  184. return;
  185. int labratory = manufactureSchematic->getLabratory();
  186. SharedLabratory* lab = labs.get(labratory);
  187. lab->setInitialCraftingValues(prototype,manufactureSchematic,assemblySuccess);
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement