Recipe.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. vector<RecipeComp> comp_list;
  249. int8 i = 0;
  250. int32 firstID = 0;
  251. int32 primary_comp_id = 0;
  252. if(client)
  253. version = client->GetVersion();
  254. if(!struct_name)
  255. struct_name = "WS_ExamineRecipeInfo";
  256. PacketStruct *packet = configReader.getStruct(struct_name, version);
  257. if(display)
  258. packet->setSubstructDataByName("info_header", "show_name", 1);
  259. else
  260. packet->setSubstructDataByName("info_header", "show_popup", 1);
  261. if(packet_type > 0)
  262. packet->setSubstructDataByName("info_header", "packettype", GetItemPacketType(packet->GetVersion()));
  263. else
  264. if(version == 1096)
  265. packet->setSubstructDataByName("info_header", "packettype",0x35FE);
  266. if (version == 1208)
  267. packet->setSubstructDataByName("info_header", "packettype", 0x45FE);
  268. if(version >= 57048)
  269. packet->setSubstructDataByName("info_header", "packettype",0x48FE);
  270. if(subpacket_type == 0)
  271. subpacket_type = 0x02;
  272. packet->setSubstructDataByName("info_header", "packetsubtype", subpacket_type);
  273. packet->setSubstructDataByName("recipe_info", "id", recipe->GetID());
  274. packet->setSubstructDataByName("recipe_info", "unknown", 3);
  275. packet->setSubstructDataByName("recipe_info", "level", recipe->GetLevel());
  276. packet->setSubstructDataByName("recipe_info", "technique", recipe->GetTechnique());
  277. packet->setSubstructDataByName("recipe_info", "skill_level", 50); //50
  278. packet->setSubstructDataByName("recipe_info", "knowledge", recipe->GetKnowledge());
  279. packet->setSubstructDataByName("recipe_info", "device", recipe->GetDevice());
  280. packet->setSubstructDataByName("recipe_info", "icon", recipe->GetIcon());
  281. packet->setSubstructDataByName("recipe_info", "unknown3", 1);
  282. packet->setSubstructDataByName("recipe_info", "adventure_id", 0xFF);
  283. packet->setSubstructDataByName("recipe_info", "tradeskill_id", client ? client->GetPlayer()->GetTradeskillClass() : 0);
  284. packet->setSubstructDataByName("recipe_info", "unknown4", 100);
  285. packet->setSubstructDataByName("recipe_info", "unknown4aa", 1);
  286. packet->setSubstructDataByName("recipe_info", "unknown5a", 20);
  287. packet->setSubstructDataByName("recipe_info", "product_classes", recipe->GetClasses());
  288. packet->setSubstructDataByName("recipe_info", "show_previous", 15);
  289. packet->setSubstructDataByName("recipe_info", "previous1_icon", 186);
  290. packet->setSubstructDataByName("recipe_info", "previous1_name", "previous1_name");
  291. packet->setSubstructDataByName("recipe_info", "previous1_qty", 1);
  292. packet->setSubstructDataByName("recipe_info", "previous1_item_id", 4142);
  293. packet->setSubstructDataByName("recipe_info", "previous1_item_crc", -853046774);
  294. packet->setSubstructDataByName("recipe_info", "previous2_icon", 186);
  295. packet->setSubstructDataByName("recipe_info", "previous2_name", "previous2_name");
  296. packet->setSubstructDataByName("recipe_info", "previous2_qty", 1);
  297. packet->setSubstructDataByName("recipe_info", "previous2_item_id", 4142);
  298. packet->setSubstructDataByName("recipe_info", "previous2_item_crc", -853046774);
  299. packet->setSubstructDataByName("recipe_info", "previous3_icon", 186);
  300. packet->setSubstructDataByName("recipe_info", "previous3_name", "previous3_name");
  301. packet->setSubstructDataByName("recipe_info", "previous3_qty", 1);
  302. packet->setSubstructDataByName("recipe_info", "previous3_item_id", 4142);
  303. packet->setSubstructDataByName("recipe_info", "previous3_item_crc", -853046774);
  304. packet->setSubstructDataByName("recipe_info", "firstbar_icon", 186);
  305. packet->setSubstructDataByName("recipe_info", "firstbar_name", "firstbar_name");
  306. packet->setSubstructDataByName("recipe_info", "firstbar_qty", 1);
  307. packet->setSubstructDataByName("recipe_info", "firstbar_item_id", 4142);
  308. packet->setSubstructDataByName("recipe_info", "firstbar_item_crc", -853046774);
  309. packet->setSubstructDataByName("recipe_info", "secondbar_icon", 186);
  310. packet->setSubstructDataByName("recipe_info", "secondbar_name", "secondbar_name");
  311. packet->setSubstructDataByName("recipe_info", "secondbar_qty", 1);
  312. packet->setSubstructDataByName("recipe_info", "secondbar_item_id", 4142);
  313. packet->setSubstructDataByName("recipe_info", "secondbar_item_crc", -853046774);
  314. packet->setSubstructDataByName("recipe_info", "thirdbar_icon", 198);
  315. packet->setSubstructDataByName("recipe_info", "thirdbar_name", "thirdbar_name");
  316. packet->setSubstructDataByName("recipe_info", "thirdbar_qty", 1);
  317. packet->setSubstructDataByName("recipe_info", "thirdbar_item_id", 12098);
  318. packet->setSubstructDataByName("recipe_info", "thirdbar_item_crc", -2065846136);
  319. item = master_item_list.GetItemByName(recipe->GetName());
  320. if(item) {
  321. packet->setSubstructDataByName("recipe_info", "product_icon", item->details.icon); //item->details.icon);
  322. packet->setSubstructDataByName("recipe_info", "product_name", item->name.c_str()); //item->name);
  323. packet->setSubstructDataByName("recipe_info", "product_qty", 1);
  324. packet->setSubstructDataByName("recipe_info", "product_item_id", item->details.item_id); //item->details.item_id);
  325. packet->setSubstructDataByName("recipe_info", "product_item_crc", 0); //item->details.item_crc);
  326. }
  327. rp = recipe->products[0];
  328. if (rp->byproduct_id > 0) {
  329. item = 0;
  330. item = master_item_list.GetItem(rp->byproduct_id);
  331. if (item) {
  332. packet->setSubstructDataByName("recipe_info", "byproduct_icon", item->details.icon);//11
  333. packet->setSubstructDataByName("recipe_info", "byproduct_id", item->details.item_id);
  334. }
  335. }
  336. //string xxx = recipe->
  337. //item = master_item_list.GetItemByName (recipe->GetBuild1ComponentTitle());
  338. // Reset item to 0
  339. item = 0;
  340. // Check to see if we have a primary component (slot = 0)
  341. if (recipe->components.count(0) > 0) {
  342. vector<int32> rc = recipe->components[0];
  343. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  344. if (firstID == 0)
  345. firstID = *itr;
  346. item = master_item_list.GetItem(*itr);
  347. item = 0;
  348. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  349. if (item) {
  350. packet->setSubstructDataByName("recipe_info", "primary_qty_avail", item->details.count);
  351. packet->setSubstructDataByName("recipe_info", "primary_comp", recipe->primary_build_comp_title);
  352. break;
  353. }
  354. }
  355. // store the id of the primary comp
  356. primary_comp_id = firstID;
  357. // Set the default item id to the first component id
  358. item = 0;
  359. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  360. if (item) {
  361. }
  362. // Reset the variables we will reuse
  363. i = 0;
  364. firstID = 0;
  365. item = 0;
  366. }
  367. else {
  368. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no primary component");
  369. }
  370. int8 total_build_components = 0;
  371. if (recipe->components.count(1) > 0)
  372. total_build_components++;
  373. if (recipe->components.count(2) > 0)
  374. total_build_components++;
  375. if (recipe->components.count(3) > 0)
  376. total_build_components++;
  377. if (recipe->components.count(4) > 0)
  378. total_build_components++;
  379. if (total_build_components > 0) {
  380. packet->setSubstructArrayLengthByName("recipe_info", "num_comps", total_build_components);
  381. for (int8 index = 0; index < 4; index++) {
  382. if (recipe->components.count(index + 1) == 0)
  383. continue;
  384. //packet->setArrayDataByName("build_slot", index, index);
  385. vector<int32> rc = recipe->components[index + 1];
  386. //packet->setSubArrayLengthByName("num_build_choices", rc.size(), index);
  387. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  388. if (firstID == 0)
  389. firstID = *itr;
  390. string comp_title;
  391. int8 comp_qty;
  392. if (index == 0) {
  393. comp_title = recipe->build1_comp_title;
  394. comp_qty = recipe->build_comp_qty;
  395. item = master_item_list.GetItem(*itr);
  396. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  397. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  398. item = master_item_list.GetItem(*itr);
  399. item = 0;
  400. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  401. if (item) {
  402. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  403. }
  404. }
  405. else if (index == 1) {
  406. comp_title = recipe->build2_comp_title;
  407. comp_qty = recipe->build2_comp_qty;
  408. item = master_item_list.GetItem(*itr);
  409. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  410. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  411. item = master_item_list.GetItem(*itr);
  412. item = 0;
  413. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  414. if (item) {
  415. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  416. break;
  417. }
  418. }
  419. else if (index == 2) {
  420. comp_title = recipe->build3_comp_title;
  421. comp_qty = recipe->build3_comp_qty;
  422. item = master_item_list.GetItem(*itr);
  423. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  424. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  425. item = master_item_list.GetItem(*itr);
  426. item = 0;
  427. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  428. if (item) {
  429. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  430. break;
  431. }
  432. }
  433. else if (index == 3) {
  434. comp_title = recipe->build4_comp_title;
  435. comp_qty = recipe->build4_comp_qty;
  436. item = master_item_list.GetItem(*itr);
  437. packet->setArrayDataByName("build_comp", comp_title.c_str(), index );
  438. packet->setArrayDataByName("build_comp_qty", comp_qty, index );
  439. item = master_item_list.GetItem(*itr);
  440. item = 0;
  441. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  442. if (item) {
  443. packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index );
  444. break;
  445. }
  446. }
  447. //item = master_item_list.GetItem(*itr);
  448. //packet->setArrayDataByName("build_comp", comp_title.c_str(), index -1);
  449. //packet->setArrayDataByName("build_comp_qty", comp_qty, index - 1);
  450. //item = master_item_list.GetItem(*itr);
  451. //item = 0;
  452. //item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  453. //if (item) {
  454. // packet->setArrayDataByName("build_comp_qty_avail", item->details.count, index - 1);
  455. //}
  456. item = 0;
  457. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  458. if (item) {
  459. //packet->setSubArrayDataByName("build_total_quantity", item->details.count, index, i);
  460. }
  461. }
  462. // Set the default item id to the first component id
  463. //packet->setArrayDataByName("build_item_selected", 1, index);
  464. //packet->setArrayDataByName("build_selected_item_id", firstID, index);
  465. item = 0;
  466. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  467. int8 qty = 0;
  468. if (item) {
  469. qty = (int8)item->details.count;
  470. if (qty > 0 && firstID == primary_comp_id)
  471. qty -= 1;
  472. }
  473. if (index == 0) {
  474. // packet->setArrayDataByName("build_title", recipe->GetBuild1ComponentTitle(), index);
  475. //packet->setArrayDataByName("build_qty", recipe->GetBuild1ComponentQuantity(), index);
  476. if (item) {
  477. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild1ComponentQuantity()), index);
  478. }
  479. }
  480. else if (index == 1) {
  481. // packet->setArrayDataByName("build_title", recipe->GetBuild2ComponentTitle(), index);
  482. // packet->setArrayDataByName("build_qty", recipe->GetBuild2ComponentQuantity(), index);
  483. if (item) {
  484. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild2ComponentQuantity()), index);
  485. }
  486. }
  487. else if (index == 2) {
  488. // packet->setArrayDataByName("build_title", recipe->GetBuild3ComponentTitle(), index);
  489. // packet->setArrayDataByName("build_qty", recipe->GetBuild3ComponentQuantity(), index);
  490. if (item) {
  491. // packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild3ComponentQuantity()), index);
  492. }
  493. }
  494. else {
  495. // packet->setArrayDataByName("build_title", recipe->GetBuild4ComponentTitle(), index);
  496. // packet->setArrayDataByName("build_qty", recipe->GetBuild4ComponentQuantity(), index);
  497. if (item) {
  498. //packet->setArrayDataByName("build_selected_item_qty", min(qty, recipe->GetBuild4ComponentQuantity()), index);
  499. }
  500. }
  501. // Reset the variables we will reuse
  502. i = 0;
  503. firstID = 0;
  504. item = 0;
  505. }
  506. }
  507. //packet->setArrayDataByName("build_comp", "build_comp1", 0);
  508. //packet->setArrayDataByName("build_comp_qty", 1, 0);
  509. //packet->setArrayDataByName("build_comp_qty_avail", 24, 0);
  510. //packet->setArrayDataByName("build_comp", "build_comp2", 1);
  511. //packet->setArrayDataByName("build_comp_qty", 1, 1);
  512. //packet->setArrayDataByName("build_comp_qty_avail", 16, 1);
  513. //packet->setArrayDataByName("build_comp", "build_comp3", 2);
  514. //packet->setArrayDataByName("build_comp_qty", 1, 2);
  515. //packet->setArrayDataByName("build_comp_qty_avail", 15, 2);
  516. // Check to see if we have a fuel component (slot = 5)
  517. if (recipe->components.count(5) > 0) {
  518. vector<int32> rc = recipe->components[5];
  519. //packet->setArrayLengthByName("num_fuel_choices", rc.size());
  520. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  521. if (firstID == 0)
  522. firstID = *itr;
  523. item = master_item_list.GetItem(*itr);
  524. //packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", item->details.count);
  525. item = 0;
  526. item = client->GetPlayer()->item_list.GetItemFromID((*itr));
  527. if (item) {
  528. packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", item->details.count);
  529. }
  530. }
  531. // Set the default item id to the first component id
  532. //packet->setDataByName("fuel_selected_item_id", firstID);
  533. //packet->setDataByName("fuel_item_selected", 1);
  534. item = 0;
  535. item = client->GetPlayer()->item_list.GetItemFromID(firstID);
  536. if (item) {
  537. // packet->setDataByName("fuel_selected_item_qty", min(recipe->GetFuelComponentQuantity(), (int8)item->details.count));
  538. }
  539. //packet->setDataByName("fuel_title", recipe->GetFuelComponentTitle());
  540. //packet->setDataByName("fuel_qty", recipe->GetFuelComponentQuantity());
  541. // Reset the variables we will reuse
  542. i = 0;
  543. firstID = 0;
  544. item = 0;
  545. }
  546. else {
  547. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no fuel component");
  548. }
  549. packet->setSubstructDataByName("recipe_info", "fuel_comp", recipe->fuel_comp_title);
  550. packet->setSubstructDataByName("recipe_info", "fuel_comp_qty", recipe->fuel_comp_qty);
  551. //packet->setSubstructDataByName("recipe_info", "fuel_comp_qty_avail", 10);
  552. packet->setSubstructDataByName("recipe_info", "build_comp_qty_avail_flag", 1);
  553. packet->setSubstructDataByName("recipe_info", "unknown6", 4, 0);
  554. packet->setSubstructDataByName("recipe_info", "min_product", 1);
  555. packet->setSubstructDataByName("recipe_info", "max_product", 1);
  556. packet->setSubstructDataByName("recipe_info", "available_flag", 4);
  557. packet->setSubstructDataByName("recipe_info", "not_commissionable", 1);
  558. packet->setSubstructDataByName("recipe_info", "recipe_name", recipe->GetName());
  559. packet->setSubstructDataByName("recipe_info", "recipe_description", "The art of sculpting metal into a candelabra.");
  560. //packet->PrintPacket();
  561. EQ2Packet* data = packet->serialize();
  562. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  563. safe_delete(packet);
  564. safe_delete(data);
  565. //DumpPacket(app);
  566. return app;
  567. }
  568. void Recipe::AddBuildComp(int32 itemID, int8 slot, bool preffered) {
  569. if (preffered = 1)
  570. components[slot].insert(components[slot].begin(), itemID);
  571. else
  572. components[slot].push_back(itemID);
  573. }