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