Items.cpp 143 KB

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