Items.cpp 147 KB

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