9
3

ItemsDB.cpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  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("flags_32768") == 1)
  151. item->generic_info.item_flags += FLAGS_32768;
  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->GetInt32Str("skill_id_req") == 0 )
  171. item->generic_info.skill_req1 = 0xFFFFFFFF;
  172. else
  173. item->generic_info.skill_req1 = result->GetInt32Str("skill_id_req");
  174. if( result->GetInt32Str("skill_id_req2") == 0 )
  175. item->generic_info.skill_req2 = 0xFFFFFFFF;
  176. else
  177. item->generic_info.skill_req2 = result->GetInt32Str("skill_id_req2");
  178. item->generic_info.skill_min = result->GetInt16Str("skill_min");
  179. if( result->GetInt32Str("slots") > 0)
  180. item->SetSlots(result->GetInt32Str("slots"));
  181. item->sell_price = result->GetInt32Str("sell_price");
  182. item->sell_status = result->GetInt32Str("sell_status_amount");
  183. item->stack_count = result->GetInt16Str("stack_count");
  184. item->generic_info.collectable = result->GetInt8Str("collectable");
  185. item->generic_info.offers_quest_id = result->GetInt32Str("offers_quest_id");
  186. item->generic_info.part_of_quest_id = result->GetInt32Str("part_of_quest_id");
  187. item->details.recommended_level = result->GetInt16Str("recommended_level");
  188. item->generic_info.adventure_default_level = result->GetInt16Str("adventure_default_level");
  189. item->generic_info.max_charges = result->GetInt16Str("max_charges");
  190. item->generic_info.display_charges = result->GetInt8Str("display_charges");
  191. item->generic_info.tradeskill_default_level = result->GetInt16Str("tradeskill_default_level");
  192. #ifdef WIN32
  193. item->generic_info.adventure_classes = result->GetInt64Str("adventure_classes");
  194. item->generic_info.tradeskill_classes = result->GetInt64Str("tradeskill_classes");
  195. #else
  196. item->generic_info.adventure_classes = result->GetInt64Str("adventure_classes");
  197. item->generic_info.tradeskill_classes = result->GetInt64Str("tradeskill_classes");
  198. #endif
  199. if( !result->IsNullStr("lua_script") && strlen(result->GetStringStr("lua_script")) > 0 )
  200. {
  201. item->SetItemScript(string(result->GetStringStr("lua_script")));
  202. LogWrite(ITEM__DEBUG, 5, "LUA", "--Loading LUA Item Script: '%s'", item->item_script.c_str());
  203. }
  204. if(item->generic_info.max_charges > 0)
  205. item->details.count = item->generic_info.max_charges;
  206. if(item->details.count == 0)
  207. item->details.count = 1;
  208. item->generic_info.usable = result->GetInt8Str("usable");
  209. item->details.soe_id = result->GetSInt32Str("soe_item_id");
  210. item->generic_info.harvest = result->GetInt8Str("harvest");
  211. }
  212. int32 WorldDatabase::LoadSkillItems()
  213. {
  214. Query query;
  215. MYSQL_ROW row;
  216. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, spell_id, spell_tier FROM item_details_skill");
  217. int32 total = 0;
  218. int32 id = 0;
  219. if(result)
  220. {
  221. while(result && (row = mysql_fetch_row(result)))
  222. {
  223. id = atoul(row[0]);
  224. Item* item = master_item_list.GetItem(id);
  225. if(item)
  226. {
  227. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading Skill for item_id %u", id);
  228. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, spell: %i, tier: %i", ITEM_TYPE_SKILL, atoi(row[1]), atoi(row[2]));
  229. item->SetItemType(ITEM_TYPE_SKILL);
  230. item->skill_info->spell_id = atoul(row[1]);
  231. item->skill_info->spell_tier = atoi(row[2]);
  232. total++;
  233. }
  234. else
  235. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_skill`, ID: %i", id);
  236. }
  237. }
  238. return total;
  239. }
  240. int32 WorldDatabase::LoadShields()
  241. {
  242. Query query;
  243. MYSQL_ROW row;
  244. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_shield");
  245. int32 total = 0;
  246. int32 id = 0;
  247. if(result)
  248. {
  249. while(result && (row = mysql_fetch_row(result)))
  250. {
  251. id = strtoul(row[0], NULL, 0);
  252. Item* item = master_item_list.GetItem(id);
  253. if(item)
  254. {
  255. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Shield for item_id: %u", id);
  256. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_SHIELD, atoi(row[1]), atoi(row[2]));
  257. item->SetItemType(ITEM_TYPE_SHIELD);
  258. item->armor_info->mitigation_low = atoi(row[1]);
  259. item->armor_info->mitigation_high = atoi(row[2]);
  260. total++;
  261. }
  262. else
  263. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_shield`, ID: %i", id);
  264. }
  265. }
  266. return total;
  267. }
  268. int32 WorldDatabase::LoadAdornments()
  269. {
  270. Query query;
  271. MYSQL_ROW row;
  272. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, duration, item_types,slot_type FROM item_details_adornments");
  273. int32 total = 0;
  274. int32 id = 0;
  275. if (result)
  276. {
  277. while (result && (row = mysql_fetch_row(result)))
  278. {
  279. id = strtoul(row[0], NULL, 0);
  280. Item* item = master_item_list.GetItem(id);
  281. if (item)
  282. {
  283. //LogWrite(ITEM__DEBUG, 0, "Items", "\tItem Adornment for item_id: %u", id);
  284. //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]));
  285. item->SetItemType(ITEM_TYPE_ADORNMENT);
  286. item->adornment_info->duration = atof(row[1]);
  287. item->adornment_info->item_types = atoi(row[2]);
  288. item->adornment_info->slot_type = atoi(row[3]);
  289. //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);
  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::LoadClassifications()
  299. {
  300. int32 total = 0;
  301. int32 id = 0;
  302. return total;
  303. }
  304. int32 WorldDatabase::LoadBaubles()
  305. {
  306. Query query;
  307. MYSQL_ROW row;
  308. 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");
  309. int32 total = 0;
  310. int32 id = 0;
  311. if(result)
  312. {
  313. while(result && (row = mysql_fetch_row(result)))
  314. {
  315. id = strtoul(row[0], NULL, 0);
  316. Item* item = master_item_list.GetItem(id);
  317. if(item)
  318. {
  319. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bauble for item_id %u", id);
  320. 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]));
  321. item->SetItemType(ITEM_TYPE_BAUBLE);
  322. item->bauble_info->cast = atoi(row[1]);
  323. item->bauble_info->recovery = atoi(row[2]);
  324. item->bauble_info->duration = atoi(row[3]);
  325. item->bauble_info->recast = atoi(row[4]);
  326. item->bauble_info->display_slot_optional = atoi(row[5]);
  327. item->bauble_info->display_cast_time = atoi(row[6]);
  328. item->bauble_info->display_bauble_type = atoi(row[7]);
  329. item->bauble_info->effect_radius = atof(row[8]);
  330. item->bauble_info->max_aoe_targets = atoi(row[9]);
  331. item->bauble_info->display_until_cancelled = atoi(row[10]);
  332. total++;
  333. }
  334. else
  335. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bauble`, ID: %i", id);
  336. }
  337. }
  338. return total;
  339. }
  340. int32 WorldDatabase::LoadBooks()
  341. {
  342. DatabaseResult result;
  343. int32 total = 0;
  344. int32 id = 0;
  345. if( database_new.Select(&result, "SELECT item_id, language, author, title FROM item_details_book") )
  346. {
  347. while( result.Next() )
  348. {
  349. id = result.GetInt32Str("item_id");
  350. Item* item = master_item_list.GetItem(id);
  351. if(item)
  352. {
  353. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Book for item_id %u", id);
  354. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %s, %s",
  355. ITEM_TYPE_BOOK,
  356. result.GetInt8Str("language"),
  357. result.GetStringStr("author"),
  358. result.GetStringStr("title"));
  359. item->SetItemType(ITEM_TYPE_BOOK);
  360. item->book_info->language = result.GetInt8Str("language");
  361. item->book_info->author.data = result.GetStringStr("author");
  362. item->book_info->author.size = item->book_info->author.data.length();
  363. item->book_info->title.data = result.GetStringStr("title");
  364. item->book_info->title.size = item->book_info->title.data.length();
  365. total++;
  366. }
  367. else
  368. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_book`, ID: %i", id);
  369. }
  370. }
  371. return total;
  372. }
  373. int32 WorldDatabase::LoadItemsets()
  374. {
  375. DatabaseResult result;
  376. int32 total = 0;
  377. int32 id = 0;
  378. 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"))
  379. {
  380. while (result.Next())
  381. {
  382. id = result.GetInt32Str("itemset_item_id");
  383. Item* item = master_item_list.GetItem(id);
  384. if (item)
  385. {
  386. item->SetItemType(ITEM_TYPE_ITEMCRATE);
  387. //int32 item_id = result.GetInt32Str("item_id");
  388. item->AddSet(result.GetInt32Str("item_id"),0, result.GetInt16Str("item_icon"), result.GetInt16Str("item_stack_size"), result.GetInt32Str("item_list_color"));
  389. total++;
  390. }
  391. else
  392. LogWrite(ITEM__ERROR, 0, "Item Set Crate Items", "Error loading `item_details_Items`, ID: %i", id);
  393. }
  394. }
  395. return total;
  396. }
  397. int32 WorldDatabase::LoadHouseItem()
  398. {
  399. Query query;
  400. MYSQL_ROW row;
  401. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, rent_reduction, status_rent_reduction, coin_rent_reduction, house_only FROM item_details_house");
  402. int32 total = 0;
  403. int32 id = 0;
  404. if(result)
  405. {
  406. while(result && (row = mysql_fetch_row(result)))
  407. {
  408. id = strtoul(row[0], NULL, 0);
  409. Item* item = master_item_list.GetItem(id);
  410. if(item)
  411. {
  412. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem HouseItem for item_id %u", id);
  413. 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]));
  414. item->SetItemType(ITEM_TYPE_HOUSE);
  415. item->houseitem_info->status_rent_reduction = atoi(row[2]);
  416. item->houseitem_info->coin_rent_reduction = atof(row[3]);
  417. item->houseitem_info->house_only = atoi(row[4]);
  418. total++;
  419. }
  420. else
  421. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house`, ID: %i", id);
  422. }
  423. }
  424. return total;
  425. }
  426. int32 WorldDatabase::LoadRecipeBookItems()
  427. {
  428. Query query;
  429. MYSQL_ROW row;
  430. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, name FROM item_details_recipe_items");
  431. int32 total = 0;
  432. int32 id = 0;
  433. if (result)
  434. {
  435. while(result && (row = mysql_fetch_row(result)))
  436. {
  437. id = strtoul(row[0], NULL, 0);
  438. Item* item = master_item_list.GetItem(id);
  439. if(item)
  440. {
  441. LogWrite(ITEM__DEBUG, 5, "Items", "\tRecipe Book for item_id %u", id);
  442. LogWrite(ITEM__DEBUG, 5, "Items", "\tType: %i, '%s'", ITEM_TYPE_RECIPE, row[1]);
  443. item->SetItemType(ITEM_TYPE_RECIPE);
  444. item->recipebook_info->recipes.push_back(string(row[1]));
  445. total++;
  446. }
  447. else
  448. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_recipe_items`, ID: %u", id);
  449. }
  450. }
  451. return total;
  452. }
  453. int32 WorldDatabase::LoadHouseContainers(){
  454. DatabaseResult result;
  455. int32 total = 0;
  456. int32 id = 0;
  457. if( database_new.Select(&result, "SELECT item_id, num_slots, allowed_types, broker_commission, fence_commission FROM item_details_house_container") )
  458. {
  459. while (result.Next() )
  460. {
  461. id = result.GetInt32Str("item_id");
  462. Item* item = master_item_list.GetItem(id);
  463. if (item)
  464. {
  465. LogWrite(ITEM__DEBUG, 5, "Items", "\tHouse Container for item_id %u", id);
  466. 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"));
  467. item->SetItemType(ITEM_TYPE_HOUSE_CONTAINER);
  468. item->housecontainer_info->num_slots = result.GetInt8Str("num_slots");
  469. item->housecontainer_info->allowed_types = result.GetInt64Str("allowed_types");
  470. item->housecontainer_info->broker_commission = result.GetInt8Str("broker_commission");
  471. item->housecontainer_info->fence_commission = result.GetInt8Str("fence_commission");
  472. total++;
  473. }
  474. else
  475. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_house_container`, ID: %u", id);
  476. }
  477. }
  478. return total;
  479. }
  480. int32 WorldDatabase::LoadArmor()
  481. {
  482. Query query;
  483. MYSQL_ROW row;
  484. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, mitigation_low, mitigation_high FROM item_details_armor");
  485. int32 total = 0;
  486. int32 id = 0;
  487. if(result)
  488. {
  489. while(result && (row = mysql_fetch_row(result)))
  490. {
  491. id = strtoul(row[0], NULL, 0);
  492. Item* item = master_item_list.GetItem(id);
  493. if(item)
  494. {
  495. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Armor for item_id %u", id);
  496. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, mit_low: %i, mit_high: %i", ITEM_TYPE_ARMOR, atoi(row[1]), atoi(row[2]));
  497. item->SetItemType(ITEM_TYPE_ARMOR);
  498. item->armor_info->mitigation_low = atoi(row[1]);
  499. item->armor_info->mitigation_high = atoi(row[2]);
  500. total++;
  501. }
  502. else
  503. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_armor`, ID: %i", id);
  504. }
  505. }
  506. return total;
  507. }
  508. int32 WorldDatabase::LoadBags()
  509. {
  510. Query query;
  511. MYSQL_ROW row;
  512. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, num_slots, weight_reduction FROM item_details_bag");
  513. int32 total = 0;
  514. int32 id = 0;
  515. if(result)
  516. {
  517. while(result && (row = mysql_fetch_row(result)))
  518. {
  519. id = strtoul(row[0], NULL, 0);
  520. Item* item = master_item_list.GetItem(id);
  521. if(item)
  522. {
  523. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Bag for item_id %u", id);
  524. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, slots: %i, wt_red: %i", id, ITEM_TYPE_BAG, atoi(row[1]), atoi(row[2]));
  525. item->SetItemType(ITEM_TYPE_BAG);
  526. item->details.num_slots = atoi(row[1]);
  527. item->details.num_free_slots = item->details.num_slots;
  528. item->bag_info->num_slots = item->details.num_slots;
  529. item->bag_info->weight_reduction = atoi(row[2]);
  530. total++;
  531. }
  532. else
  533. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_bag`, ID: %i", id);
  534. }
  535. }
  536. return total;
  537. }
  538. int32 WorldDatabase::LoadFoods()
  539. {
  540. Query query;
  541. MYSQL_ROW row;
  542. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, level, duration, satiation FROM item_details_food");
  543. int32 total = 0;
  544. int32 id = 0;
  545. if(result)
  546. {
  547. while(result && (row = mysql_fetch_row(result)))
  548. {
  549. id = strtoul(row[0], NULL, 0);
  550. Item* item = master_item_list.GetItem(id);
  551. if(item)
  552. {
  553. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Food for item_id %u", id);
  554. 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]));
  555. item->SetItemType(ITEM_TYPE_FOOD);
  556. item->food_info->type = atoi(row[1]);
  557. item->food_info->level = atoi(row[2]);
  558. item->food_info->duration = atof(row[3]);
  559. item->food_info->satiation = atoi(row[4]);
  560. item->details.tier = atoi(row[4]);
  561. total++;
  562. }
  563. else
  564. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_food`, ID: %i", id);
  565. }
  566. }
  567. return total;
  568. }
  569. int32 WorldDatabase::LoadRangeWeapons()
  570. {
  571. Query query;
  572. MYSQL_ROW row;
  573. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, damage_low1, damage_high1, damage_low2, damage_high2, damage_low3, damage_high3, delay, damage_rating, range_low, range_high, damage_type FROM item_details_range");
  574. int32 total = 0;
  575. int32 id = 0;
  576. if(result)
  577. {
  578. while(result && (row = mysql_fetch_row(result)))
  579. {
  580. id = strtoul(row[0], NULL, 0);
  581. Item* item = master_item_list.GetItem(id);
  582. if(item)
  583. {
  584. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Ranged for item_id %u", id);
  585. 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]));
  586. item->SetItemType(ITEM_TYPE_RANGED);
  587. item->ranged_info->weapon_info.damage_low1 = atoi(row[1]);
  588. item->ranged_info->weapon_info.damage_high1 = atoi(row[2]);
  589. item->ranged_info->weapon_info.damage_low2 = atoi(row[3]);
  590. item->ranged_info->weapon_info.damage_high2 = atoi(row[4]);
  591. item->ranged_info->weapon_info.damage_low3 = atoi(row[5]);
  592. item->ranged_info->weapon_info.damage_high3 = atoi(row[6]);
  593. item->ranged_info->weapon_info.delay = atoi(row[7]);
  594. item->ranged_info->weapon_info.rating = atof(row[8]);
  595. item->ranged_info->range_low = atoi(row[9]);
  596. item->ranged_info->range_high = atoi(row[10]);
  597. item->SetWeaponType(atoi(row[11]));
  598. total++;
  599. }
  600. else
  601. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_range`, ID: %i", id);
  602. }
  603. }
  604. return total;
  605. }
  606. int32 WorldDatabase::LoadThrownWeapons()
  607. {
  608. Query query;
  609. MYSQL_ROW row;
  610. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, range_bonus, damage_bonus, hit_bonus, damage_type FROM item_details_thrown");
  611. int32 total = 0;
  612. int32 id = 0;
  613. if(result)
  614. {
  615. while(result && (row = mysql_fetch_row(result)))
  616. {
  617. id = strtoul(row[0], NULL, 0);
  618. Item* item = master_item_list.GetItem(id);
  619. if(item)
  620. {
  621. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Thrown for item_id %u", id);
  622. 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]));
  623. item->SetItemType(ITEM_TYPE_THROWN);
  624. item->thrown_info->range = atoul(row[1]);
  625. item->thrown_info->damage_modifier = atoul(row[2]);
  626. item->thrown_info->hit_bonus = atof(row[3]);
  627. item->thrown_info->damage_type = atoul(row[4]);
  628. item->SetWeaponType(item->thrown_info->damage_type);
  629. total++;
  630. }
  631. else
  632. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_thrown`, ID: %i", id);
  633. }
  634. }
  635. return total;
  636. }
  637. int32 WorldDatabase::LoadWeapons()
  638. {
  639. Query query;
  640. MYSQL_ROW row;
  641. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, wield_style, damage_low1, damage_high1, damage_low2, damage_high2, damage_low3, damage_high3, delay, damage_rating, damage_type FROM item_details_weapon");
  642. int32 total = 0;
  643. int32 id = 0;
  644. if(result)
  645. {
  646. while(result && (row = mysql_fetch_row(result)))
  647. {
  648. id = strtoul(row[0], NULL, 0);
  649. Item* item = master_item_list.GetItem(id);
  650. if(item)
  651. {
  652. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Weapon for item_id %u", id);
  653. 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]));
  654. item->SetItemType(ITEM_TYPE_WEAPON);
  655. item->weapon_info->wield_type = atoi(row[1]);
  656. item->weapon_info->damage_low1 = atoi(row[2]);
  657. item->weapon_info->damage_high1 = atoi(row[3]);
  658. item->weapon_info->damage_low2 = atoi(row[4]);
  659. item->weapon_info->damage_high2 = atoi(row[5]);
  660. item->weapon_info->damage_low3 = atoi(row[6]);
  661. item->weapon_info->damage_high3 = atoi(row[7]);
  662. item->weapon_info->delay = atoi(row[8]);
  663. item->weapon_info->rating = atof(row[9]);
  664. item->SetWeaponType(atoi(row[10]));
  665. total++;
  666. }
  667. else
  668. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_weapons`, ID: %i", id);
  669. }
  670. }
  671. return total;
  672. }
  673. int32 WorldDatabase::LoadItemAppearances()
  674. {
  675. Query query;
  676. MYSQL_ROW row;
  677. 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");
  678. int32 id = 0;
  679. Item* item = 0;
  680. int32 total = 0;
  681. if(result && mysql_num_rows(result) >0)
  682. {
  683. while(result && (row = mysql_fetch_row(result)))
  684. {
  685. if(id != strtoul(row[0], NULL, 0))
  686. {
  687. id = strtoul(row[0], NULL, 0);
  688. item = master_item_list.GetItem(id);
  689. if(item)
  690. {
  691. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Appearance for item_id %u", id);
  692. 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]));
  693. item->SetAppearance(atoi(row[1]), atoi(row[2]), atoi(row[3]), atoi(row[4]), atoi(row[5]), atoi(row[6]), atoi(row[7]));
  694. total++;
  695. }
  696. else
  697. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_appearances, ID: %i", id);
  698. }
  699. }
  700. }
  701. return total;
  702. }
  703. int32 WorldDatabase::LoadItemEffects()
  704. {
  705. Query query;
  706. MYSQL_ROW row;
  707. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, effect, percentage, bullet FROM item_effects ORDER BY item_id, id");
  708. int32 id = 0;
  709. Item* item = 0;
  710. int32 total = 0;
  711. if(result && mysql_num_rows(result) >0)
  712. {
  713. while(result && (row = mysql_fetch_row(result)))
  714. {
  715. if(id != atoul(row[0]))
  716. {
  717. id = atoul(row[0]);
  718. item = master_item_list.GetItem(id);
  719. }
  720. if(item && row[1])
  721. {
  722. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Effects for item_id %u", id);
  723. LogWrite(ITEM__DEBUG, 5, "Items", "\tEffect: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  724. item->AddEffect(row[1], atoi(row[2]), atoi(row[3]));
  725. total++;
  726. }
  727. else
  728. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_effects, ID: %i", id);
  729. }
  730. }
  731. return total;
  732. }
  733. int32 WorldDatabase::LoadBookPages()
  734. {
  735. Query query;
  736. MYSQL_ROW row;
  737. 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");
  738. int32 id = 0;
  739. Item* item = 0;
  740. int32 total = 0;
  741. if (result && mysql_num_rows(result) > 0)
  742. {
  743. while (result && (row = mysql_fetch_row(result)))
  744. {
  745. if (id != atoul(row[0]))
  746. {
  747. id = atoul(row[0]);
  748. item = master_item_list.GetItem(id);
  749. }
  750. if (item && row[1])
  751. {
  752. LogWrite(ITEM__DEBUG, 5, "Items", "\tBook Pages for item_id %u", id);
  753. //LogWrite(ITEM__DEBUG, 5, "Items", "\tPages: '%s', Percent: %i, Sub: %i", row[1], atoi(row[2]), atoi(row[3]));
  754. item->AddBookPage(atoi(row[1]), row[2], atoi(row[3]), atoi(row[4]));
  755. total++;
  756. }
  757. else
  758. LogWrite(ITEM__ERROR, 0, "Items", "Error Loading item_details_book_pages, ID: %i", id);
  759. }
  760. }
  761. return total;
  762. }
  763. int32 WorldDatabase::LoadItemLevelOverride()
  764. {
  765. Query query;
  766. MYSQL_ROW row;
  767. 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");
  768. int32 id = 0;
  769. Item* item = 0;
  770. int32 total = 0;
  771. if(result && mysql_num_rows(result) >0)
  772. {
  773. while(result && (row = mysql_fetch_row(result)))
  774. {
  775. if(id != strtoul(row[0], NULL, 0))
  776. {
  777. id = strtoul(row[0], NULL, 0);
  778. item = master_item_list.GetItem(id);
  779. }
  780. if(item)
  781. {
  782. LogWrite(ITEM__DEBUG, 5, "Items", "\tLevel Override for item_id %u", id);
  783. LogWrite(ITEM__DEBUG, 5, "Items", "\tAdv: %i, TS: %i, Lvl: %i", atoi(row[1]), atoi(row[2]), atoi(row[3]));
  784. item->AddLevelOverride(atoi(row[1]), atoi(row[2]), atoi(row[3]));
  785. total++;
  786. }
  787. else
  788. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_levels_override`, ID: %i", id);
  789. }
  790. }
  791. return total;
  792. }
  793. int32 WorldDatabase::LoadItemStats()
  794. {
  795. Query query;
  796. MYSQL_ROW row;
  797. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT item_id, type, subtype, value, text FROM item_stats ORDER BY item_id asc");
  798. int32 id = 0;
  799. Item* item = 0;
  800. int32 total = 0;
  801. if(result && mysql_num_rows(result) >0)
  802. {
  803. while(result && (row = mysql_fetch_row(result)))
  804. {
  805. if(id != strtoul(row[0], NULL, 0))
  806. {
  807. id = strtoul(row[0], NULL, 0);
  808. item = master_item_list.GetItem(id);
  809. }
  810. if(item)
  811. {
  812. LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Stats for item_id %u", id);
  813. LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, sub: %i, val: %.2f, name: %s", atoi(row[1]), atoi(row[2]), atof(row[3]), row[4]);
  814. item->AddStat(atoi(row[1]), atoi(row[2]), atof(row[3]), row[4]);
  815. total++;
  816. }
  817. else
  818. LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_stats`, ID: %i", id);
  819. }
  820. }
  821. return total;
  822. }
  823. void WorldDatabase::ReloadItemList()
  824. {
  825. LogWrite(ITEM__DEBUG, 0, "Items", "Unloading Item List...");
  826. master_item_list.RemoveAll();
  827. LoadItemList();
  828. }
  829. void WorldDatabase::LoadItemList()
  830. {
  831. DatabaseResult result;
  832. int32 t_now = Timer::GetUnixTimeStamp();
  833. int32 total = 0;
  834. int32 normal_items = 0;
  835. string item_type;
  836. if( !database_new.Select(&result, "SELECT * FROM items") )
  837. LogWrite(ITEM__ERROR, 0, "Items", "Cannot load items in %s, line: %i", __FUNCTION__, __LINE__);
  838. else
  839. {
  840. while( result.Next() )
  841. {
  842. item_type = result.GetStringStr("item_type");
  843. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading: %s (ID: %i, Type: %s)...", result.GetStringStr("name"), result.GetInt32Str("id"), item_type.c_str());
  844. Item* item = new Item;
  845. LoadDataFromRow(&result, item);
  846. master_item_list.AddItem(item);
  847. if( strcmp(item_type.c_str(), "Normal") == 0 )
  848. {
  849. item->SetItemType(ITEM_TYPE_NORMAL);
  850. normal_items++;
  851. }
  852. total++;
  853. }
  854. }
  855. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Normal Items", normal_items);
  856. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Baubles", LoadBaubles());
  857. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Bags", LoadBags());
  858. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Books", LoadBooks());
  859. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Sets", LoadItemsets());
  860. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Items", LoadHouseItem());
  861. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Food Items", LoadFoods());
  862. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Weapons", LoadWeapons());
  863. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Ranged Weapons", LoadRangeWeapons());
  864. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Thrown Weapons", LoadThrownWeapons());
  865. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Armor Pieces", LoadArmor());
  866. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Shields", LoadShields());
  867. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Skill Items", LoadSkillItems());
  868. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Adornment Items", LoadAdornments());
  869. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Recipe Book Items", LoadRecipeBookItems());
  870. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u House Containers", LoadHouseContainers());
  871. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Appearances...");
  872. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Appearances", LoadItemAppearances());
  873. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Stats...");
  874. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Stats", LoadItemStats());
  875. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Effects...");
  876. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Effects", LoadItemEffects());
  877. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Book Pages...");
  878. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Book Pages", LoadBookPages());
  879. LogWrite(ITEM__DEBUG, 0, "Items", "Loading Item Level Overrides...");
  880. LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Level Overrides", LoadItemLevelOverride());
  881. LogWrite(ITEM__INFO, 0, "Items", "Loaded %u Total Item%s (took %u seconds)", total, ( total == 1 ) ? "" : "s", Timer::GetUnixTimeStamp() - t_now);
  882. }
  883. int32 WorldDatabase::LoadNextUniqueItemID()
  884. {
  885. Query query;
  886. MYSQL_ROW row;
  887. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT max(id) FROM character_items");
  888. if(result && (row = mysql_fetch_row(result)))
  889. {
  890. if(row[0])
  891. {
  892. LogWrite(ITEM__DEBUG, 0, "Items", "%s: max(id): %u", __FUNCTION__, atoul(row[0]));
  893. return strtoul(row[0], NULL, 0);
  894. }
  895. else
  896. return 0;
  897. }
  898. else if(!result)
  899. LogWrite(ITEM__ERROR, 0, "Items", "%s: Unable to load next unique item ID.", __FUNCTION__);
  900. return 0;
  901. }
  902. void WorldDatabase::SaveItems(Client* client)
  903. {
  904. LogWrite(ITEM__DEBUG, 3, "Items", "Save Items for Player %i", client->GetCharacterID());
  905. map<int32, Item*>* items = client->GetPlayer()->GetItemList();
  906. map<int32, Item*>::iterator item_iter;
  907. Item* item = 0;
  908. for(item_iter = items->begin(); item_iter != items->end(); item_iter++)
  909. {
  910. item = item_iter->second;
  911. if(item && item->save_needed)
  912. {
  913. LogWrite(ITEM__DEBUG, 5, "Items", "SaveItems: Acct: %u, Char: %u, Item: %u, NOT-EQUIPPED", client->GetAccountID(), client->GetCharacterID(), item);
  914. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  915. item->save_needed = false;
  916. }
  917. }
  918. safe_delete(items);
  919. vector<Item*>* equipped_list = client->GetPlayer()->GetEquippedItemList();
  920. for(int32 i=0;i<equipped_list->size();i++)
  921. {
  922. item = equipped_list->at(i);
  923. if(item && item->save_needed)
  924. {
  925. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "EQUIPPED");
  926. item->save_needed = false;
  927. }
  928. }
  929. safe_delete(equipped_list);
  930. vector<Item*>* overflow = client->GetPlayer()->item_list.GetOverflowItemList();
  931. for (int32 i = 0; i < overflow->size(); i++){
  932. item = overflow->at(i);
  933. if (item) {
  934. sint16 slot = item->details.slot_id;
  935. item->details.slot_id = i;
  936. SaveItem(client->GetAccountID(), client->GetCharacterID(), item, "NOT-EQUIPPED");
  937. item->details.slot_id = slot;
  938. }
  939. }
  940. safe_delete(overflow);
  941. }
  942. void WorldDatabase::SaveItem(int32 account_id, int32 char_id, Item* item, const char* type)
  943. {
  944. LogWrite(ITEM__DEBUG, 1, "Items", "Saving ItemID: %u (Type: %s) for account: %u, player: %u", item->details.item_id, type, account_id, char_id);
  945. Query query;
  946. 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, account_id, login_checksum) VALUES (%u, '%s', %u, %i, %u, '%s', %i, %i, %i, %i, %i, %i, %i, %u, %u, 0)");
  947. 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,
  948. 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(), account_id);
  949. }
  950. void WorldDatabase::DeleteItem(int32 char_id, Item* item, const char* type)
  951. {
  952. Query query;
  953. string delete_item;
  954. if(type)
  955. {
  956. LogWrite(ITEM__DEBUG, 1, "Items", "Deleting item_id %u (Type: %s) for player %u", item->details.item_id, type, char_id);
  957. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u) AND type='%s'");
  958. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id, type);
  959. }
  960. else
  961. {
  962. LogWrite(ITEM__DEBUG, 0, "Items", "Deleting item_id %u for player %u", item->details.item_id, char_id);
  963. delete_item = string("DELETE FROM character_items WHERE char_id = %u AND (id = %u OR bag_id = %u)");
  964. query.RunQuery2(Q_DELETE, delete_item.c_str(), char_id, item->details.unique_id, item->details.unique_id);
  965. }
  966. }
  967. void WorldDatabase::LoadCharacterItemList(int32 account_id, int32 char_id, Player* player, int16 version)
  968. {
  969. LogWrite(ITEM__DEBUG, 0, "Items", "Loading items for character '%s' (%u)", player->GetName(), char_id);
  970. Query query;
  971. MYSQL_ROW row;
  972. 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 FROM character_items where char_id = %u or (bag_id = -4 and account_id = %u) ORDER BY slot asc", char_id, account_id);
  973. if(result)
  974. {
  975. bool ret = true;
  976. while(result && (row = mysql_fetch_row(result)))
  977. {
  978. LogWrite(ITEM__DEBUG, 5, "Items", "\tLoading character item: %u, slot: %i", strtoul(row[1], NULL, 0), atoi(row[2]));
  979. Item* master_item = master_item_list.GetItem(strtoul(row[3], NULL, 0));
  980. if(master_item)
  981. {
  982. Item* item = new Item(master_item);
  983. item->details.unique_id = strtoul(row[1], NULL, 0);
  984. item->details.slot_id = atoi(row[2]);
  985. if(item->details.num_slots > 0)
  986. item->details.bag_id = item->details.unique_id;
  987. item->save_needed = false;
  988. if(row[4])
  989. item->creator = string(row[4]);//creator
  990. item->adorn0 = atoi(row[5]); //adorn0
  991. item->adorn1 = atoi(row[6]); //adorn1
  992. item->adorn2 = atoi(row[7]); //adorn2
  993. item->generic_info.condition = atoi(row[8]); //condition
  994. if(row[9] && atoi(row[9])>0) //attuned
  995. {
  996. if(item->CheckFlag(ATTUNEABLE))
  997. item->generic_info.item_flags -= ATTUNEABLE;
  998. if(!item->CheckFlag(NO_TRADE))
  999. item->generic_info.item_flags += NO_TRADE;
  1000. item->generic_info.item_flags += ATTUNED;
  1001. }
  1002. item->details.inv_slot_id = atol(row[10]); //bag_id
  1003. item->details.count = atoi(row[11]); //count
  1004. item->SetMaxSellValue(atoul(row[12])); //max sell value
  1005. if(strncasecmp(row[0], "EQUIPPED", 8)==0)
  1006. ret = player->GetEquipmentList()->AddItem(item->details.slot_id, item);
  1007. else if (strncasecmp(row[0], "APPEARANCE", 10) == 2)
  1008. ret = player->GetEquipmentList()->AddItem(item->details.slot_id, item);
  1009. else {
  1010. if (version < 1209 && item->details.count > 255) {
  1011. int stacks = item->details.count / 255;
  1012. int8 remainder = item->details.count % 255;
  1013. item->details.count = remainder;
  1014. if (item->details.inv_slot_id == -2)
  1015. player->item_list.AddOverflowItem(item);
  1016. else
  1017. player->item_list.AddItem(item);
  1018. for (int stack = 1; stack <= stacks; stack++) {
  1019. item->details.count = 255;
  1020. item->details.inv_slot_id = -2;
  1021. player->item_list.AddOverflowItem(item);
  1022. }
  1023. }
  1024. else {
  1025. if (item->details.inv_slot_id == -2)
  1026. player->item_list.AddOverflowItem(item);
  1027. else
  1028. player->item_list.AddItem(item);
  1029. }
  1030. }
  1031. }
  1032. else
  1033. ret = false;
  1034. }
  1035. if(!ret)
  1036. LogWrite(ITEM__ERROR, 0, "Items", "%s: Error Loading item(s) for Char ID: %u (%s)", __FUNCTION__, char_id, player->GetName());
  1037. }
  1038. }