Recipe.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. #include <assert.h>
  17. #include "../../common/debug.h"
  18. #include "../../common/Log.h"
  19. #include "../../common/database.h"
  20. #include "Recipe.h"
  21. #include "../../common/ConfigReader.h"
  22. #include "../Items/Items.h"
  23. extern ConfigReader configReader;
  24. extern MasterItemList master_item_list;
  25. Recipe::Recipe() {
  26. id = 0;
  27. book_id = 0;
  28. memset(name, 0, sizeof(name));
  29. memset(book_name, 0, sizeof(book_name));
  30. memset(book, 0, sizeof(book));
  31. memset(device, 0, sizeof(device));
  32. level = 0;
  33. tier = 0;
  34. icon = 0;
  35. skill = 0;
  36. technique = 0;
  37. knowledge = 0;
  38. classes = 0;
  39. unknown2 = 0;
  40. unknown3 = 0;
  41. unknown4 = 0;
  42. }
  43. Recipe::~Recipe() {
  44. map<int8, RecipeProducts*>::iterator itr;
  45. for (itr = products.begin(); itr != products.end(); itr++)
  46. safe_delete(itr->second);
  47. }
  48. Recipe::Recipe(Recipe *in){
  49. assert(in);
  50. id = in->GetID();
  51. book_id = in->GetBookID();
  52. strncpy(name, in->GetName(), sizeof(name));
  53. strncpy(book_name, in->GetBookName(), sizeof(book_name));
  54. strncpy(book, in->GetBook(), sizeof(book));
  55. strncpy(device, in->GetDevice(), sizeof(device));
  56. level = in->GetLevel();
  57. tier = in->GetTier();
  58. icon = in->GetIcon();
  59. skill = in->GetSkill();
  60. technique = in->GetTechnique();
  61. knowledge = in->GetKnowledge();
  62. classes = in->GetClasses();
  63. unknown2 = in->GetUnknown2();
  64. unknown3 = in->GetUnknown3();
  65. unknown4 = in->GetUnknown4();
  66. }
  67. MasterRecipeList::MasterRecipeList() {
  68. m_recipes.SetName("MasterRecipeList::recipes");
  69. }
  70. MasterRecipeList::~MasterRecipeList() {
  71. ClearRecipes();
  72. }
  73. bool MasterRecipeList::AddRecipe(Recipe *recipe) {
  74. bool ret = false;
  75. int32 id;
  76. assert(recipe);
  77. id = recipe->GetID();
  78. m_recipes.writelock(__FUNCTION__, __LINE__);
  79. if (recipes.count(id) == 0) {
  80. recipes[id] = recipe;
  81. ret = true;
  82. }
  83. m_recipes.releasewritelock(__FUNCTION__, __LINE__);
  84. return ret;
  85. }
  86. Recipe * MasterRecipeList::GetRecipe(int32 recipe_id) {
  87. Recipe *ret = 0;
  88. m_recipes.readlock(__FUNCTION__, __LINE__);
  89. if (recipes.count(recipe_id) > 0)
  90. ret = recipes[recipe_id];
  91. m_recipes.releasereadlock(__FUNCTION__, __LINE__);
  92. return ret;
  93. }
  94. Recipe* MasterRecipeList::GetRecipeByName(const char* name) {
  95. Recipe* ret = 0;
  96. map<int32, Recipe*>::iterator itr;
  97. m_recipes.readlock(__FUNCTION__, __LINE__);
  98. for (itr = recipes.begin(); itr != recipes.end(); itr++) {
  99. if (::ToLower(string(name)) == ::ToLower(string(itr->second->GetName()))) {
  100. ret = itr->second;
  101. break;
  102. }
  103. }
  104. m_recipes.releasereadlock(__FUNCTION__, __LINE__);
  105. return ret;
  106. }
  107. void MasterRecipeList::ClearRecipes() {
  108. map<int32, Recipe *>::iterator itr;
  109. m_recipes.writelock(__FUNCTION__, __LINE__);
  110. for (itr = recipes.begin(); itr != recipes.end(); itr++)
  111. safe_delete(itr->second);
  112. recipes.clear();
  113. m_recipes.releasewritelock(__FUNCTION__, __LINE__);
  114. }
  115. int32 MasterRecipeList::Size() {
  116. int32 ret;
  117. m_recipes.readlock(__FUNCTION__, __LINE__);
  118. ret = (int32)recipes.size();
  119. m_recipes.releasereadlock(__FUNCTION__, __LINE__);
  120. return ret;
  121. }
  122. vector<Recipe*>* MasterRecipeList::GetRecipes(const char* book_name) {
  123. vector<Recipe*>* ret = new vector<Recipe*>;
  124. map<int32, Recipe *>::iterator itr;
  125. m_recipes.writelock(__FUNCTION__, __LINE__);
  126. for (itr = recipes.begin(); itr != recipes.end(); itr++) {
  127. if (::ToLower(string(book_name)) == ::ToLower(string(itr->second->GetBook())))
  128. ret->push_back(itr->second);
  129. }
  130. m_recipes.releasewritelock(__FUNCTION__, __LINE__);
  131. return ret;
  132. }
  133. PlayerRecipeList::PlayerRecipeList(){
  134. }
  135. PlayerRecipeList::~PlayerRecipeList(){
  136. ClearRecipes();
  137. }
  138. bool PlayerRecipeList::AddRecipe(Recipe *recipe){
  139. assert(recipe);
  140. if(recipes.count(recipe->GetID()) == 0){
  141. recipes[recipe->GetID()] = recipe;
  142. return true;
  143. }
  144. return false;
  145. }
  146. Recipe * PlayerRecipeList::GetRecipe(int32 recipe_id){
  147. if (recipes.count(recipe_id) > 0)
  148. return recipes[recipe_id];
  149. return 0;
  150. }
  151. void PlayerRecipeList::ClearRecipes(){
  152. map<int32, Recipe *>::iterator itr;
  153. for (itr = recipes.begin(); itr != recipes.end(); itr++)
  154. safe_delete(itr->second);
  155. recipes.clear();
  156. }
  157. MasterRecipeBookList::MasterRecipeBookList(){
  158. m_recipeBooks.SetName("MasterRecipeBookList::recipeBooks");
  159. }
  160. MasterRecipeBookList::~MasterRecipeBookList(){
  161. ClearRecipeBooks();
  162. }
  163. bool MasterRecipeBookList::AddRecipeBook(Recipe *recipe){
  164. bool ret = false;
  165. int32 id = 0;
  166. assert(recipe);
  167. id = recipe->GetBookID();
  168. m_recipeBooks.writelock(__FUNCTION__, __LINE__);
  169. if(recipeBooks.count(id) == 0){
  170. recipeBooks[id] = recipe;
  171. ret = true;
  172. }
  173. m_recipeBooks.releasewritelock(__FUNCTION__, __LINE__);
  174. return ret;
  175. }
  176. Recipe * MasterRecipeBookList::GetRecipeBooks(int32 recipebook_id){
  177. Recipe *ret = 0;
  178. m_recipeBooks.readlock(__FUNCTION__, __LINE__);
  179. if (recipeBooks.count(recipebook_id) > 0)
  180. ret = recipeBooks[recipebook_id];
  181. m_recipeBooks.releasereadlock(__FUNCTION__, __LINE__);
  182. return ret;
  183. }
  184. void MasterRecipeBookList::ClearRecipeBooks(){
  185. map<int32, Recipe *>::iterator itr;
  186. m_recipeBooks.writelock(__FUNCTION__, __LINE__);
  187. for (itr = recipeBooks.begin(); itr != recipeBooks.end(); itr++)
  188. safe_delete(itr->second);
  189. recipeBooks.clear();
  190. m_recipeBooks.releasewritelock(__FUNCTION__, __LINE__);
  191. }
  192. int32 MasterRecipeBookList::Size(){
  193. int32 ret = 0;
  194. m_recipeBooks.readlock(__FUNCTION__, __LINE__);
  195. ret = (int32)recipeBooks.size();
  196. m_recipeBooks.releasereadlock(__FUNCTION__, __LINE__);
  197. return ret;
  198. }
  199. EQ2Packet* MasterRecipeList::GetRecipePacket(int32 recipe_id, Client* client, bool display, int8 packet_type){
  200. Recipe *recipe = GetRecipe(recipe_id);
  201. if(recipe){
  202. LogWrite(TRADESKILL__DEBUG, 5, "Recipes", "Recipe ID: %u Recipe Name: %s", recipe->GetID(), recipe->GetName());
  203. return recipe->SerializeRecipe(client, recipe, display, packet_type);
  204. }
  205. return 0;
  206. }
  207. PlayerRecipeBookList::PlayerRecipeBookList(){
  208. }
  209. PlayerRecipeBookList::~PlayerRecipeBookList(){
  210. ClearRecipeBooks();
  211. }
  212. bool PlayerRecipeBookList::AddRecipeBook(Recipe *recipe){
  213. assert(recipe);
  214. if(recipeBooks.count(recipe->GetBookID()) == 0){
  215. recipeBooks[recipe->GetBookID()] = recipe;
  216. return true;
  217. }
  218. return false;
  219. }
  220. Recipe * PlayerRecipeBookList::GetRecipeBook(int32 recipebook_id){
  221. if(recipeBooks.count(recipebook_id) > 0)
  222. return recipeBooks[recipebook_id];
  223. return 0;
  224. }
  225. bool PlayerRecipeBookList::HasRecipeBook(int32 book_id) {
  226. if (recipeBooks.count(book_id) > 0)
  227. return true;
  228. return false;
  229. }
  230. void PlayerRecipeBookList::ClearRecipeBooks(){
  231. map<int32, Recipe*>::iterator itr;
  232. for(itr = recipeBooks.begin(); itr != recipeBooks.end(); itr++)
  233. safe_delete(itr->second);
  234. recipeBooks.clear();
  235. }
  236. EQ2Packet * Recipe::SerializeRecipe(Client *client, Recipe *recipe, bool display, int8 packet_type, int8 subpacket_type, const char *struct_name){
  237. int16 version = 1;
  238. Item* item = 0;
  239. RecipeProducts* rp = 0;
  240. vector<int32>::iterator itr;
  241. int8 i = 0;
  242. int32 firstID = 0;
  243. int32 primary_comp_id = 0;
  244. if(client)
  245. version = client->GetVersion();
  246. if(!struct_name)
  247. struct_name = "WS_ExamineRecipeInfo";
  248. PacketStruct *packet = configReader.getStruct(struct_name, version);
  249. if(display)
  250. packet->setSubstructDataByName("info_header", "show_name", 1);
  251. else
  252. packet->setSubstructDataByName("info_header", "show_popup", 1);
  253. if(packet_type > 0)
  254. packet->setSubstructDataByName("info_header", "packettype", packet_type*256 + 0xFE);
  255. else
  256. if(version == 1096)
  257. packet->setSubstructDataByName("info_header", "packettype",0x35FE);
  258. if (version == 1208)
  259. packet->setSubstructDataByName("info_header", "packettype", 0x45FE);
  260. if(version >= 57048)
  261. packet->setSubstructDataByName("info_header", "packettype",0x48FE);
  262. if(subpacket_type == 0)
  263. subpacket_type = 0x02;
  264. packet->setSubstructDataByName("info_header", "packetsubtype", subpacket_type);
  265. packet->setSubstructDataByName("recipe_info", "id", recipe->GetID());
  266. packet->setSubstructDataByName("recipe_info", "unknown", 3);
  267. packet->setSubstructDataByName("recipe_info", "level", recipe->GetLevel());
  268. packet->setSubstructDataByName("recipe_info", "technique", recipe->GetTechnique());
  269. packet->setSubstructDataByName("recipe_info", "skill_level", 50); //50
  270. packet->setSubstructDataByName("recipe_info", "knowledge", recipe->GetKnowledge());
  271. packet->setSubstructDataByName("recipe_info", "device", recipe->GetDevice());
  272. packet->setSubstructDataByName("recipe_info", "icon", recipe->GetIcon());
  273. packet->setSubstructDataByName("recipe_info", "unknown3", 1);
  274. packet->setSubstructDataByName("recipe_info", "adventure_id", 0xFF);
  275. packet->setSubstructDataByName("recipe_info", "tradeskill_id", client ? client->GetPlayer()->GetTradeskillClass() : 0);
  276. packet->setSubstructDataByName("recipe_info", "unknown4", 100);
  277. packet->setSubstructDataByName("recipe_info", "unknown4aa", 1);
  278. packet->setSubstructDataByName("recipe_info", "unknown5a", 20);
  279. packet->setSubstructDataByName("recipe_info", "product_classes", recipe->GetClasses());
  280. packet->setSubstructDataByName("recipe_info", "show_previous", 15);
  281. packet->setSubstructDataByName("recipe_info", "previous1_icon", 186);
  282. packet->setSubstructDataByName("recipe_info", "previous1_name", "previous1_name");
  283. packet->setSubstructDataByName("recipe_info", "previous1_qty", 1);
  284. packet->setSubstructDataByName("recipe_info", "previous1_item_id", 4142);
  285. packet->setSubstructDataByName("recipe_info", "previous1_item_crc", -853046774);
  286. packet->setSubstructDataByName("recipe_info", "previous2_icon", 186);
  287. packet->setSubstructDataByName("recipe_info", "previous2_name", "previous2_name");
  288. packet->setSubstructDataByName("recipe_info", "previous2_qty", 1);
  289. packet->setSubstructDataByName("recipe_info", "previous2_item_id", 4142);
  290. packet->setSubstructDataByName("recipe_info", "previous2_item_crc", -853046774);
  291. packet->setSubstructDataByName("recipe_info", "previous3_icon", 186);
  292. packet->setSubstructDataByName("recipe_info", "previous3_name", "previous3_name");
  293. packet->setSubstructDataByName("recipe_info", "previous3_qty", 1);
  294. packet->setSubstructDataByName("recipe_info", "previous3_item_id", 4142);
  295. packet->setSubstructDataByName("recipe_info", "previous3_item_crc", -853046774);
  296. packet->setSubstructDataByName("recipe_info", "firstbar_icon", 186);
  297. packet->setSubstructDataByName("recipe_info", "firstbar_name", "firstbar_name");
  298. packet->setSubstructDataByName("recipe_info", "firstbar_qty", 1);
  299. packet->setSubstructDataByName("recipe_info", "firstbar_item_id", 4142);
  300. packet->setSubstructDataByName("recipe_info", "firstbar_item_crc", -853046774);
  301. packet->setSubstructDataByName("recipe_info", "secondbar_icon", 186);
  302. packet->setSubstructDataByName("recipe_info", "secondbar_name", "secondbar_name");
  303. packet->setSubstructDataByName("recipe_info", "secondbar_qty", 1);
  304. packet->setSubstructDataByName("recipe_info", "secondbar_item_id", 4142);
  305. packet->setSubstructDataByName("recipe_info", "secondbar_item_crc", -853046774);
  306. packet->setSubstructDataByName("recipe_info", "thirdbar_icon", 198);
  307. packet->setSubstructDataByName("recipe_info", "thirdbar_name", "thirdbar_name");
  308. packet->setSubstructDataByName("recipe_info", "thirdbar_qty", 1);
  309. packet->setSubstructDataByName("recipe_info", "thirdbar_item_id", 12098);
  310. packet->setSubstructDataByName("recipe_info", "thirdbar_item_crc", -2065846136);
  311. item = master_item_list.GetItemByName(recipe->GetName());
  312. if(item) {
  313. packet->setSubstructDataByName("recipe_info", "product_icon", item->details.icon); //item->details.icon);
  314. packet->setSubstructDataByName("recipe_info", "product_name", item->name.c_str()); //item->name);
  315. packet->setSubstructDataByName("recipe_info", "product_qty", 1);
  316. packet->setSubstructDataByName("recipe_info", "product_item_id", item->details.item_id); //item->details.item_id);
  317. packet->setSubstructDataByName("recipe_info", "product_item_crc", 0); //item->details.item_crc);
  318. }
  319. rp = recipe->products[0];
  320. if (rp->byproduct_id > 0) {
  321. item = 0;
  322. item = master_item_list.GetItem(rp->byproduct_id);
  323. if (item) {
  324. packet->setSubstructDataByName("recipe_info", "byproduct_icon", item->details.icon);//11
  325. packet->setSubstructDataByName("recipe_info", "byproduct_id", item->details.item_id);
  326. }
  327. }
  328. //string xxx = recipe->
  329. //item = master_item_list.GetItemByName (recipe->GetBuild1ComponentTitle());
  330. // Reset item to 0
  331. item = 0;
  332. // Check to see if we have a primary component (slot = 0)
  333. if (recipe->components.count(0) > 0) {
  334. vector<int32> rc = recipe->components[0];
  335. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  336. if (firstID == 0)
  337. firstID = *itr;
  338. item = master_item_list.GetItem(*itr);
  339. item = 0;
  340. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  341. if (item) {
  342. packet->setSubstructDataByName("recipe_info", "primary_qty_avail", item->details.count);
  343. packet->setSubstructDataByName("recipe_info", "primary_comp", recipe->primary_build_comp_title);
  344. }
  345. }
  346. // store the id of the primary comp
  347. primary_comp_id = firstID;
  348. // Set the default item id to the first component id
  349. item = 0;
  350. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  351. if (item) {
  352. }
  353. // Reset the variables we will reuse
  354. i = 0;
  355. firstID = 0;
  356. item = 0;
  357. }
  358. else {
  359. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no primary component");
  360. }
  361. int8 total_build_components = 0;
  362. if (recipe->components.count(1) > 0)
  363. total_build_components++;
  364. if (recipe->components.count(2))
  365. total_build_components++;
  366. if (recipe->components.count(3))
  367. total_build_components++;
  368. if (recipe->components.count(4))
  369. total_build_components++;
  370. if (total_build_components > 0) {
  371. packet->setSubstructArrayLengthByName("recipe_info", "num_comps", total_build_components);
  372. for (int8 index = 0; index < 4; index++) {
  373. if (recipe->components.count(index + 1) == 0)
  374. continue;
  375. //packet->setArrayDataByName("build_slot", index, index);
  376. vector<int32> rc = recipe->components[index + 1];
  377. //packet->setSubArrayLengthByName("num_build_choices", rc.size(), index);
  378. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  379. if (firstID == 0)
  380. firstID = *itr;
  381. string comp_title;
  382. int8 comp_qty;
  383. if (index == 0) {
  384. comp_title = recipe->build1_comp_title;
  385. comp_qty = recipe->build_comp_qty;
  386. item = master_item_list.GetItem(*itr);
  387. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  388. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  389. item = master_item_list.GetItem(*itr);
  390. item = 0;
  391. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  392. if (item) {
  393. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  394. }
  395. }
  396. else if (index == 1) {
  397. comp_title = recipe->build2_comp_title;
  398. comp_qty = recipe->build2_comp_qty;
  399. item = master_item_list.GetItem(*itr);
  400. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  401. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  402. item = master_item_list.GetItem(*itr);
  403. item = 0;
  404. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  405. if (item) {
  406. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  407. }
  408. }
  409. else if (index == 2) {
  410. comp_title = recipe->build3_comp_title;
  411. comp_qty = recipe->build3_comp_qty;
  412. item = master_item_list.GetItem(*itr);
  413. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  414. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  415. item = master_item_list.GetItem(*itr);
  416. item = 0;
  417. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  418. if (item) {
  419. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  420. }
  421. }
  422. else if (index == 3) {
  423. comp_title = recipe->build4_comp_title;
  424. comp_qty = recipe->build4_comp_qty;
  425. item = master_item_list.GetItem(*itr);
  426. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  427. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  428. item = master_item_list.GetItem(*itr);
  429. item = 0;
  430. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  431. if (item) {
  432. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  433. }
  434. }
  435. //item = master_item_list.GetItem(*itr);
  436. //packet->setArrayDataByName("build_comp", comp_title.c_str(), index -1);
  437. //packet->setArrayDataByName("build_comp_qty", comp_qty, index - 1);
  438. //item = master_item_list.GetItem(*itr);
  439. //item = 0;
  440. //item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  441. //if (item) {
  442. // packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index - 1);
  443. //}
  444. item = 0;
  445. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  446. if (item) {
  447. //packet->setSubArrayDataByName("build_total_quantity", item->details.count, index, i);
  448. }
  449. }
  450. // Set the default item id to the first component id
  451. //packet->setArrayDataByName("build_item_selected", 1, index);
  452. //packet->setArrayDataByName("build_selected_item_id", firstID, index);
  453. item = 0;
  454. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  455. int8 qty = 0;
  456. if (item) {
  457. qty = (int8)item->details.count;
  458. if (qty > 0 && firstID == primary_comp_id)
  459. qty -= 1;
  460. }
  461. if (index == 0) {
  462. // packet->setArrayDataByName("build_title", recipe->GetBuild1ComponentTitle(), index);
  463. //packet->setArrayDataByName("build_qty", recipe->GetBuild1ComponentQuantity(), index);
  464. if (item) {
  465. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild1ComponentQuantity()), index);
  466. }
  467. }
  468. else if (index == 1) {
  469. // packet->setArrayDataByName("build_title", recipe->GetBuild2ComponentTitle(), index);
  470. // packet->setArrayDataByName("build_qty", recipe->GetBuild2ComponentQuantity(), index);
  471. if (item) {
  472. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild2ComponentQuantity()), index);
  473. }
  474. }
  475. else if (index == 2) {
  476. // packet->setArrayDataByName("build_title", recipe->GetBuild3ComponentTitle(), index);
  477. // packet->setArrayDataByName("build_qty", recipe->GetBuild3ComponentQuantity(), index);
  478. if (item) {
  479. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild3ComponentQuantity()), index);
  480. }
  481. }
  482. else {
  483. // packet->setArrayDataByName("build_title", recipe->GetBuild4ComponentTitle(), index);
  484. // packet->setArrayDataByName("build_qty", recipe->GetBuild4ComponentQuantity(), index);
  485. if (item) {
  486. //packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild4ComponentQuantity()), index);
  487. }
  488. }
  489. // Reset the variables we will reuse
  490. i = 0;
  491. firstID = 0;
  492. item = 0;
  493. }
  494. }
  495. //packet->setArrayDataByName("build_comp", "build_comp1", 0);
  496. //packet->setArrayDataByName("build_comp_qty", 1, 0);
  497. //packet->setArrayDataByName("build_comp_qty_avail", 24, 0);
  498. //packet->setArrayDataByName("build_comp", "build_comp2", 1);
  499. //packet->setArrayDataByName("build_comp_qty", 1, 1);
  500. //packet->setArrayDataByName("build_comp_qty_avail", 16, 1);
  501. //packet->setArrayDataByName("build_comp", "build_comp3", 2);
  502. //packet->setArrayDataByName("build_comp_qty", 1, 2);
  503. //packet->setArrayDataByName("build_comp_qty_avail", 15, 2);
  504. // Check to see if we have a fuel component (slot = 5)
  505. if (recipe->components.count(5) > 0) {
  506. vector<int32> rc = recipe->components[5];
  507. //packet->setArrayLengthByName("num_fuel_choices", rc.size());
  508. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  509. if (firstID == 0)
  510. firstID = *itr;
  511. item = master_item_list.GetItem(*itr);
  512. //packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", item->details.count);
  513. item = 0;
  514. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  515. if (item) {
  516. packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", item->details.count);
  517. }
  518. }
  519. // Set the default item id to the first component id
  520. //packet->setDataByName("fuel_selected_item_id", firstID);
  521. //packet->setDataByName("fuel_item_selected", 1);
  522. item = 0;
  523. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  524. if (item) {
  525. // packet->setDataByName("fuel_selected_item_qty", min(recipe->GetFuelComponentQuantity(), (int8)item->details.count));
  526. }
  527. //packet->setDataByName("fuel_title", recipe->GetFuelComponentTitle());
  528. //packet->setDataByName("fuel_qty", recipe->GetFuelComponentQuantity());
  529. // Reset the variables we will reuse
  530. i = 0;
  531. firstID = 0;
  532. item = 0;
  533. }
  534. else {
  535. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no fuel component");
  536. }
  537. packet->setSubstructDataByName("recipe_info", "fuel_comp", recipe->fuel_comp_title);
  538. packet->setSubstructDataByName("recipe_info", "fuel_comp_qty", recipe->fuel_comp_qty);
  539. //packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", 10);
  540. packet->setSubstructDataByName("recipe_info", "build_comp_qty_avail_flag", 1);
  541. packet->setSubstructDataByName("recipe_info", "unknown6", 4, 0);
  542. packet->setSubstructDataByName("recipe_info", "min_product", 1);
  543. packet->setSubstructDataByName("recipe_info", "max_product", 1);
  544. packet->setSubstructDataByName("recipe_info", "available_flag", 4);
  545. packet->setSubstructDataByName("recipe_info", "not_commissionable", 1);
  546. packet->setSubstructDataByName("recipe_info", "recipe_name", recipe->GetName());
  547. packet->setSubstructDataByName("recipe_info", "recipe_description", "The art of sculpting metal into a candelabra.");
  548. //packet->PrintPacket();
  549. EQ2Packet* data = packet->serialize();
  550. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  551. safe_delete(packet);
  552. safe_delete(data);
  553. //DumpPacket(app);
  554. return app;
  555. }
  556. void Recipe::AddBuildComp(int32 itemID, int8 slot) {
  557. components[slot].push_back(itemID);
  558. }