9
3

ItemsDB.cpp 41 KB

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