9
3

Items.cpp 141 KB

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