Recipe.cpp 23 KB

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