9
3

ItemsDB.cpp 44 KB

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