Recipe.h 9.2 KB

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