Recipe.h 8.7 KB

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