ItemsDB.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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. #ifdef WIN32
  17. #include <WinSock2.h>
  18. #include <windows.h>
  19. #endif
  20. #include <mysql.h>
  21. #include <assert.h>
  22. #include "../../common/Log.h"
  23. #include "../WorldDatabase.h"
  24. #include "Items.h"
  25. #include "../World.h"
  26. extern World world;
  27. // handle new database class til all functions are converted
  28. void WorldDatabase::LoadDataFromRow(DatabaseResult* result, Item* item)
  29. {
  30. // this is too much on top of already having the top level load item debug msg
  31. // LogWrite(ITEM__DEBUG, 5, "Items", "\tSetting details for item ID: %i", result->GetInt32Str("id"));
  32. item->details.item_id = result->GetInt32Str("id");
  33. int8 size = strlen(result->GetStringStr("name"));
  34. if(size > 63)
  35. size = 63;
  36. item->name = string(result->GetStringStr("name"));
  37. item->lowername = ToLower(item->name);
  38. item->details.icon = result->GetInt16Str("icon");
  39. item->details.count = result->GetInt16Str("count");
  40. item->details.tier = result->GetInt8Str("tier");
  41. item->generic_info.weight = result->GetInt32Str("weight");
  42. if( strlen(result->GetStringStr("description")) > 0 )
  43. item->description = string(result->GetStringStr("description"));
  44. item->generic_info.show_name = result->GetInt8Str("show_name");
  45. if( result->GetInt8Str("attuneable") == 1 )
  46. item->generic_info.item_flags += ATTUNEABLE;
  47. if( result->GetInt8Str("artifact") == 1 )
  48. item->generic_info.item_flags += ARTIFACT;
  49. if( result->GetInt8Str("lore") == 1 )
  50. item->generic_info.item_flags += LORE;
  51. if( result->GetInt8Str("temporary") == 1 )
  52. item->generic_info.item_flags += TEMPORARY;
  53. if( result->GetInt8Str("notrade") == 1 )
  54. item->generic_info.item_flags += NO_TRADE;
  55. if( result->GetInt8Str("novalue") == 1 )
  56. item->generic_info.item_flags += NO_VALUE;
  57. if( result->GetInt8Str("nozone") == 1 )
  58. item->generic_info.item_flags += NO_ZONE;
  59. if( result->GetInt8Str("nodestroy") == 1 )
  60. item->generic_info.item_flags += NO_DESTROY;
  61. if( result->GetInt8Str("crafted") == 1 )
  62. item->generic_info.item_flags += CRAFTED;
  63. if( result->GetInt8Str("good_only") == 1 )
  64. item->generic_info.item_flags += GOOD_ONLY;
  65. if( result->GetInt8Str("evil_only") == 1 )
  66. item->generic_info.item_flags += EVIL_ONLY;
  67. if( result->GetInt8Str("stacklore") == 1 )
  68. item->generic_info.item_flags += STACK_LORE;
  69. // add more Flags/Flags2 here
  70. if (result->GetInt8Str("lore_equip") == 1)
  71. item->generic_info.item_flags += LORE_EQUIP;
  72. if (result->GetInt8Str("no_transmute") == 1)
  73. item->generic_info.item_flags += NO_TRANSMUTE;
  74. if (result->GetInt8Str("CURSED_flags_32768") == 1)
  75. item->generic_info.item_flags += CURSED;
  76. if (result->GetInt8Str("ornate") == 1)
  77. item->generic_info.item_flags2 += ORNATE;
  78. if (result->GetInt8Str("heirloom") == 1)
  79. item->generic_info.item_flags2 += HEIRLOOM;
  80. if (result->GetInt8Str("appearance_only") == 1)
  81. item->generic_info.item_flags2 += APPEARANCE_ONLY;
  82. if (result->GetInt8Str("unlocked") == 1)
  83. item->generic_info.item_flags2 += UNLOCKED;
  84. if (result->GetInt8Str("reforged") == 1)
  85. item->generic_info.item_flags2 += REFORGED;
  86. if (result->GetInt8Str("norepair") == 1)
  87. item->generic_info.item_flags2 += NO_REPAIR;
  88. if (result->GetInt8Str("etheral") == 1)
  89. item->generic_info.item_flags2 += ETHERAL;
  90. if (result->GetInt8Str("refined") == 1)
  91. item->generic_info.item_flags2 += REFINED;
  92. if (result->GetInt8Str("no_salvage") == 1)
  93. item->generic_info.item_flags2 += NO_SALVAGE;
  94. if (result->GetInt8Str("indestructable") == 1)
  95. item->generic_info.item_flags2 += INDESTRUCTABLE;
  96. if (result->GetInt8Str("no_experiment") == 1)
  97. item->generic_info.item_flags2 += NO_EXPERIMENT;
  98. if (result->GetInt8Str("house_lore") == 1)
  99. item->generic_info.item_flags2 += HOUSE_LORE;
  100. if (result->GetInt8Str("building_block") == 1)
  101. item->generic_info.item_flags2 += BUILDING_BLOCK;
  102. if (result->GetInt8Str("free_reforge") == 1)
  103. item->generic_info.item_flags2 += FREE_REFORGE;
  104. if( result->GetInt32Str("skill_id_req") == 0 )
  105. item->generic_info.skill_req1 = 0xFFFFFFFF;
  106. else
  107. item->generic_info.skill_req1 = result->GetInt32Str("skill_id_req");
  108. if( result->GetInt32Str("skill_id_req2") == 0 )
  109. item->generic_info.skill_req2 = 0xFFFFFFFF;
  110. else
  111. item->generic_info.skill_req2 = result->GetInt32Str("skill_id_req2");
  112. item->generic_info.skill_min = result->GetInt16Str("skill_min");
  113. if( result->GetInt32Str("slots") > 0)
  114. item->SetSlots(result->GetInt32Str("slots"));
  115. item->sell_price = result->GetInt32Str("sell_price");
  116. item->sell_status = result->GetInt32Str("sell_status_amount");
  117. item->stack_count = result->GetInt16Str("stack_count");
  118. item->generic_info.collectable = result->GetInt8Str("collectable");
  119. item->generic_info.offers_quest_id = result->GetInt32Str("offers_quest_id");
  120. item->generic_info.part_of_quest_id = result->GetInt32Str("part_of_quest_id");
  121. item->details.recommended_level = result->GetInt16Str("recommended_level");
  122. item->details.item_locked = false;
  123. item->generic_info.adventure_default_level = result->GetInt16Str("adventure_default_level");
  124. item->generic_info.max_charges = result->GetInt16Str("max_charges");
  125. item->generic_info.display_charges = result->GetInt8Str("display_charges");
  126. item->generic_info.tradeskill_default_level = result->GetInt16Str("tradeskill_default_level");
  127. #ifdef WIN32
  128. item->generic_info.adventure_classes = result->GetInt64Str("adventure_classes");
  129. item->generic_info.tradeskill_classes = result->GetInt64Str("tradeskill_classes");
  130. #else
  131. item->generic_info.adventure_classes = result->GetInt64Str("adventure_classes");
  132. item->generic_info.tradeskill_classes = result->GetInt64Str("tradeskill_classes");
  133. #endif
  134. if( !result->IsNullStr("lua_script") && strlen(result->GetStringStr("lua_script")) > 0 )
  135. {
  136. item->SetItemScript(string(result->GetStringStr("lua_script")));
  137. LogWrite(ITEM__DEBUG, 5, "LUA", "--Loading LUA Item Script: '%s'", item->item_script.c_str());
  138. }
  139. if(item->generic_info.max_charges > 0)
  140. item->details.count = item->generic_info.max_charges;
  141. if(item->details.count == 0)
  142. item->details.count = 1;
  143. item->generic_info.usable = result->GetInt8Str("usable");
  144. item->details.soe_id = result->GetSInt32Str("soe_item_id");
  145. item->generic_info.harvest = result->GetInt8Str("harvest");
  146. item->generic_info.body_drop = result->GetInt8Str("body_drop");
  147. item->no_buy_back = (result->GetInt8Str("no_buy_back") == 1);
  148. item->generic_info.pvp_description = result->GetInt8Str("bPvpDesc");
  149. item->generic_info.merc_only = (result->GetInt8Str("merc_only") == 1);
  150. item->generic_info.mount_only = (result->GetInt8Str("mount_only") == 1);
  151. item->generic_info.set_id = result->GetInt32Str("set_id");
  152. item->generic_info.collectable_unk = result->GetInt8Str("collectable_unk");
  153. const char* offerQuestName = result->GetFieldValueStr("offers_quest_name");
  154. if(offerQuestName)
  155. strncpy(item->generic_info.offers_quest_name,offerQuestName,255);
  156. else
  157. strcpy(item->generic_info.offers_quest_name,"");
  158. const char* requiredQuestName = result->GetFieldValueStr("required_by_quest_name");
  159. if(requiredQuestName)
  160. strncpy(item->generic_info.required_by_quest_name,requiredQuestName,255);
  161. else
  162. strcpy(item->generic_info.required_by_quest_name,"");
  163. item->generic_info.transmuted_material = result->GetInt8Str("transmuted_material");
  164. }
  165. int32 WorldDatabase::LoadSkillItems()
  166. {
  167. Query query;
  168. MYSQL_ROW row;
  169. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, spell_id, spell_tier FROM item_details_skill");
  170. int32 total = 0;
  171. int32 id = 0;
  172. if(result)
  173. {
  174. while(result && (row = mysql_fetch_row(result)))
  175. {
  176. id = atoul(row[0]);
  177. Item* item = master_item_list.GetItem(id);
  178. if(!row[1] || !row[2])
  179. continue;
  180. if(item)
  181. {
  182. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading Skill for item_id %u", id);
  183. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, spell: %i, tier: %i", ITEM_TYPE_SKILL, atoi(row[1]), atoi(row[2]));
  184. item->SetItemType(ITEM_TYPE_SKILL);
  185. item->skill_info->spell_id = atoul(row[1]);
  186. item->skill_info->spell_tier = atoi(row[2]);
  187. total++;
  188. }
  189. else
  190. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_skill`, ID: %i", id);
  191. }
  192. }
  193. return total;
  194. }
  195. int32 WorldDatabase::LoadShields()
  196. {
  197. Query query;
  198. MYSQL_ROW row;
  199. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_shield");
  200. int32 total = 0;
  201. int32 id = 0;
  202. if(result)
  203. {
  204. while(result && (row = mysql_fetch_row(result)))
  205. {
  206. id = strtoul(row[0], NULL, 0);
  207. Item* item = master_item_list.GetItem(id);
  208. if(item)
  209. {
  210. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Shield for item_id: %u", id);
  211. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_SHIELD, atoi(row[1]), atoi(row[2]));
  212. item->SetItemType(ITEM_TYPE_SHIELD);
  213. item->armor_info->mitigation_low = atoi(row[1]);
  214. item->armor_info->mitigation_high = atoi(row[2]);
  215. total++;
  216. }
  217. else
  218. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_shield`, ID: %i", id);
  219. }
  220. }
  221. return total;
  222. }
  223. int32 WorldDatabase::LoadAdornments()
  224. {
  225. Query query;
  226. MYSQL_ROW row;
  227. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, duration, item_types,slot_type FROM item_details_adornments");
  228. int32 total = 0;
  229. int32 id = 0;
  230. if (result)
  231. {
  232. while (result && (row = mysql_fetch_row(result)))
  233. {
  234. id = strtoul(row[0], NULL, 0);
  235. Item* item = master_item_list.GetItem(id);
  236. if (item)
  237. {
  238. //LogWrite(ITEM__DEBUG, 0, "Items", "\tItem Adornment for item_id: %u", id);
  239. //LogWrite(ITEM__DEBUG, 0, "Items", "\ttype: %i, Duration: %i, item_types_: %i, slot_type: %i", ITEM_TYPE_ADORNMENT, atoi(row[1]), atoi(row[2]), atoi(row[3]));
  240. item->SetItemType(ITEM_TYPE_ADORNMENT);
  241. item->adornment_info->duration = atof(row[1]);
  242. item->adornment_info->item_types = atoi(row[2]);
  243. item->adornment_info->slot_type = atoi(row[3]);
  244. //LogWrite(ITEM__DEBUG, 0, "Items", "\ttype: %i, Duration: %i, item_types_: %i, slot_type: %i",item->generic_info.item_type, item->adornment_info->duration, item->adornment_info->item_types, item->adornment_info->slot_type);
  245. total++;
  246. }
  247. else
  248. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_shield`, ID: %i", id);
  249. }
  250. }
  251. return total;
  252. }
  253. int32 WorldDatabase::LoadClassifications()
  254. {
  255. int32 total = 0;
  256. int32 id = 0;
  257. return total;
  258. }
  259. int32 WorldDatabase::LoadBaubles()
  260. {
  261. Query query;
  262. MYSQL_ROW row;
  263. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, cast, recovery, duration, recast, display_slot_optional, display_cast_time, display_bauble_type, effect_radius, max_aoe_targets, display_until_cancelled FROM item_details_bauble");
  264. int32 total = 0;
  265. int32 id = 0;
  266. if(result)
  267. {
  268. while(result && (row = mysql_fetch_row(result)))
  269. {
  270. id = strtoul(row[0], NULL, 0);
  271. Item* item = master_item_list.GetItem(id);
  272. if(item)
  273. {
  274. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bauble for item_id %u", id);
  275. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i", ITEM_TYPE_BAUBLE, atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atof(row[7]), atoi(row[8]), atoi(row[9]), atoi(row[10]));
  276. item->SetItemType(ITEM_TYPE_BAUBLE);
  277. item->bauble_info->cast = atoi(row[1]);
  278. item->bauble_info->recovery = atoi(row[2]);
  279. item->bauble_info->duration = atoi(row[3]);
  280. item->bauble_info->recast = atoi(row[4]);
  281. item->bauble_info->display_slot_optional = atoi(row[5]);
  282. item->bauble_info->display_cast_time = atoi(row[6]);
  283. item->bauble_info->display_bauble_type = atoi(row[7]);
  284. item->bauble_info->effect_radius = atof(row[8]);
  285. item->bauble_info->max_aoe_targets = atoi(row[9]);
  286. item->bauble_info->display_until_cancelled = atoi(row[10]);
  287. total++;
  288. }
  289. else
  290. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bauble`, ID: %i", id);
  291. }
  292. }
  293. return total;
  294. }
  295. int32 WorldDatabase::LoadBooks()
  296. {
  297. DatabaseResult result;
  298. int32 total = 0;
  299. int32 id = 0;
  300. if( database_new.Select(&result, "SELECT item_id, language, author, title FROM item_details_book") )
  301. {
  302. while( result.Next() )
  303. {
  304. id = result.GetInt32Str("item_id");
  305. Item* item = master_item_list.GetItem(id);
  306. if(item)
  307. {
  308. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Book for item_id %u", id);
  309. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %s, %s",
  310. ITEM_TYPE_BOOK,
  311. result.GetInt8Str("language"),
  312. result.GetStringStr("author"),
  313. result.GetStringStr("title"));
  314. item->SetItemType(ITEM_TYPE_BOOK);
  315. item->book_info->language = result.GetInt8Str("language");
  316. item->book_info->author.data = result.GetStringStr("author");
  317. item->book_info->author.size = item->book_info->author.data.length();
  318. item->book_info->title.data = result.GetStringStr("title");
  319. item->book_info->title.size = item->book_info->title.data.length();
  320. total++;
  321. }
  322. else
  323. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_book`, ID: %i", id);
  324. }
  325. }
  326. return total;
  327. }
  328. int32 WorldDatabase::LoadItemsets()
  329. {
  330. DatabaseResult result;
  331. int32 total = 0;
  332. int32 id = 0;
  333. //if (database_new.Select(&result, "SELECT id, itemset_item_id, item_id, item_icon,item_stack_size,item_list_color,language_type FROM item_details_itemset"))
  334. if (database_new.Select(&result, "select crate.item_id, crateitem.reward_item_id, crateitem.icon, crateitem.stack_size, crateitem.name_color, crateitem.name, crateitem.language_type from item_details_reward_crate crate, item_details_reward_crate_item crateitem where crateitem.crate_item_id = crate.item_id"))
  335. {
  336. while (result.Next())
  337. {
  338. id = result.GetInt32(0);
  339. Item* item = master_item_list.GetItem(id);
  340. if (item)
  341. {
  342. item->SetItemType(ITEM_TYPE_ITEMCRATE);
  343. //int32 item_id = result.GetInt32Str("item_id");
  344. const char* setName = result.GetString(5);
  345. item->AddSet(result.GetInt32(1),0, result.GetInt16(2), result.GetInt16(3), result.GetInt32(4), setName ? string(setName) : string(""), result.GetInt8(6));
  346. total++;
  347. }
  348. else
  349. LogWrite(ITEM__ERROR, 0, "Item Set Crate Items", "Error loading `item_details_Items`, ID: %i", id);
  350. }
  351. }
  352. return total;
  353. }
  354. int32 WorldDatabase::LoadHouseItem()
  355. {
  356. Query query;
  357. MYSQL_ROW row;
  358. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, rent_reduction, status_rent_reduction, coin_rent_reduction, house_only FROM item_details_house");
  359. int32 total = 0;
  360. int32 id = 0;
  361. if(result)
  362. {
  363. while(result && (row = mysql_fetch_row(result)))
  364. {
  365. id = strtoul(row[0], NULL, 0);
  366. Item* item = master_item_list.GetItem(id);
  367. if(item)
  368. {
  369. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem HouseItem for item_id %u", id);
  370. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %u, %.2f, %u", ITEM_TYPE_HOUSE, atoul(row[1]), atoi(row[2]), atof(row[3]), atoul(row[4]));
  371. item->SetItemType(ITEM_TYPE_HOUSE);
  372. item->houseitem_info->status_rent_reduction = atoi(row[2]);
  373. item->houseitem_info->coin_rent_reduction = atof(row[3]);
  374. item->houseitem_info->house_only = atoi(row[4]);
  375. total++;
  376. }
  377. else
  378. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house`, ID: %i", id);
  379. }
  380. }
  381. return total;
  382. }
  383. int32 WorldDatabase::LoadRecipeBookItems()
  384. {
  385. Query query;
  386. MYSQL_ROW row;
  387. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, name FROM item_details_recipe_items");
  388. int32 total = 0;
  389. int32 id = 0;
  390. if (result)
  391. {
  392. while(result && (row = mysql_fetch_row(result)))
  393. {
  394. id = strtoul(row[0], NULL, 0);
  395. Item* item = master_item_list.GetItem(id);
  396. if(item)
  397. {
  398. LogWrite(ITEM__DEBUG, 5, "Items", "\tRecipe Book for item_id %u", id);
  399. LogWrite(ITEM__DEBUG, 5, "Items", "\tType: %i, '%s'", ITEM_TYPE_RECIPE, row[1]);
  400. item->SetItemType(ITEM_TYPE_RECIPE);
  401. item->recipebook_info->recipes.push_back(string(row[1]));
  402. total++;
  403. }
  404. else
  405. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_recipe_items`, ID: %u", id);
  406. }
  407. }
  408. return total;
  409. }
  410. int32 WorldDatabase::LoadHouseContainers(){
  411. DatabaseResult result;
  412. int32 total = 0;
  413. int32 id = 0;
  414. if( database_new.Select(&result, "SELECT item_id, num_slots, allowed_types, broker_commission, fence_commission FROM item_details_house_container") )
  415. {
  416. while (result.Next() )
  417. {
  418. id = result.GetInt32Str("item_id");
  419. Item* item = master_item_list.GetItem(id);
  420. if (item)
  421. {
  422. LogWrite(ITEM__DEBUG, 5, "Items", "\tHouse Container for item_id %u", id);
  423. LogWrite(ITEM__DEBUG, 5, "Items", "\tType: %i, '%i', '%u', '%i', '%i'", ITEM_TYPE_RECIPE, result.GetInt8Str("num_slots"), result.GetInt64Str("allowed_types"), result.GetInt8Str("broker_commission"), result.GetInt8Str("fence_commission"));
  424. item->SetItemType(ITEM_TYPE_HOUSE_CONTAINER);
  425. item->housecontainer_info->num_slots = result.GetInt8Str("num_slots");
  426. item->housecontainer_info->allowed_types = result.GetInt64Str("allowed_types");
  427. item->housecontainer_info->broker_commission = result.GetInt8Str("broker_commission");
  428. item->housecontainer_info->fence_commission = result.GetInt8Str("fence_commission");
  429. total++;
  430. }
  431. else
  432. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house_container`, ID: %u", id);
  433. }
  434. }
  435. return total;
  436. }
  437. int32 WorldDatabase::LoadArmor()
  438. {
  439. Query query;
  440. MYSQL_ROW row;
  441. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_armor");
  442. int32 total = 0;
  443. int32 id = 0;
  444. if(result)
  445. {
  446. while(result && (row = mysql_fetch_row(result)))
  447. {
  448. id = strtoul(row[0], NULL, 0);
  449. Item* item = master_item_list.GetItem(id);
  450. if(item)
  451. {
  452. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Armor for item_id %u", id);
  453. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_ARMOR, atoi(row[1]), atoi(row[2]));
  454. item->SetItemType(ITEM_TYPE_ARMOR);
  455. item->armor_info->mitigation_low = atoi(row[1]);
  456. item->armor_info->mitigation_high = atoi(row[2]);
  457. total++;
  458. }
  459. else
  460. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_armor`, ID: %i", id);
  461. }
  462. }
  463. return total;
  464. }
  465. int32 WorldDatabase::LoadBags()
  466. {
  467. Query query;
  468. MYSQL_ROW row;
  469. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, num_slots, weight_reduction FROM item_details_bag");
  470. int32 total = 0;
  471. int32 id = 0;
  472. if(result)
  473. {
  474. while(result && (row = mysql_fetch_row(result)))
  475. {
  476. id = strtoul(row[0], NULL, 0);
  477. Item* item = master_item_list.GetItem(id);
  478. if(item)
  479. {
  480. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bag for item_id %u", id);
  481. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, slots: %i, wt_red: %i", id, ITEM_TYPE_BAG, atoi(row[1]), atoi(row[2]));
  482. item->SetItemType(ITEM_TYPE_BAG);
  483. item->details.num_slots = atoi(row[1]);
  484. item->details.num_free_slots = item->details.num_slots;
  485. item->bag_info->num_slots = item->details.num_slots;
  486. item->bag_info->weight_reduction = atoi(row[2]);
  487. total++;
  488. }
  489. else
  490. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bag`, ID: %i", id);
  491. }
  492. }
  493. return total;
  494. }
  495. int32 WorldDatabase::LoadFoods()
  496. {
  497. Query query;
  498. MYSQL_ROW row;
  499. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, level, duration, satiation FROM item_details_food");
  500. int32 total = 0;
  501. int32 id = 0;
  502. if(result)
  503. {
  504. while(result && (row = mysql_fetch_row(result)))
  505. {
  506. id = strtoul(row[0], NULL, 0);
  507. Item* item = master_item_list.GetItem(id);
  508. if(item)
  509. {
  510. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Food for item_id %u", id);
  511. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, lvl: %i, dur: %i, sat: %.2f, tier: %i", ITEM_TYPE_FOOD, atoi(row[1]), atoi(row[2]), atof(row[3]), atoi(row[4]));
  512. item->SetItemType(ITEM_TYPE_FOOD);
  513. item->food_info->type = atoi(row[1]);
  514. item->food_info->level = atoi(row[2]);
  515. item->food_info->duration = atof(row[3]);
  516. item->food_info->satiation = atoi(row[4]);
  517. item->details.tier = atoi(row[4]);
  518. total++;
  519. }
  520. else
  521. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_food`, ID: %i", id);
  522. }
  523. }
  524. return total;
  525. }
  526. int32 WorldDatabase::LoadRangeWeapons()
  527. {
  528. Query query;
  529. MYSQL_ROW row;
  530. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, dmg_low, dmg_high, dmg_mastery_low, dmg_mastery_high, dmg_base_low, dmg_base_high, delay, damage_rating, range_low, range_high, damage_type FROM item_details_range");
  531. int32 total = 0;
  532. int32 id = 0;
  533. if(result)
  534. {
  535. while(result && (row = mysql_fetch_row(result)))
  536. {
  537. id = strtoul(row[0], NULL, 0);
  538. Item* item = master_item_list.GetItem(id);
  539. if(item)
  540. {
  541. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Ranged for item_id %u", id);
  542. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %i, %i, %i, %i, %i, %i, %.2f, %i, %i, %i", ITEM_TYPE_RANGED, atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]), atof(row[8]), atoi(row[9]), atoi(row[10]), atoi(row[11]));
  543. item->SetItemType(ITEM_TYPE_RANGED);
  544. item->ranged_info->weapon_info.damage_low1 = atoi(row[1]);
  545. item->ranged_info->weapon_info.damage_high1 = atoi(row[2]);
  546. item->ranged_info->weapon_info.damage_low2 = atoi(row[3]);
  547. item->ranged_info->weapon_info.damage_high2 = atoi(row[4]);
  548. item->ranged_info->weapon_info.damage_low3 = atoi(row[5]);
  549. item->ranged_info->weapon_info.damage_high3 = atoi(row[6]);
  550. item->ranged_info->weapon_info.delay = atoi(row[7]);
  551. item->ranged_info->weapon_info.rating = atof(row[8]);
  552. item->ranged_info->range_low = atoi(row[9]);
  553. item->ranged_info->range_high = atoi(row[10]);
  554. item->SetWeaponType(atoi(row[11]));
  555. total++;
  556. }
  557. else
  558. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_range`, ID: %i", id);
  559. }
  560. }
  561. return total;
  562. }
  563. int32 WorldDatabase::LoadThrownWeapons()
  564. {
  565. Query query;
  566. MYSQL_ROW row;
  567. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, range_bonus, damage_bonus, hit_bonus, damage_type FROM item_details_thrown");
  568. int32 total = 0;
  569. int32 id = 0;
  570. if(result)
  571. {
  572. while(result && (row = mysql_fetch_row(result)))
  573. {
  574. id = strtoul(row[0], NULL, 0);
  575. Item* item = master_item_list.GetItem(id);
  576. if(item)
  577. {
  578. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Thrown for item_id %u", id);
  579. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %u, %.2f, %u", ITEM_TYPE_THROWN, atoul(row[1]), atoi(row[2]), atof(row[3]), atoul(row[4]));
  580. item->SetItemType(ITEM_TYPE_THROWN);
  581. item->thrown_info->range = atoul(row[1]);
  582. item->thrown_info->damage_modifier = atoul(row[2]);
  583. item->thrown_info->hit_bonus = atof(row[3]);
  584. item->thrown_info->damage_type = atoul(row[4]);
  585. item->SetWeaponType(item->thrown_info->damage_type);
  586. total++;
  587. }
  588. else
  589. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_thrown`, ID: %i", id);
  590. }
  591. }
  592. return total;
  593. }
  594. int32 WorldDatabase::LoadWeapons()
  595. {
  596. Query query;
  597. MYSQL_ROW row;
  598. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, wield_style, dmg_low, dmg_high, dmg_mastery_low, dmg_mastery_high, dmg_base_low, dmg_base_high, delay, damage_rating, damage_type FROM item_details_weapon");
  599. int32 total = 0;
  600. int32 id = 0;
  601. if(result)
  602. {
  603. while(result && (row = mysql_fetch_row(result)))
  604. {
  605. id = strtoul(row[0], NULL, 0);
  606. Item* item = master_item_list.GetItem(id);
  607. if(item)
  608. {
  609. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Weapon for item_id %u", id);
  610. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %i, %i, %i, %i, %i, %i, %i, %.2f, %i", ITEM_TYPE_WEAPON, atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]), atoi(row[8]), atof(row[9]), atoi(row[10]));
  611. item->SetItemType(ITEM_TYPE_WEAPON);
  612. item->weapon_info->wield_type = atoi(row[1]);
  613. item->weapon_info->damage_low1 = atoi(row[2]);
  614. item->weapon_info->damage_high1 = atoi(row[3]);
  615. item->weapon_info->damage_low2 = atoi(row[4]);
  616. item->weapon_info->damage_high2 = atoi(row[5]);
  617. item->weapon_info->damage_low3 = atoi(row[6]);
  618. item->weapon_info->damage_high3 = atoi(row[7]);
  619. item->weapon_info->delay = atoi(row[8]);
  620. item->weapon_info->rating = atof(row[9]);
  621. item->SetWeaponType(atoi(row[10]));
  622. total++;
  623. }
  624. else
  625. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_weapons`, ID: %i", id);
  626. }
  627. }
  628. return total;
  629. }
  630. int32 WorldDatabase::LoadItemAppearances()
  631. {
  632. Query query;
  633. MYSQL_ROW row;
  634. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, equip_type, red, green, blue, highlight_red, highlight_green, highlight_blue FROM item_appearances ORDER BY item_id asc");
  635. int32 id = 0;
  636. Item* item = 0;
  637. int32 total = 0;
  638. if(result && mysql_num_rows(result) >0)
  639. {
  640. while(result && (row = mysql_fetch_row(result)))
  641. {
  642. if(id != strtoul(row[0], NULL, 0))
  643. {
  644. id = strtoul(row[0], NULL, 0);
  645. item = master_item_list.GetItem(id);
  646. if(item)
  647. {
  648. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Appearance for item_id %u", id);
  649. LogWrite(ITEM__DEBUG, 5, "Items", "\tequip_type: %i, R: %i, G: %i, B: %i, HR: %i, HG: %i, HB: %i", atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]));
  650. item->SetAppearance(atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]));
  651. total++;
  652. }
  653. else
  654. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_appearances, ID: %i", id);
  655. }
  656. }
  657. }
  658. return total;
  659. }
  660. int32 WorldDatabase::LoadItemEffects()
  661. {
  662. Query query;
  663. MYSQL_ROW row;
  664. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, effect, percentage, bullet FROM item_effects ORDER BY item_id, id");
  665. int32 id = 0;
  666. Item* item = 0;
  667. int32 total = 0;
  668. if(result && mysql_num_rows(result) >0)
  669. {
  670. while(result && (row = mysql_fetch_row(result)))
  671. {
  672. if(id != atoul(row[0]))
  673. {
  674. id = atoul(row[0]);
  675. item = master_item_list.GetItem(id);
  676. }
  677. if(item && row[1])
  678. {
  679. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Effects for item_id %u", id);
  680. LogWrite(ITEM__DEBUG, 5, "Items", "\tEffect: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  681. item->AddEffect(row[1], atoi(row[2]), atoi(row[3]));
  682. total++;
  683. }
  684. else
  685. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_effects, ID: %i", id);
  686. }
  687. }
  688. return total;
  689. }
  690. int32 WorldDatabase::LoadBookPages()
  691. {
  692. Query query;
  693. MYSQL_ROW row;
  694. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, page, page_text, page_text_valign, page_text_halign FROM item_details_book_pages ORDER BY item_id, id");
  695. int32 id = 0;
  696. Item* item = 0;
  697. int32 total = 0;
  698. if (result && mysql_num_rows(result) > 0)
  699. {
  700. while (result && (row = mysql_fetch_row(result)))
  701. {
  702. if (id != atoul(row[0]))
  703. {
  704. id = atoul(row[0]);
  705. item = master_item_list.GetItem(id);
  706. }
  707. if (item && row[1])
  708. {
  709. LogWrite(ITEM__DEBUG, 5, "Items", "\tBook Pages for item_id %u", id);
  710. //LogWrite(ITEM__DEBUG, 5, "Items", "\tPages: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  711. item->AddBookPage(atoi(row[1]), row[2], atoi(row[3]), atoi(row[4]));
  712. total++;
  713. }
  714. else
  715. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_details_book_pages, ID: %i", id);
  716. }
  717. }
  718. return total;
  719. }
  720. int32 WorldDatabase::LoadItemLevelOverride()
  721. {
  722. Query query;
  723. MYSQL_ROW row;
  724. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, adventure_class_id, tradeskill_class_id, level FROM item_levels_override ORDER BY item_id asc");
  725. int32 id = 0;
  726. Item* item = 0;
  727. int32 total = 0;
  728. if(result && mysql_num_rows(result) >0)
  729. {
  730. while(result && (row = mysql_fetch_row(result)))
  731. {
  732. if(id != strtoul(row[0], NULL, 0))
  733. {
  734. id = strtoul(row[0], NULL, 0);
  735. item = master_item_list.GetItem(id);
  736. }
  737. if(item)
  738. {
  739. LogWrite(ITEM__DEBUG, 5, "Items", "\tLevel Override for item_id %u", id);
  740. LogWrite(ITEM__DEBUG, 5, "Items", "\tAdv: %i, TS: %i, Lvl: %i", atoi(row[1]), atoi(row[2]), atoi(row[3]));
  741. item->AddLevelOverride(atoi(row[1]), atoi(row[2]), atoi(row[3]));
  742. total++;
  743. }
  744. else
  745. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_levels_override`, ID: %i", id);
  746. }
  747. }
  748. return total;
  749. }
  750. int32 WorldDatabase::LoadItemStats()
  751. {
  752. Query query;
  753. MYSQL_ROW row;
  754. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, subtype, iValue, fValue, sValue, level FROM item_mod_stats ORDER BY stats_order asc");
  755. int32 id = 0;
  756. Item* item = 0;
  757. int32 total = 0;
  758. if(result && mysql_num_rows(result) >0)
  759. {
  760. while(result && (row = mysql_fetch_row(result)))
  761. {
  762. if(id != strtoul(row[0], NULL, 0))
  763. {
  764. id = strtoul(row[0], NULL, 0);
  765. item = master_item_list.GetItem(id);
  766. }
  767. if(item)
  768. {
  769. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Stats for item_id %u", id);
  770. float fValue = 0.0f;
  771. if(row[3])
  772. fValue = atof(row[3]);
  773. else if(row[4])
  774. fValue = atof(row[4]);
  775. //LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, sub: %i, val: %.2f, name: %s", atoi(row[1]), atoi(row[2]), atof(row[3]), row[4]);
  776. item->AddStat(atoi(row[1]), atoi(row[2]), fValue, atoul(row[6]), row[5]);
  777. total++;
  778. }
  779. else
  780. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_stats`, ID: %i", id);
  781. }
  782. }
  783. return total;
  784. }
  785. int32 WorldDatabase::LoadItemModStrings()
  786. {
  787. DatabaseResult result;
  788. int32 id = 0;
  789. Item* item = 0;
  790. int32 total = 0;
  791. if( !database_new.Select(&result, "SELECT * FROM item_mod_strings") ) {
  792. LogWrite(ITEM__ERROR, 0, "Items", "Cannot load WorldDatabase::LoadItemModStrings in %s, line: %i", __FUNCTION__, __LINE__);
  793. return 0;
  794. }
  795. else {
  796. while( result.Next() )
  797. {
  798. int32 item_id = result.GetInt32Str("item_id");
  799. if(id != item_id)
  800. {
  801. item = master_item_list.GetItem(item_id);
  802. id = item_id;
  803. }
  804. const char* modName = result.GetFieldValueStr("mod");
  805. if(item && modName)
  806. {
  807. Item::ItemStatString* stat_ = new Item::ItemStatString;
  808. stat_->stat_string.data = string(modName);
  809. stat_->stat_string.size = stat_->stat_string.data.length();
  810. item->AddStatString(stat_);
  811. }
  812. total++;
  813. }
  814. }
  815. return total;
  816. }
  817. void WorldDatabase::ReloadItemList()
  818. {
  819. LogWrite(ITEM__DEBUG, 0, "Items", "Unloading Item List...");
  820. master_item_list.RemoveAll();
  821. LoadItemList();
  822. }
  823. void WorldDatabase::LoadItemList()
  824. {
  825. DatabaseResult result;
  826. int32 t_now = Timer::GetUnixTimeStamp();
  827. int32 total = 0;
  828. int32 normal_items = 0;
  829. string item_type;
  830. if( !database_new.Select(&result, "SELECT * FROM items") )
  831. LogWrite(ITEM__ERROR, 0, "Items", "Cannot load items in %s, line: %i", __FUNCTION__, __LINE__);
  832. else
  833. {
  834. while( result.Next() )
  835. {
  836. item_type = result.GetStringStr("item_type");
  837. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading: %s (ID: %i, Type: %s)...", result.GetStringStr("name"), result.GetInt32Str("id"), item_type.c_str());
  838. Item* item = new Item;
  839. LoadDataFromRow(&result, item);
  840. master_item_list.AddItem(item);
  841. if( strcmp(item_type.c_str(), "Normal") == 0 )
  842. {
  843. item->SetItemType(ITEM_TYPE_NORMAL);
  844. normal_items++;
  845. }
  846. total++;
  847. }
  848. }
  849. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Normal Items", normal_items);
  850. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Baubles", LoadBaubles());
  851. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Bags", LoadBags());
  852. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Books", LoadBooks());
  853. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Sets", LoadItemsets());
  854. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Items", LoadHouseItem());
  855. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Food Items", LoadFoods());
  856. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Weapons", LoadWeapons());
  857. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Ranged Weapons", LoadRangeWeapons());
  858. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Thrown Weapons", LoadThrownWeapons());
  859. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Armor Pieces", LoadArmor());
  860. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Shields", LoadShields());
  861. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Skill Items", LoadSkillItems());
  862. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Adornment Items", LoadAdornments());
  863. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Recipe Book Items", LoadRecipeBookItems());
  864. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Containers", LoadHouseContainers());
  865. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Appearances...");
  866. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Appearances", LoadItemAppearances());
  867. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Stats...");
  868. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Stats", LoadItemStats());
  869. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Stats Mods (Strings)...");
  870. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Stats", LoadItemModStrings());
  871. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Effects...");
  872. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Effects", LoadItemEffects());
  873. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Book Pages...");
  874. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Book Pages", LoadBookPages());
  875. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Level Overrides...");
  876. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Level Overrides", LoadItemLevelOverride());
  877. LogWrite(ITEM__INFO, 0, "Items", "Loaded %u Total Item%s (took %u seconds)", total, ( total == 1 ) ? "" : "s", Timer::GetUnixTimeStamp() - t_now);
  878. }
  879. int32 WorldDatabase::LoadNextUniqueItemID()
  880. {
  881. Query query;
  882. MYSQL_ROW row;
  883. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT max(id) FROM character_items");
  884. if(result && (row = mysql_fetch_row(result)))
  885. {
  886. if(row[0])
  887. {
  888. LogWrite(ITEM__DEBUG, 0, "Items", "%s: max(id): %u", __FUNCTION__, atoul(row[0]));
  889. return strtoul(row[0], NULL, 0);
  890. }
  891. else
  892. return 0;
  893. }
  894. else if(!result)
  895. LogWrite(ITEM__ERROR, 0, "Items", "%s: Unable to load next unique item ID.", __FUNCTION__);
  896. return 0;
  897. }
  898. void WorldDatabase::SaveItems(Client* client)
  899. {
  900. LogWrite(ITEM__DEBUG, 3, "Items", "Save Items for Player %i", client->GetCharacterID());
  901. map<int32, Item*>* items = client->GetPlayer()->GetItemList();
  902. map<int32, Item*>::iterator item_iter;
  903. Item* item = 0;
  904. for(item_iter = items->begin(); item_iter != items->end(); item_iter++)
  905. {
  906. item = item_iter->second;
  907. if(item) {
  908. if(item->needs_deletion || (client->IsZoning() && item->CheckFlag(NO_ZONE))) {
  909. DeleteItem(client->GetCharacterID(), item, 0);
  910. client->GetPlayer()->item_list.DestroyItem(item->details.index);
  911. if(!client->IsZoning()) {
  912. client->QueuePacket(client->GetPlayer()->SendInventoryUpdate(client->GetVersion()));
  913. }
  914. }
  915. else if(item->save_needed)
  916. {
  917. LogWrite(ITEM__DEBUG, 5, "Items", "SaveItems: Acct: %u, Char: %u, Item: %u, NOT-EQUIPPED", client->GetAccountID(), client->GetCharacterID(), item);
  918. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  919. item->save_needed = false;
  920. }
  921. }
  922. }
  923. safe_delete(items);
  924. vector<Item*>* equipped_list = client->GetPlayer()->GetEquippedItemList();
  925. for(int32 i=0;i<equipped_list->size();i++)
  926. {
  927. item = equipped_list->at(i);
  928. if(item)
  929. {
  930. if(item->needs_deletion || (client->IsZoning() && item->CheckFlag(NO_ZONE))) {
  931. DeleteItem(client->GetCharacterID(), item, 0);
  932. client->GetPlayer()->item_list.DestroyItem(item->details.index);
  933. if(!client->IsZoning()) {
  934. client->QueuePacket(client->GetPlayer()->SendInventoryUpdate(client->GetVersion()));
  935. }
  936. }
  937. else if(item->save_needed) {
  938. if(item->details.appearance_type)
  939. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "APPEARANCE");
  940. else
  941. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "EQUIPPED");
  942. }
  943. item->save_needed = false;
  944. }
  945. }
  946. safe_delete(equipped_list);
  947. vector<Item*>* appearance_equipped_list = client->GetPlayer()->GetAppearanceEquippedItemList();
  948. for(int32 i=0;i<appearance_equipped_list->size();i++)
  949. {
  950. item = appearance_equipped_list->at(i);
  951. if(item)
  952. {
  953. if(item->needs_deletion || (client->IsZoning() && item->CheckFlag(NO_ZONE))) {
  954. DeleteItem(client->GetCharacterID(), item, 0);
  955. client->GetPlayer()->item_list.DestroyItem(item->details.index);
  956. if(!client->IsZoning()) {
  957. client->QueuePacket(client->GetPlayer()->SendInventoryUpdate(client->GetVersion()));
  958. }
  959. }
  960. else if(item->save_needed) {
  961. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "APPEARANCE");
  962. item->save_needed = false;
  963. }
  964. }
  965. }
  966. safe_delete(appearance_equipped_list);
  967. vector<Item*>* overflow = client->GetPlayer()->item_list.GetOverflowItemList();
  968. for (int32 i = 0; i < overflow->size(); i++){
  969. item = overflow->at(i);
  970. if (item) {
  971. if(item->needs_deletion || (client->IsZoning() && item->CheckFlag(NO_ZONE))) {
  972. DeleteItem(client->GetCharacterID(), item, 0);
  973. client->GetPlayer()->item_list.DestroyItem(item->details.index);
  974. if(!client->IsZoning()) {
  975. client->QueuePacket(client->GetPlayer()->SendInventoryUpdate(client->GetVersion()));
  976. }
  977. }
  978. else {
  979. sint16 slot = item->details.slot_id;
  980. item->details.slot_id = i;
  981. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  982. item->details.slot_id = slot;
  983. }
  984. }
  985. }
  986. safe_delete(overflow);
  987. }
  988. void WorldDatabase::SaveItem(int32 account_id, int32 char_id, Item* item, const char* type)
  989. {
  990. LogWrite(ITEM__DEBUG, 1, "Items", "Saving ItemID: %u (Type: %s) for account: %u, player: %u", item->details.item_id, type, account_id, char_id);
  991. Query query;
  992. string update_item = string("REPLACE INTO character_items (id, type, char_id, slot, item_id, creator,adorn0,adorn1,adorn2, condition_, attuned, bag_id, count, max_sell_value, no_sale, account_id, login_checksum) VALUES (%u, '%s', %u, %i, %u, '%s', %i, %i, %i, %i, %i, %i, %i, %u, %u, %u, 0)");
  993. query.AddQueryAsync(char_id, this, Q_REPLACE, update_item.c_str(), item->details.unique_id, type, char_id, item->details.slot_id, item->details.item_id,
  994. getSafeEscapeString(item->creator.c_str()).c_str(),item->adorn0,item->adorn1,item->adorn2, item->generic_info.condition, item->CheckFlag(ATTUNED) ? 1 : 0, item->details.inv_slot_id, item->details.count, item->GetMaxSellValue(), item->no_sale, account_id);
  995. }
  996. void WorldDatabase::DeleteItem(int32 char_id, Item* item, const char* type)
  997. {
  998. Query query;
  999. string delete_item;
  1000. if(type)
  1001. {
  1002. LogWrite(ITEM__DEBUG, 1, "Items", "Deleting item_id %u (Type: %s) for player %u", item->details.item_id, type, char_id);
  1003. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u) AND type='%s'");
  1004. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id, type);
  1005. }
  1006. else
  1007. {
  1008. LogWrite(ITEM__DEBUG, 0, "Items", "Deleting item_id %u for player %u", item->details.item_id, char_id);
  1009. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u)");
  1010. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id);
  1011. }
  1012. }
  1013. void WorldDatabase::LoadCharacterItemList(int32 account_id, int32 char_id, Player* player, int16 version)
  1014. {
  1015. LogWrite(ITEM__DEBUG, 0, "Items", "Loading items for character '%s' (%u)", player->GetName(), char_id);
  1016. Query query;
  1017. MYSQL_ROW row;
  1018. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT type, id, slot, item_id, creator,adorn0,adorn1,adorn2, condition_, attuned, bag_id, count, max_sell_value, no_sale FROM character_items where char_id = %u or (bag_id = -4 and account_id = %u) ORDER BY slot asc", char_id, account_id);
  1019. if(result)
  1020. {
  1021. bool ret = true;
  1022. while(result && (row = mysql_fetch_row(result)))
  1023. {
  1024. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading character item: %u, slot: %i", strtoul(row[1], NULL, 0), atoi(row[2]));
  1025. Item* master_item = master_item_list.GetItem(strtoul(row[3], NULL, 0));
  1026. if(master_item)
  1027. {
  1028. Item* item = new Item(master_item);
  1029. item->details.unique_id = strtoul(row[1], NULL, 0);
  1030. item->details.slot_id = atoi(row[2]);
  1031. if(item->details.num_slots > 0)
  1032. item->details.bag_id = item->details.unique_id;
  1033. item->save_needed = false;
  1034. if(row[4])
  1035. item->creator = string(row[4]);//creator
  1036. item->adorn0 = atoi(row[5]); //adorn0
  1037. item->adorn1 = atoi(row[6]); //adorn1
  1038. item->adorn2 = atoi(row[7]); //adorn2
  1039. item->generic_info.condition = atoi(row[8]); //condition
  1040. if(row[9] && atoi(row[9])>0) //attuned
  1041. {
  1042. if(item->CheckFlag(ATTUNEABLE))
  1043. item->generic_info.item_flags -= ATTUNEABLE;
  1044. if(!item->CheckFlag(NO_TRADE))
  1045. item->generic_info.item_flags += NO_TRADE;
  1046. item->generic_info.item_flags += ATTUNED;
  1047. }
  1048. item->details.inv_slot_id = atol(row[10]); //bag_id
  1049. item->details.count = atoi(row[11]); //count
  1050. item->SetMaxSellValue(atoul(row[12])); //max sell value
  1051. item->no_sale = (atoul(row[13]) == 1);
  1052. item->details.appearance_type = 0;
  1053. if(strncasecmp(row[0], "EQUIPPED", 8)==0)
  1054. ret = player->GetEquipmentList()->AddItem(item->details.slot_id, item);
  1055. else if (strncasecmp(row[0], "APPEARANCE", 10) == 0)
  1056. {
  1057. item->details.appearance_type = 1;
  1058. ret = player->GetAppearanceEquipmentList()->AddItem(item->details.slot_id, item);
  1059. }
  1060. else {
  1061. if (version < 1209 && item->details.count > 255) {
  1062. int stacks = item->details.count / 255;
  1063. int8 remainder = item->details.count % 255;
  1064. item->details.count = remainder;
  1065. if (item->details.inv_slot_id == -2)
  1066. player->item_list.AddOverflowItem(item);
  1067. else {
  1068. if(!player->item_list.AddItem(item))
  1069. item = nullptr;
  1070. }
  1071. if(item) {
  1072. for (int stack = 1; stack <= stacks; stack++) {
  1073. item->details.count = 255;
  1074. item->details.inv_slot_id = -2;
  1075. player->item_list.AddOverflowItem(item);
  1076. }
  1077. }
  1078. }
  1079. else {
  1080. if (item->details.inv_slot_id == -2)
  1081. player->item_list.AddOverflowItem(item);
  1082. else
  1083. player->item_list.AddItem(item);
  1084. }
  1085. }
  1086. }
  1087. else
  1088. ret = false;
  1089. }
  1090. if(!ret)
  1091. LogWrite(ITEM__ERROR, 0, "Items", "%s: Error Loading item(s) for Char ID: %u (%s)", __FUNCTION__, char_id, player->GetName());
  1092. }
  1093. }