ItemsDB.cpp 46 KB

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