TradeskillsPackets.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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 <algorithm>
  17. #include "../ClientPacketFunctions.h"
  18. #include "../client.h"
  19. #include "../../common/ConfigReader.h"
  20. #include "../../common/PacketStruct.h"
  21. #include "../Recipes/Recipe.h"
  22. #include "../../common/Log.h"
  23. #include "../Spells.h"
  24. #include "../../common/MiscFunctions.h"
  25. extern ConfigReader configReader;
  26. extern MasterRecipeList master_recipe_list;
  27. extern MasterSpellList master_spell_list;
  28. void ClientPacketFunctions::SendCreateFromRecipe(Client* client, int32 recipeID) {
  29. // if recipeID is 0 we are repeating the last recipe, if not set the players current recipe to the new one
  30. if (recipeID == 0)
  31. recipeID = client->GetPlayer()->GetCurrentRecipe();
  32. else
  33. client->GetPlayer()->SetCurrentRecipe(recipeID);
  34. Recipe* playerRecipe = client->GetPlayer()->GetRecipeList()->GetRecipe(recipeID);
  35. // Get the recipe
  36. Recipe* recipe = master_recipe_list.GetRecipe(recipeID);
  37. if(!playerRecipe)
  38. {
  39. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "%s: ClientPacketFunctions::SendCreateFromRecipe Error finding player recipe %s in their recipe book for recipe id %u", client->GetPlayer()->GetName(), client->GetPlayer()->GetName(), recipe ? recipe->GetID() : 0);
  40. client->Message(CHANNEL_COLOR_RED, "You do not have %s (%u) in your recipe book.", recipe ? recipe->GetName() : "Unknown", recipe ? recipe->GetID() : 0);
  41. return;
  42. }
  43. if (!recipe) {
  44. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Error loading recipe (%u) in ClientPacketFunctions::SendCreateFromRecipe()", recipeID);
  45. return;
  46. }
  47. // Create the packet
  48. PacketStruct* packet = configReader.getStruct("WS_CreateFromRecipe", client->GetVersion());
  49. if (!packet) {
  50. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Error loading WS_CreateFromRecipe in ClientPacketFunctions::SendCreateFromRecipe()");
  51. return;
  52. }
  53. vector<int32>::iterator itr;
  54. vector<Item*> itemss;
  55. int8 i = 0;
  56. int8 k = 0;
  57. int32 firstID = 0;
  58. int32 IDcount = 0;
  59. int32 primary_comp_id = 0;
  60. Item* first_item = 0;
  61. Item* item = 0;
  62. Item* item_player = 0;
  63. Spawn* target = 0;
  64. if (!(target = client->GetPlayer()->GetTarget())) {
  65. client->Message(CHANNEL_COLOR_YELLOW, "You must be at a %s in order to crafte this recipe", recipe->GetDevice());
  66. return;
  67. }
  68. // Recipe and crafting table info
  69. packet->setDataByName("crafting_station", recipe->GetDevice());
  70. packet->setDataByName("recipe_name", recipe->GetName());
  71. packet->setDataByName("tier", recipe->GetTier());
  72. // Mass Production
  73. int32 mpq = 1;
  74. int32 mp = 5;
  75. vector<int> v{ 1,2,4,6,11,21 };
  76. // mpq will eventually be retrieved from achievement for mass production
  77. mpq = v[mp];
  78. packet->setArrayLengthByName("num_mass_production_choices",mpq);
  79. packet->setArrayDataByName("mass_qty", 1, 0);
  80. for (int x = 1; x < mpq; x++) {
  81. packet->setArrayDataByName("mass_qty", x * 5, x);
  82. }
  83. // Product info
  84. item = master_item_list.GetItem(recipe->GetProductID());
  85. packet->setDataByName("product_name", item->name.c_str());
  86. packet->setDataByName("icon", item->details.icon);
  87. packet->setDataByName("product_qty", recipe->GetProductQuantity());
  88. packet->setDataByName("primary_title", recipe->GetPrimaryBuildComponentTitle());
  89. packet->setDataByName("primary_qty_needed", recipe->GetPrimaryComponentQuantity());
  90. packet->setDataByName("unknown6", 11);
  91. packet->setDataByName("unknown3", 18);
  92. // Reset item to 0
  93. item, item_player = 0;
  94. // Check to see if we have a primary component (slot = 0)
  95. if (recipe->components.count(0) > 0) {
  96. vector<int32> rc = recipe->components[0];
  97. vector <pair<int32, int16>> selected_items;
  98. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  99. if (firstID == 0)
  100. firstID = *itr;
  101. item = master_item_list.GetItem(*itr);
  102. if (!item)
  103. {
  104. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Error creating packet to client missing item %u", *itr);
  105. client->Message(CHANNEL_COLOR_RED, "Error producing create recipe packet! Recipe is trying to find item %u, but it is missing!", *itr);
  106. safe_delete(packet);
  107. return;
  108. }
  109. item_player = 0;
  110. item_player = client->GetPlayer()->item_list.GetItemFromID((*itr));
  111. itemss = client->GetPlayer()->item_list.GetAllItemsFromID((*itr));
  112. packet->setArrayLengthByName("num_primary_choices", itemss.size());
  113. if (itemss.size() > 0) {
  114. int16 needed_qty = recipe->GetPrimaryComponentQuantity();
  115. int16 have_qty = 0;
  116. if (firstID == 0)
  117. firstID = *itr;
  118. for (int8 i = 0; i < itemss.size(); i++) {
  119. IDcount++;
  120. if (have_qty < needed_qty) {
  121. int16 stack_count = itemss[i]->details.count;
  122. int16 min_qty = min(stack_count, int16(needed_qty - have_qty));
  123. selected_items.push_back(make_pair(int32(itemss[i]->details.unique_id), min_qty));
  124. have_qty += min_qty;
  125. }
  126. packet->setArrayDataByName("primary_component", itemss[i]->name.c_str(), i);
  127. packet->setArrayDataByName("primary_item_id", itemss[i]->details.unique_id, i);
  128. packet->setArrayDataByName("primary_icon", itemss[i]->details.icon, i);
  129. packet->setArrayDataByName("primary_total_quantity", itemss[i]->details.count, i);
  130. //packet->setArrayDataByName("primary_supply_depot", itemss[i]->details.count, i); // future need
  131. //packet->setArrayDataByName("primary_unknown3a",); // future need
  132. }
  133. packet->setDataByName("primary_id", itemss[0]->details.unique_id);
  134. packet->setDataByName("primary_default_selected_id", itemss[0]->details.unique_id);
  135. for (int8 i = 0; i < selected_items.size(); i++) {
  136. }
  137. int16 qty = 0;
  138. if (item) {
  139. qty = (int8)item->details.count;
  140. if (qty > 0 && firstID == primary_comp_id)
  141. qty -= 1;
  142. }
  143. }
  144. else
  145. packet->setDataByName("primary_id",*itr);
  146. }
  147. // store the id of the primary comp
  148. primary_comp_id = firstID;
  149. // Set the default item id to the first component id
  150. packet->setArrayLengthByName("num_primary_items_selected", selected_items.size());
  151. for (int8 i = 0; i < selected_items.size(); i++) {
  152. packet->setArrayDataByName("primary_selected_item_qty", selected_items[i].second,i );
  153. packet->setArrayDataByName("primary_selected_item_id", selected_items[i].first,i);
  154. }
  155. // Reset the variables we will reuse
  156. i = 0;
  157. firstID = 0;
  158. item = 0;
  159. }
  160. else {
  161. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no primary component");
  162. return;
  163. }
  164. // Check to see if we have build components (slot = 1 - 4)
  165. int8 total_build_components = 0;
  166. if (recipe->components.count(1) > 0)
  167. total_build_components++;
  168. if (recipe->components.count(2))
  169. total_build_components++;
  170. if (recipe->components.count(3))
  171. total_build_components++;
  172. if (recipe->components.count(4))
  173. total_build_components++;
  174. //--------------------------------------------------------------Start Build Components-------------------------------------------------------------
  175. if (total_build_components > 0) {
  176. packet->setArrayLengthByName("num_build_components", total_build_components);
  177. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "num_build_components ", total_build_components);
  178. for (int8 index = 0; index < 4; index++) {
  179. if (recipe->components.count(index + 1) == 0)
  180. continue;
  181. packet->setArrayDataByName("build_slot", index, index);
  182. vector<int32> rc = recipe->components[index + 1];
  183. int32 total_component_items = 0;
  184. int8 hasComp = 0;
  185. vector <pair<int32, int16>> selected_items;
  186. for (itr = rc.begin(); itr != rc.end(); itr++) {
  187. itemss = client->GetPlayer()->item_list.GetAllItemsFromID((*itr));
  188. if (itemss.size() > 0)
  189. total_component_items += itemss.size();
  190. }
  191. packet->setSubArrayLengthByName("num_build_choices", total_component_items, index);// get # build choces first
  192. hasComp = 0;
  193. char msgbuf[200] = "";
  194. for (itr = rc.begin(); itr != rc.end(); itr++) {// iterates through each recipe component to find the stacks in inventory
  195. item = master_item_list.GetItem(*itr);
  196. itemss = client->GetPlayer()->item_list.GetAllItemsFromID((*itr));
  197. sprintf(msgbuf, "k=%d hascomp=%d \n", k, hasComp);
  198. //OutputDebugString(msgbuf);
  199. if (itemss.size() > 0) {
  200. int16 needed_qty = 0;
  201. int16 have_qty = 0;
  202. if (index == 0) {
  203. needed_qty = recipe->GetBuild1ComponentQuantity();
  204. have_qty = 0;
  205. }
  206. else if (index == 1) {
  207. needed_qty = recipe->GetBuild2ComponentQuantity();
  208. have_qty = 0;
  209. }
  210. else if (index == 2) {
  211. needed_qty = recipe->GetBuild3ComponentQuantity();
  212. have_qty = 0;
  213. }
  214. else if (index == 3) {
  215. needed_qty = recipe->GetBuild4ComponentQuantity();
  216. have_qty = 0;
  217. }
  218. if (firstID == 0)
  219. firstID = *itr;
  220. if (hasComp == 0) {
  221. hasComp = 100 + k;
  222. }
  223. for (int8 j = 0; j < itemss.size(); j++, k++) { // go through each stack of a compnent
  224. if (have_qty < needed_qty) {
  225. int16 stack_count = itemss[j]->details.count;
  226. int16 min_qty = min(stack_count, int16(needed_qty - have_qty));
  227. selected_items.push_back(make_pair(int32(itemss[j]->details.unique_id), min_qty));
  228. have_qty += min_qty;
  229. }
  230. item = master_item_list.GetItem(itemss[j]->details.item_id);
  231. packet->setSubArrayDataByName("build_component", itemss[j]->name.c_str(), index, k);
  232. packet->setSubArrayDataByName("build_item_id", itemss[j]->details.unique_id, index, k);
  233. packet->setSubArrayDataByName("build_icon", itemss[j]->details.icon, index, k);
  234. packet->setSubArrayDataByName("build_total_quantity", itemss[j]->details.count, index, k);
  235. //packet->setSubArrayDataByName("build_supply_depot",); // future need
  236. //packet->setSubArrayDataByName("build_unknown3",); // future need
  237. }
  238. }
  239. }
  240. packet->setArrayLengthByName("num_build_items_selected", selected_items.size());
  241. for (int8 i = 0; i < selected_items.size(); i++) {
  242. packet->setArrayDataByName("build_selected_item_qty", selected_items[i].second, i);
  243. packet->setArrayDataByName("build_selected_id", selected_items[i].first, i);
  244. }
  245. int16 qty = 0;
  246. if (item) {
  247. qty = (int16)item->details.count;
  248. if (qty > 0 && firstID == primary_comp_id)
  249. qty -= 1;
  250. }
  251. if (index == 0) {
  252. packet->setArrayDataByName("build_title", recipe->GetBuild1ComponentTitle(), index);
  253. packet->setArrayDataByName("build_qty_needed", recipe->GetBuild1ComponentQuantity(), index);
  254. if (item)
  255. packet->setArrayDataByName("build_selected_item_qty_have", min(qty, recipe->GetBuild1ComponentQuantity()), index);
  256. }
  257. else if (index == 1) {
  258. packet->setArrayDataByName("build_title", recipe->GetBuild2ComponentTitle(), index);
  259. packet->setArrayDataByName("build_qty_needed", recipe->GetBuild2ComponentQuantity(), index);
  260. if (item)
  261. packet->setArrayDataByName("build_selected_item_qty_have", min(qty, recipe->GetBuild2ComponentQuantity()), index);
  262. }
  263. else if (index == 2) {
  264. packet->setArrayDataByName("build_title", recipe->GetBuild3ComponentTitle(), index);
  265. packet->setArrayDataByName("build_qty_needed", recipe->GetBuild3ComponentQuantity(), index);
  266. if (item)
  267. packet->setArrayDataByName("build_selected_item_qty_have", min(qty, recipe->GetBuild3ComponentQuantity()), index);
  268. }
  269. else {
  270. packet->setArrayDataByName("build_title", recipe->GetBuild4ComponentTitle(), index);
  271. packet->setArrayDataByName("build_qty_needed", recipe->GetBuild4ComponentQuantity(), index);
  272. if (item)
  273. packet->setArrayDataByName("build_selected_item_qty_have", min(qty, recipe->GetBuild4ComponentQuantity()), index);
  274. }
  275. // Reset the variables we will reuse
  276. i = 0;
  277. firstID = 0;
  278. item = 0;
  279. k = 0;
  280. }
  281. int32 xxx = 0;
  282. }
  283. // Check to see if we have a fuel component (slot = 5)
  284. if (recipe->components.count(5) > 0) {
  285. vector<int32> rc = recipe->components[5];
  286. vector <pair<int32, int16>> selected_items;
  287. for (itr = rc.begin(); itr != rc.end(); itr++, i++) {
  288. if (firstID == 0)
  289. firstID = *itr;
  290. item = master_item_list.GetItem(*itr);
  291. if (!item)
  292. {
  293. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Error creating packet to client missing item %u", *itr);
  294. client->Message(CHANNEL_COLOR_RED, "Error producing create recipe packet! Recipe is trying to find item %u, but it is missing!", *itr);
  295. safe_delete(packet);
  296. return;
  297. }
  298. item_player = 0;
  299. item_player = client->GetPlayer()->item_list.GetItemFromID((*itr));
  300. itemss = client->GetPlayer()->item_list.GetAllItemsFromID((*itr));
  301. packet->setArrayLengthByName("num_fuel_choices", itemss.size());
  302. if (itemss.size() > 0) {
  303. int16 needed_qty = recipe->GetFuelComponentQuantity();
  304. int16 have_qty = 0;
  305. if (firstID == 0)
  306. firstID = *itr;
  307. for (int8 i = 0; i < itemss.size(); i++) {
  308. IDcount++;
  309. if (have_qty < needed_qty) {
  310. int16 stack_count = itemss[i]->details.count;
  311. int16 min_qty = min(stack_count, int16(needed_qty - have_qty));
  312. selected_items.push_back(make_pair(int32(itemss[i]->details.unique_id), min_qty));
  313. have_qty += min_qty;
  314. }
  315. packet->setArrayDataByName("fuel_component", itemss[i]->name.c_str(), i);
  316. packet->setArrayDataByName("fuel_item_id", itemss[i]->details.unique_id, i);
  317. packet->setArrayDataByName("fuel_icon", itemss[i]->details.icon, i);
  318. packet->setArrayDataByName("fuel_total_quantity", itemss[i]->details.count, i);
  319. //packet->setArrayDataByName("fuel_supply_depot", itemss[i]->details.count, i); // future need
  320. //packet->setArrayDataByName("primary_unknown3a",); // future need
  321. }
  322. packet->setDataByName("fuel_selected_item_id", itemss[0]->details.unique_id);
  323. int16 qty = 0;
  324. if (item) {
  325. qty = (int8)item->details.count;
  326. if (qty > 0 && firstID == primary_comp_id)
  327. qty -= 1;
  328. }
  329. }
  330. else
  331. packet->setDataByName("primary_vvv", *itr);
  332. }
  333. // store the id of the primary comp
  334. primary_comp_id = firstID;
  335. // Set the default item id to the first component id
  336. packet->setArrayLengthByName("num_fuel_items_selected", selected_items.size());
  337. for (int8 i = 0; i < selected_items.size(); i++) {
  338. packet->setArrayDataByName("fuel_selected_item_qty", selected_items[i].second, i);
  339. packet->setArrayDataByName("fuel_selected_item_id", selected_items[i].first, i);
  340. }
  341. packet->setDataByName("fuel_title", recipe->GetFuelComponentTitle());
  342. packet->setDataByName("fuel_qty_needed", recipe->GetFuelComponentQuantity());
  343. // Reset the variables we will reuse
  344. i = 0;
  345. firstID = 0;
  346. item = 0;
  347. }
  348. else {
  349. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe has no fuel component");
  350. return;
  351. }
  352. packet->setDataByName("recipe_id", recipeID);
  353. packet->PrintPacket();
  354. // Send the packet
  355. client->QueuePacket(packet->serialize());
  356. safe_delete(packet);
  357. }
  358. void ClientPacketFunctions::SendItemCreationUI(Client* client, Recipe* recipe) {
  359. // Check for valid recipe
  360. if (!recipe) {
  361. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Recipe = null in ClientPacketFunctions::SendItemCreationUI()");
  362. return;
  363. }
  364. // Load the packet
  365. PacketStruct* packet = configReader.getStruct("WS_ShowItemCreation", client->GetVersion());
  366. if (!packet) {
  367. LogWrite(TRADESKILL__ERROR, 0, "Recipes", "Error loading WS_ShowItemCreation in ClientPacketFunctions::SendItemCreationUI()");
  368. return;
  369. }
  370. int16 item_version = GetItemPacketType(packet->GetVersion());
  371. Item* item = 0;
  372. RecipeProducts* rp = 0;
  373. packet->setDataByName("max_possible_durability", 1000);
  374. packet->setDataByName("max_possible_progress", 1000);
  375. // All the packets I have looked at these unknowns are always the same
  376. // so hardcoding them until they are identified.
  377. packet->setDataByName("unknown2", 1045220557, 0);
  378. packet->setDataByName("unknown2", 1061997773, 1);
  379. // Highest stage the player has been able to complete
  380. // TODO: store this for the player, for now use 0 (none known)
  381. Recipe* playerRecipe = client->GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID());
  382. if(!playerRecipe)
  383. {
  384. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "%s: ClientPacketFunctions::SendItemCreationUI Error finding player recipe in their recipe book for recipe id %u", client->GetPlayer()->GetName(), recipe->GetID());
  385. client->Message(CHANNEL_COLOR_RED, "%s: SendItemCreationUI Error finding player recipe in their recipe book for recipe id %u!", client->GetPlayer()->GetName(), recipe->GetID());
  386. safe_delete(packet);
  387. return;
  388. }
  389. packet->setDataByName("progress_levels_known", playerRecipe ? playerRecipe->GetHighestStage() : 0);
  390. packet->setArrayLengthByName("num_process", 4);
  391. for (int8 i = 0; i < 4; i++) {
  392. // Don't like this code but need to change the IfVariableNotSet value on unknown3 element
  393. // to point to the currect progress_needed
  394. vector<DataStruct*> dataStructs = packet->GetDataStructs();
  395. vector<DataStruct*>::iterator itr;
  396. for (itr = dataStructs.begin(); itr != dataStructs.end(); itr++) {
  397. DataStruct* data = *itr;
  398. char tmp[20] = {0};
  399. sprintf(tmp,"_%i",i);
  400. string name = "unknown3";
  401. name.append(tmp);
  402. if (strcmp(data->GetName(), name.c_str()) == 0) {
  403. name = "progress_needed";
  404. name.append(tmp);
  405. data->SetIfNotSetVariable(name.c_str());
  406. }
  407. }
  408. if (i == 1)
  409. packet->setArrayDataByName("progress_needed", 400, i);
  410. else if (i == 2)
  411. packet->setArrayDataByName("progress_needed", 600, i);
  412. else if (i == 3)
  413. packet->setArrayDataByName("progress_needed", 800, i);
  414. // get the product for this stage, if none found default to fuel
  415. if (recipe->products.count(i) > 0)
  416. rp = recipe->products[i];
  417. if (!rp) {
  418. rp = new RecipeProducts;
  419. rp->product_id = recipe->components[5].front();
  420. rp->product_qty = recipe->GetFuelComponentQuantity();
  421. rp->byproduct_id = 0;
  422. rp->byproduct_qty = 0;
  423. recipe->products[i] = rp;
  424. }
  425. item = master_item_list.GetItem(rp->product_id);
  426. if (!item) {
  427. LogWrite(TRADESKILL__ERROR, 0, "Recipe", "Error loading item (%u) in ClientPacketFunctions::SendItemCreationUI()", rp->product_id);
  428. return;
  429. }
  430. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  431. packet->setArrayDataByName("item_icon", item->details.icon, i);
  432. if(client->GetVersion() < 860)
  433. packet->setItemArrayDataByName("item", item, client->GetPlayer(), i, 0, -1);
  434. else if (client->GetVersion() < 1193)
  435. packet->setItemArrayDataByName("item", item, client->GetPlayer(), i);
  436. else
  437. packet->setItemArrayDataByName("item", item, client->GetPlayer(), i, 0, 2);
  438. if (rp->byproduct_id > 0) {
  439. item = 0;
  440. item = master_item_list.GetItem(rp->byproduct_id);
  441. if (item) {
  442. packet->setArrayDataByName("item_byproduct_name", item->name.c_str(), i);
  443. packet->setArrayDataByName("item_byproduct_icon", item->details.icon, i);
  444. }
  445. }
  446. packet->setArrayDataByName("packettype", item_version, i);
  447. packet->setArrayDataByName("packetsubtype", 0xFF, i);
  448. item = 0;
  449. rp = 0;
  450. }
  451. packet->setDataByName("product_progress_needed", 1000);
  452. rp = recipe->products[4];
  453. item = master_item_list.GetItem(rp->product_id);
  454. packet->setDataByName("product_item_name", item->name.c_str());
  455. packet->setDataByName("product_item_icon", item->details.icon);
  456. if(client->GetVersion() < 860)
  457. packet->setItemByName("product_item", item, client->GetPlayer(), 0, -1);
  458. else if (client->GetVersion() < 1193)
  459. packet->setItemByName("product_item", item, client->GetPlayer());
  460. else
  461. packet->setItemByName("product_item", item, client->GetPlayer(), 0, 2);
  462. //packet->setItemByName("product_item", item, client->GetPlayer());
  463. if (rp->byproduct_id > 0) {
  464. item = 0;
  465. item = master_item_list.GetItem(rp->byproduct_id);
  466. if (item) {
  467. packet->setDataByName("product_byproduct_name", item->name.c_str());
  468. packet->setDataByName("product_byproduct_icon", item->details.icon);
  469. }
  470. }
  471. packet->setDataByName("packettype", item_version);
  472. packet->setDataByName("packetsubtype", 0xFF);
  473. // Start of basic work to get the skills to show on the tradeskill window
  474. // not even close to accurate but skills do get put on the ui
  475. int8 index = 0;
  476. int8 size = 0;
  477. vector<int32>::iterator itr;
  478. vector<int32> spells = client->GetPlayer()->GetSpellBookSpellIDBySkill(recipe->GetTechnique());
  479. for (itr = spells.begin(); itr != spells.end(); itr++) {
  480. size++;
  481. Spell* spell = master_spell_list.GetSpell(*itr,1);
  482. if(!spell) {
  483. return;
  484. }
  485. if (size > 6) {
  486. // only 6 slots for skills on the ui
  487. break;
  488. }
  489. packet->setDataByName("skill_id", *itr ,spell->GetSpellData()->ts_loc_index -1);
  490. }
  491. EQ2Packet* outapp = packet->serialize();
  492. //DumpPacket(outapp);
  493. client->QueuePacket(outapp);
  494. safe_delete(packet);
  495. }
  496. void ClientPacketFunctions::StopCrafting(Client* client) {
  497. client->QueuePacket(new EQ2Packet(OP_StopItemCreationMsg, 0, 0));
  498. }
  499. void ClientPacketFunctions::CounterReaction(Client* client, bool countered) {
  500. PacketStruct* packet = configReader.getStruct("WS_TSEventReaction", client->GetVersion());
  501. if (packet) {
  502. packet->setDataByName("counter_reaction", countered ? 1 : 0);
  503. client->QueuePacket(packet->serialize());
  504. }
  505. safe_delete(packet);
  506. }