TradeskillsPackets.cpp 22 KB

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