Items.cpp 128 KB

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