Recipe.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. #ifndef RECIPE_H_
  17. #define RECIPE_H_
  18. #include "../../common/types.h"
  19. #include "../../common/Mutex.h"
  20. #include "../classes.h"
  21. #include <string.h>
  22. #include <map>
  23. class Item;
  24. using namespace std;
  25. struct RecipeProducts {
  26. int32 product_id;
  27. int32 byproduct_id;
  28. int8 product_qty;
  29. int8 byproduct_qty;
  30. };
  31. class Recipe {
  32. public:
  33. Recipe();
  34. Recipe(Recipe *in);
  35. virtual ~Recipe();
  36. EQ2Packet *SerializeRecipe(Client *client, Recipe *recipe, bool display, int8 packet_type = 0, int8 sub_packet_type = 0, const char *struct_name = 0);
  37. void SetID(int32 id) {this->id = id;}
  38. void SetBookID(int32 book_id) {this->book_id = book_id;}
  39. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  40. void SetBookName(const char *book_name) {strncpy(this->book_name, book_name, sizeof(this->book_name));}
  41. void SetBook(const char *book) {strncpy(this->book, book, sizeof(this->book));}
  42. void SetDevice(const char *device) {strncpy(this->device, device, sizeof(this->device));}
  43. void SetLevel(int8 level) {this->level = level;}
  44. void SetTier(int8 tier) {this->tier = tier;}
  45. void SetIcon(int16 icon) {this->icon = icon;}
  46. void SetSkill(int32 skill) {this->skill = skill;}
  47. void SetTechnique(int32 technique) {this->technique = technique;}
  48. void SetKnowledge(int32 knowledge) {this->knowledge = knowledge;}
  49. void SetClasses(int32 classes) {this->classes = classes;}
  50. void SetDevice_Sub_Type(int8 device_sub_type) {this->device_sub_type = device_sub_type;}
  51. void SetUnknown2(int32 unknown2) {this->unknown2 = unknown2;}
  52. void SetUnknown3(int32 unknown3) {this->unknown3 = unknown3;}
  53. void SetUnknown4(int32 unknown4) {this->unknown4 = unknown4;}
  54. void SetProductID(int32 itemID) { product_item_id = itemID; }
  55. void SetProductQuantity(int8 qty) { product_qty = qty; }
  56. void SetProductName(const char* productName) { strncpy(product_name, productName, sizeof(product_name)); }
  57. void SetBuildComponentTitle(const char* title) { strncpy(build1_comp_title, title, sizeof(build1_comp_title)); }
  58. void SetBuild2ComponentTitle(const char* title) { strncpy(build2_comp_title, title, sizeof(build2_comp_title)); }
  59. void SetBuild3ComponentTitle(const char* title) { strncpy(build3_comp_title, title, sizeof(build3_comp_title)); }
  60. void SetBuild4ComponentTitle(const char* title) { strncpy(build4_comp_title, title, sizeof(build4_comp_title)); }
  61. void SetFuelComponentTitle(const char* title) { strncpy(fuel_comp_title, title, sizeof(fuel_comp_title)); }
  62. void SetPrimaryComponentTitle(const char* title) { strncpy(primary_build_comp_title, title, sizeof(primary_build_comp_title)); }
  63. void SetBuild1ComponentQuantity(int8 qty) { build_comp_qty = qty; }
  64. void SetBuild2ComponentQuantity(int8 qty) { build2_comp_qty = qty; }
  65. void SetBuild3ComponentQuantity(int8 qty) { build3_comp_qty = qty; }
  66. void SetBuild4ComponentQuantity(int8 qty) { build4_comp_qty = qty; }
  67. void SetFuelComponentQuantity(int8 qty) { fuel_comp_qty = qty; }
  68. int32 GetID() {return id;}
  69. int32 GetBookID() {return book_id;}
  70. const char * GetName() {return name;}
  71. const char * GetBookName() {return book_name;}
  72. const char * GetBook() {return book;}
  73. const char * GetDevice() {return device;}
  74. int8 GetLevel() {return level;}
  75. int8 GetTier() {return tier;}
  76. int16 GetIcon() {return icon;}
  77. int32 GetSkill() {return skill;}
  78. int32 GetTechnique() {return technique;}
  79. int32 GetKnowledge() {return knowledge;}
  80. int32 GetClasses() {return classes;}
  81. //class_id = classes.GetTSBaseClass(spawn->GetTradeskillClass()) bit-match on class ids 1-13
  82. //secondary_class_id = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()) bit-match on class ids 1-13
  83. //tertiary_class_id = spawn->GetTradeskillClass() (direct match)
  84. bool CanUseRecipeByClass(Item* item, int8 class_id) {
  85. /* any can use bit combination of 1+2
  86. adornments = 1
  87. artisan = 2
  88. */
  89. return item->generic_info.tradeskill_classes < 4 || (1 << class_id) & item->generic_info.tradeskill_classes;
  90. }
  91. int8 GetDevice_Sub_Type() {return device_sub_type;}
  92. int32 GetUnknown2() {return unknown2;}
  93. int32 GetUnknown3() {return unknown3;}
  94. int32 GetUnknown4() {return unknown4;}
  95. int32 GetProductID() { return product_item_id; }
  96. const char* GetProductTitle() { return product_name; }
  97. int8 GetProductQuantity() { return product_qty; }
  98. const char* GetPrimaryBuildComponentTitle() { return primary_build_comp_title; }
  99. const char* GetBuild1ComponentTitle() { return build1_comp_title; }
  100. const char* GetBuild2ComponentTitle() { return build2_comp_title; }
  101. const char* GetBuild3ComponentTitle() { return build3_comp_title; }
  102. const char* GetBuild4ComponentTitle() { return build4_comp_title; }
  103. const char* GetFuelComponentTitle() { return fuel_comp_title; }
  104. int8 GetBuild1ComponentQuantity() { return build_comp_qty; }
  105. int8 GetBuild2ComponentQuantity() { return build2_comp_qty; }
  106. int8 GetBuild3ComponentQuantity() { return build3_comp_qty; }
  107. int8 GetBuild4ComponentQuantity() { return build4_comp_qty; }
  108. int8 GetFuelComponentQuantity() { return fuel_comp_qty; }
  109. ///<summary>Add a build component to this recipe</summary>
  110. ///<param name="itemID">Item id of the component</param>
  111. ///<param name="slot">Slot id for this component</param>
  112. void AddBuildComp(int32 itemID, int8 slot);
  113. // int8 = slot, vector = itemid
  114. map<int8, vector<int32> > components;
  115. // int8 = stage, RecipeProducts = products/byproducts for this stage
  116. map<int8, RecipeProducts*> products;
  117. int8 GetHighestStage() { return highestStage; }
  118. void SetHighestStage(int8 val) { highestStage = val; }
  119. private:
  120. int32 id;
  121. int32 book_id;
  122. char name[256];
  123. char book_name[256];
  124. char book[256];
  125. char device[30];
  126. int8 level;
  127. int8 tier;
  128. int16 icon;
  129. int32 skill;
  130. int32 technique;
  131. int32 knowledge;
  132. int8 device_sub_type;
  133. int32 classes;
  134. int32 unknown2;
  135. int32 unknown3;
  136. int32 unknown4;
  137. int32 product_item_id;
  138. char product_name[256];
  139. int8 product_qty;
  140. char primary_build_comp_title[256];
  141. char build1_comp_title[256];
  142. char build2_comp_title[256];
  143. char build3_comp_title[256];
  144. char build4_comp_title[256];
  145. char fuel_comp_title[256];
  146. int8 build_comp_qty;
  147. int8 build2_comp_qty;
  148. int8 build3_comp_qty;
  149. int8 build4_comp_qty;
  150. int8 fuel_comp_qty;
  151. int8 highestStage;
  152. };
  153. class MasterRecipeList {
  154. public:
  155. MasterRecipeList();
  156. virtual ~MasterRecipeList();
  157. bool AddRecipe(Recipe *recipe);
  158. Recipe * GetRecipe(int32 recipe_id);
  159. void ClearRecipes();
  160. int32 Size();
  161. EQ2Packet* GetRecipePacket(int32 recipe_id, Client *client = 0, bool display = false, int8 packet_type = 0);
  162. /// <summary>Gets all the recipes for the given book name</summary>
  163. /// <param name="book_name">Book name to get recipes for</param>
  164. /// <returns>A vector of all the recipes for the given book</returns>
  165. vector<Recipe*> GetRecipes(const char* book_name);
  166. /// <summary>Gets a recipe with the given name</summary>
  167. /// <param name='name'>The name of the recipe to get</param>
  168. /// <returns>Recipe* whos name matches the given name</returns>
  169. Recipe* GetRecipeByName(const char* name);
  170. private:
  171. Mutex m_recipes;
  172. map<int32, Recipe *> recipes;
  173. };
  174. class MasterRecipeBookList {
  175. public:
  176. MasterRecipeBookList();
  177. virtual ~MasterRecipeBookList();
  178. bool AddRecipeBook(Recipe *recipe);
  179. Recipe * GetRecipeBooks(int32 recipe_id);
  180. void ClearRecipeBooks();
  181. int32 Size();
  182. private:
  183. Mutex m_recipeBooks;
  184. map<int32, Recipe *> recipeBooks;
  185. };
  186. class PlayerRecipeList {
  187. public:
  188. PlayerRecipeList();
  189. virtual ~PlayerRecipeList();
  190. bool AddRecipe(Recipe *recipe);
  191. Recipe * GetRecipe(int32 recipe_id);
  192. void ClearRecipes();
  193. int32 Size();
  194. map<int32, Recipe *> * GetRecipes() {return &recipes;}
  195. private:
  196. map<int32, Recipe *> recipes;
  197. };
  198. class PlayerRecipeBookList {
  199. public:
  200. PlayerRecipeBookList();
  201. virtual ~PlayerRecipeBookList();
  202. bool AddRecipeBook(Recipe *recipe);
  203. bool HasRecipeBook(int32 book_id);
  204. Recipe * GetRecipeBook(int32 recipe_id);
  205. void ClearRecipeBooks();
  206. int32 Size();
  207. map<int32, Recipe *> * GetRecipeBooks() {return &recipeBooks;}
  208. private:
  209. map<int32, Recipe *> recipeBooks;
  210. };
  211. #endif