ItemsDB.cpp 50 KB

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