ItemsDB.cpp 43 KB

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