9
3

Recipe.h 7.9 KB

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