ItemsDB.cpp 51 KB

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