Items.cpp 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513
  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. #include "Items.h"
  17. #include "../Spells.h"
  18. #include "../Quests.h"
  19. #include "../Player.h"
  20. #include "../classes.h"
  21. #include "math.h"
  22. #include "../World.h"
  23. #include "../LuaInterface.h"
  24. #include "../../common/Log.h"
  25. #include "../Entity.h"
  26. #include "../Recipes/Recipe.h"
  27. #include <algorithm>
  28. #include <sstream>
  29. extern World world;
  30. extern MasterSpellList master_spell_list;
  31. extern MasterQuestList master_quest_list;
  32. extern MasterRecipeList master_recipe_list;
  33. extern ConfigReader configReader;
  34. extern LuaInterface* lua_interface;
  35. MasterItemList::~MasterItemList(){
  36. RemoveAll();
  37. }
  38. vector<Item*>* MasterItemList::GetItems(string name, int32 itype, int32 ltype, int32 btype, int64 minprice, int64 maxprice, int8 minskill, int8 maxskill, string seller, string adornment, int8 mintier, int8 maxtier, int16 minlevel, int16 maxlevel, sint8 itemclass){
  39. vector<Item*>* ret = new vector<Item*>;
  40. map<int32,Item*>::iterator iter;
  41. Item* item = 0;
  42. const char* chkname = 0;
  43. //const char* chkseller = 0;
  44. //const char* chkadornment = 0;
  45. if(name.length() > 0)
  46. chkname = name.c_str();
  47. //if(seller.length() > 0)
  48. // chkseller = seller.c_str();
  49. //if(adornment.length() > 0)
  50. // chkadornment = adornment.c_str();
  51. bool should_add = true;
  52. for(iter = items.begin();iter != items.end(); iter++){
  53. item = iter->second;
  54. if(item){
  55. if(itype != ITEM_BROKER_TYPE_ANY){
  56. should_add = false;
  57. switch(itype){
  58. case ITEM_BROKER_TYPE_ADORNMENT:{
  59. if(item->IsAdornment())
  60. should_add = true;
  61. break;
  62. }
  63. case ITEM_BROKER_TYPE_AMMO:{
  64. if(item->IsAmmo())
  65. should_add = true;
  66. break;
  67. }
  68. case ITEM_BROKER_TYPE_ATTUNEABLE:{
  69. if(item->CheckFlag(ATTUNEABLE))
  70. should_add = true;
  71. break;
  72. }
  73. case ITEM_BROKER_TYPE_BAG:{
  74. if(item->IsBag())
  75. should_add = true;
  76. break;
  77. }
  78. case ITEM_BROKER_TYPE_BAUBLE:{
  79. if(item->IsBauble())
  80. should_add = true;
  81. break;
  82. }
  83. case ITEM_BROKER_TYPE_BOOK:{
  84. if(item->IsBook())
  85. should_add = true;
  86. break;
  87. }
  88. case ITEM_BROKER_TYPE_CHAINARMOR:{
  89. if(item->IsChainArmor())
  90. should_add = true;
  91. break;
  92. }
  93. case ITEM_BROKER_TYPE_CLOAK:{
  94. if(item->IsCloak())
  95. should_add = true;
  96. break;
  97. }
  98. case ITEM_BROKER_TYPE_CLOTHARMOR:{
  99. if(item->IsClothArmor())
  100. should_add = true;
  101. break;
  102. }
  103. case ITEM_BROKER_TYPE_COLLECTABLE:{
  104. if(item->IsCollectable())
  105. should_add = true;
  106. break;
  107. }
  108. case ITEM_BROKER_TYPE_CRUSHWEAPON:{
  109. if(item->IsCrushWeapon())
  110. should_add = true;
  111. break;
  112. }
  113. case ITEM_BROKER_TYPE_DRINK:{
  114. if(item->IsFoodDrink())
  115. should_add = true;
  116. break;
  117. }
  118. case ITEM_BROKER_TYPE_FOOD:{
  119. if(item->IsFoodFood())
  120. should_add = true;
  121. break;
  122. }
  123. case ITEM_BROKER_TYPE_HOUSEITEM:{
  124. if(item->IsHouseItem())
  125. should_add = true;
  126. break;
  127. }
  128. case ITEM_BROKER_TYPE_JEWELRY:{
  129. if(item->IsJewelry())
  130. should_add = true;
  131. break;
  132. }
  133. case ITEM_BROKER_TYPE_LEATHERARMOR:{
  134. if(item->IsLeatherArmor())
  135. should_add = true;
  136. break;
  137. }
  138. case ITEM_BROKER_TYPE_LORE:{
  139. if(item->CheckFlag(LORE))
  140. should_add = true;
  141. break;
  142. }
  143. case ITEM_BROKER_TYPE_MISC:{
  144. if(item->IsMisc())
  145. should_add = true;
  146. break;
  147. }
  148. case ITEM_BROKER_TYPE_PIERCEWEAPON:{
  149. if(item->IsPierceWeapon())
  150. should_add = true;
  151. break;
  152. }
  153. case ITEM_BROKER_TYPE_PLATEARMOR:{
  154. if(item->IsPlateArmor())
  155. should_add = true;
  156. break;
  157. }
  158. case ITEM_BROKER_TYPE_POISON:{
  159. if(item->IsPoison())
  160. should_add = true;
  161. break;
  162. }
  163. case ITEM_BROKER_TYPE_POTION:{
  164. if(item->IsPotion())
  165. should_add = true;
  166. break;
  167. }
  168. case ITEM_BROKER_TYPE_RECIPEBOOK:{
  169. if(item->IsRecipeBook())
  170. should_add = true;
  171. break;
  172. }
  173. case ITEM_BROKER_TYPE_SALESDISPLAY:{
  174. if(item->IsSalesDisplay())
  175. should_add = true;
  176. break;
  177. }
  178. case ITEM_BROKER_TYPE_SHIELD:{
  179. if(item->IsShield())
  180. should_add = true;
  181. break;
  182. }
  183. case ITEM_BROKER_TYPE_SLASHWEAPON:{
  184. if(item->IsSlashWeapon())
  185. should_add = true;
  186. break;
  187. }
  188. case ITEM_BROKER_TYPE_SPELLSCROLL:{
  189. if(item->IsSpellScroll())
  190. should_add = true;
  191. break;
  192. }
  193. case ITEM_BROKER_TYPE_TINKERED:{
  194. if(item->IsTinkered())
  195. should_add = true;
  196. break;
  197. }
  198. case ITEM_BROKER_TYPE_TRADESKILL:{
  199. if(item->IsTradeskill())
  200. should_add = true;
  201. break;
  202. }
  203. }
  204. if(!should_add)
  205. continue;
  206. }
  207. if(ltype != ITEM_BROKER_SLOT_ANY){
  208. should_add = false;
  209. switch(ltype){
  210. case ITEM_BROKER_SLOT_AMMO:{
  211. should_add = item->HasSlot(EQ2_AMMO_SLOT);
  212. break;
  213. }
  214. case ITEM_BROKER_SLOT_CHARM:{
  215. should_add = item->HasSlot(EQ2_CHARM_SLOT_1, EQ2_CHARM_SLOT_2);
  216. break;
  217. }
  218. case ITEM_BROKER_SLOT_CHEST:{
  219. should_add = item->HasSlot(EQ2_CHEST_SLOT);
  220. break;
  221. }
  222. case ITEM_BROKER_SLOT_CLOAK:{
  223. should_add = item->HasSlot(EQ2_CLOAK_SLOT);
  224. break;
  225. }
  226. case ITEM_BROKER_SLOT_DRINK:{
  227. should_add = item->HasSlot(EQ2_DRINK_SLOT);
  228. break;
  229. }
  230. case ITEM_BROKER_SLOT_EARS:{
  231. should_add = item->HasSlot(EQ2_EARS_SLOT_1, EQ2_EARS_SLOT_2);
  232. break;
  233. }
  234. case ITEM_BROKER_SLOT_FEET:{
  235. should_add = item->HasSlot(EQ2_FEET_SLOT);
  236. break;
  237. }
  238. case ITEM_BROKER_SLOT_FOOD:{
  239. should_add = item->HasSlot(EQ2_FOOD_SLOT);
  240. break;
  241. }
  242. case ITEM_BROKER_SLOT_FOREARMS:{
  243. should_add = item->HasSlot(EQ2_FOREARMS_SLOT);
  244. break;
  245. }
  246. case ITEM_BROKER_SLOT_HANDS:{
  247. should_add = item->HasSlot(EQ2_HANDS_SLOT);
  248. break;
  249. }
  250. case ITEM_BROKER_SLOT_HEAD:{
  251. should_add = item->HasSlot(EQ2_HEAD_SLOT);
  252. break;
  253. }
  254. case ITEM_BROKER_SLOT_LEGS:{
  255. should_add = item->HasSlot(EQ2_LEGS_SLOT);
  256. break;
  257. }
  258. case ITEM_BROKER_SLOT_NECK:{
  259. should_add = item->HasSlot(EQ2_NECK_SLOT);
  260. break;
  261. }
  262. case ITEM_BROKER_SLOT_PRIMARY:{
  263. should_add = item->HasSlot(EQ2_PRIMARY_SLOT);
  264. break;
  265. }
  266. case ITEM_BROKER_SLOT_PRIMARY_2H:{
  267. should_add = item->HasSlot(EQ2_PRIMARY_SLOT) && item->IsWeapon() && item->weapon_info->wield_type == ITEM_WIELD_TYPE_TWO_HAND;
  268. break;
  269. }
  270. case ITEM_BROKER_SLOT_RANGE_WEAPON:{
  271. should_add = item->HasSlot(EQ2_RANGE_SLOT);
  272. break;
  273. }
  274. case ITEM_BROKER_SLOT_RING:{
  275. should_add = item->HasSlot(EQ2_LRING_SLOT, EQ2_RRING_SLOT);
  276. break;
  277. }
  278. case ITEM_BROKER_SLOT_SECONDARY:{
  279. should_add = item->HasSlot(EQ2_SECONDARY_SLOT);
  280. break;
  281. }
  282. case ITEM_BROKER_SLOT_SHOULDERS:{
  283. should_add = item->HasSlot(EQ2_SHOULDERS_SLOT);
  284. break;
  285. }
  286. case ITEM_BROKER_SLOT_WAIST:{
  287. should_add = item->HasSlot(EQ2_WAIST_SLOT);
  288. break;
  289. }
  290. case ITEM_BROKER_SLOT_WRIST:{
  291. should_add = item->HasSlot(EQ2_LWRIST_SLOT, EQ2_RWRIST_SLOT);
  292. break;
  293. }
  294. }
  295. if(!should_add)
  296. continue;
  297. }
  298. if(btype != 0xFFFFFFFF){
  299. vector<ItemStat*>::iterator itr;
  300. bool stat_found = false;
  301. should_add = false;
  302. switch(btype){
  303. case ITEM_BROKER_STAT_TYPE_NONE:{
  304. if (item->item_stats.size() == 0)
  305. should_add = true;
  306. break;
  307. }
  308. case ITEM_BROKER_STAT_TYPE_DEF:{
  309. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  310. if ((*itr)->stat_type_combined == ITEM_STAT_DEFLECTIONCHANCE) {
  311. stat_found = true;
  312. break;
  313. }
  314. }
  315. if (stat_found)
  316. should_add = true;
  317. break;
  318. }
  319. case ITEM_BROKER_STAT_TYPE_STR:{
  320. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  321. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  322. stat_found = true;
  323. break;
  324. }
  325. }
  326. if (stat_found)
  327. should_add = true;
  328. break;
  329. }
  330. case ITEM_BROKER_STAT_TYPE_STA:{
  331. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  332. if ((*itr)->stat_type_combined == ITEM_STAT_STA) {
  333. stat_found = true;
  334. break;
  335. }
  336. }
  337. if (stat_found)
  338. should_add = true;
  339. break;
  340. }
  341. case ITEM_BROKER_STAT_TYPE_AGI:{
  342. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  343. if ((*itr)->stat_type_combined == ITEM_STAT_AGI) {
  344. stat_found = true;
  345. break;
  346. }
  347. }
  348. if (stat_found)
  349. should_add = true;
  350. break;
  351. }
  352. case ITEM_BROKER_STAT_TYPE_WIS:{
  353. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  354. if ((*itr)->stat_type_combined == ITEM_STAT_WIS) {
  355. stat_found = true;
  356. break;
  357. }
  358. }
  359. if (stat_found)
  360. should_add = true;
  361. break;
  362. }
  363. case ITEM_BROKER_STAT_TYPE_INT:{
  364. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  365. if ((*itr)->stat_type_combined == ITEM_STAT_INT) {
  366. stat_found = true;
  367. break;
  368. }
  369. }
  370. if (stat_found)
  371. should_add = true;
  372. break;
  373. }
  374. case ITEM_BROKER_STAT_TYPE_HEALTH:{
  375. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  376. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  377. stat_found = true;
  378. break;
  379. }
  380. }
  381. if (stat_found)
  382. should_add = true;
  383. break;
  384. }
  385. case ITEM_BROKER_STAT_TYPE_POWER:{
  386. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  387. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  388. stat_found = true;
  389. break;
  390. }
  391. }
  392. if (stat_found)
  393. should_add = true;
  394. break;
  395. }
  396. case ITEM_BROKER_STAT_TYPE_HEAT:{
  397. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  398. if ((*itr)->stat_type_combined == ITEM_STAT_VS_HEAT) {
  399. stat_found = true;
  400. break;
  401. }
  402. }
  403. if (stat_found)
  404. should_add = true;
  405. break;
  406. }
  407. case ITEM_BROKER_STAT_TYPE_COLD:{
  408. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  409. if ((*itr)->stat_type_combined == ITEM_STAT_VS_COLD) {
  410. stat_found = true;
  411. break;
  412. }
  413. }
  414. if (stat_found)
  415. should_add = true;
  416. break;
  417. }
  418. case ITEM_BROKER_STAT_TYPE_MAGIC:{
  419. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  420. if ((*itr)->stat_type_combined == ITEM_STAT_VS_MAGIC) {
  421. stat_found = true;
  422. break;
  423. }
  424. }
  425. if (stat_found)
  426. should_add = true;
  427. break;
  428. }
  429. case ITEM_BROKER_STAT_TYPE_MENTAL:{
  430. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  431. if ((*itr)->stat_type_combined == ITEM_STAT_VS_MENTAL) {
  432. stat_found = true;
  433. break;
  434. }
  435. }
  436. if (stat_found)
  437. should_add = true;
  438. break;
  439. }
  440. case ITEM_BROKER_STAT_TYPE_DIVINE:{
  441. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  442. if ((*itr)->stat_type_combined == ITEM_STAT_VS_DIVINE) {
  443. stat_found = true;
  444. break;
  445. }
  446. }
  447. if (stat_found)
  448. should_add = true;
  449. break;
  450. }
  451. case ITEM_BROKER_STAT_TYPE_POISON:{
  452. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  453. if ((*itr)->stat_type_combined == ITEM_STAT_VS_POISON) {
  454. stat_found = true;
  455. break;
  456. }
  457. }
  458. if (stat_found)
  459. should_add = true;
  460. break;
  461. }
  462. case ITEM_BROKER_STAT_TYPE_DISEASE:{
  463. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  464. if ((*itr)->stat_type_combined == ITEM_STAT_VS_DISEASE) {
  465. stat_found = true;
  466. break;
  467. }
  468. }
  469. if (stat_found)
  470. should_add = true;
  471. break;
  472. }
  473. case ITEM_BROKER_STAT_TYPE_CRUSH:{
  474. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  475. if ((*itr)->stat_type_combined == ITEM_STAT_DMG_CRUSH) {
  476. stat_found = true;
  477. break;
  478. }
  479. }
  480. if (stat_found)
  481. should_add = true;
  482. break;
  483. }
  484. case ITEM_BROKER_STAT_TYPE_SLASH:{
  485. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  486. if ((*itr)->stat_type_combined == ITEM_STAT_DMG_SLASH) {
  487. stat_found = true;
  488. break;
  489. }
  490. }
  491. if (stat_found)
  492. should_add = true;
  493. break;
  494. }
  495. case ITEM_BROKER_STAT_TYPE_PIERCE:{
  496. for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  497. if ((*itr)->stat_type_combined == ITEM_STAT_DMG_PIERCE) {
  498. stat_found = true;
  499. break;
  500. }
  501. }
  502. if (stat_found)
  503. should_add = true;
  504. break;
  505. }
  506. case ITEM_BROKER_STAT_TYPE_CRITICAL: {
  507. /*for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  508. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  509. stat_found = true;
  510. break;
  511. }
  512. }
  513. if (stat_found)
  514. should_add = true;*/
  515. LogWrite(ITEM__DEBUG, 0, "Item", "Scatman debugging :). This needs to be updated when fully support the new expansion");
  516. break;
  517. }
  518. case ITEM_BROKER_STAT_TYPE_DBL_ATTACK:{
  519. /*for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  520. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  521. stat_found = true;
  522. break;
  523. }
  524. }
  525. if (stat_found)
  526. should_add = true;*/
  527. LogWrite(ITEM__DEBUG, 0, "Item", "Scatman debugging :). This needs to be updated when fully support the new expansion");
  528. break;
  529. }
  530. case ITEM_BROKER_STAT_TYPE_ABILITY_MOD:{
  531. /*for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  532. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  533. stat_found = true;
  534. break;
  535. }
  536. }
  537. if (stat_found)
  538. should_add = true;*/
  539. LogWrite(ITEM__DEBUG, 0, "Item", "Scatman debugging :). This needs to be updated when fully support the new expansion");
  540. break;
  541. }
  542. case ITEM_BROKER_STAT_TYPE_POTENCY:{
  543. /*for (itr = item->item_stats.begin(); itr != item->item_stats.end() && !stat_found; itr++) {
  544. if ((*itr)->stat_type_combined == ITEM_STAT_STR) {
  545. stat_found = true;
  546. break;
  547. }
  548. }
  549. if (stat_found)
  550. should_add = true;*/
  551. LogWrite(ITEM__DEBUG, 0, "Item", "Scatman debugging :). This needs to be updated when fully support the new expansion");
  552. break;
  553. }
  554. default: {
  555. LogWrite(ITEM__ERROR, 0, "Item", "Unknown item broker stat type %u", btype);
  556. LogWrite(ITEM__DEBUG, 0, "Item", "If you have a client before the new expansion this may be the reason. Please be patient while we update items to support the new client.", btype);
  557. break;
  558. }
  559. }
  560. if (!should_add)
  561. continue;
  562. }
  563. if(itemclass > 0){
  564. int64 tmpVal = ((int64)2) << (itemclass-1);
  565. should_add = (item->generic_info.adventure_classes & tmpVal);
  566. if(!should_add && !(item->generic_info.tradeskill_classes & tmpVal))
  567. continue;
  568. }
  569. if(chkname && item->lowername.find(chkname) >= 0xFFFFFFFF)
  570. continue;
  571. if(item->generic_info.adventure_default_level == 0 && item->generic_info.tradeskill_default_level == 0 && minlevel > 0 && maxlevel > 0){
  572. if(item->details.recommended_level < minlevel)
  573. continue;
  574. if(item->details.recommended_level > maxlevel)
  575. continue;
  576. }
  577. else{
  578. if(minlevel > 0 && ((item->generic_info.adventure_default_level == 0 && item->generic_info.tradeskill_default_level == 0) || (item->generic_info.adventure_default_level > 0 && item->generic_info.adventure_default_level < minlevel) || (item->generic_info.tradeskill_default_level > 0 && item->generic_info.tradeskill_default_level < minlevel)))
  579. continue;
  580. if(maxlevel > 0 && ((item->generic_info.adventure_default_level > 0 && item->generic_info.adventure_default_level > maxlevel) || (item->generic_info.tradeskill_default_level > 0 && item->generic_info.tradeskill_default_level > maxlevel)))
  581. continue;
  582. }
  583. if(mintier > 0 && item->details.tier < mintier)
  584. continue;
  585. if(maxtier > 0 && item->details.tier > maxtier)
  586. continue;
  587. if(minskill > 0 && item->generic_info.skill_min < minskill)
  588. continue;
  589. if(maxskill > 0 && item->generic_info.skill_min > maxskill)
  590. continue;
  591. ret->push_back(item);
  592. }
  593. }
  594. return ret;
  595. }
  596. vector<Item*>* MasterItemList::GetItems(map<string, string> criteria){
  597. string name, seller, adornment;
  598. int32 itype = 0xFFFFFFFF;
  599. int32 ltype = 0xFFFFFFFF;
  600. int32 btype = 0xFFFFFFFF;
  601. int64 minprice = 0;
  602. int64 maxprice = 0;
  603. int8 minskill = 0;
  604. int8 maxskill = 0;
  605. int8 mintier = 0;
  606. int8 maxtier = 0;
  607. int16 minlevel = 0;
  608. int16 maxlevel = 0;
  609. sint8 itemclass = 0;
  610. if(criteria.count("ITEM") > 0)
  611. name = criteria["ITEM"];
  612. if(criteria.count("MINSKILL") > 0)
  613. minskill = (int8)ParseIntValue(criteria["MINSKILL"]);
  614. if(criteria.count("MAXSKILL") > 0)
  615. maxskill = (int8)ParseIntValue(criteria["MAXSKILL"]);
  616. if(criteria.count("MINTIER") > 0)
  617. mintier = (int8)ParseIntValue(criteria["MINTIER"]);
  618. if(criteria.count("MAXTIER") > 0)
  619. maxtier = (int8)ParseIntValue(criteria["MAXTIER"]);
  620. if(criteria.count("MINLEVEL") > 0)
  621. minlevel = (int16)ParseIntValue(criteria["MINLEVEL"]);
  622. if(criteria.count("MAXLEVEL") > 0)
  623. maxlevel = (int16)ParseIntValue(criteria["MAXLEVEL"]);
  624. if(criteria.count("ITYPE") > 0)
  625. itype = ParseIntValue(criteria["ITYPE"]);
  626. if(criteria.count("LTYPE") > 0)
  627. ltype = ParseIntValue(criteria["LTYPE"]);
  628. if(criteria.count("BTYPE") > 0)
  629. btype = ParseIntValue(criteria["BTYPE"]);
  630. if(criteria.count("SKILLNAME") > 0)
  631. itemclass = world.GetClassID(criteria["SKILLNAME"].c_str());
  632. return GetItems(name, itype, ltype, btype, minprice, maxprice, minskill, maxskill, seller, adornment, mintier, maxtier, minlevel, maxlevel, itemclass);
  633. }
  634. void MasterItemList::ResetUniqueID(int32 new_id){
  635. next_unique_id = new_id;
  636. }
  637. int32 MasterItemList::NextUniqueID(){
  638. next_unique_id++;
  639. if(next_unique_id >= 0xFFFFFFF0)
  640. next_unique_id = 1;
  641. return next_unique_id;
  642. }
  643. bool MasterItemList::IsBag(int32 item_id){
  644. Item* item = GetItem(item_id);
  645. if(item && item->details.num_slots > 0)
  646. return true;
  647. else
  648. return false;
  649. }
  650. Item* MasterItemList::GetItem(int32 id){
  651. Item* item = 0;
  652. if(items.count(id) > 0)
  653. item = items[id];
  654. return item;
  655. }
  656. Item* MasterItemList::GetItemByName(const char* name) {
  657. Item* item = 0;
  658. map<int32, Item*>::iterator itr;
  659. for (itr = items.begin(); itr != items.end(); itr++) {
  660. Item* current_item = itr->second;
  661. if (::ToLower(string(current_item->name.c_str())) == ::ToLower(string(name))) {
  662. item = current_item;
  663. break;
  664. }
  665. }
  666. return item;
  667. }
  668. ItemStatsValues* MasterItemList::CalculateItemBonuses(int32 item_id, Entity* entity){
  669. return CalculateItemBonuses(items[item_id], entity);
  670. }
  671. ItemStatsValues* MasterItemList::CalculateItemBonuses(Item* item, Entity* entity, ItemStatsValues* values){
  672. if(item){
  673. if(!values){
  674. values = new ItemStatsValues;
  675. memset(values, 0, sizeof(ItemStatsValues));
  676. }
  677. for(int32 i=0;i<item->item_stats.size();i++){
  678. ItemStat* stat = item->item_stats[i];
  679. world.AddBonuses(values, stat->stat_type*100 + stat->stat_subtype, stat->value, entity);
  680. }
  681. return values;
  682. }
  683. return 0;
  684. }
  685. void MasterItemList::RemoveAll(){
  686. map<int32,Item*>::iterator iter;
  687. for(iter = items.begin();iter != items.end(); iter++){
  688. safe_delete(iter->second);
  689. }
  690. items.clear();
  691. if(lua_interface)
  692. lua_interface->DestroyItemScripts();
  693. }
  694. void MasterItemList::AddItem(Item* item){
  695. items[item->details.item_id] = item;
  696. }
  697. Item::Item(){
  698. item_script = "";
  699. sell_price = 0;
  700. sell_status = 0;
  701. max_sell_value = 0;
  702. save_needed = true;
  703. needs_deletion = false;
  704. weapon_info = 0;
  705. ranged_info = 0;
  706. adornment_info = 0;
  707. bag_info = 0;
  708. food_info = 0;
  709. bauble_info = 0;
  710. thrown_info = 0;
  711. skill_info = 0;
  712. recipebook_info = 0;
  713. itemset_info = 0;
  714. armor_info = 0;
  715. book_info = 0;
  716. book_info_pages = 0;
  717. houseitem_info = 0;
  718. housecontainer_info = 0;
  719. memset(&details, 0, sizeof(ItemCore));
  720. memset(&generic_info, 0, sizeof(Generic_Info));
  721. generic_info.condition = 100;
  722. }
  723. Item::Item(Item* in_item){
  724. needs_deletion = false;
  725. sell_price = in_item->sell_price;
  726. sell_status = in_item->sell_status;
  727. max_sell_value = in_item->max_sell_value;
  728. save_needed = true;
  729. SetItem(in_item);
  730. details.unique_id = master_item_list.NextUniqueID();
  731. generic_info.condition = 100;
  732. spell_id = in_item->spell_id;
  733. spell_tier = in_item->spell_tier;
  734. }
  735. Item::~Item(){
  736. for(int32 i=0;i<item_stats.size();i++)
  737. safe_delete(item_stats[i]);
  738. for(int32 i=0;i<item_string_stats.size();i++)
  739. safe_delete(item_string_stats[i]);
  740. for(int32 i=0;i<item_level_overrides.size();i++)
  741. safe_delete(item_level_overrides[i]);
  742. for(int32 i=0;i<item_effects.size();i++)
  743. safe_delete(item_effects[i]);
  744. for (int32 i = 0; i < book_pages.size(); i++)
  745. safe_delete(book_pages[i]);
  746. safe_delete(weapon_info);
  747. safe_delete(ranged_info);
  748. safe_delete(adornment_info);
  749. safe_delete(bag_info);
  750. safe_delete(food_info);
  751. safe_delete(bauble_info);
  752. safe_delete(thrown_info);
  753. safe_delete(armor_info);
  754. safe_delete(skill_info);
  755. safe_delete(recipebook_info);
  756. safe_delete(itemset_info);
  757. safe_delete(book_info);
  758. safe_delete(houseitem_info);
  759. safe_delete(housecontainer_info);
  760. }
  761. void Item::SetItem(Item* old_item){
  762. if(old_item->GetItemScript())
  763. SetItemScript(old_item->GetItemScript());
  764. name = old_item->name;
  765. lowername = old_item->lowername;
  766. description = old_item->description;
  767. memcpy(&generic_info, &old_item->generic_info, sizeof(Generic_Info));
  768. weapon_info = 0;
  769. ranged_info = 0;
  770. adornment_info = 0;
  771. adorn0 = 0;
  772. adorn1 = 0;
  773. adorn2 = 0;
  774. bag_info = 0;
  775. food_info = 0;
  776. bauble_info = 0;
  777. thrown_info = 0;
  778. skill_info = 0;
  779. recipebook_info = 0;
  780. itemset_info = 0;
  781. armor_info = 0;
  782. book_info = 0;
  783. book_info_pages = 0;
  784. houseitem_info = 0;
  785. housecontainer_info = 0;
  786. stack_count = old_item->stack_count;
  787. generic_info.skill_req1 = old_item->generic_info.skill_req1;
  788. generic_info.skill_req2 = old_item->generic_info.skill_req2;
  789. memcpy(&details, &old_item->details, sizeof(ItemCore));
  790. weapon_type = old_item->GetWeaponType();
  791. switch(old_item->generic_info.item_type){
  792. case ITEM_TYPE_WEAPON:{
  793. weapon_info = new Weapon_Info;
  794. memcpy(weapon_info, old_item->weapon_info, sizeof(Weapon_Info));
  795. break;
  796. }
  797. case ITEM_TYPE_RANGED:{
  798. ranged_info = new Ranged_Info;
  799. memcpy(ranged_info, old_item->ranged_info, sizeof(Ranged_Info));
  800. break;
  801. }
  802. case ITEM_TYPE_SHIELD:
  803. case ITEM_TYPE_ARMOR:{
  804. armor_info = new Armor_Info;
  805. memcpy(armor_info, old_item->armor_info, sizeof(Armor_Info));
  806. break;
  807. }
  808. case ITEM_TYPE_BAG:{
  809. bag_info = new Bag_Info;
  810. memcpy(bag_info, old_item->bag_info, sizeof(Bag_Info));
  811. break;
  812. }
  813. case ITEM_TYPE_FOOD:{
  814. food_info = new Food_Info;
  815. memcpy(food_info, old_item->food_info, sizeof(Food_Info));
  816. break;
  817. }
  818. case ITEM_TYPE_BAUBLE:{
  819. bauble_info = new Bauble_Info;
  820. memcpy(bauble_info, old_item->bauble_info, sizeof(Bauble_Info));
  821. break;
  822. }
  823. case ITEM_TYPE_SKILL:{
  824. skill_info = new Skill_Info;
  825. memcpy(skill_info, old_item->skill_info, sizeof(Skill_Info));
  826. break;
  827. }
  828. case ITEM_TYPE_THROWN:{
  829. thrown_info = new Thrown_Info;
  830. memcpy(thrown_info, old_item->thrown_info, sizeof(Thrown_Info));
  831. break;
  832. }
  833. case ITEM_TYPE_BOOK:{
  834. book_info = new Book_Info;
  835. book_info->language = old_item->book_info->language;
  836. book_info->author.data = old_item->book_info->author.data;
  837. book_info->author.size = old_item->book_info->author.size;
  838. book_info->title.data = old_item->book_info->title.data;
  839. book_info->title.size = old_item->book_info->title.size;
  840. break;
  841. }
  842. case ITEM_TYPE_HOUSE:{
  843. houseitem_info = new HouseItem_Info;
  844. memcpy(houseitem_info, old_item->houseitem_info, sizeof(HouseItem_Info));
  845. break;
  846. }
  847. case ITEM_TYPE_RECIPE:{
  848. // Recipe Book
  849. recipebook_info = new RecipeBook_Info;
  850. if (old_item->recipebook_info) {
  851. recipebook_info->uses = old_item->recipebook_info->uses;
  852. for (int32 i = 0; i < old_item->recipebook_info->recipes.size(); i++)
  853. recipebook_info->recipes.push_back(old_item->recipebook_info->recipes.at(i));
  854. }
  855. break;
  856. }
  857. case ITEM_TYPE_ADORNMENT:{
  858. adornment_info = new Adornment_Info;
  859. memcpy(adornment_info, old_item->adornment_info, sizeof(Adornment_Info));
  860. break;
  861. }
  862. case ITEM_TYPE_HOUSE_CONTAINER:{
  863. // House Containers
  864. housecontainer_info = new HouseContainer_Info;
  865. if (old_item->housecontainer_info) {
  866. housecontainer_info->broker_commission = old_item->housecontainer_info->broker_commission;
  867. housecontainer_info->fence_commission = old_item->housecontainer_info->fence_commission;
  868. housecontainer_info->allowed_types = old_item->housecontainer_info->allowed_types;
  869. housecontainer_info->num_slots = old_item->housecontainer_info->num_slots;
  870. }
  871. break;
  872. }
  873. }
  874. creator = old_item->creator;
  875. adornment = old_item->adornment;
  876. item_sets.clear();
  877. for (int32 i = 0; i<old_item->item_sets.size(); i++){
  878. ItemSet* set = old_item->item_sets[i];
  879. if (set){
  880. ItemSet* set2 = new ItemSet;
  881. set2->item_id = set->item_id;
  882. set2->item_crc = set->item_crc;
  883. set2->item_icon = set->item_icon;
  884. set2->item_stack_size = set->item_stack_size;
  885. set2->item_list_color = set->item_list_color;
  886. item_sets.push_back(set2);
  887. }
  888. }
  889. item_stats.clear();
  890. for(int32 i=0;i<old_item->item_stats.size();i++){
  891. ItemStat* stat = old_item->item_stats[i];
  892. if(stat){
  893. ItemStat* stat2 = new ItemStat;
  894. stat2->stat_name = stat->stat_name;
  895. stat2->stat_type = stat->stat_type;
  896. stat2->stat_subtype = stat->stat_subtype;
  897. stat2->value = stat->value;
  898. stat2->stat_type_combined = stat->stat_type_combined;
  899. item_stats.push_back(stat2);
  900. }
  901. }
  902. item_string_stats.clear();
  903. for(int32 i=0;i<old_item->item_string_stats.size();i++){
  904. ItemStatString* stat = old_item->item_string_stats[i];
  905. if(stat){
  906. ItemStatString* stat2 = new ItemStatString;
  907. stat2->stat_string.data = stat->stat_string.data;
  908. stat2->stat_string.size = stat->stat_string.size;
  909. item_string_stats.push_back(stat2);
  910. }
  911. }
  912. item_level_overrides.clear();
  913. for(int32 i=0;i<old_item->item_level_overrides.size();i++){
  914. ItemLevelOverride* item_override = old_item->item_level_overrides[i];
  915. if(item_override){
  916. ItemLevelOverride* item_override2 = new ItemLevelOverride;
  917. memcpy(item_override2, item_override, sizeof(ItemLevelOverride));
  918. item_level_overrides.push_back(item_override2);
  919. }
  920. }
  921. item_effects.clear();
  922. for(int32 i=0;i<old_item->item_effects.size();i++){
  923. ItemEffect* effect = old_item->item_effects[i];
  924. if(effect){
  925. ItemEffect* effect_2 = new ItemEffect;
  926. effect_2->effect = effect->effect;
  927. effect_2->percentage = effect->percentage;
  928. effect_2->subbulletflag = effect->subbulletflag;
  929. item_effects.push_back(effect_2);
  930. }
  931. }
  932. book_pages.clear();
  933. for (int32 i = 0; i < old_item->book_pages.size(); i++) {
  934. BookPage* bookpage = old_item->book_pages[i];
  935. if (bookpage) {
  936. BookPage* bookpage_2 = new BookPage;
  937. bookpage_2->page = bookpage->page;
  938. bookpage_2->page_text.data = bookpage->page_text.data;
  939. bookpage_2->page_text.size = bookpage->page_text.size;
  940. bookpage_2->valign = bookpage->valign;
  941. bookpage_2->halign = bookpage->halign;
  942. book_pages.push_back(bookpage_2);
  943. }
  944. }
  945. slot_data.clear();
  946. slot_data = old_item->slot_data;
  947. spell_id = old_item->spell_id;
  948. spell_tier = old_item->spell_tier;
  949. }
  950. bool Item::CheckClass(int8 adventure_class, int8 tradeskill_class) {
  951. int64 adv_classes = ((int64)2) << (adventure_class - 1);
  952. int64 ts_classes = ((int64)2) << (tradeskill_class - 1);
  953. if( ((generic_info.adventure_classes & adv_classes) || generic_info.adventure_classes == 0) && ((generic_info.tradeskill_classes & ts_classes) || generic_info.tradeskill_classes == 0) )
  954. return true;
  955. return false;
  956. }
  957. bool Item::CheckLevel(int8 adventure_class, int8 tradeskill_class, int16 level) {
  958. if ((level >= generic_info.adventure_default_level && adventure_class < 255) && (level >= generic_info.tradeskill_default_level && tradeskill_class < 255))
  959. return true;
  960. return false;
  961. }
  962. void Item::AddStat(ItemStat* in_stat){
  963. item_stats.push_back(in_stat);
  964. }
  965. void Item::AddSet(ItemSet* in_set){
  966. item_sets.push_back(in_set);
  967. }
  968. void Item::AddStatString(ItemStatString* in_stat){
  969. item_string_stats.push_back(in_stat);
  970. }
  971. bool Item::IsNormal(){
  972. return generic_info.item_type == ITEM_TYPE_NORMAL;
  973. }
  974. bool Item::IsWeapon(){
  975. return generic_info.item_type == ITEM_TYPE_WEAPON;
  976. }
  977. bool Item::IsArmor(){
  978. return generic_info.item_type == ITEM_TYPE_ARMOR || generic_info.item_type == ITEM_TYPE_SHIELD;
  979. }
  980. bool Item::IsRanged(){
  981. return generic_info.item_type == ITEM_TYPE_RANGED;
  982. }
  983. bool Item::IsBag(){
  984. return generic_info.item_type == ITEM_TYPE_BAG;
  985. }
  986. bool Item::IsFood(){
  987. return generic_info.item_type == ITEM_TYPE_FOOD;
  988. }
  989. bool Item::IsBauble(){
  990. return generic_info.item_type == ITEM_TYPE_BAUBLE;
  991. }
  992. bool Item::IsSkill(){
  993. return generic_info.item_type == ITEM_TYPE_SKILL;
  994. }
  995. bool Item::IsHouseItem(){
  996. return generic_info.item_type == ITEM_TYPE_HOUSE;
  997. }
  998. bool Item::IsHouseContainer(){
  999. return generic_info.item_type == ITEM_TYPE_HOUSE_CONTAINER;
  1000. }
  1001. bool Item::IsShield(){
  1002. return generic_info.item_type == ITEM_TYPE_SHIELD;
  1003. }
  1004. bool Item::IsAdornment(){
  1005. LogWrite(MISC__TODO, 1, "TODO", "Item Adornments\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1006. return generic_info.item_type == ITEM_TYPE_ADORNMENT;
  1007. }
  1008. bool Item::IsAmmo(){
  1009. return HasSlot(EQ2_AMMO_SLOT);
  1010. }
  1011. bool Item::HasAdorn0(){
  1012. if (adorn0 > 0)
  1013. return true;
  1014. return false;
  1015. }
  1016. bool Item::HasAdorn1(){
  1017. if (adorn1 > 0)
  1018. return true;
  1019. return false;
  1020. }
  1021. bool Item::HasAdorn2(){
  1022. if (adorn2 > 0)
  1023. return true;
  1024. return false;
  1025. }
  1026. bool Item::IsBook(){
  1027. return generic_info.item_type == ITEM_TYPE_BOOK;
  1028. }
  1029. bool Item::IsChainArmor(){
  1030. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 2246237129UL || generic_info.skill_req2 == 2246237129UL);
  1031. }
  1032. bool Item::IsClothArmor(){
  1033. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 3539032716UL || generic_info.skill_req2 == 3539032716UL);
  1034. }
  1035. bool Item::IsCollectable(){
  1036. return generic_info.collectable == 1;
  1037. }
  1038. bool Item::HasSlot(int8 slot, int8 slot2){
  1039. for(int32 i=0;i<slot_data.size();i++){
  1040. if(slot_data[i] == slot || slot_data[i] == slot2)
  1041. return true;
  1042. }
  1043. return false;
  1044. }
  1045. bool Item::IsCloak(){
  1046. return HasSlot(EQ2_CLOAK_SLOT);
  1047. }
  1048. bool Item::IsCrushWeapon(){
  1049. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 1;
  1050. }
  1051. bool Item::IsFoodFood(){
  1052. return generic_info.item_type == ITEM_TYPE_FOOD && food_info && food_info->type == 1;
  1053. }
  1054. bool Item::IsFoodDrink(){
  1055. return generic_info.item_type == ITEM_TYPE_FOOD && food_info && food_info->type == 0;
  1056. }
  1057. bool Item::IsJewelry(){
  1058. if(generic_info.item_type != ITEM_TYPE_ARMOR || (generic_info.skill_req1 != 2072844078 && generic_info.skill_req2 != 2072844078))
  1059. return false;
  1060. for(int32 i=0;i<slot_data.size();i++){
  1061. if(slot_data[i] == EQ2_LRING_SLOT || slot_data[i] == EQ2_RRING_SLOT || slot_data[i] == EQ2_EARS_SLOT_1 || slot_data[i] == EQ2_EARS_SLOT_2 || slot_data[i] == EQ2_NECK_SLOT || slot_data[i] == EQ2_LWRIST_SLOT || slot_data[i] == EQ2_RWRIST_SLOT)
  1062. return true;
  1063. }
  1064. return false;
  1065. }
  1066. bool Item::IsLeatherArmor(){
  1067. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 2897193374UL || generic_info.skill_req2 == 2897193374UL);
  1068. }
  1069. bool Item::IsMisc(){
  1070. return IsNormal();
  1071. }
  1072. bool Item::IsPierceWeapon(){
  1073. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 2;
  1074. }
  1075. bool Item::IsPlateArmor(){
  1076. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 241174330UL || generic_info.skill_req2 == 241174330UL);
  1077. }
  1078. bool Item::IsPoison(){
  1079. LogWrite(MISC__TODO, 1, "TODO", "Separate poisons from potions\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1080. return IsBauble();
  1081. }
  1082. bool Item::IsPotion(){
  1083. LogWrite(MISC__TODO, 1, "TODO", "Separate poisons from potions\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1084. return IsBauble();
  1085. }
  1086. bool Item::IsRecipeBook(){
  1087. return generic_info.item_type == ITEM_TYPE_RECIPE;
  1088. }
  1089. bool Item::IsSalesDisplay(){
  1090. LogWrite(MISC__TODO, 1, "TODO", "Item Sales Displays\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1091. return false;
  1092. }
  1093. bool Item::IsSlashWeapon(){
  1094. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 0;
  1095. }
  1096. bool Item::IsSpellScroll(){
  1097. return IsSkill();
  1098. }
  1099. bool Item::IsTinkered(){
  1100. LogWrite(MISC__TODO, 1, "TODO", "Item Is Tinkered\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1101. return false;
  1102. }
  1103. bool Item::IsThrown(){
  1104. return generic_info.item_type == ITEM_TYPE_THROWN;
  1105. }
  1106. bool Item::IsHarvest() {
  1107. return generic_info.harvest == 1;
  1108. }
  1109. bool Item::IsTradeskill(){
  1110. LogWrite(MISC__TODO, 1, "TODO", "Item Is Crafted\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1111. return false;
  1112. }
  1113. void Item::SetItemType(int8 in_type){
  1114. generic_info.item_type = in_type;
  1115. if(IsArmor() && !armor_info){
  1116. armor_info = new Armor_Info;
  1117. memset(armor_info, 0, sizeof(Armor_Info));
  1118. }
  1119. else if (IsWeapon() && !weapon_info){
  1120. weapon_info = new Weapon_Info;
  1121. memset(weapon_info, 0, sizeof(Weapon_Info));
  1122. }
  1123. else if (IsAdornment() && !adornment_info){
  1124. adornment_info = new Adornment_Info;
  1125. memset(adornment_info, 0, sizeof(Adornment_Info));
  1126. }
  1127. else if(IsRanged() && !ranged_info){
  1128. ranged_info = new Ranged_Info;
  1129. memset(ranged_info, 0, sizeof(Ranged_Info));
  1130. }
  1131. else if(IsBag() && !bag_info){
  1132. bag_info = new Bag_Info;
  1133. memset(bag_info, 0, sizeof(Bag_Info));
  1134. }
  1135. else if(IsFood() && !food_info){
  1136. food_info = new Food_Info;
  1137. memset(food_info, 0, sizeof(Food_Info));
  1138. }
  1139. else if(IsBauble() && !bauble_info){
  1140. bauble_info = new Bauble_Info;
  1141. memset(bauble_info, 0, sizeof(Bauble_Info));
  1142. }
  1143. else if(IsThrown() && !thrown_info){
  1144. thrown_info = new Thrown_Info;
  1145. memset(thrown_info, 0, sizeof(Thrown_Info));
  1146. }
  1147. else if(IsSkill() && !skill_info){
  1148. skill_info = new Skill_Info;
  1149. memset(skill_info, 0, sizeof(Skill_Info));
  1150. }
  1151. else if(IsRecipeBook() && !recipebook_info){
  1152. recipebook_info = new RecipeBook_Info;
  1153. recipebook_info->uses = 0;
  1154. }
  1155. else if(IsBook() && !book_info){
  1156. book_info = new Book_Info;
  1157. book_info->language = 0;
  1158. book_info->author.size = 0;
  1159. book_info->title.size = 0;
  1160. }
  1161. else if(IsHouseItem() && !houseitem_info){
  1162. houseitem_info = new HouseItem_Info;
  1163. memset(houseitem_info, 0, sizeof(HouseItem_Info));
  1164. }
  1165. else if(IsHouseContainer() && !housecontainer_info){
  1166. housecontainer_info = new HouseContainer_Info;
  1167. housecontainer_info->allowed_types = 0;
  1168. housecontainer_info->broker_commission = 0;
  1169. housecontainer_info->fence_commission = 0;
  1170. housecontainer_info->num_slots = 0;
  1171. }
  1172. }
  1173. bool Item::CheckFlag2(int32 flag){
  1174. int32 value = 0;
  1175. int32 flag_val = generic_info.item_flags2;
  1176. while (flag_val > 0){
  1177. if (flag_val >= FLAGS2_32768)
  1178. value = FLAGS2_32768;
  1179. else if (flag_val >= FLAGS2_16384)
  1180. value = FLAGS2_16384;
  1181. else if (flag_val >= FLAGS2_8192)
  1182. value = FLAGS2_8192;
  1183. else if (flag_val >= FLAGS2_4096)
  1184. value = FLAGS2_4096;
  1185. else if (flag_val >= FLAGS2_2048)
  1186. value = FLAGS2_2048;
  1187. else if (flag_val >= FLAGS2_1024)
  1188. value = FLAGS2_1024;
  1189. else if (flag_val >= FLAGS2_512)
  1190. value = FLAGS2_512;
  1191. else if (flag_val >= FLAGS2_256)
  1192. value = FLAGS2_256;
  1193. else if (flag_val >= REFINED)
  1194. value = REFINED;
  1195. else if (flag_val >= ETHERAL)
  1196. value = ETHERAL;
  1197. else if (flag_val >= NO_REPAIR)
  1198. value = NO_REPAIR;
  1199. else if (flag_val >= REFORGED)
  1200. value = REFORGED;
  1201. else if (flag_val >= UNLOCKED)
  1202. value = UNLOCKED;
  1203. else if (flag_val >= APPEARANCE_ONLY)
  1204. value = APPEARANCE_ONLY;
  1205. else if (flag_val >= HEIRLOOM)
  1206. value = HEIRLOOM;
  1207. else if (flag_val >= ORNATE)
  1208. value = ORNATE;
  1209. if (value == flag)
  1210. return true;
  1211. else
  1212. flag_val -= value;
  1213. }
  1214. return false;
  1215. }
  1216. bool Item::CheckFlag(int32 flag){
  1217. int32 value = 0;
  1218. int32 flag_val = generic_info.item_flags;
  1219. while(flag_val>0){
  1220. if (flag_val >= FLAGS_32768) //change this
  1221. value = FLAGS_32768;
  1222. else if (flag_val >= FLAGS_16384) //change this
  1223. value = FLAGS_16384;
  1224. else if (flag_val >= LORE_EQUIP) //change this
  1225. value = LORE_EQUIP;
  1226. else if (flag_val >= STACK_LORE) //change this
  1227. value = STACK_LORE;
  1228. else if(flag_val >= EVIL_ONLY)
  1229. value = EVIL_ONLY;
  1230. else if(flag_val >= GOOD_ONLY)
  1231. value = GOOD_ONLY;
  1232. else if(flag_val >= CRAFTED)
  1233. value = CRAFTED;
  1234. else if(flag_val >= NO_DESTROY)
  1235. value = NO_DESTROY;
  1236. else if(flag_val >= NO_ZONE)
  1237. value = NO_ZONE;
  1238. else if(flag_val >= NO_VALUE)
  1239. value = NO_VALUE;
  1240. else if(flag_val >= NO_TRADE)
  1241. value = NO_TRADE;
  1242. else if(flag_val >= TEMPORARY)
  1243. value = TEMPORARY;
  1244. else if(flag_val >= LORE)
  1245. value = LORE;
  1246. else if(flag_val >= ARTIFACT)
  1247. value = ARTIFACT;
  1248. else if(flag_val >= ATTUNEABLE)
  1249. value = ATTUNEABLE;
  1250. else if(flag_val >= ATTUNED)
  1251. value = ATTUNED;
  1252. if(value == flag)
  1253. return true;
  1254. else
  1255. flag_val -= value;
  1256. }
  1257. return false;
  1258. }
  1259. void Item::SetSlots(int32 slots){
  1260. if(slots & PRIMARY_SLOT)
  1261. AddSlot(EQ2_PRIMARY_SLOT);
  1262. if(slots & SECONDARY_SLOT)
  1263. AddSlot(EQ2_SECONDARY_SLOT);
  1264. if(slots & HEAD_SLOT)
  1265. AddSlot(EQ2_HEAD_SLOT);
  1266. if(slots & CHEST_SLOT)
  1267. AddSlot(EQ2_CHEST_SLOT);
  1268. if(slots & SHOULDERS_SLOT)
  1269. AddSlot(EQ2_SHOULDERS_SLOT);
  1270. if(slots & FOREARMS_SLOT)
  1271. AddSlot(EQ2_FOREARMS_SLOT);
  1272. if(slots & HANDS_SLOT)
  1273. AddSlot(EQ2_HANDS_SLOT);
  1274. if(slots & LEGS_SLOT)
  1275. AddSlot(EQ2_LEGS_SLOT);
  1276. if(slots & FEET_SLOT)
  1277. AddSlot(EQ2_FEET_SLOT);
  1278. if(slots & LRING_SLOT)
  1279. AddSlot(EQ2_LRING_SLOT);
  1280. if(slots & RRING_SLOT)
  1281. AddSlot(EQ2_RRING_SLOT);
  1282. if(slots & EARS_SLOT_1)
  1283. AddSlot(EQ2_EARS_SLOT_1);
  1284. if(slots & EARS_SLOT_2)
  1285. AddSlot(EQ2_EARS_SLOT_2);
  1286. if(slots & NECK_SLOT)
  1287. AddSlot(EQ2_NECK_SLOT);
  1288. if(slots & LWRIST_SLOT)
  1289. AddSlot(EQ2_LWRIST_SLOT);
  1290. if(slots & RWRIST_SLOT)
  1291. AddSlot(EQ2_RWRIST_SLOT);
  1292. if(slots & RANGE_SLOT)
  1293. AddSlot(EQ2_RANGE_SLOT);
  1294. if(slots & AMMO_SLOT)
  1295. AddSlot(EQ2_AMMO_SLOT);
  1296. if(slots & WAIST_SLOT)
  1297. AddSlot(EQ2_WAIST_SLOT);
  1298. if(slots & CLOAK_SLOT)
  1299. AddSlot(EQ2_CLOAK_SLOT);
  1300. if(slots & CHARM_SLOT_1)
  1301. AddSlot(EQ2_CHARM_SLOT_1);
  1302. if(slots & CHARM_SLOT_2)
  1303. AddSlot(EQ2_CHARM_SLOT_2);
  1304. if(slots & FOOD_SLOT)
  1305. AddSlot(EQ2_FOOD_SLOT);
  1306. if(slots & DRINK_SLOT)
  1307. AddSlot(EQ2_DRINK_SLOT);
  1308. if(slots & TEXTURES_SLOT)
  1309. AddSlot(EQ2_TEXTURES_SLOT);
  1310. }
  1311. void Item::AddStat(int8 type, int16 subtype, float value, char* name){
  1312. char item_stat_combined_string[8] = {0};
  1313. if(name && strlen(name) > 0 && type != 1){
  1314. ItemStatString* stat = new ItemStatString;
  1315. stat->stat_string.data = string(name);
  1316. stat->stat_string.size = stat->stat_string.data.length();
  1317. AddStatString(stat);
  1318. }
  1319. else{
  1320. ItemStat* stat = new ItemStat;
  1321. if(name && strlen(name) > 0)
  1322. stat->stat_name = string(name);
  1323. stat->stat_type = type;
  1324. stat->stat_subtype = subtype;
  1325. stat->value = value;
  1326. snprintf(item_stat_combined_string, 7, "%u%02u", type, subtype);
  1327. stat->stat_type_combined = atoi(item_stat_combined_string);
  1328. AddStat(stat);
  1329. }
  1330. }
  1331. void Item::AddSet(int32 item_id, int32 item_crc, int16 item_icon, int32 item_stack_size, int32 item_list_color){
  1332. ItemSet* set = new ItemSet;
  1333. set->item_id = item_id;
  1334. set->item_icon = item_icon;
  1335. set->item_crc = item_crc;
  1336. set->item_stack_size = item_stack_size;
  1337. set->item_list_color = item_list_color;
  1338. AddSet(set);
  1339. }
  1340. int16 Item::GetOverrideLevel(int8 adventure_class, int8 tradeskill_class){
  1341. int16 ret = 0;
  1342. int8 tmp_class = 0;
  1343. bool found_class = false;
  1344. for(int32 i=0;i<item_level_overrides.size();i++){
  1345. found_class = false;
  1346. if(adventure_class != 255){
  1347. tmp_class = item_level_overrides[i]->adventure_class;
  1348. if(tmp_class == PRIEST && (adventure_class >= CLERIC && adventure_class <= DEFILER))
  1349. found_class = true;
  1350. else if(tmp_class == MAGE && (adventure_class >= SORCERER && adventure_class <= NECROMANCER))
  1351. found_class = true;
  1352. else if(tmp_class == SCOUT && (adventure_class >= ROGUE && adventure_class <= ASSASSIN))
  1353. found_class = true;
  1354. else if(tmp_class == adventure_class || tmp_class == COMMONER || (tmp_class == FIGHTER && (adventure_class >= WARRIOR && adventure_class <= PALADIN)))
  1355. found_class = true;
  1356. }
  1357. else if(tradeskill_class != 255){
  1358. tmp_class = item_level_overrides[i]->tradeskill_class;
  1359. if(tmp_class == CRAFTSMAN && (tradeskill_class >= PROVISIONER && adventure_class <= CARPENTER))
  1360. found_class = true;
  1361. else if(tmp_class == OUTFITTER && (tradeskill_class >= ARMORER && tradeskill_class <= TAILOR))
  1362. found_class = true;
  1363. else if(tmp_class == SCHOLAR && (tradeskill_class >= JEWELER && tradeskill_class <= ALCHEMIST))
  1364. found_class = true;
  1365. else if(tmp_class == tradeskill_class || tmp_class == ARTISAN)
  1366. found_class = true;
  1367. }
  1368. if(found_class){
  1369. ret = item_level_overrides[i]->level;
  1370. break;
  1371. }
  1372. }
  1373. return ret;
  1374. }
  1375. void Item::serialize(PacketStruct* packet, bool show_name, Player* player, int16 packet_type, int8 subtype, bool loot_item){
  1376. int64 classes = 0;
  1377. Client *client;
  1378. int8 tmp_subtype = 0;
  1379. if (!packet || !player)
  1380. return;
  1381. client = player->GetZone()->GetClientBySpawn(player);
  1382. if (!client)
  1383. return;
  1384. if(creator.length() > 0){
  1385. packet->setSubstructSubstructDataByName("header", "info_header", "creator_flag", 1);
  1386. packet->setSubstructSubstructDataByName("header", "info_header", "creator", creator.c_str());
  1387. }
  1388. if(show_name)
  1389. packet->setSubstructSubstructDataByName("header", "info_header", "show_name", show_name);
  1390. if(packet_type == 0)
  1391. packet->setSubstructSubstructDataByName("header", "info_header", "packettype", GetItemPacketType(packet->GetVersion()));
  1392. else
  1393. packet->setSubstructSubstructDataByName("header", "info_header", "packettype", packet_type);
  1394. packet->setSubstructSubstructDataByName("header", "info_header", "packetsubtype", subtype); // should be substype
  1395. packet->setSubstructDataByName("header_info", "footer_type", 3);
  1396. packet->setSubstructDataByName("header_info", "item_id", details.item_id);
  1397. if (!loot_item)
  1398. packet->setSubstructDataByName("header_info", "broker_item_id", details.item_id);
  1399. else
  1400. packet->setSubstructDataByName("header_info", "broker_item_id", 0xFFFFFFFFFFFFFFFF);
  1401. if(details.unique_id == 0)
  1402. packet->setSubstructDataByName("header_info", "unique_id", details.item_id);
  1403. else
  1404. packet->setSubstructDataByName("header_info", "unique_id", details.unique_id);
  1405. packet->setSubstructDataByName("header_info", "icon", details.icon);
  1406. packet->setSubstructDataByName("header_info", "tier", details.tier);
  1407. packet->setSubstructDataByName("header_info", "flags", generic_info.item_flags);
  1408. packet->setSubstructDataByName("header_info", "flags2", generic_info.item_flags2);
  1409. if(item_stats.size() > 0){
  1410. //packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size());
  1411. int8 dropstat = 0;
  1412. int8 bluemod = 0;
  1413. for (int32 i = 0; i < item_stats.size(); i++){
  1414. ItemStat* stat = item_stats[i];
  1415. if (stat->stat_type == 9){
  1416. bluemod += 1;
  1417. }
  1418. if (stat->stat_type == 6){ //Convert stats to proper client
  1419. //if (client->GetVersion() >= 63137){ //TEST
  1420. // tmp_subtype =stat->stat_subtype;
  1421. //}
  1422. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331){ //KA
  1423. tmp_subtype = world.GetItemStatKAValue(stat->stat_subtype);
  1424. }
  1425. else if (client->GetVersion() >= 57107){ //TOV
  1426. tmp_subtype = world.GetItemStatTOVValue(stat->stat_subtype);
  1427. }
  1428. else if (client->GetVersion() >= 1193){ //COE
  1429. tmp_subtype = world.GetItemStatCOEValue(stat->stat_subtype);
  1430. //tmp_subtype = stat->stat_subtype;
  1431. }
  1432. else if (client->GetVersion() >= 1096){ //DOV
  1433. tmp_subtype = world.GetItemStatDOVValue(stat->stat_subtype);
  1434. //tmp_subtype = stat->stat_subtype; //comment for normal use
  1435. }
  1436. }
  1437. else
  1438. tmp_subtype = stat->stat_subtype;
  1439. if (tmp_subtype == 255 ){
  1440. dropstat += 1;
  1441. }
  1442. }
  1443. packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size() - dropstat);
  1444. dropstat = 0;
  1445. for (int32 i = 0; i < item_stats.size(); i++) {
  1446. ItemStat* stat = item_stats[i];
  1447. if (stat->stat_type == 6){ //Convert stats to proper client
  1448. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331){ //KA
  1449. tmp_subtype = world.GetItemStatKAValue(stat->stat_subtype);
  1450. }
  1451. else if (client->GetVersion() >= 57107){ //TOV
  1452. tmp_subtype = world.GetItemStatTOVValue(stat->stat_subtype);
  1453. }
  1454. else if (client->GetVersion() >= 1193){ //COE
  1455. tmp_subtype = world.GetItemStatCOEValue(stat->stat_subtype);
  1456. //tmp_subtype = stat->stat_subtype;
  1457. }
  1458. else if (client->GetVersion() >= 1096){ //DOV
  1459. tmp_subtype = world.GetItemStatDOVValue(stat->stat_subtype); //comment out for testing
  1460. //tmp_subtype = stat->stat_subtype; //comment for normal use
  1461. }
  1462. }
  1463. else
  1464. tmp_subtype = stat->stat_subtype;
  1465. if (tmp_subtype == 255 ){
  1466. dropstat += 1;
  1467. //packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size()-dropstat);
  1468. }
  1469. else {
  1470. packet->setArrayDataByName("stat_type", stat->stat_type, i-dropstat);
  1471. packet->setArrayDataByName("stat_subtype", tmp_subtype, i-dropstat);
  1472. }
  1473. if (stat->stat_name.length() > 0)
  1474. packet->setArrayDataByName("stat_name", stat->stat_name.c_str(), i-dropstat);
  1475. /* SF client */
  1476. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331) {
  1477. if (stat->stat_type == 6){
  1478. packet->setArrayDataByName("value", stat->value , i - dropstat);//63119 or when diety started (this is actually the modified stat
  1479. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value (this is the unmodified stat
  1480. }
  1481. else {
  1482. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat, 0U, true);
  1483. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1484. }
  1485. }
  1486. else if (client->GetVersion() >= 1028) {
  1487. if (stat->stat_type == 6){
  1488. packet->setArrayDataByName("value", stat->value , i - dropstat);//63119 or when diety started (this is actually the infused modified stat
  1489. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value (this is the unmodified stat
  1490. }
  1491. else {
  1492. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat, 0U, true);
  1493. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1494. }
  1495. }
  1496. else{
  1497. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat);
  1498. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1499. }
  1500. }
  1501. }
  1502. if (item_string_stats.size() > 0 && !loot_item){
  1503. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331) {
  1504. packet->setSubstructArrayLengthByName("header_info", "mod_count", item_string_stats.size());
  1505. for (int32 i = 0; i < item_string_stats.size(); i++){
  1506. ItemStatString* stat = item_string_stats[i];
  1507. packet->setArrayDataByName("mod_string", &(stat->stat_string), i);
  1508. packet->setArrayDataByName("mod_need", 0, i);
  1509. }
  1510. }
  1511. else if (client->GetVersion() >= 1096) {
  1512. packet->setSubstructArrayLengthByName("header_info", "stat_string_count", item_string_stats.size());
  1513. for (int32 i = 0; i < item_string_stats.size(); i++){
  1514. ItemStatString* stat = item_string_stats[i];
  1515. packet->setArrayDataByName("stat_string", &(stat->stat_string), i);
  1516. }
  1517. }
  1518. }
  1519. if (item_sets.size() > 0){
  1520. packet->setArrayLengthByName("num_pieces", item_sets.size());
  1521. for (int32 i = 0; i < item_sets.size(); i++){
  1522. ItemSet* set = item_sets[i];
  1523. packet->setArrayDataByName("item_id", set->item_id, i);
  1524. packet->setArrayDataByName("item_crc", set->item_crc, i);
  1525. packet->setArrayDataByName("item_icon", set->item_icon, i);
  1526. packet->setArrayDataByName("item_unknown1", set->item_stack_size, i);
  1527. Item* item2 = master_item_list.GetItem(set->item_id);
  1528. if (item2)
  1529. packet->setArrayDataByName("item_name", item2->name.c_str(), i);
  1530. packet->setArrayDataByName("item_unknown2", set->item_list_color, i);
  1531. }
  1532. }
  1533. if(!loot_item && item_effects.size() > 0){
  1534. packet->setSubstructArrayLengthByName("footer", "num_effects", item_effects.size());
  1535. for(int32 i=0;i<item_effects.size();i++){
  1536. ItemEffect* effect = item_effects[i];
  1537. packet->setArrayDataByName("subbulletflag", effect->subbulletflag, i);
  1538. packet->setArrayDataByName("effect", &(effect->effect), i);
  1539. packet->setArrayDataByName("percentage", effect->percentage, i);
  1540. }
  1541. }
  1542. if (packet->GetVersion() < 1096) {
  1543. packet->setSubstructDataByName("header_info", "adornment_id", 0xFFFFFFFF); // Send no ID for now
  1544. packet->setSubstructDataByName("header_info", "unknown3", 0xFFFFFFFF);
  1545. }
  1546. packet->setSubstructDataByName("header_info", "unknown21", 0x00000000);
  1547. packet->setSubstructDataByName("header_info", "condition", generic_info.condition);
  1548. packet->setSubstructDataByName("header_info", "weight", generic_info.weight);
  1549. if(generic_info.skill_req1 == 0)
  1550. packet->setSubstructDataByName("header_info", "skill_req1", 0xFFFFFFFF);
  1551. else
  1552. packet->setSubstructDataByName("header_info", "skill_req1", generic_info.skill_req1);
  1553. if(generic_info.skill_req2 == 0)
  1554. packet->setSubstructDataByName("header_info", "skill_req2", 0xFFFFFFFF);
  1555. else
  1556. packet->setSubstructDataByName("header_info", "skill_req2", generic_info.skill_req2);
  1557. if(generic_info.skill_min != 0)
  1558. packet->setSubstructDataByName("header_info", "skill_min", generic_info.skill_min);
  1559. if(generic_info.adventure_classes > 0 || generic_info.tradeskill_classes > 0 || item_level_overrides.size() > 0){
  1560. //int64 classes = 0;
  1561. int16 tmp_level = 0;
  1562. map<int8, int16> adv_class_levels;
  1563. map<int8, int16> tradeskill_class_levels;
  1564. map<int8, int16>::iterator itr;
  1565. int64 tmpVal = 0;
  1566. int8 temp = ASSASSIN;
  1567. // AoD + clients with beastlords
  1568. if (packet->GetVersion() >= 1142)
  1569. temp += 2;
  1570. // Chaneler class, get a more accurate version
  1571. if (packet->GetVersion() >= 60000)
  1572. temp += 2;
  1573. for(int32 i=0;i<=temp;i++){
  1574. tmpVal = (int64)pow(2.0, (double)i);
  1575. if((generic_info.adventure_classes & tmpVal)){
  1576. //classes += 2 << (i - 1);
  1577. classes += tmpVal;
  1578. tmp_level = GetOverrideLevel(i, 255);
  1579. if(tmp_level == 0)
  1580. adv_class_levels[i] = generic_info.adventure_default_level;
  1581. else
  1582. adv_class_levels[i] = tmp_level;
  1583. }
  1584. if(tmpVal == 0) {
  1585. if (packet->GetVersion() >= 60000)
  1586. classes = 576379072454289112;
  1587. else if (packet->GetVersion() >= 57048)
  1588. classes = 6281081087704;
  1589. else if (packet->GetVersion() >= 1142)
  1590. classes = 144095080877876952;
  1591. else
  1592. classes = 36024082983773912;
  1593. }
  1594. }
  1595. for(int i=ALCHEMIST + 1 - ARTISAN ;i>=0;i--){
  1596. //tmpVal = 2 << i;
  1597. tmpVal = (int64)pow(2.0, (double)i);
  1598. if((generic_info.tradeskill_classes & tmpVal)){
  1599. classes += pow(2, (i + ARTISAN ));
  1600. //classes += 2 << (i+ARTISAN-1);
  1601. tmp_level = GetOverrideLevel(i, 255);
  1602. if(tmp_level == 0)
  1603. tradeskill_class_levels[i] = generic_info.tradeskill_default_level;
  1604. else
  1605. tradeskill_class_levels[i] = tmp_level;
  1606. }
  1607. }
  1608. packet->setSubstructArrayLengthByName("header_info", "class_count", adv_class_levels.size() + tradeskill_class_levels.size());
  1609. int i = 0;
  1610. for(itr = adv_class_levels.begin(); itr != adv_class_levels.end(); itr++, i++){
  1611. packet->setArrayDataByName("adventure_class", itr->first, i);
  1612. packet->setArrayDataByName("tradeskill_class", 255, i);
  1613. packet->setArrayDataByName("level", itr->second*10, i);
  1614. }
  1615. for(itr = tradeskill_class_levels.begin(); itr != tradeskill_class_levels.end(); itr++, i++){
  1616. packet->setArrayDataByName("adventure_class", 255, i);
  1617. packet->setArrayDataByName("tradeskill_class", itr->first, i);
  1618. packet->setArrayDataByName("level", itr->second, i);
  1619. }
  1620. packet->setSubstructDataByName("footer", "required_classes", classes);
  1621. }
  1622. else {
  1623. if (packet->GetVersion() >= 60000)
  1624. classes = 576379072454289112;
  1625. else if (packet->GetVersion() >= 57048)
  1626. classes = 6281081087704;
  1627. else if (packet->GetVersion() >= 1142)
  1628. classes = 144095080877876952;
  1629. else
  1630. classes = 36024082983773912;
  1631. packet->setSubstructDataByName("footer", "required_classes", classes);
  1632. }
  1633. // Is this a copy and paste error???
  1634. packet->setSubstructDataByName("footer", "required_classes2", classes);
  1635. {
  1636. if (packet->GetVersion() >= 60000)
  1637. classes = 576379072454289112;
  1638. else if (packet->GetVersion() >= 57048)
  1639. classes = 6281081087704;
  1640. else if (packet->GetVersion() >= 1142)
  1641. classes = 144095080877876952;
  1642. else
  1643. classes = 36024082983773912;
  1644. }
  1645. packet->setSubstructDataByName("footer", "recommended_level", details.recommended_level);
  1646. if(generic_info.adventure_default_level > 0){
  1647. packet->setSubstructDataByName("footer", "required_level", generic_info.adventure_default_level);
  1648. packet->setSubstructDataByName("footer", "footer_unknown2", 0);// remove defualt
  1649. }
  1650. else{
  1651. packet->setSubstructDataByName("footer", "required_level", generic_info.tradeskill_default_level);
  1652. packet->setSubstructDataByName("footer", "footer_unknown2", 0);//remove default
  1653. }
  1654. if(slot_data.size() > 0){
  1655. packet->setSubstructArrayLengthByName("header_info", "slot_count", slot_data.size());
  1656. for(int32 i=0;i<slot_data.size();i++){
  1657. int8 slot = slot_data[i];
  1658. packet->setArrayDataByName("slot", slot, i);
  1659. }
  1660. }
  1661. if(!loot_item){
  1662. if (adornment_info)
  1663. LogWrite(ITEM__DEBUG, 0, "Items", "\ttype: %i, Duration: %i, item_types_: %i, slot_type: %i", generic_info.item_type, adornment_info->duration, adornment_info->item_types, adornment_info->slot_type);
  1664. packet->setSubstructDataByName("header", "item_type", generic_info.item_type);
  1665. switch(generic_info.item_type){
  1666. case ITEM_TYPE_WEAPON:{
  1667. if(weapon_info){
  1668. packet->setDataByName("wield_type", weapon_info->wield_type);
  1669. packet->setDataByName("damage_low1", weapon_info->damage_low1);
  1670. packet->setDataByName("damage_high1", weapon_info->damage_high1);
  1671. packet->setDataByName("damage_low2", weapon_info->damage_low2);
  1672. packet->setDataByName("damage_high2", weapon_info->damage_high2);
  1673. packet->setDataByName("damage_low3", weapon_info->damage_low3);
  1674. packet->setDataByName("damage_high3", weapon_info->damage_high3);
  1675. packet->setDataByName("damage_type", weapon_type);
  1676. packet->setDataByName("delay", weapon_info->delay);
  1677. packet->setDataByName("rating", weapon_info->rating);
  1678. }
  1679. break;
  1680. }
  1681. case ITEM_TYPE_RANGED:{
  1682. if(ranged_info){
  1683. packet->setDataByName("damage_low1", ranged_info->weapon_info.damage_low1);
  1684. packet->setDataByName("damage_high1", ranged_info->weapon_info.damage_high1);
  1685. packet->setDataByName("damage_low2", ranged_info->weapon_info.damage_low2);
  1686. packet->setDataByName("damage_high2", ranged_info->weapon_info.damage_high2);
  1687. packet->setDataByName("damage_low3", ranged_info->weapon_info.damage_low3);
  1688. packet->setDataByName("damage_high3", ranged_info->weapon_info.damage_high3);
  1689. packet->setDataByName("delay", ranged_info->weapon_info.delay);
  1690. packet->setDataByName("range_low", ranged_info->range_low);
  1691. packet->setDataByName("range_high", ranged_info->range_high);
  1692. packet->setDataByName("rating", ranged_info->weapon_info.rating);
  1693. }
  1694. break;
  1695. }
  1696. case ITEM_TYPE_SHIELD:
  1697. case ITEM_TYPE_ARMOR:{
  1698. if(armor_info){
  1699. packet->setDataByName("mitigation_low", armor_info->mitigation_low);
  1700. packet->setDataByName("mitigation_high", armor_info->mitigation_high);
  1701. }
  1702. break;
  1703. }
  1704. case ITEM_TYPE_BAG:{
  1705. if(bag_info){
  1706. int16 free_slots=bag_info->num_slots;
  1707. if(player){
  1708. Item* bag = player->GetPlayerItemList()->GetItemFromUniqueID(details.unique_id, true);
  1709. if(bag && bag->IsBag()){
  1710. vector<Item*>* bag_items = player->GetPlayerItemList()->GetItemsInBag(bag);
  1711. if(bag_items->size() > bag->bag_info->num_slots){
  1712. free_slots = 0;
  1713. packet->setArrayLengthByName("num_names", bag->bag_info->num_slots);
  1714. }
  1715. else{
  1716. free_slots = bag->bag_info->num_slots - bag_items->size();
  1717. packet->setArrayLengthByName("num_names", bag_items->size());
  1718. }
  1719. vector<Item*>::iterator itr;
  1720. int16 i = 0;
  1721. Item* tmp_bag_item = 0;
  1722. for(itr = bag_items->begin(); itr != bag_items->end();itr++){
  1723. tmp_bag_item = *itr;
  1724. if(tmp_bag_item && tmp_bag_item->details.slot_id < bag->bag_info->num_slots){
  1725. packet->setArrayDataByName("item_name", tmp_bag_item->name.c_str(), i);
  1726. i++;
  1727. }
  1728. }
  1729. safe_delete(bag_items);
  1730. }
  1731. }
  1732. packet->setDataByName("num_slots", bag_info->num_slots);
  1733. packet->setDataByName("num_empty", free_slots);
  1734. packet->setDataByName("weight_reduction", bag_info->weight_reduction);
  1735. packet->setDataByName("item_score", 2);
  1736. //packet->setDataByName("unknown5", 0x1e50a86f);
  1737. //packet->setDataByName("unknown6", 0x2c17f61d);
  1738. //1 armorer
  1739. //2 weaponsmith
  1740. //4 tailor
  1741. //16 jeweler
  1742. //32 sage
  1743. //64 alchemist
  1744. //120 all scholars
  1745. //250 all craftsman
  1746. //int8 blah[] = {0x00,0x00,0x01,0x01,0xb6,0x01,0x01};
  1747. //int8 blah[] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  1748. int8 blah[] = {0xd8,0x66,0x9b,0x6d,0xb6,0xfb,0x7f};
  1749. for(int8 i=0;i<sizeof(blah);i++)
  1750. packet->setSubstructDataByName("footer", "footer_unknown_0", blah[i], 0, i);
  1751. }
  1752. break;
  1753. }
  1754. case ITEM_TYPE_FOOD:{
  1755. if(food_info){
  1756. packet->setDataByName("food_type", food_info->type);
  1757. packet->setDataByName("level", food_info->level);
  1758. packet->setDataByName("duration", food_info->duration);
  1759. }
  1760. break;
  1761. }
  1762. case ITEM_TYPE_SKILL:{
  1763. //Spell Books
  1764. if(skill_info->spell_id > 0){
  1765. Spell* spell = master_spell_list.GetSpell(skill_info->spell_id, skill_info->spell_tier);
  1766. if(spell){
  1767. if(player) {
  1768. packet->setSubstructDataByName("header_info", "footer_type", 0);
  1769. spell->SetPacketInformation(packet, player->GetZone()->GetClientBySpawn(player));
  1770. if (player->HasSpell(skill_info->spell_id, skill_info->spell_tier))
  1771. packet->setDataByName("scribed", 1);
  1772. else
  1773. if (packet->GetVersion() >= 927){
  1774. if (player->HasSpell(skill_info->spell_id, skill_info->spell_tier, true))
  1775. packet->setAddToPacketByName("better_version", 1);// need to confirm
  1776. }
  1777. else
  1778. packet->setAddToPacketByName("better_version", 0); //if not scribed
  1779. packet->setDataByName("require_previous", 0);
  1780. }
  1781. else {
  1782. spell->SetPacketInformation(packet);
  1783. }
  1784. //packet->setDataByName("unknown26", 0);
  1785. }
  1786. }
  1787. break;
  1788. }
  1789. case ITEM_TYPE_BAUBLE:{
  1790. if(bauble_info){
  1791. packet->setDataByName("cast", bauble_info->cast);
  1792. packet->setDataByName("recovery", bauble_info->recovery);
  1793. packet->setDataByName("duration", bauble_info->duration);
  1794. packet->setDataByName("recast", bauble_info->recast);
  1795. packet->setDataByName("display_slot_optional", bauble_info->display_slot_optional);
  1796. packet->setDataByName("display_cast_time", bauble_info->display_cast_time);
  1797. packet->setDataByName("display_bauble_type", bauble_info->display_bauble_type);
  1798. packet->setDataByName("effect_radius", bauble_info->effect_radius);
  1799. packet->setDataByName("max_aoe_targets", bauble_info->max_aoe_targets);
  1800. packet->setDataByName("display_until_cancelled", bauble_info->display_until_cancelled);
  1801. //packet->setDataByName("item_score", 1);
  1802. }
  1803. break;
  1804. }
  1805. case ITEM_TYPE_THROWN:{
  1806. if(thrown_info){
  1807. packet->setDataByName("range", thrown_info->range);
  1808. packet->setDataByName("damage_modifier", thrown_info->damage_modifier);
  1809. packet->setDataByName("hit_bonus", thrown_info->hit_bonus);
  1810. packet->setDataByName("damage_type", thrown_info->damage_type);
  1811. }
  1812. break;
  1813. }
  1814. case ITEM_TYPE_HOUSE:{
  1815. if(houseitem_info){
  1816. packet->setDataByName("status_rent_reduction", houseitem_info->status_rent_reduction);
  1817. packet->setDataByName("coin_rent_reduction", houseitem_info->coin_rent_reduction);
  1818. packet->setDataByName("house_only", houseitem_info->house_only);
  1819. }
  1820. break;
  1821. }
  1822. case ITEM_TYPE_BOOK:{
  1823. if(book_info){
  1824. packet->setDataByName("language", book_info->language);
  1825. packet->setMediumStringByName("author", book_info->author.data.c_str());
  1826. packet->setMediumStringByName("title", book_info->title.data.c_str());
  1827. }
  1828. if (packet->GetVersion() <= 1096) packet->setDataByName("item_type", 13);
  1829. break;
  1830. }
  1831. case ITEM_TYPE_RECIPE:{
  1832. // Recipe Books
  1833. if(recipebook_info){
  1834. packet->setArrayLengthByName("num_recipes", recipebook_info->recipes.size());
  1835. for(int32 i = 0; i < recipebook_info->recipes.size(); i++){
  1836. packet->setArrayDataByName("recipe_name", recipebook_info->recipes.at(i).c_str(), i);
  1837. Recipe* recipe = master_recipe_list.GetRecipeByName(recipebook_info->recipes.at(i).c_str());
  1838. if (recipe) {
  1839. packet->setArrayDataByName("recipe_id", recipe->GetID(), i);
  1840. packet->setArrayDataByName("recipe_icon", recipe->GetIcon(), i);
  1841. }
  1842. }
  1843. packet->setDataByName("uses", recipebook_info->uses);
  1844. if(player->GetRecipeBookList()->HasRecipeBook(details.item_id))
  1845. packet->setDataByName("scribed", 1);
  1846. else
  1847. packet->setDataByName("scribed", 0);
  1848. }
  1849. break;
  1850. }
  1851. case ITEM_TYPE_ADORNMENT:{
  1852. //Adornements
  1853. packet->setDataByName("item_types",adornment_info->item_types);
  1854. packet->setDataByName("duration", adornment_info->duration); // need to calcualte for remaining duration
  1855. packet->setDataByName("slot_type", adornment_info->slot_type);
  1856. packet->setDataByName("footer_set_name", "test footer set name");
  1857. packet->setArrayLengthByName("footer_set_bonus_list_count", 1);// list of the bonus items
  1858. packet->setArrayDataByName("footer_set_bonus_items_needed", 2, 0); //this is nember of items needed for granteing that stat //name,value,array
  1859. packet->setSubArrayLengthByName("footer_set_bonus_stats_count", 2, 0);//name,value,array,subarray
  1860. packet->setSubArrayDataByName("set_stat_type", 5, 0,0);
  1861. packet->setSubArrayDataByName("set_stat_subtype", 1, 0, 0);
  1862. packet->setSubArrayDataByName("set_value", 25000, 0, 0);
  1863. }
  1864. case ITEM_TYPE_HOUSE_CONTAINER:{
  1865. //House Containers
  1866. if(housecontainer_info){
  1867. packet->setDataByName("allowed_types", housecontainer_info->allowed_types);
  1868. packet->setDataByName("num_slots", housecontainer_info->num_slots);
  1869. packet->setDataByName("broker_commission", housecontainer_info->broker_commission);
  1870. packet->setDataByName("fence_commission", housecontainer_info->fence_commission);
  1871. }
  1872. }
  1873. }
  1874. }
  1875. LogWrite(MISC__TODO, 1, "TODO", "Item Set information\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1876. if (IsBauble()) {
  1877. packet->setSubstructDataByName("footer", "stack_size", stack_count);
  1878. }
  1879. else {
  1880. packet->setSubstructDataByName("footer", "stack_size", stack_count);
  1881. }
  1882. packet->setSubstructDataByName("footer", "collectable", generic_info.collectable);
  1883. packet->setSubstructDataByName("footer", "status_item", sell_status);
  1884. LogWrite(MISC__TODO, 1, "TODO", "Set collection_needed information properly\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1885. packet->setSubstructDataByName("footer", "collection_needed", player->GetCollectionList()->NeedsItem(this) ? 1 : 0);
  1886. if(generic_info.offers_quest_id > 0){
  1887. Quest* quest = master_quest_list.GetQuest(generic_info.offers_quest_id);
  1888. if(quest){
  1889. packet->setSubstructDataByName("footer", "offers_quest", quest->GetName());
  1890. packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));
  1891. }
  1892. }
  1893. if(generic_info.part_of_quest_id > 0){
  1894. Quest* quest = master_quest_list.GetQuest(generic_info.part_of_quest_id);
  1895. if(quest){
  1896. packet->setSubstructDataByName("footer", "part_of_quest", quest->GetName());
  1897. packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));
  1898. }
  1899. }
  1900. if(generic_info.max_charges > 0){
  1901. packet->setSubstructDataByName("footer", "charges", 1);
  1902. packet->setSubstructDataByName("footer", "total_charges", generic_info.max_charges);
  1903. packet->setSubstructDataByName("footer", "charges_left", details.count);
  1904. packet->setSubstructDataByName("footer", "display_charges", generic_info.display_charges);
  1905. }
  1906. if ((packet->GetVersion() >= 63119) || packet->GetVersion() == 61331){
  1907. if (sell_status > 0){
  1908. }
  1909. }
  1910. //packet->setSubstructDataByName("footer", "status_item", 0);
  1911. if (IsHarvest()){
  1912. packet->setSubstructDataByName("footer", "crafting_flag", 1);
  1913. }
  1914. // Set these to 0 for now
  1915. if(packet->GetVersion() >= 1188){
  1916. packet->setSubstructDataByName("footer", "locked_flag", 0);
  1917. packet->setSubstructDataByName("footer", "account_retricted", 0);
  1918. }
  1919. // Adorns, set all to FF for now
  1920. if (packet->GetVersion() >= 1096) {// changed to 1096 for dov from 1188
  1921. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 0);
  1922. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 1);
  1923. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 2);
  1924. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 3);
  1925. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 4);
  1926. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 5);
  1927. }
  1928. if (packet->GetVersion() >= 1289) {// at some point after this there are 10 adornment slots all FF for now but will skip this if not needed for a version
  1929. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 6);
  1930. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 7);
  1931. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 8);
  1932. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 9);
  1933. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 10);
  1934. }
  1935. packet->setSubstructDataByName("footer", "name", name.c_str());
  1936. packet->setSubstructDataByName("footer", "description", description.c_str());
  1937. LogWrite(ITEM__PACKET, 0, "Items", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1938. //packet->PrintPacket();
  1939. #if EQDEBUG >= 9
  1940. packet->PrintPacket();
  1941. #endif
  1942. }
  1943. PacketStruct* Item::PrepareItem(int16 version, bool merchant_item, bool loot_item){
  1944. PacketStruct* packet = 0;
  1945. if(loot_item)
  1946. packet = configReader.getStruct("WS_LootItemGeneric", version);
  1947. else{
  1948. switch(generic_info.item_type){
  1949. case ITEM_TYPE_WEAPON:{
  1950. if(merchant_item)
  1951. packet = configReader.getStruct("WS_MerchantItemWeapon", version);
  1952. else
  1953. packet = configReader.getStruct("WS_ItemWeapon", version);
  1954. break;
  1955. }
  1956. case ITEM_TYPE_RANGED:{
  1957. if(merchant_item)
  1958. packet = configReader.getStruct("WS_MerchantItemRange", version);
  1959. else
  1960. packet = configReader.getStruct("WS_ItemRange", version);
  1961. break;
  1962. }
  1963. case ITEM_TYPE_SHIELD:{
  1964. if (merchant_item)
  1965. packet = configReader.getStruct("WS_MerchantItemShield", version);
  1966. else
  1967. packet = configReader.getStruct("WS_ItemShield", version);
  1968. break;
  1969. }
  1970. case ITEM_TYPE_ARMOR:{
  1971. if(merchant_item)
  1972. packet = configReader.getStruct("WS_MerchantItemArmor", version);
  1973. else
  1974. packet = configReader.getStruct("WS_ItemArmor", version);
  1975. break;
  1976. }
  1977. case ITEM_TYPE_BAG:{
  1978. if(merchant_item)
  1979. packet = configReader.getStruct("WS_MerchantItemBag", version);
  1980. else
  1981. packet = configReader.getStruct("WS_ItemBag", version);
  1982. break;
  1983. }
  1984. case ITEM_TYPE_BOOK:{
  1985. if(merchant_item)
  1986. packet = configReader.getStruct("WS_MerchantItemBook", version);
  1987. else
  1988. packet = configReader.getStruct("WS_ItemBook", version);
  1989. break;
  1990. }
  1991. case ITEM_TYPE_SKILL:{
  1992. if(merchant_item)
  1993. packet = configReader.getStruct("WS_MerchantItemSkill", version);
  1994. else
  1995. packet = configReader.getStruct("WS_ItemSkill", version);
  1996. break;
  1997. }
  1998. case ITEM_TYPE_RECIPE:{
  1999. if(merchant_item)
  2000. packet = configReader.getStruct("WS_MerchantItemRecipeBook", version);
  2001. else
  2002. packet = configReader.getStruct("WS_ItemRecipeBook", version);
  2003. break;
  2004. }
  2005. case ITEM_TYPE_FOOD:{
  2006. if(merchant_item)
  2007. packet = configReader.getStruct("WS_MerchantItemFood", version);
  2008. else
  2009. packet = configReader.getStruct("WS_ItemFood", version);
  2010. break;
  2011. }
  2012. case ITEM_TYPE_BAUBLE:{
  2013. if(merchant_item)
  2014. packet = configReader.getStruct("WS_MerchantItemBauble", version);
  2015. else
  2016. packet = configReader.getStruct("WS_ItemBauble", version);
  2017. break;
  2018. }
  2019. case ITEM_TYPE_ITEMCRATE:{
  2020. if (merchant_item)
  2021. packet = configReader.getStruct("WS_MerchantItemSet", version);
  2022. else
  2023. packet = configReader.getStruct("WS_ItemSet", version);
  2024. break;
  2025. }
  2026. case ITEM_TYPE_HOUSE:{
  2027. if(merchant_item)
  2028. packet = configReader.getStruct("WS_MerchantItemHouse", version);
  2029. else
  2030. packet = configReader.getStruct("WS_ItemHouse", version);
  2031. break;
  2032. }
  2033. case ITEM_TYPE_THROWN:{
  2034. if(merchant_item)
  2035. packet = configReader.getStruct("WS_MerchantItemThrown", version);
  2036. else
  2037. packet = configReader.getStruct("WS_ItemThrown", version);
  2038. break;
  2039. }
  2040. case ITEM_TYPE_HOUSE_CONTAINER:{
  2041. if(merchant_item)
  2042. packet = configReader.getStruct("WS_MerchantItemHouseContainer", version);
  2043. else
  2044. packet = configReader.getStruct("WS_ItemHouseContainer", version);
  2045. break;
  2046. }
  2047. case ITEM_TYPE_ADORNMENT:{
  2048. if(merchant_item)
  2049. packet = configReader.getStruct("WS_MerchantAdornment", version);
  2050. else
  2051. packet = configReader.getStruct("WS_ItemAdornment", version);
  2052. break;
  2053. }
  2054. default:{
  2055. if(merchant_item)
  2056. packet = configReader.getStruct("WS_MerchantItemGeneric", version);
  2057. else
  2058. packet = configReader.getStruct("WS_ItemGeneric", version);
  2059. }
  2060. }
  2061. }
  2062. if(!packet){
  2063. LogWrite(ITEM__ERROR, 0, "Item", "Unhandled Item type: %i", (int)generic_info.item_type);
  2064. return 0;
  2065. }
  2066. return packet;
  2067. }
  2068. EQ2Packet* Item::serialize(int16 version, bool show_name, Player* player, bool include_twice, int16 packet_type, int8 subtype, bool merchant_item, bool loot_item){
  2069. PacketStruct* packet = PrepareItem(version, merchant_item, loot_item);
  2070. if(!packet)
  2071. return 0;
  2072. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false)
  2073. serialize(packet, show_name, player, packet_type, 0x80, loot_item);
  2074. else
  2075. serialize(packet, show_name, player, packet_type, 0, loot_item);
  2076. if(merchant_item)
  2077. packet->setSubstructDataByName("header_info", "unique_id", 0xFFFFFFFF);
  2078. string* generic_string_data = packet->serializeString();
  2079. //packet->PrintPacket();
  2080. //LogWrite(ITEM__DEBUG, 9, "Items", "generic_string_data:");
  2081. //DumpPacket((uchar*)generic_string_data->c_str(), generic_string_data->length());
  2082. int32 size = generic_string_data->length();
  2083. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false)
  2084. size = (size*2)-13;
  2085. uchar* out_data = new uchar[size+1];
  2086. uchar* out_ptr = out_data;
  2087. memcpy(out_ptr, (uchar*)generic_string_data->c_str(), generic_string_data->length());
  2088. out_ptr += generic_string_data->length();
  2089. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false){
  2090. memcpy(out_ptr, (uchar*)generic_string_data->c_str() + 13, generic_string_data->length() -13);
  2091. }
  2092. int32 size2 = size-4;
  2093. memcpy(out_data, &size2, sizeof(int32));
  2094. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, out_data, size);
  2095. //DumpPacket(outapp);
  2096. safe_delete(packet);
  2097. safe_delete_array(out_data);
  2098. return outapp;
  2099. }
  2100. void Item::SetAppearance(ItemAppearance* appearance){
  2101. SetAppearance(appearance->type, appearance->red, appearance->green, appearance->blue, appearance->highlight_red, appearance->highlight_green, appearance->highlight_blue);
  2102. }
  2103. void Item::SetAppearance(int16 type, int8 red, int8 green, int8 blue, int8 highlight_red, int8 highlight_green, int8 highlight_blue){
  2104. generic_info.appearance_id = type;
  2105. generic_info.appearance_red = red;
  2106. generic_info.appearance_green = green;
  2107. generic_info.appearance_blue = blue;
  2108. generic_info.appearance_highlight_red = highlight_red;
  2109. generic_info.appearance_highlight_green = highlight_green;
  2110. generic_info.appearance_highlight_blue = highlight_blue;
  2111. }
  2112. void Item::AddEffect(string effect, int8 percentage, int8 subbulletflag){
  2113. ItemEffect* item_effect = new ItemEffect;
  2114. item_effect->subbulletflag = subbulletflag;
  2115. item_effect->effect.data = effect;
  2116. item_effect->effect.size = effect.length();
  2117. item_effect->percentage = percentage;
  2118. item_effects.push_back(item_effect);
  2119. }
  2120. void Item::AddBookPage(int8 page, string page_text, int8 valign, int8 halign) {
  2121. BookPage * bookpage = new BookPage;
  2122. bookpage->page = page;
  2123. bookpage->page_text.data = page_text;
  2124. bookpage->page_text.size = page_text.length();
  2125. bookpage->valign = valign;
  2126. bookpage->halign = halign;
  2127. book_pages.push_back(bookpage);
  2128. }
  2129. void Item::AddLevelOverride(ItemLevelOverride* level_override){
  2130. AddLevelOverride(level_override->adventure_class, level_override->tradeskill_class, level_override->level);
  2131. }
  2132. void Item::AddLevelOverride(int8 adventure_class, int8 tradeskill_class, int16 level){
  2133. ItemLevelOverride* item_override = new ItemLevelOverride;
  2134. item_override->adventure_class = adventure_class;
  2135. item_override->tradeskill_class = tradeskill_class;
  2136. item_override->level = level;
  2137. item_level_overrides.push_back(item_override);
  2138. }
  2139. void Item::AddSlot(int8 slot_id){
  2140. slot_data.push_back(slot_id);
  2141. }
  2142. void Item::SetWeaponType(int8 type){
  2143. weapon_type = type;
  2144. }
  2145. int8 Item::GetWeaponType(){
  2146. return weapon_type;
  2147. }
  2148. int32 Item::GetMaxSellValue(){
  2149. return max_sell_value;
  2150. }
  2151. void Item::SetMaxSellValue(int32 val){
  2152. max_sell_value = val;
  2153. }
  2154. void Item::SetItemScript(string name){
  2155. item_script = name;
  2156. }
  2157. const char* Item::GetItemScript(){
  2158. if(item_script.length() > 0)
  2159. return item_script.c_str();
  2160. return 0;
  2161. }
  2162. int32 Item::CalculateRepairCost() {
  2163. if (generic_info.condition == 100)
  2164. return 0;
  2165. float repair_cost = (float)generic_info.adventure_default_level * (10.0 - ((float)generic_info.condition * 0.1));
  2166. if (details.tier == ITEM_TAG_LEGENDARY)
  2167. repair_cost *= 4;
  2168. else if (details.tier == ITEM_TAG_FABLED)
  2169. repair_cost *= 8;
  2170. else if (details.tier == ITEM_TAG_MYTHICAL)
  2171. repair_cost *= 12;
  2172. return (int32)repair_cost;
  2173. }
  2174. PlayerItemList::PlayerItemList(){
  2175. packet_count = 0;
  2176. xor_packet = 0;
  2177. orig_packet = 0;
  2178. MPlayerItems.SetName("PlayerItemList::MPlayerItems");
  2179. }
  2180. PlayerItemList::~PlayerItemList(){
  2181. safe_delete_array(xor_packet);
  2182. safe_delete_array(orig_packet);
  2183. map<sint32, map<int16, Item*> >::iterator bag_iter;
  2184. map<int16, Item*>::iterator itr;
  2185. for(bag_iter = items.begin(); bag_iter != items.end(); bag_iter++){
  2186. for(itr = bag_iter->second.begin(); itr != bag_iter->second.end(); itr++){
  2187. safe_delete(itr->second);
  2188. }
  2189. bag_iter->second.clear();
  2190. }
  2191. items.clear();
  2192. while (!overflowItems.empty()){
  2193. safe_delete(overflowItems.back());
  2194. overflowItems.pop_back();
  2195. }
  2196. }
  2197. map<int32, Item*>* PlayerItemList::GetAllItems(){
  2198. map<int32, Item*>* ret = new map<int32, Item*>;
  2199. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2200. ret->insert(indexed_items.begin(), indexed_items.end());
  2201. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2202. return ret;
  2203. }
  2204. Item* PlayerItemList::GetItemFromIndex(int32 index){
  2205. Item* ret = 0;
  2206. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2207. if(indexed_items.count(index) > 0)
  2208. ret = indexed_items[index];
  2209. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2210. return ret;
  2211. }
  2212. Item* PlayerItemList::GetItem(sint32 bag_slot, int16 slot){
  2213. Item* ret = 0;
  2214. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2215. if(items.count(bag_slot) > 0 && items[bag_slot].count(slot) > 0)
  2216. ret = items[bag_slot][slot];
  2217. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2218. return ret;
  2219. }
  2220. void PlayerItemList::AddItem(Item* item){ //is called with a slot already set
  2221. //quick check to verify item
  2222. if(!item)
  2223. return;
  2224. else{
  2225. if(item->details.inv_slot_id != 0){
  2226. Item* bag = GetItemFromUniqueID(item->details.inv_slot_id, true);
  2227. if(bag && bag->IsBag()){
  2228. if(item->details.slot_id > bag->details.num_slots){
  2229. LogWrite(ITEM__ERROR, 0, "Item", "Error Adding Item: Invalid slot for item unique id: %u", item->details.unique_id);
  2230. safe_delete(item);
  2231. return;
  2232. }
  2233. }
  2234. }
  2235. }
  2236. int32 max_index = indexed_items.size();
  2237. int32 new_index = 0;
  2238. map<int32, Item*>::iterator itr;
  2239. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2240. for(itr = indexed_items.begin();itr != indexed_items.end(); itr++){
  2241. if(itr->first > max_index) //just grab the highest index val for next loop
  2242. max_index = itr->first;
  2243. }
  2244. for(int32 i=0;i<max_index;i++){
  2245. if(!indexed_items[i]){
  2246. new_index = i;
  2247. break;
  2248. }
  2249. }
  2250. if(new_index == 0 && max_index > 0)
  2251. new_index = max_index;
  2252. indexed_items[new_index] = item;
  2253. items[item->details.inv_slot_id][item->details.slot_id] = item;
  2254. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2255. }
  2256. Item* PlayerItemList::GetBag(int8 inventory_slot, bool lock){
  2257. Item* bag = 0;
  2258. if(lock)
  2259. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2260. if(items.count(0) > 0 && items[0].count(inventory_slot) > 0 && items[0][inventory_slot]->IsBag())
  2261. bag = items[0][inventory_slot];
  2262. if(lock)
  2263. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2264. return bag;
  2265. }
  2266. Item* PlayerItemList::GetBankBag(int8 inventory_slot, bool lock){
  2267. Item* bag = 0;
  2268. if(lock)
  2269. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2270. if(items.count(-3) > 0 && items[-3].count(inventory_slot) > 0 && items[-3][inventory_slot]->IsBag())
  2271. bag = items[-3][inventory_slot];
  2272. if(lock)
  2273. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2274. return bag;
  2275. }
  2276. int16 PlayerItemList::GetNumberOfFreeSlots(){
  2277. int16 count = 0;
  2278. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2279. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2280. if(items.count(i) == 0)
  2281. count++;
  2282. }
  2283. Item* bag = 0;
  2284. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2285. bag = GetBag(i, false);
  2286. if(bag && bag->details.num_slots > 0){
  2287. if(items.count(bag->details.bag_id) > 0){
  2288. for(int16 x=0;x<bag->details.num_slots;x++){
  2289. if(items[bag->details.bag_id].count(x) == 0)
  2290. count++;
  2291. }
  2292. }
  2293. else
  2294. count += bag->bag_info->num_slots; //if the bag hasnt been used yet, add all the free slots
  2295. }
  2296. }
  2297. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2298. return count;
  2299. }
  2300. bool PlayerItemList::HasFreeBagSlot(){
  2301. bool ret = false;
  2302. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2303. if(items.count(0) > 0){
  2304. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2305. if(items[0].count(i) == 0){
  2306. ret = true;
  2307. break;
  2308. }
  2309. }
  2310. }
  2311. else
  2312. ret = true;
  2313. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2314. return ret;
  2315. }
  2316. bool PlayerItemList::HasFreeSlot(){
  2317. bool ret = false;
  2318. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2319. if(items.count(0) > 0){
  2320. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2321. if(items[0].count(i) == 0){
  2322. ret = true;
  2323. break;
  2324. }
  2325. }
  2326. }
  2327. else
  2328. ret = true;
  2329. if(!ret){ //inventory slots full, check bags
  2330. Item* bag = 0;
  2331. for(int8 i=0;!ret && i<NUM_INV_SLOTS;i++){
  2332. bag = GetBag(i, false);
  2333. if(bag && bag->details.num_slots > 0){
  2334. if(items.count(bag->details.bag_id) > 0){
  2335. for(int16 x=0;x<bag->details.num_slots;x++){
  2336. if(items[bag->details.bag_id].count(x) == 0){
  2337. ret = true;
  2338. break;
  2339. }
  2340. }
  2341. }
  2342. else{ //if the bag hasnt been used yet, then all slots are free
  2343. ret = true;
  2344. break;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2350. return ret;
  2351. }
  2352. bool PlayerItemList::GetFirstFreeBankSlot(sint32* bag_id, sint16* slot) {
  2353. bool ret = false;
  2354. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2355. if (items.count(-3) > 0) {
  2356. for (int8 i = 0; i < NUM_BANK_SLOTS; i++) {
  2357. if (items[-3].count(i) == 0) {
  2358. *bag_id = -3;
  2359. *slot = i;
  2360. ret = true;
  2361. break;
  2362. }
  2363. }
  2364. }
  2365. else {
  2366. *bag_id = -3;
  2367. *slot = 0;
  2368. ret = true;
  2369. }
  2370. if(!ret) {
  2371. // Inventory slots were full so check bags
  2372. Item* bag = 0;
  2373. for(int8 i = 0; !ret && i < NUM_BANK_SLOTS; i++) {
  2374. // Check to see if the item in the inventory slot is a bag and it has slots
  2375. bag = GetBankBag(i, false);
  2376. if(bag && bag->details.num_slots > 0) {
  2377. // Item was a bag so lets loop through the slots and try to find an empty one
  2378. if(items.count(bag->details.bag_id) > 0) {
  2379. for(int16 x = 0; x < bag->details.num_slots; x++) {
  2380. if(items[bag->details.bag_id].count(x) == 0) {
  2381. // Found a free slot, get the bag id of this bag
  2382. *bag_id = bag->details.bag_id;
  2383. // Get the slot
  2384. *slot = x;
  2385. ret = true;
  2386. break;
  2387. }
  2388. }
  2389. }
  2390. else {
  2391. //if the bag hasnt been used yet, then all slots are free, so set the bag_id to this bag
  2392. // and the slot to 0 (the first slot)
  2393. *bag_id = bag->details.bag_id;
  2394. *slot = 0;
  2395. ret = true;
  2396. break;
  2397. }
  2398. }
  2399. }
  2400. }
  2401. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2402. return ret;
  2403. }
  2404. bool PlayerItemList::GetFirstFreeSlot(sint32* bag_id, sint16* slot) {
  2405. // Mostly copy and paste from the above function
  2406. bool ret = false;
  2407. // Try to place the item in the normal inventory slots first
  2408. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2409. if(items.count(0) > 0){
  2410. for(int8 i=0; i < NUM_INV_SLOTS; i++) {
  2411. if(items[0].count(i) == 0) {
  2412. // Found an empty slot, store the slot id and set the return value
  2413. *bag_id = 0;
  2414. *slot = i;
  2415. ret = true;
  2416. break;
  2417. }
  2418. }
  2419. }
  2420. else {
  2421. // no items in the players inventory, set it to the first slot
  2422. *bag_id = 0;
  2423. *slot = 0;
  2424. ret = true;
  2425. }
  2426. if(!ret) {
  2427. // Inventory slots were full so check bags
  2428. Item* bag = 0;
  2429. for(int8 i = 0; !ret && i < NUM_INV_SLOTS; i++) {
  2430. // Check to see if the item in the inventory slot is a bag and it has slots
  2431. bag = GetBag(i, false);
  2432. if(bag && bag->details.num_slots > 0) {
  2433. // Item was a bag so lets loop through the slots and try to find an empty one
  2434. if(items.count(bag->details.bag_id) > 0) {
  2435. for(int16 x = 0; x < bag->details.num_slots; x++) {
  2436. if(items[bag->details.bag_id].count(x) == 0) {
  2437. // Found a free slot, get the bag id of this bag
  2438. *bag_id = bag->details.bag_id;
  2439. // Get the slot
  2440. *slot = x;
  2441. ret = true;
  2442. break;
  2443. }
  2444. }
  2445. }
  2446. else {
  2447. //if the bag hasnt been used yet, then all slots are free, so set the bag_id to this bag
  2448. // and the slot to 0 (the first slot)
  2449. *bag_id = bag->details.bag_id;
  2450. *slot = 0;
  2451. ret = true;
  2452. break;
  2453. }
  2454. }
  2455. }
  2456. }
  2457. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2458. return ret;
  2459. }
  2460. Item* PlayerItemList::CanStack(Item* item, bool include_bank){
  2461. if(!item)
  2462. return 0;
  2463. Item* ret = 0;
  2464. map<sint32, map<int16, Item*> >::iterator itr;
  2465. map<int16, Item*>::iterator slot_itr;
  2466. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2467. for(itr = items.begin(); itr != items.end(); itr++){
  2468. if(include_bank || (!include_bank && itr->first >= 0)){
  2469. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2470. if(slot_itr->second && slot_itr->second->details.item_id == item->details.item_id && ((slot_itr->second->details.count + item->details.count) <= slot_itr->second->stack_count)){
  2471. ret = slot_itr->second;
  2472. break;
  2473. }
  2474. }
  2475. }
  2476. if(ret)
  2477. break;
  2478. }
  2479. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2480. return ret;
  2481. }
  2482. void PlayerItemList::Stack(Item* orig_item, Item* item){
  2483. if(!orig_item || !item)
  2484. return;
  2485. orig_item->details.count += item->details.count;
  2486. orig_item->save_needed = true;
  2487. }
  2488. bool PlayerItemList::AssignItemToFreeSlot(Item* item){
  2489. if(item){
  2490. Item* orig_item = CanStack(item);
  2491. if(orig_item){
  2492. Stack(orig_item, item);
  2493. return true;
  2494. }
  2495. bool use_bag_freeslot = false;
  2496. if(item->IsBag())
  2497. use_bag_freeslot = HasFreeBagSlot();
  2498. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2499. if(!use_bag_freeslot){
  2500. Item* bag = 0;
  2501. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2502. bag = GetBag(i, false);
  2503. if(bag && bag->details.num_slots > 0){
  2504. for(int16 x=0;x<bag->details.num_slots;x++){
  2505. if(items[bag->details.bag_id].count(x) == 0){
  2506. item->details.inv_slot_id = bag->details.bag_id;
  2507. item->details.slot_id = x;
  2508. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2509. AddItem(item);
  2510. return true;
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. //bags full, check inventory slots
  2517. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2518. if(items[0].count(i) == 0){
  2519. item->details.inv_slot_id = 0;
  2520. item->details.slot_id = i;
  2521. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2522. AddItem(item);
  2523. return true;
  2524. }
  2525. }
  2526. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2527. }
  2528. return false;
  2529. }
  2530. void PlayerItemList::RemoveItem(Item* item, bool delete_item){
  2531. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2532. if(items.count(item->details.inv_slot_id) > 0 && items[item->details.inv_slot_id].count(item->details.slot_id) > 0){
  2533. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2534. indexed_items[item->details.index] = 0;
  2535. }
  2536. if(item->IsBag() && item->details.inv_slot_id == 0 && item->details.slot_id < NUM_INV_SLOTS && items.count(item->details.bag_id) > 0){
  2537. map<int16, Item*>::iterator itr;
  2538. for(itr = items[item->details.bag_id].begin(); itr != items[item->details.bag_id].end(); itr++){
  2539. indexed_items[itr->second->details.index] = 0;
  2540. if(delete_item){
  2541. safe_delete(itr->second);
  2542. }
  2543. }
  2544. items.erase(item->details.bag_id);
  2545. }
  2546. if(delete_item){
  2547. safe_delete(item);
  2548. }
  2549. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2550. }
  2551. void PlayerItemList::DestroyItem(int16 index){
  2552. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2553. Item* item = indexed_items[index];
  2554. map<int16, Item*>::iterator itr;
  2555. if(item && item->IsBag() && item->details.inv_slot_id == 0 && item->details.slot_id < NUM_INV_SLOTS && items.count((sint32)item->details.bag_id) > 0){ //inventory
  2556. map<int16, Item*>* tmp_map = &(items[(sint32)item->details.bag_id]);
  2557. for(itr = tmp_map->begin(); itr != tmp_map->end(); itr++){
  2558. indexed_items[itr->second->details.index] = 0;
  2559. if(itr->second != item){
  2560. safe_delete(itr->second);
  2561. }
  2562. }
  2563. items.erase(item->details.bag_id);
  2564. }
  2565. if(items.count(item->details.inv_slot_id) > 0 && items[item->details.inv_slot_id].count(item->details.slot_id) > 0)
  2566. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2567. indexed_items[index] = 0;
  2568. safe_delete(item);
  2569. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2570. }
  2571. void PlayerItemList::MoveItem(Item* item, sint32 inv_slot, int16 slot, bool erase_old){
  2572. if(erase_old && items.count(item->details.inv_slot_id) > 0)
  2573. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2574. items[inv_slot][slot] = item;
  2575. item->details.inv_slot_id = inv_slot;
  2576. item->details.slot_id = slot;
  2577. item->save_needed = true;
  2578. }
  2579. int16 PlayerItemList::GetNumberOfItems(){
  2580. int16 ret = 0;
  2581. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2582. if(items.size() > 0){
  2583. map<sint32, map<int16, Item*> >::iterator itr;
  2584. sint32 bag_id = 0;
  2585. for(itr = items.begin(); itr != items.end(); itr++){
  2586. bag_id = itr->first;
  2587. if(items.count(bag_id) > 0)
  2588. ret += items[bag_id].size();
  2589. }
  2590. }
  2591. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2592. return ret;
  2593. }
  2594. bool PlayerItemList::MoveItem(sint32 to_bag_id, int16 from_index, sint8 to, int8 charges){
  2595. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2596. Item* item_from = indexed_items[from_index];
  2597. Item* item_to = 0;
  2598. if(item_from){
  2599. if(to_bag_id > 0){ //bag item
  2600. Item* bag = GetItemFromUniqueID(to_bag_id, true, false);
  2601. if(bag && bag->details.num_slots > to)
  2602. item_to = items[to_bag_id][to];
  2603. else{
  2604. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2605. return false;
  2606. }
  2607. }
  2608. else
  2609. item_to = items[to_bag_id][to];
  2610. if(charges > 0) {
  2611. if (item_to && item_from->details.item_id == item_to->details.item_id){
  2612. if(item_to->details.count > 0 && item_to->details.count < item_to->stack_count){
  2613. int32 total_tmp_price = 0;
  2614. if((item_to->details.count + item_from->details.count) <= item_to->stack_count){
  2615. total_tmp_price = (item_to->GetMaxSellValue()*item_to->details.count) + (item_from->GetMaxSellValue()*item_from->details.count);
  2616. item_to->details.count += item_from->details.count;
  2617. indexed_items[from_index] = 0;
  2618. items[item_from->details.inv_slot_id].erase(item_from->details.slot_id);
  2619. item_from->needs_deletion = true;
  2620. item_to->save_needed = true;
  2621. }
  2622. else{
  2623. int8 diff = item_to->stack_count - item_to->details.count;
  2624. total_tmp_price = (item_to->GetMaxSellValue()*item_to->details.count) + (item_from->GetMaxSellValue()*diff);
  2625. item_to->details.count = item_to->stack_count;
  2626. item_from->details.count -= diff;
  2627. item_to->save_needed = true;
  2628. }
  2629. item_to->SetMaxSellValue(total_tmp_price/item_to->details.count);
  2630. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2631. return true;
  2632. }
  2633. }
  2634. else {
  2635. if (item_from->details.count == charges) {
  2636. if (item_to)
  2637. MoveItem(item_to, item_from->details.inv_slot_id, item_from->details.slot_id);
  2638. MoveItem(item_from, to_bag_id, to, item_to ? false:true);
  2639. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2640. }
  2641. else {
  2642. if (item_to) {
  2643. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2644. return false;
  2645. }
  2646. item_from->details.count -= charges;
  2647. Item* new_item = new Item(master_item_list.GetItem(item_from->details.item_id));
  2648. new_item->details.count = charges;
  2649. new_item->details.slot_id = to;
  2650. new_item->details.inv_slot_id = to_bag_id;
  2651. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2652. new_item->save_needed = true;
  2653. AddItem(new_item);
  2654. if (item_from->details.count == 0)
  2655. RemoveItem(item_from);
  2656. }
  2657. return true;
  2658. }
  2659. }
  2660. else if(item_to && item_to->IsBag() && item_to->details.num_slots > 0){
  2661. // if item we are moving is a bag
  2662. if (item_from->IsBag() && item_from->details.num_slots > 0) {
  2663. for (int8 i = 0; i < item_from->details.num_slots; i++) {
  2664. // if there is something in the bag return, can't put bags with items into other bags
  2665. if (items[item_from->details.bag_id].count(i) != 0) {
  2666. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2667. return false;
  2668. }
  2669. }
  2670. }
  2671. if(items.count(item_to->details.bag_id) > 0){
  2672. for(int8 i=0;i<item_to->details.num_slots;i++){
  2673. if(items[item_to->details.bag_id].count(i) == 0){
  2674. MoveItem(item_from, item_to->details.bag_id, i);
  2675. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2676. return true;
  2677. }
  2678. }
  2679. }
  2680. else{
  2681. printf("7\n");
  2682. MoveItem(item_from, item_to->details.bag_id, 0);
  2683. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2684. return true;
  2685. }
  2686. }
  2687. if (item_to)
  2688. MoveItem(item_to, item_from->details.inv_slot_id, item_from->details.slot_id);
  2689. MoveItem(item_from, to_bag_id, to, item_to ? false:true);
  2690. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2691. return true;
  2692. }
  2693. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2694. return false;
  2695. }
  2696. EQ2Packet* PlayerItemList::serialize(Player* player, int16 version){
  2697. EQ2Packet* app = 0;
  2698. PacketStruct* packet = configReader.getStruct("WS_UpdateInventory",version);
  2699. Item* item = 0;
  2700. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2701. if(packet && indexed_items.size() > 0){
  2702. int8 packet_size = 0;
  2703. int16 size = indexed_items.size();
  2704. if (overflowItems.size() > 0)
  2705. size++;
  2706. PacketStruct* packet2 = configReader.getStruct("Substruct_Item", version);
  2707. packet_size = packet2->GetTotalPacketSize();
  2708. safe_delete(packet2);
  2709. packet->setArrayLengthByName("item_count", size);
  2710. if(packet_count < size){
  2711. if(!orig_packet){
  2712. xor_packet = new uchar[packet_size * size];
  2713. orig_packet = new uchar[packet_size * size];
  2714. memset(xor_packet, 0, packet_size * size);
  2715. memset(orig_packet, 0, packet_size * size);
  2716. }
  2717. else{
  2718. uchar* tmp = new uchar[packet_size * size];
  2719. memset(tmp, 0, packet_size * size);
  2720. memcpy(tmp, orig_packet, packet_size * packet_count);
  2721. safe_delete_array(orig_packet);
  2722. orig_packet = tmp;
  2723. safe_delete_array(xor_packet);
  2724. xor_packet = new uchar[packet_size * size];
  2725. }
  2726. packet_count = size;
  2727. }
  2728. for(int16 i = 0; i < indexed_items.size(); i++){
  2729. item = indexed_items[i];
  2730. if (item && item->details.item_id > 0)
  2731. AddItemToPacket(packet, player, item, i);
  2732. }
  2733. if (overflowItems.size() > 0) {
  2734. // We have overflow items, lets get the first one
  2735. item = overflowItems.at(0);
  2736. // Lets make sure the item is valid
  2737. if (item && item->details.item_id > 0) {
  2738. // Set the slot to 6 as that is what overflow requires to work
  2739. item->details.slot_id = 6;
  2740. // now add it to the packet
  2741. AddItemToPacket(packet, player, item, size - 1, true);
  2742. }
  2743. }
  2744. LogWrite(ITEM__PACKET, 0, "Items", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  2745. #if EQDEBUG >= 9
  2746. packet->PrintPacket();
  2747. #endif
  2748. packet->setDataByName("equip_flag",0);
  2749. app = packet->serializeCountPacket(version, 1, orig_packet, xor_packet);
  2750. safe_delete(packet);
  2751. }
  2752. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2753. return app;
  2754. }
  2755. void PlayerItemList::AddItemToPacket(PacketStruct* packet, Player* player, Item* item, int16 i, bool overflow){
  2756. Client *client;
  2757. int8 tmp_subtype = 0;
  2758. if (!packet || !player)
  2759. return;
  2760. client = player->GetZone()->GetClientBySpawn(player);
  2761. int32 menu_data = 3;
  2762. if(item->slot_data.size() > 0)
  2763. menu_data -= ITEM_MENU_TYPE_GENERIC;
  2764. if(item->details.num_slots > 0)
  2765. menu_data += ITEM_MENU_TYPE_BAG;
  2766. if (item->details.item_id == 21355) {
  2767. //menu_data += ITEM_MENU_TYPE_GENERIC;
  2768. //menu_data += ITEM_MENU_TYPE_EQUIP;
  2769. menu_data += ITEM_MENU_TYPE_BOOK;
  2770. //menu_data += ITEM_MENU_TYPE_BAG;
  2771. //menu_data += ITEM_MENU_TYPE_HOUSE;
  2772. //menu_data += ITEM_MENU_TYPE_TEST12;
  2773. //menu_data += ITEM_MENU_TYPE_SCRIBE;
  2774. //menu_data += ITEM_MENU_TYPE_TEST13;
  2775. //menu_data += ITEM_MENU_TYPE_INVALID;
  2776. //menu_data += ITEM_MENU_TYPE_TEST14;
  2777. //menu_data += ITEM_MENU_TYPE_BROKEN;
  2778. }
  2779. if (item->details.item_id == 21356) {
  2780. menu_data += ITEM_MENU_TYPE_TEST15;
  2781. menu_data += ITEM_MENU_TYPE_ATTUNED;
  2782. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  2783. menu_data += ITEM_MENU_TYPE_BOOK;
  2784. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  2785. menu_data += ITEM_MENU_TYPE_TEST1;
  2786. menu_data += ITEM_MENU_TYPE_NAMEPET;
  2787. menu_data += ITEM_MENU_TYPE_TEST2;
  2788. menu_data += ITEM_MENU_TYPE_CONSUME;
  2789. menu_data += ITEM_MENU_TYPE_USE;
  2790. }
  2791. if (item->details.item_id == 21357) {
  2792. menu_data += ITEM_MENU_TYPE_CONSUME_OFF ;
  2793. menu_data += ITEM_MENU_TYPE_TEST3 ;
  2794. menu_data += ITEM_MENU_TYPE_TEST4 ;
  2795. menu_data += ITEM_MENU_TYPE_TEST5 ;
  2796. menu_data += ITEM_MENU_TYPE_TEST6 ;
  2797. menu_data += ITEM_MENU_TYPE_TEST7 ;
  2798. menu_data += ITEM_MENU_TYPE_TEST8 ;
  2799. menu_data += ITEM_MENU_TYPE_TEST9 ;
  2800. menu_data += ITEM_MENU_TYPE_DAMAGED ;
  2801. menu_data += ITEM_MENU_TYPE_BROKEN2 ;
  2802. menu_data += ITEM_MENU_TYPE_REDEEM ;
  2803. menu_data += ITEM_MENU_TYPE_TEST10 ;
  2804. menu_data += ITEM_MENU_TYPE_UNPACK ;
  2805. }
  2806. if(item->IsSkill()){
  2807. Spell* spell = master_spell_list.GetSpell(item->skill_info->spell_id, item->skill_info->spell_tier);
  2808. if (spell && spell->ScribeAllowed(player))
  2809. menu_data += ITEM_MENU_TYPE_SCRIBE;
  2810. else
  2811. menu_data += ITEM_MENU_TYPE_INVALID;
  2812. }
  2813. if(item->IsRecipeBook()){
  2814. //TODO: Add check to allow scribe
  2815. menu_data += ITEM_MENU_TYPE_SCRIBE;
  2816. }
  2817. if (item->generic_info.item_type == 10){
  2818. menu_data += ITEM_MENU_TYPE_TEST1;
  2819. menu_data += ITEM_MENU_TYPE_HOUSE;
  2820. }
  2821. if (item->generic_info.item_type == 18){
  2822. menu_data += ITEM_MENU_TYPE_UNPACK;
  2823. packet->setSubstructArrayDataByName("items", "unknown3", ITEM_MENU_TYPE2_UNPACK, 0, i);
  2824. }
  2825. if(item->generic_info.condition == 0)
  2826. menu_data += ITEM_MENU_TYPE_BROKEN;
  2827. if(item->CheckFlag(ATTUNED) || item->CheckFlag(NO_TRADE))
  2828. menu_data += ITEM_MENU_TYPE_ATTUNED;
  2829. else if(item->CheckFlag(ATTUNEABLE))
  2830. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  2831. if (item->generic_info.usable == 1)
  2832. menu_data += ITEM_MENU_TYPE_USE;
  2833. if (item->details.count > 0 && item->stack_count > 1)
  2834. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  2835. // Added the if (overflow) so mouseover examines work properly
  2836. if (overflow)
  2837. packet->setSubstructArrayDataByName("items", "unique_id", item->details.item_id, 0, i);
  2838. else
  2839. packet->setSubstructArrayDataByName("items", "unique_id", item->details.unique_id, 0, i);
  2840. packet->setSubstructArrayDataByName("items", "bag_id", item->details.bag_id, 0, i);
  2841. packet->setSubstructArrayDataByName("items", "inv_slot_id", item->details.inv_slot_id, 0, i);
  2842. packet->setSubstructArrayDataByName("items", "menu_type", menu_data, 0, i);
  2843. if (overflow)
  2844. packet->setSubstructArrayDataByName("items", "index", 0xFFFF, 0, i);
  2845. else
  2846. packet->setSubstructArrayDataByName("items", "index", i, 0, i);
  2847. item->details.index = i;
  2848. packet->setSubstructArrayDataByName("items", "icon", item->details.icon, 0, i);
  2849. packet->setSubstructArrayDataByName("items", "slot_id", item->details.slot_id, 0, i);
  2850. if (client->GetVersion() <= 1208) {
  2851. packet->setSubstructArrayDataByName("items", "count", (std::min)(item->details.count, (int16)255), 0, i);
  2852. }
  2853. else
  2854. packet->setSubstructArrayDataByName("items", "count", item->details.count, 0, i);
  2855. //packet->setSubstructArrayDataByName("items", "unknown4", 5, 0, i);
  2856. // need item level
  2857. packet->setSubstructArrayDataByName("items", "item_level", item->details.recommended_level , 0, i);
  2858. packet->setSubstructArrayDataByName("items", "tier", item->details.tier, 0, i);
  2859. packet->setSubstructArrayDataByName("items", "num_slots", item->details.num_slots, 0, i);
  2860. // need empty slots
  2861. packet->setSubstructArrayDataByName("items", "item_id", item->details.item_id, 0, i);
  2862. //need broker id
  2863. packet->setSubstructArrayDataByName("items", "name", item->name.c_str(), 0, i);
  2864. }
  2865. bool PlayerItemList::AddOverflowItem(Item* item) {
  2866. bool ret = false;
  2867. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2868. if (item && item->details.item_id > 0 && overflowItems.size() < 255) {
  2869. item->details.slot_id = 6;
  2870. item->details.inv_slot_id = -2;
  2871. overflowItems.push_back(item);
  2872. ret = true;
  2873. }
  2874. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2875. return ret;
  2876. }
  2877. Item* PlayerItemList::GetOverflowItem() {
  2878. return overflowItems.at(0);
  2879. }
  2880. void PlayerItemList::RemoveOverflowItem(Item* item) {
  2881. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2882. vector<Item*>::iterator itr = std::find(overflowItems.begin(), overflowItems.end(), item);
  2883. overflowItems.erase(itr);
  2884. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2885. }
  2886. vector<Item*>* PlayerItemList::GetOverflowItemList() {
  2887. vector<Item*>* ret = new vector<Item*>;
  2888. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2889. vector<Item*>::iterator itr= ret->begin();
  2890. ret->insert(itr, overflowItems.begin(), overflowItems.end());
  2891. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2892. return ret;
  2893. }
  2894. bool PlayerItemList::HasItem(int32 id, bool include_bank){
  2895. map<sint32, map<int16, Item*> >::iterator itr;
  2896. map<int16, Item*>::iterator slot_itr;
  2897. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2898. for(itr = items.begin(); itr != items.end(); itr++){
  2899. if(include_bank || (!include_bank && itr->first >= 0)){
  2900. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2901. if(slot_itr->second && slot_itr->second->details.item_id == id){
  2902. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2903. return true;
  2904. }
  2905. }
  2906. }
  2907. }
  2908. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2909. return false;
  2910. }
  2911. bool PlayerItemList::SharedBankAddAllowed(Item* item){
  2912. if(!item || item->CheckFlag(NO_TRADE))
  2913. return false;
  2914. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2915. if(item->IsBag() && items.count(item->details.bag_id) > 0){
  2916. map<int16, Item*>::iterator itr;
  2917. for(itr = items[item->details.bag_id].begin(); itr != items[item->details.bag_id].end(); itr++){
  2918. if(itr->second->CheckFlag(NO_TRADE)){
  2919. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2920. return false;
  2921. }
  2922. }
  2923. }
  2924. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2925. return true;
  2926. }
  2927. vector<Item*>* PlayerItemList::GetItemsFromBagID(sint32 bag_id){
  2928. vector<Item*>* ret = new vector<Item*>;
  2929. if(items.count(bag_id) > 0){
  2930. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2931. map<int16, Item*>::iterator itr;
  2932. map<int16, Item*>::iterator itr2;
  2933. Item* item = 0;
  2934. for(itr = items[bag_id].begin(); itr != items[bag_id].end(); itr++){
  2935. item = itr->second;
  2936. if(item)
  2937. ret->push_back(item);
  2938. }
  2939. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2940. }
  2941. return ret;
  2942. }
  2943. vector<Item*>* PlayerItemList::GetItemsInBag(Item* bag){
  2944. vector<Item*>* ret_items = new vector<Item*>;
  2945. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2946. if(bag && bag->IsBag() && items.count(bag->details.bag_id) > 0){
  2947. map<int16, Item*>::iterator itr;
  2948. for(itr = items[bag->details.bag_id].begin(); itr != items[bag->details.bag_id].end(); itr++){
  2949. ret_items->push_back(itr->second);
  2950. }
  2951. }
  2952. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2953. return ret_items;
  2954. }
  2955. Item* PlayerItemList::GetItemFromID(int32 id, int8 count, bool include_bank, bool lock){
  2956. //first check for an exact count match
  2957. map<sint32, map<int16, Item*> >::iterator itr;
  2958. map<int16, Item*>::iterator slot_itr;
  2959. if(lock)
  2960. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2961. for(itr = items.begin(); itr != items.end(); itr++){
  2962. if(include_bank || (!include_bank && itr->first >= 0)){
  2963. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2964. if(slot_itr->second && slot_itr->second->details.item_id == id && (count == 0 || slot_itr->second->details.count == count)){
  2965. if(lock)
  2966. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2967. return slot_itr->second;
  2968. }
  2969. }
  2970. }
  2971. }
  2972. //couldn't find an exact match, look for closest
  2973. Item* closest = 0;
  2974. for(itr = items.begin(); itr != items.end(); itr++){
  2975. if(include_bank || (!include_bank && itr->first >= 0)){
  2976. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2977. if(slot_itr->second && slot_itr->second->details.item_id == id && slot_itr->second->details.count > count && (closest == 0 || slot_itr->second->details.count < closest->details.count))
  2978. closest = slot_itr->second;
  2979. }
  2980. }
  2981. }
  2982. if(lock)
  2983. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2984. return closest;
  2985. }
  2986. Item* PlayerItemList::GetItemFromUniqueID(int32 id, bool include_bank, bool lock){
  2987. map<sint32, map<int16, Item*> >::iterator itr;
  2988. map<int16, Item*>::iterator slot_itr;
  2989. if(lock)
  2990. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2991. for(itr = items.begin(); itr != items.end(); itr++){
  2992. if(include_bank || (!include_bank && itr->first >= 0)){
  2993. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2994. if(slot_itr->second && slot_itr->second->details.unique_id == id){
  2995. if(lock)
  2996. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2997. return slot_itr->second;
  2998. }
  2999. }
  3000. }
  3001. }
  3002. if(lock)
  3003. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3004. return 0;
  3005. }
  3006. bool PlayerItemList::HasFreeBankSlot() {
  3007. bool ret = false;
  3008. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3009. if (items[-3].size() < 12) //12 slots in the bank
  3010. ret = true;
  3011. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3012. return ret;
  3013. }
  3014. int8 PlayerItemList::FindFreeBankSlot() {
  3015. int8 ret = 0;
  3016. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3017. for (int8 i = 0; i < 12; i++) { //12 slots in the bank
  3018. if (items[-3].count(i) == 0) {
  3019. ret = i;
  3020. break;
  3021. }
  3022. }
  3023. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3024. return ret;
  3025. }
  3026. EquipmentItemList::EquipmentItemList(){
  3027. orig_packet = 0;
  3028. xor_packet = 0;
  3029. for(int8 i=0;i<NUM_SLOTS;i++)
  3030. items[i] = 0;
  3031. MEquipmentItems.SetName("EquipmentItemList::MEquipmentItems");
  3032. }
  3033. EquipmentItemList::EquipmentItemList(const EquipmentItemList& list){
  3034. orig_packet = 0;
  3035. xor_packet = 0;
  3036. for(int8 i=0;i<NUM_SLOTS;i++)
  3037. items[i] = 0;
  3038. MEquipmentItems.SetName("EquipmentItemList::MEquipmentItems");
  3039. }
  3040. EquipmentItemList::~EquipmentItemList(){
  3041. for(int8 i=0;i<NUM_SLOTS;i++)
  3042. safe_delete(items[i]);
  3043. safe_delete_array(orig_packet);
  3044. safe_delete_array(xor_packet);
  3045. }
  3046. bool EquipmentItemList::AddItem(int8 slot, Item* item){
  3047. if(item){
  3048. MEquipmentItems.lock();
  3049. SetItem(slot, item);
  3050. if(item->details.unique_id == 0)
  3051. GetItem(slot)->details.unique_id = MasterItemList::NextUniqueID();
  3052. MEquipmentItems.unlock();
  3053. return true;
  3054. }
  3055. return false;
  3056. }
  3057. int8 EquipmentItemList::GetNumberOfItems(){
  3058. int8 ret = 0;
  3059. MEquipmentItems.lock();
  3060. for(int8 i=0;i<NUM_SLOTS;i++){
  3061. if(items[i])
  3062. ret++;
  3063. }
  3064. MEquipmentItems.unlock();
  3065. return ret;
  3066. }
  3067. void EquipmentItemList::SetItem(int8 slot_id, Item* item){
  3068. item->details.inv_slot_id = 0;
  3069. item->details.slot_id = slot_id;
  3070. item->details.index = slot_id;
  3071. items[slot_id] = item;
  3072. }
  3073. vector<Item*>* EquipmentItemList::GetAllEquippedItems(){
  3074. vector<Item*>* ret = new vector<Item*>;
  3075. MEquipmentItems.lock();
  3076. for(int8 i=0;i<NUM_SLOTS;i++){
  3077. if(items[i])
  3078. ret->push_back(items[i]);
  3079. }
  3080. MEquipmentItems.unlock();
  3081. return ret;
  3082. }
  3083. Item* EquipmentItemList::GetItem(int8 slot_id){
  3084. return items[slot_id];
  3085. }
  3086. EQ2Packet* EquipmentItemList::serialize(int16 version, Player* player){
  3087. EQ2Packet* app = 0;
  3088. Item* item = 0;
  3089. PacketStruct* packet = configReader.getStruct("WS_UpdateInventory", version);
  3090. if(packet){
  3091. int8 packet_size = 0;
  3092. PacketStruct* packet2 = configReader.getStruct("Substruct_Item", version);
  3093. packet_size = packet2->GetTotalPacketSize();
  3094. safe_delete(packet2);
  3095. packet->setArrayLengthByName("item_count", NUM_SLOTS);
  3096. if(!orig_packet){
  3097. xor_packet = new uchar[packet_size*NUM_SLOTS];
  3098. orig_packet = new uchar[packet_size*NUM_SLOTS];
  3099. memset(xor_packet, 0, packet_size*NUM_SLOTS);
  3100. memset(orig_packet, 0, packet_size*NUM_SLOTS);
  3101. }
  3102. MEquipmentItems.lock();
  3103. int32 menu_data = 3;
  3104. for(int16 i=0;i<NUM_SLOTS;i++){
  3105. menu_data = 3;
  3106. item = items[i];
  3107. if(item && item->details.item_id > 0){
  3108. if(item->slot_data.size() > 0)
  3109. menu_data -= ITEM_MENU_TYPE_GENERIC;
  3110. if(item->details.num_slots > 0)
  3111. menu_data += ITEM_MENU_TYPE_BAG;
  3112. if(item->IsSkill())
  3113. menu_data += ITEM_MENU_TYPE_SCRIBE;
  3114. if(item->generic_info.condition == 0)
  3115. menu_data += ITEM_MENU_TYPE_BROKEN2;
  3116. else if (item->generic_info.condition <= 20)
  3117. menu_data += ITEM_MENU_TYPE_DAMAGED;
  3118. if(item->CheckFlag(ATTUNED) || item->CheckFlag(NO_TRADE))
  3119. menu_data += ITEM_MENU_TYPE_ATTUNED;
  3120. else if(item->CheckFlag(ATTUNEABLE))
  3121. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  3122. if (item->generic_info.usable == 1)
  3123. menu_data += ITEM_MENU_TYPE_USE;
  3124. if (item->IsFood())
  3125. {
  3126. menu_data += ITEM_MENU_TYPE_CONSUME;
  3127. if (player && ((item->IsFoodFood() && player->get_character_flag(CF_FOOD_AUTO_CONSUME)) || (item->IsFoodDrink() && player->get_character_flag(CF_DRINK_AUTO_CONSUME))))
  3128. menu_data += ITEM_MENU_TYPE_CONSUME_OFF;
  3129. }
  3130. packet->setSubstructArrayDataByName("items", "unique_id", item->details.unique_id, 0, i);
  3131. packet->setSubstructArrayDataByName("items", "bag_id", item->details.bag_id, 0, i);
  3132. packet->setSubstructArrayDataByName("items", "inv_slot_id", item->details.inv_slot_id, 0, i);
  3133. if(item->details.count > 0 && item->stack_count > 1)
  3134. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  3135. packet->setSubstructArrayDataByName("items", "menu_type", menu_data, 0, i);
  3136. packet->setSubstructArrayDataByName("items", "icon", item->details.icon, 0, i);
  3137. packet->setSubstructArrayDataByName("items", "slot_id", item->details.slot_id, 0, i);
  3138. packet->setSubstructArrayDataByName("items", "count", item->details.count, 0, i);
  3139. // item level needed here
  3140. packet->setSubstructArrayDataByName("items", "tier", item->details.tier, 0, i);
  3141. packet->setSubstructArrayDataByName("items", "num_slots", item->details.num_slots, 0, i);
  3142. //empty slots needed here
  3143. packet->setSubstructArrayDataByName("items", "item_id", item->details.item_id, 0, i);
  3144. //broker id needed here
  3145. packet->setSubstructArrayDataByName("items", "name", item->name.c_str(), 0, i);
  3146. //packet->setSubstructArrayDataByName("items", "unknown4", 10, 0, i);
  3147. item->details.index = i;
  3148. }
  3149. packet->setSubstructArrayDataByName("items", "index", i, 0, i);
  3150. }
  3151. MEquipmentItems.unlock();
  3152. packet->setDataByName("equip_flag", 1);
  3153. app = packet->serializeCountPacket(version, 1, orig_packet, xor_packet);
  3154. safe_delete(packet);
  3155. }
  3156. return app;
  3157. }
  3158. ItemStatsValues* EquipmentItemList::CalculateEquipmentBonuses(Entity* entity){
  3159. ItemStatsValues* stats = new ItemStatsValues;
  3160. memset(stats, 0, sizeof(ItemStatsValues));
  3161. entity->GetInfoStruct()->mitigation_base = 0;
  3162. MEquipmentItems.lock();
  3163. for(int8 i=0;i<NUM_SLOTS;i++){
  3164. if(items[i] && items[i]->details.item_id > 0){
  3165. master_item_list.CalculateItemBonuses(items[i], entity, stats);
  3166. if (items[i]->armor_info && !items[i]->IsShield())
  3167. entity->GetInfoStruct()->mitigation_base += items[i]->armor_info->mitigation_high;
  3168. }
  3169. }
  3170. MEquipmentItems.unlock();
  3171. return stats;
  3172. }
  3173. bool EquipmentItemList::HasItem(int32 id){
  3174. MEquipmentItems.lock();
  3175. for(int8 i=0;i<NUM_SLOTS;i++){
  3176. if(items[i] && items[i]->details.item_id == id){
  3177. MEquipmentItems.unlock();
  3178. return true;
  3179. }
  3180. }
  3181. MEquipmentItems.unlock();
  3182. return false;
  3183. }
  3184. void EquipmentItemList::RemoveItem(int8 slot, bool delete_item){
  3185. if(slot < NUM_SLOTS){
  3186. MEquipmentItems.lock();
  3187. if(delete_item){
  3188. safe_delete(items[slot]);
  3189. }
  3190. items[slot] = 0;
  3191. MEquipmentItems.unlock();
  3192. }
  3193. }
  3194. Item* EquipmentItemList::GetItemFromUniqueID(int32 item_id){
  3195. MEquipmentItems.lock();
  3196. for(int8 i=0;i<NUM_SLOTS;i++){
  3197. if(items[i] && items[i]->details.unique_id == item_id){
  3198. MEquipmentItems.unlock();
  3199. return items[i];
  3200. }
  3201. }
  3202. MEquipmentItems.unlock();
  3203. return 0;
  3204. }
  3205. Item* EquipmentItemList::GetItemFromItemID(int32 item_id) {
  3206. Item* item = 0;
  3207. MEquipmentItems.lock();
  3208. for(int8 i = 0; i < NUM_SLOTS; i++) {
  3209. if(items[i] && items[i]->details.item_id == item_id) {
  3210. item = items[i];
  3211. break;
  3212. }
  3213. }
  3214. MEquipmentItems.unlock();
  3215. return item;
  3216. }
  3217. bool EquipmentItemList::CanItemBeEquippedInSlot(Item* tmp, int8 slot){
  3218. MEquipmentItems.lock();
  3219. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3220. if(tmp->slot_data[i] == slot){
  3221. MEquipmentItems.unlock();
  3222. return true;
  3223. }
  3224. }
  3225. MEquipmentItems.unlock();
  3226. return false;
  3227. }
  3228. bool EquipmentItemList::CheckEquipSlot(Item* tmp, int8 slot){
  3229. MEquipmentItems.lock();
  3230. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3231. if(tmp->slot_data[i] == slot){
  3232. Item* tmp_item = GetItem(tmp->slot_data[i]);
  3233. if(!tmp_item || tmp_item->details.item_id == 0){
  3234. MEquipmentItems.unlock();
  3235. return true;
  3236. }
  3237. }
  3238. }
  3239. MEquipmentItems.unlock();
  3240. return false;
  3241. }
  3242. int8 EquipmentItemList::GetFreeSlot(Item* tmp, int8 slot_id){
  3243. int8 slot = 0;
  3244. MEquipmentItems.lock();
  3245. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3246. slot = tmp->slot_data[i];
  3247. if(slot_id == 255 || slot == slot_id){
  3248. Item* tmp_item = GetItem(slot);
  3249. if(!tmp_item || tmp_item->details.item_id == 0){
  3250. MEquipmentItems.unlock();
  3251. return slot;
  3252. }
  3253. }
  3254. }
  3255. MEquipmentItems.unlock();
  3256. return 255;
  3257. }
  3258. int8 EquipmentItemList::GetSlotByItem(Item* item) {
  3259. int8 slot = 255;
  3260. for (int8 i = 0; i < NUM_SLOTS; i++) {
  3261. if (items[i] && items[i] == item) {
  3262. slot = i;
  3263. break;
  3264. }
  3265. }
  3266. return slot;
  3267. }
  3268. string Item::CreateItemLink(bool bUseUniqueID) {
  3269. ostringstream ss;
  3270. ss << "\\aITEM " << details.item_id << ' ' << (bUseUniqueID ? details.unique_id : 0) << ':' << name << "\\/a";
  3271. return ss.str();
  3272. }