ItemsDB.cpp 43 KB

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