TradeskillsPackets.cpp 21 KB

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