Recipe.cpp 23 KB

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