9
3

Recipe.h 9.4 KB

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