ItemsDB.cpp 44 KB

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