Items.cpp 140 KB

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