9
3

ItemsDB.cpp 50 KB

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