Items.cpp 134 KB

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