9
3

ItemsDB.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. }
  213. int32 WorldDatabase::LoadSkillItems()
  214. {
  215. Query query;
  216. MYSQL_ROW row;
  217. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, spell_id, spell_tier FROM item_details_skill");
  218. int32 total = 0;
  219. int32 id = 0;
  220. if(result)
  221. {
  222. while(result && (row = mysql_fetch_row(result)))
  223. {
  224. id = atoul(row[0]);
  225. Item* item = master_item_list.GetItem(id);
  226. if(item)
  227. {
  228. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading Skill for item_id %u", id);
  229. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, spell: %i, tier: %i", ITEM_TYPE_SKILL, atoi(row[1]), atoi(row[2]));
  230. item->SetItemType(ITEM_TYPE_SKILL);
  231. item->skill_info->spell_id = atoul(row[1]);
  232. item->skill_info->spell_tier = atoi(row[2]);
  233. total++;
  234. }
  235. else
  236. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_skill`, ID: %i", id);
  237. }
  238. }
  239. return total;
  240. }
  241. int32 WorldDatabase::LoadShields()
  242. {
  243. Query query;
  244. MYSQL_ROW row;
  245. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_shield");
  246. int32 total = 0;
  247. int32 id = 0;
  248. if(result)
  249. {
  250. while(result && (row = mysql_fetch_row(result)))
  251. {
  252. id = strtoul(row[0], NULL, 0);
  253. Item* item = master_item_list.GetItem(id);
  254. if(item)
  255. {
  256. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Shield for item_id: %u", id);
  257. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_SHIELD, atoi(row[1]), atoi(row[2]));
  258. item->SetItemType(ITEM_TYPE_SHIELD);
  259. item->armor_info->mitigation_low = atoi(row[1]);
  260. item->armor_info->mitigation_high = atoi(row[2]);
  261. total++;
  262. }
  263. else
  264. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_shield`, ID: %i", id);
  265. }
  266. }
  267. return total;
  268. }
  269. int32 WorldDatabase::LoadAdornments()
  270. {
  271. Query query;
  272. MYSQL_ROW row;
  273. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, duration, item_types,slot_type FROM item_details_adornments");
  274. int32 total = 0;
  275. int32 id = 0;
  276. if (result)
  277. {
  278. while (result && (row = mysql_fetch_row(result)))
  279. {
  280. id = strtoul(row[0], NULL, 0);
  281. Item* item = master_item_list.GetItem(id);
  282. if (item)
  283. {
  284. //LogWrite(ITEM__DEBUG, 0, "Items", "\tItem Adornment for item_id: %u", id);
  285. //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]));
  286. item->SetItemType(ITEM_TYPE_ADORNMENT);
  287. item->adornment_info->duration = atof(row[1]);
  288. item->adornment_info->item_types = atoi(row[2]);
  289. item->adornment_info->slot_type = atoi(row[3]);
  290. //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);
  291. total++;
  292. }
  293. else
  294. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_shield`, ID: %i", id);
  295. }
  296. }
  297. return total;
  298. }
  299. int32 WorldDatabase::LoadClassifications()
  300. {
  301. int32 total = 0;
  302. int32 id = 0;
  303. return total;
  304. }
  305. int32 WorldDatabase::LoadBaubles()
  306. {
  307. Query query;
  308. MYSQL_ROW row;
  309. 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");
  310. int32 total = 0;
  311. int32 id = 0;
  312. if(result)
  313. {
  314. while(result && (row = mysql_fetch_row(result)))
  315. {
  316. id = strtoul(row[0], NULL, 0);
  317. Item* item = master_item_list.GetItem(id);
  318. if(item)
  319. {
  320. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bauble for item_id %u", id);
  321. 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]));
  322. item->SetItemType(ITEM_TYPE_BAUBLE);
  323. item->bauble_info->cast = atoi(row[1]);
  324. item->bauble_info->recovery = atoi(row[2]);
  325. item->bauble_info->duration = atoi(row[3]);
  326. item->bauble_info->recast = atoi(row[4]);
  327. item->bauble_info->display_slot_optional = atoi(row[5]);
  328. item->bauble_info->display_cast_time = atoi(row[6]);
  329. item->bauble_info->display_bauble_type = atoi(row[7]);
  330. item->bauble_info->effect_radius = atof(row[8]);
  331. item->bauble_info->max_aoe_targets = atoi(row[9]);
  332. item->bauble_info->display_until_cancelled = atoi(row[10]);
  333. total++;
  334. }
  335. else
  336. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bauble`, ID: %i", id);
  337. }
  338. }
  339. return total;
  340. }
  341. int32 WorldDatabase::LoadBooks()
  342. {
  343. DatabaseResult result;
  344. int32 total = 0;
  345. int32 id = 0;
  346. if( database_new.Select(&result, "SELECT item_id, language, author, title FROM item_details_book") )
  347. {
  348. while( result.Next() )
  349. {
  350. id = result.GetInt32Str("item_id");
  351. Item* item = master_item_list.GetItem(id);
  352. if(item)
  353. {
  354. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Book for item_id %u", id);
  355. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %s, %s",
  356. ITEM_TYPE_BOOK,
  357. result.GetInt8Str("language"),
  358. result.GetStringStr("author"),
  359. result.GetStringStr("title"));
  360. item->SetItemType(ITEM_TYPE_BOOK);
  361. item->book_info->language = result.GetInt8Str("language");
  362. item->book_info->author.data = result.GetStringStr("author");
  363. item->book_info->author.size = item->book_info->author.data.length();
  364. item->book_info->title.data = result.GetStringStr("title");
  365. item->book_info->title.size = item->book_info->title.data.length();
  366. total++;
  367. }
  368. else
  369. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_book`, ID: %i", id);
  370. }
  371. }
  372. return total;
  373. }
  374. int32 WorldDatabase::LoadItemsets()
  375. {
  376. DatabaseResult result;
  377. int32 total = 0;
  378. int32 id = 0;
  379. 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"))
  380. {
  381. while (result.Next())
  382. {
  383. id = result.GetInt32Str("itemset_item_id");
  384. Item* item = master_item_list.GetItem(id);
  385. if (item)
  386. {
  387. item->SetItemType(ITEM_TYPE_ITEMCRATE);
  388. //int32 item_id = result.GetInt32Str("item_id");
  389. item->AddSet(result.GetInt32Str("item_id"),0, result.GetInt16Str("item_icon"), result.GetInt16Str("item_stack_size"), result.GetInt32Str("item_list_color"));
  390. total++;
  391. }
  392. else
  393. LogWrite(ITEM__ERROR, 0, "Item Set Crate Items", "Error loading `item_details_Items`, ID: %i", id);
  394. }
  395. }
  396. return total;
  397. }
  398. int32 WorldDatabase::LoadHouseItem()
  399. {
  400. Query query;
  401. MYSQL_ROW row;
  402. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, rent_reduction, status_rent_reduction, coin_rent_reduction, house_only FROM item_details_house");
  403. int32 total = 0;
  404. int32 id = 0;
  405. if(result)
  406. {
  407. while(result && (row = mysql_fetch_row(result)))
  408. {
  409. id = strtoul(row[0], NULL, 0);
  410. Item* item = master_item_list.GetItem(id);
  411. if(item)
  412. {
  413. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem HouseItem for item_id %u", id);
  414. 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]));
  415. item->SetItemType(ITEM_TYPE_HOUSE);
  416. item->houseitem_info->status_rent_reduction = atoi(row[2]);
  417. item->houseitem_info->coin_rent_reduction = atof(row[3]);
  418. item->houseitem_info->house_only = atoi(row[4]);
  419. total++;
  420. }
  421. else
  422. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house`, ID: %i", id);
  423. }
  424. }
  425. return total;
  426. }
  427. int32 WorldDatabase::LoadRecipeBookItems()
  428. {
  429. Query query;
  430. MYSQL_ROW row;
  431. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, name FROM item_details_recipe_items");
  432. int32 total = 0;
  433. int32 id = 0;
  434. if (result)
  435. {
  436. while(result && (row = mysql_fetch_row(result)))
  437. {
  438. id = strtoul(row[0], NULL, 0);
  439. Item* item = master_item_list.GetItem(id);
  440. if(item)
  441. {
  442. LogWrite(ITEM__DEBUG, 5, "Items", "\tRecipe Book for item_id %u", id);
  443. LogWrite(ITEM__DEBUG, 5, "Items", "\tType: %i, '%s'", ITEM_TYPE_RECIPE, row[1]);
  444. item->SetItemType(ITEM_TYPE_RECIPE);
  445. item->recipebook_info->recipes.push_back(string(row[1]));
  446. total++;
  447. }
  448. else
  449. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_recipe_items`, ID: %u", id);
  450. }
  451. }
  452. return total;
  453. }
  454. int32 WorldDatabase::LoadHouseContainers(){
  455. DatabaseResult result;
  456. int32 total = 0;
  457. int32 id = 0;
  458. if( database_new.Select(&result, "SELECT item_id, num_slots, allowed_types, broker_commission, fence_commission FROM item_details_house_container") )
  459. {
  460. while (result.Next() )
  461. {
  462. id = result.GetInt32Str("item_id");
  463. Item* item = master_item_list.GetItem(id);
  464. if (item)
  465. {
  466. LogWrite(ITEM__DEBUG, 5, "Items", "\tHouse Container for item_id %u", id);
  467. 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"));
  468. item->SetItemType(ITEM_TYPE_HOUSE_CONTAINER);
  469. item->housecontainer_info->num_slots = result.GetInt8Str("num_slots");
  470. item->housecontainer_info->allowed_types = result.GetInt64Str("allowed_types");
  471. item->housecontainer_info->broker_commission = result.GetInt8Str("broker_commission");
  472. item->housecontainer_info->fence_commission = result.GetInt8Str("fence_commission");
  473. total++;
  474. }
  475. else
  476. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house_container`, ID: %u", id);
  477. }
  478. }
  479. return total;
  480. }
  481. int32 WorldDatabase::LoadArmor()
  482. {
  483. Query query;
  484. MYSQL_ROW row;
  485. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_armor");
  486. int32 total = 0;
  487. int32 id = 0;
  488. if(result)
  489. {
  490. while(result && (row = mysql_fetch_row(result)))
  491. {
  492. id = strtoul(row[0], NULL, 0);
  493. Item* item = master_item_list.GetItem(id);
  494. if(item)
  495. {
  496. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Armor for item_id %u", id);
  497. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_ARMOR, atoi(row[1]), atoi(row[2]));
  498. item->SetItemType(ITEM_TYPE_ARMOR);
  499. item->armor_info->mitigation_low = atoi(row[1]);
  500. item->armor_info->mitigation_high = atoi(row[2]);
  501. total++;
  502. }
  503. else
  504. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_armor`, ID: %i", id);
  505. }
  506. }
  507. return total;
  508. }
  509. int32 WorldDatabase::LoadBags()
  510. {
  511. Query query;
  512. MYSQL_ROW row;
  513. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, num_slots, weight_reduction FROM item_details_bag");
  514. int32 total = 0;
  515. int32 id = 0;
  516. if(result)
  517. {
  518. while(result && (row = mysql_fetch_row(result)))
  519. {
  520. id = strtoul(row[0], NULL, 0);
  521. Item* item = master_item_list.GetItem(id);
  522. if(item)
  523. {
  524. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bag for item_id %u", id);
  525. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, slots: %i, wt_red: %i", id, ITEM_TYPE_BAG, atoi(row[1]), atoi(row[2]));
  526. item->SetItemType(ITEM_TYPE_BAG);
  527. item->details.num_slots = atoi(row[1]);
  528. item->details.num_free_slots = item->details.num_slots;
  529. item->bag_info->num_slots = item->details.num_slots;
  530. item->bag_info->weight_reduction = atoi(row[2]);
  531. total++;
  532. }
  533. else
  534. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bag`, ID: %i", id);
  535. }
  536. }
  537. return total;
  538. }
  539. int32 WorldDatabase::LoadFoods()
  540. {
  541. Query query;
  542. MYSQL_ROW row;
  543. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, level, duration, satiation FROM item_details_food");
  544. int32 total = 0;
  545. int32 id = 0;
  546. if(result)
  547. {
  548. while(result && (row = mysql_fetch_row(result)))
  549. {
  550. id = strtoul(row[0], NULL, 0);
  551. Item* item = master_item_list.GetItem(id);
  552. if(item)
  553. {
  554. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Food for item_id %u", id);
  555. 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]));
  556. item->SetItemType(ITEM_TYPE_FOOD);
  557. item->food_info->type = atoi(row[1]);
  558. item->food_info->level = atoi(row[2]);
  559. item->food_info->duration = atof(row[3]);
  560. item->food_info->satiation = atoi(row[4]);
  561. item->details.tier = atoi(row[4]);
  562. total++;
  563. }
  564. else
  565. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_food`, ID: %i", id);
  566. }
  567. }
  568. return total;
  569. }
  570. int32 WorldDatabase::LoadRangeWeapons()
  571. {
  572. Query query;
  573. MYSQL_ROW row;
  574. 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");
  575. int32 total = 0;
  576. int32 id = 0;
  577. if(result)
  578. {
  579. while(result && (row = mysql_fetch_row(result)))
  580. {
  581. id = strtoul(row[0], NULL, 0);
  582. Item* item = master_item_list.GetItem(id);
  583. if(item)
  584. {
  585. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Ranged for item_id %u", id);
  586. 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]));
  587. item->SetItemType(ITEM_TYPE_RANGED);
  588. item->ranged_info->weapon_info.damage_low1 = atoi(row[1]);
  589. item->ranged_info->weapon_info.damage_high1 = atoi(row[2]);
  590. item->ranged_info->weapon_info.damage_low2 = atoi(row[3]);
  591. item->ranged_info->weapon_info.damage_high2 = atoi(row[4]);
  592. item->ranged_info->weapon_info.damage_low3 = atoi(row[5]);
  593. item->ranged_info->weapon_info.damage_high3 = atoi(row[6]);
  594. item->ranged_info->weapon_info.delay = atoi(row[7]);
  595. item->ranged_info->weapon_info.rating = atof(row[8]);
  596. item->ranged_info->range_low = atoi(row[9]);
  597. item->ranged_info->range_high = atoi(row[10]);
  598. item->SetWeaponType(atoi(row[11]));
  599. total++;
  600. }
  601. else
  602. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_range`, ID: %i", id);
  603. }
  604. }
  605. return total;
  606. }
  607. int32 WorldDatabase::LoadThrownWeapons()
  608. {
  609. Query query;
  610. MYSQL_ROW row;
  611. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, range_bonus, damage_bonus, hit_bonus, damage_type FROM item_details_thrown");
  612. int32 total = 0;
  613. int32 id = 0;
  614. if(result)
  615. {
  616. while(result && (row = mysql_fetch_row(result)))
  617. {
  618. id = strtoul(row[0], NULL, 0);
  619. Item* item = master_item_list.GetItem(id);
  620. if(item)
  621. {
  622. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Thrown for item_id %u", id);
  623. 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]));
  624. item->SetItemType(ITEM_TYPE_THROWN);
  625. item->thrown_info->range = atoul(row[1]);
  626. item->thrown_info->damage_modifier = atoul(row[2]);
  627. item->thrown_info->hit_bonus = atof(row[3]);
  628. item->thrown_info->damage_type = atoul(row[4]);
  629. item->SetWeaponType(item->thrown_info->damage_type);
  630. total++;
  631. }
  632. else
  633. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_thrown`, ID: %i", id);
  634. }
  635. }
  636. return total;
  637. }
  638. int32 WorldDatabase::LoadWeapons()
  639. {
  640. Query query;
  641. MYSQL_ROW row;
  642. 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");
  643. int32 total = 0;
  644. int32 id = 0;
  645. if(result)
  646. {
  647. while(result && (row = mysql_fetch_row(result)))
  648. {
  649. id = strtoul(row[0], NULL, 0);
  650. Item* item = master_item_list.GetItem(id);
  651. if(item)
  652. {
  653. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Weapon for item_id %u", id);
  654. 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]));
  655. item->SetItemType(ITEM_TYPE_WEAPON);
  656. item->weapon_info->wield_type = atoi(row[1]);
  657. item->weapon_info->damage_low1 = atoi(row[2]);
  658. item->weapon_info->damage_high1 = atoi(row[3]);
  659. item->weapon_info->damage_low2 = atoi(row[4]);
  660. item->weapon_info->damage_high2 = atoi(row[5]);
  661. item->weapon_info->damage_low3 = atoi(row[6]);
  662. item->weapon_info->damage_high3 = atoi(row[7]);
  663. item->weapon_info->delay = atoi(row[8]);
  664. item->weapon_info->rating = atof(row[9]);
  665. item->SetWeaponType(atoi(row[10]));
  666. total++;
  667. }
  668. else
  669. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_weapons`, ID: %i", id);
  670. }
  671. }
  672. return total;
  673. }
  674. int32 WorldDatabase::LoadItemAppearances()
  675. {
  676. Query query;
  677. MYSQL_ROW row;
  678. 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");
  679. int32 id = 0;
  680. Item* item = 0;
  681. int32 total = 0;
  682. if(result && mysql_num_rows(result) >0)
  683. {
  684. while(result && (row = mysql_fetch_row(result)))
  685. {
  686. if(id != strtoul(row[0], NULL, 0))
  687. {
  688. id = strtoul(row[0], NULL, 0);
  689. item = master_item_list.GetItem(id);
  690. if(item)
  691. {
  692. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Appearance for item_id %u", id);
  693. 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]));
  694. item->SetAppearance(atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]));
  695. total++;
  696. }
  697. else
  698. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_appearances, ID: %i", id);
  699. }
  700. }
  701. }
  702. return total;
  703. }
  704. int32 WorldDatabase::LoadItemEffects()
  705. {
  706. Query query;
  707. MYSQL_ROW row;
  708. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, effect, percentage, bullet FROM item_effects ORDER BY item_id, id");
  709. int32 id = 0;
  710. Item* item = 0;
  711. int32 total = 0;
  712. if(result && mysql_num_rows(result) >0)
  713. {
  714. while(result && (row = mysql_fetch_row(result)))
  715. {
  716. if(id != atoul(row[0]))
  717. {
  718. id = atoul(row[0]);
  719. item = master_item_list.GetItem(id);
  720. }
  721. if(item && row[1])
  722. {
  723. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Effects for item_id %u", id);
  724. LogWrite(ITEM__DEBUG, 5, "Items", "\tEffect: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  725. item->AddEffect(row[1], atoi(row[2]), atoi(row[3]));
  726. total++;
  727. }
  728. else
  729. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_effects, ID: %i", id);
  730. }
  731. }
  732. return total;
  733. }
  734. int32 WorldDatabase::LoadBookPages()
  735. {
  736. Query query;
  737. MYSQL_ROW row;
  738. 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");
  739. int32 id = 0;
  740. Item* item = 0;
  741. int32 total = 0;
  742. if (result && mysql_num_rows(result) > 0)
  743. {
  744. while (result && (row = mysql_fetch_row(result)))
  745. {
  746. if (id != atoul(row[0]))
  747. {
  748. id = atoul(row[0]);
  749. item = master_item_list.GetItem(id);
  750. }
  751. if (item && row[1])
  752. {
  753. LogWrite(ITEM__DEBUG, 5, "Items", "\tBook Pages for item_id %u", id);
  754. //LogWrite(ITEM__DEBUG, 5, "Items", "\tPages: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  755. item->AddBookPage(atoi(row[1]), row[2], atoi(row[3]), atoi(row[4]));
  756. total++;
  757. }
  758. else
  759. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_details_book_pages, ID: %i", id);
  760. }
  761. }
  762. return total;
  763. }
  764. int32 WorldDatabase::LoadItemLevelOverride()
  765. {
  766. Query query;
  767. MYSQL_ROW row;
  768. 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");
  769. int32 id = 0;
  770. Item* item = 0;
  771. int32 total = 0;
  772. if(result && mysql_num_rows(result) >0)
  773. {
  774. while(result && (row = mysql_fetch_row(result)))
  775. {
  776. if(id != strtoul(row[0], NULL, 0))
  777. {
  778. id = strtoul(row[0], NULL, 0);
  779. item = master_item_list.GetItem(id);
  780. }
  781. if(item)
  782. {
  783. LogWrite(ITEM__DEBUG, 5, "Items", "\tLevel Override for item_id %u", id);
  784. LogWrite(ITEM__DEBUG, 5, "Items", "\tAdv: %i, TS: %i, Lvl: %i", atoi(row[1]), atoi(row[2]), atoi(row[3]));
  785. item->AddLevelOverride(atoi(row[1]), atoi(row[2]), atoi(row[3]));
  786. total++;
  787. }
  788. else
  789. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_levels_override`, ID: %i", id);
  790. }
  791. }
  792. return total;
  793. }
  794. int32 WorldDatabase::LoadItemStats()
  795. {
  796. Query query;
  797. MYSQL_ROW row;
  798. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, subtype, value, text FROM item_stats ORDER BY item_id asc");
  799. int32 id = 0;
  800. Item* item = 0;
  801. int32 total = 0;
  802. if(result && mysql_num_rows(result) >0)
  803. {
  804. while(result && (row = mysql_fetch_row(result)))
  805. {
  806. if(id != strtoul(row[0], NULL, 0))
  807. {
  808. id = strtoul(row[0], NULL, 0);
  809. item = master_item_list.GetItem(id);
  810. }
  811. if(item)
  812. {
  813. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Stats for item_id %u", id);
  814. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, sub: %i, val: %.2f, name: %s", atoi(row[1]), atoi(row[2]), atof(row[3]), row[4]);
  815. item->AddStat(atoi(row[1]), atoi(row[2]), atof(row[3]), row[4]);
  816. total++;
  817. }
  818. else
  819. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_stats`, ID: %i", id);
  820. }
  821. }
  822. return total;
  823. }
  824. void WorldDatabase::ReloadItemList()
  825. {
  826. LogWrite(ITEM__DEBUG, 0, "Items", "Unloading Item List...");
  827. master_item_list.RemoveAll();
  828. LoadItemList();
  829. }
  830. void WorldDatabase::LoadItemList()
  831. {
  832. DatabaseResult result;
  833. int32 t_now = Timer::GetUnixTimeStamp();
  834. int32 total = 0;
  835. int32 normal_items = 0;
  836. string item_type;
  837. if( !database_new.Select(&result, "SELECT * FROM items") )
  838. LogWrite(ITEM__ERROR, 0, "Items", "Cannot load items in %s, line: %i", __FUNCTION__, __LINE__);
  839. else
  840. {
  841. while( result.Next() )
  842. {
  843. item_type = result.GetStringStr("item_type");
  844. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading: %s (ID: %i, Type: %s)...", result.GetStringStr("name"), result.GetInt32Str("id"), item_type.c_str());
  845. Item* item = new Item;
  846. LoadDataFromRow(&result, item);
  847. master_item_list.AddItem(item);
  848. if( strcmp(item_type.c_str(), "Normal") == 0 )
  849. {
  850. item->SetItemType(ITEM_TYPE_NORMAL);
  851. normal_items++;
  852. }
  853. total++;
  854. }
  855. }
  856. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Normal Items", normal_items);
  857. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Baubles", LoadBaubles());
  858. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Bags", LoadBags());
  859. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Books", LoadBooks());
  860. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Sets", LoadItemsets());
  861. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Items", LoadHouseItem());
  862. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Food Items", LoadFoods());
  863. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Weapons", LoadWeapons());
  864. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Ranged Weapons", LoadRangeWeapons());
  865. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Thrown Weapons", LoadThrownWeapons());
  866. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Armor Pieces", LoadArmor());
  867. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Shields", LoadShields());
  868. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Skill Items", LoadSkillItems());
  869. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Adornment Items", LoadAdornments());
  870. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Recipe Book Items", LoadRecipeBookItems());
  871. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Containers", LoadHouseContainers());
  872. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Appearances...");
  873. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Appearances", LoadItemAppearances());
  874. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Stats...");
  875. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Stats", LoadItemStats());
  876. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Effects...");
  877. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Effects", LoadItemEffects());
  878. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Book Pages...");
  879. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Book Pages", LoadBookPages());
  880. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Level Overrides...");
  881. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Level Overrides", LoadItemLevelOverride());
  882. LogWrite(ITEM__INFO, 0, "Items", "Loaded %u Total Item%s (took %u seconds)", total, ( total == 1 ) ? "" : "s", Timer::GetUnixTimeStamp() - t_now);
  883. }
  884. int32 WorldDatabase::LoadNextUniqueItemID()
  885. {
  886. Query query;
  887. MYSQL_ROW row;
  888. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT max(id) FROM character_items");
  889. if(result && (row = mysql_fetch_row(result)))
  890. {
  891. if(row[0])
  892. {
  893. LogWrite(ITEM__DEBUG, 0, "Items", "%s: max(id): %u", __FUNCTION__, atoul(row[0]));
  894. return strtoul(row[0], NULL, 0);
  895. }
  896. else
  897. return 0;
  898. }
  899. else if(!result)
  900. LogWrite(ITEM__ERROR, 0, "Items", "%s: Unable to load next unique item ID.", __FUNCTION__);
  901. return 0;
  902. }
  903. void WorldDatabase::SaveItems(Client* client)
  904. {
  905. LogWrite(ITEM__DEBUG, 3, "Items", "Save Items for Player %i", client->GetCharacterID());
  906. map<int32, Item*>* items = client->GetPlayer()->GetItemList();
  907. map<int32, Item*>::iterator item_iter;
  908. Item* item = 0;
  909. for(item_iter = items->begin(); item_iter != items->end(); item_iter++)
  910. {
  911. item = item_iter->second;
  912. if(item && item->save_needed)
  913. {
  914. LogWrite(ITEM__DEBUG, 5, "Items", "SaveItems: Acct: %u, Char: %u, Item: %u, NOT-EQUIPPED", client->GetAccountID(), client->GetCharacterID(), item);
  915. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  916. item->save_needed = false;
  917. }
  918. }
  919. safe_delete(items);
  920. vector<Item*>* equipped_list = client->GetPlayer()->GetEquippedItemList();
  921. for(int32 i=0;i<equipped_list->size();i++)
  922. {
  923. item = equipped_list->at(i);
  924. if(item && item->save_needed)
  925. {
  926. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "EQUIPPED");
  927. item->save_needed = false;
  928. }
  929. }
  930. safe_delete(equipped_list);
  931. vector<Item*>* overflow = client->GetPlayer()->item_list.GetOverflowItemList();
  932. for (int32 i = 0; i < overflow->size(); i++){
  933. item = overflow->at(i);
  934. if (item) {
  935. sint16 slot = item->details.slot_id;
  936. item->details.slot_id = i;
  937. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  938. item->details.slot_id = slot;
  939. }
  940. }
  941. safe_delete(overflow);
  942. }
  943. void WorldDatabase::SaveItem(int32 account_id, int32 char_id, Item* item, const char* type)
  944. {
  945. LogWrite(ITEM__DEBUG, 1, "Items", "Saving ItemID: %u (Type: %s) for account: %u, player: %u", item->details.item_id, type, account_id, char_id);
  946. Query query;
  947. 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, account_id, login_checksum) VALUES (%u, '%s', %u, %i, %u, '%s', %i, %i, %i, %i, %i, %i, %i, %u, %u, 0)");
  948. 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,
  949. 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(), account_id);
  950. }
  951. void WorldDatabase::DeleteItem(int32 char_id, Item* item, const char* type)
  952. {
  953. Query query;
  954. string delete_item;
  955. if(type)
  956. {
  957. LogWrite(ITEM__DEBUG, 1, "Items", "Deleting item_id %u (Type: %s) for player %u", item->details.item_id, type, char_id);
  958. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u) AND type='%s'");
  959. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id, type);
  960. }
  961. else
  962. {
  963. LogWrite(ITEM__DEBUG, 0, "Items", "Deleting item_id %u for player %u", item->details.item_id, char_id);
  964. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u)");
  965. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id);
  966. }
  967. }
  968. void WorldDatabase::LoadCharacterItemList(int32 account_id, int32 char_id, Player* player, int16 version)
  969. {
  970. LogWrite(ITEM__DEBUG, 0, "Items", "Loading items for character '%s' (%u)", player->GetName(), char_id);
  971. Query query;
  972. MYSQL_ROW row;
  973. 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 FROM character_items where char_id = %u or (bag_id = -4 and account_id = %u) ORDER BY slot asc", char_id, account_id);
  974. if(result)
  975. {
  976. bool ret = true;
  977. while(result && (row = mysql_fetch_row(result)))
  978. {
  979. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading character item: %u, slot: %i", strtoul(row[1], NULL, 0), atoi(row[2]));
  980. Item* master_item = master_item_list.GetItem(strtoul(row[3], NULL, 0));
  981. if(master_item)
  982. {
  983. Item* item = new Item(master_item);
  984. item->details.unique_id = strtoul(row[1], NULL, 0);
  985. item->details.slot_id = atoi(row[2]);
  986. if(item->details.num_slots > 0)
  987. item->details.bag_id = item->details.unique_id;
  988. item->save_needed = false;
  989. if(row[4])
  990. item->creator = string(row[4]);//creator
  991. item->adorn0 = atoi(row[5]); //adorn0
  992. item->adorn1 = atoi(row[6]); //adorn1
  993. item->adorn2 = atoi(row[7]); //adorn2
  994. item->generic_info.condition = atoi(row[8]); //condition
  995. if(row[9] && atoi(row[9])>0) //attuned
  996. {
  997. if(item->CheckFlag(ATTUNEABLE))
  998. item->generic_info.item_flags -= ATTUNEABLE;
  999. if(!item->CheckFlag(NO_TRADE))
  1000. item->generic_info.item_flags += NO_TRADE;
  1001. item->generic_info.item_flags += ATTUNED;
  1002. }
  1003. item->details.inv_slot_id = atol(row[10]); //bag_id
  1004. item->details.count = atoi(row[11]); //count
  1005. item->SetMaxSellValue(atoul(row[12])); //max sell value
  1006. if(strncasecmp(row[0], "EQUIPPED", 8)==0)
  1007. ret = player->GetEquipmentList()->AddItem(item->details.slot_id, item);
  1008. else if (strncasecmp(row[0], "APPEARANCE", 10) == 2)
  1009. ret = player->GetEquipmentList()->AddItem(item->details.slot_id, item);
  1010. else {
  1011. if (version < 1209 && item->details.count > 255) {
  1012. int stacks = item->details.count / 255;
  1013. int8 remainder = item->details.count % 255;
  1014. item->details.count = remainder;
  1015. if (item->details.inv_slot_id == -2)
  1016. player->item_list.AddOverflowItem(item);
  1017. else
  1018. player->item_list.AddItem(item);
  1019. for (int stack = 1; stack <= stacks; stack++) {
  1020. item->details.count = 255;
  1021. item->details.inv_slot_id = -2;
  1022. player->item_list.AddOverflowItem(item);
  1023. }
  1024. }
  1025. else {
  1026. if (item->details.inv_slot_id == -2)
  1027. player->item_list.AddOverflowItem(item);
  1028. else
  1029. player->item_list.AddItem(item);
  1030. }
  1031. }
  1032. }
  1033. else
  1034. ret = false;
  1035. }
  1036. if(!ret)
  1037. LogWrite(ITEM__ERROR, 0, "Items", "%s: Error Loading item(s) for Char ID: %u (%s)", __FUNCTION__, char_id, player->GetName());
  1038. }
  1039. }