9
3

ItemsDB.cpp 40 KB

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