ItemsDB.cpp 40 KB

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