9
3

Recipe.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. int8 GetTotalBuildComponents();
  132. bool ProvidedAllRequiredComponents(Client* client, vector<Item*>* player_components, vector<pair<int32,int16>>* player_component_pair_qty);
  133. bool PlayerHasComponentByItemID(Client* client, vector<Item*>* player_components, vector<pair<int32,int16>>* player_component_pair_qty, int32 item_id, int8 required_qty);
  134. int8 GetItemRequiredQuantity(int32 item_id);
  135. private:
  136. int32 id;
  137. int32 soe_id;
  138. int32 book_id;
  139. char name[256];
  140. char description[256];
  141. char book_name[256];
  142. char book[256];
  143. char device[30];
  144. int8 level;
  145. int8 tier;
  146. int16 icon;
  147. int32 skill;
  148. int32 technique;
  149. int32 knowledge;
  150. int8 device_sub_type;
  151. int32 classes;
  152. int8 unknown1;
  153. int32 unknown2;
  154. int32 unknown3;
  155. int32 unknown4;
  156. int32 product_item_id;
  157. char product_name[256];
  158. int8 product_qty;
  159. char primary_build_comp_title[256];
  160. char build1_comp_title[256];
  161. char build2_comp_title[256];
  162. char build3_comp_title[256];
  163. char build4_comp_title[256];
  164. char fuel_comp_title[256];
  165. int16 build1_comp_qty;
  166. int16 build2_comp_qty;
  167. int16 build3_comp_qty;
  168. int16 build4_comp_qty;
  169. int16 fuel_comp_qty;
  170. int16 primary_comp_qty;
  171. int8 highestStage;
  172. };
  173. class MasterRecipeList {
  174. public:
  175. MasterRecipeList();
  176. virtual ~MasterRecipeList();
  177. bool AddRecipe(Recipe *recipe);
  178. Recipe* GetRecipe(int32 recipe_id);
  179. Recipe* GetRecipeByCRC(int32 recipe_crc);
  180. void ClearRecipes();
  181. int32 Size();
  182. EQ2Packet* GetRecipePacket(int32 recipe_id, Client *client = 0, bool display = false, int8 packet_type = 0);
  183. /// <summary>Gets all the recipes for the given book name</summary>
  184. /// <param name="book_name">Book name to get recipes for</param>
  185. /// <returns>A vector of all the recipes for the given book</returns>
  186. vector<Recipe*> GetRecipes(const char* book_name);
  187. /// <summary>Gets a recipe with the given name</summary>
  188. /// <param name='name'>The name of the recipe to get</param>
  189. /// <returns>Recipe* whos name matches the given name</returns>
  190. Recipe* GetRecipeByName(const char* name);
  191. private:
  192. Mutex m_recipes;
  193. map<int32, Recipe *> recipes;
  194. map<int32, Recipe *> recipes_crc;
  195. };
  196. class MasterRecipeBookList {
  197. public:
  198. MasterRecipeBookList();
  199. virtual ~MasterRecipeBookList();
  200. bool AddRecipeBook(Recipe *recipe);
  201. Recipe * GetRecipeBooks(int32 recipe_id);
  202. void ClearRecipeBooks();
  203. int32 Size();
  204. private:
  205. Mutex m_recipeBooks;
  206. map<int32, Recipe *> recipeBooks;
  207. };
  208. class PlayerRecipeList {
  209. public:
  210. PlayerRecipeList();
  211. virtual ~PlayerRecipeList();
  212. bool AddRecipe(Recipe *recipe);
  213. Recipe * GetRecipe(int32 recipe_id);
  214. void ClearRecipes();
  215. bool RemoveRecipe(int32 recipe_id);
  216. int32 Size();
  217. map<int32, Recipe *> * GetRecipes() {return &recipes;}
  218. private:
  219. map<int32, Recipe *> recipes;
  220. mutable std::shared_mutex player_recipe_mutex;
  221. };
  222. class PlayerRecipeBookList {
  223. public:
  224. PlayerRecipeBookList();
  225. virtual ~PlayerRecipeBookList();
  226. bool AddRecipeBook(Recipe *recipe);
  227. bool HasRecipeBook(int32 book_id);
  228. Recipe * GetRecipeBook(int32 recipe_id);
  229. void ClearRecipeBooks();
  230. int32 Size();
  231. map<int32, Recipe *> * GetRecipeBooks() {return &recipeBooks;}
  232. private:
  233. map<int32, Recipe *> recipeBooks;
  234. };
  235. #endif