Recipe.h 8.5 KB

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