ItemsDB.cpp 45 KB

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