ItemsDB.cpp 45 KB

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