Items.cpp 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927
  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. }
  797. Item::Item(Item* in_item){
  798. needs_deletion = false;
  799. sell_price = in_item->sell_price;
  800. sell_status = in_item->sell_status;
  801. max_sell_value = in_item->max_sell_value;
  802. save_needed = true;
  803. SetItem(in_item);
  804. details.unique_id = master_item_list.NextUniqueID();
  805. if (IsBag())
  806. details.bag_id = details.unique_id;
  807. generic_info.condition = 100;
  808. spell_id = in_item->spell_id;
  809. spell_tier = in_item->spell_tier;
  810. }
  811. Item::~Item(){
  812. for(int32 i=0;i<item_stats.size();i++)
  813. safe_delete(item_stats[i]);
  814. for(int32 i=0;i<item_string_stats.size();i++)
  815. safe_delete(item_string_stats[i]);
  816. for(int32 i=0;i<item_level_overrides.size();i++)
  817. safe_delete(item_level_overrides[i]);
  818. for(int32 i=0;i<item_effects.size();i++)
  819. safe_delete(item_effects[i]);
  820. for (int32 i = 0; i < book_pages.size(); i++)
  821. safe_delete(book_pages[i]);
  822. safe_delete(weapon_info);
  823. safe_delete(ranged_info);
  824. safe_delete(adornment_info);
  825. safe_delete(bag_info);
  826. safe_delete(food_info);
  827. safe_delete(bauble_info);
  828. safe_delete(thrown_info);
  829. safe_delete(armor_info);
  830. safe_delete(skill_info);
  831. safe_delete(recipebook_info);
  832. safe_delete(itemset_info);
  833. safe_delete(book_info);
  834. safe_delete(houseitem_info);
  835. safe_delete(housecontainer_info);
  836. DeleteItemSets();
  837. }
  838. void Item::SetItem(Item* old_item){
  839. if(old_item->GetItemScript())
  840. SetItemScript(old_item->GetItemScript());
  841. name = old_item->name;
  842. lowername = old_item->lowername;
  843. description = old_item->description;
  844. memcpy(&generic_info, &old_item->generic_info, sizeof(Generic_Info));
  845. weapon_info = 0;
  846. ranged_info = 0;
  847. adornment_info = 0;
  848. adorn0 = 0;
  849. adorn1 = 0;
  850. adorn2 = 0;
  851. bag_info = 0;
  852. food_info = 0;
  853. bauble_info = 0;
  854. thrown_info = 0;
  855. skill_info = 0;
  856. recipebook_info = 0;
  857. itemset_info = 0;
  858. armor_info = 0;
  859. book_info = 0;
  860. book_info_pages = 0;
  861. houseitem_info = 0;
  862. housecontainer_info = 0;
  863. stack_count = old_item->stack_count;
  864. generic_info.skill_req1 = old_item->generic_info.skill_req1;
  865. generic_info.skill_req2 = old_item->generic_info.skill_req2;
  866. memcpy(&details, &old_item->details, sizeof(ItemCore));
  867. weapon_type = old_item->GetWeaponType();
  868. switch(old_item->generic_info.item_type){
  869. case ITEM_TYPE_WEAPON:{
  870. weapon_info = new Weapon_Info;
  871. memcpy(weapon_info, old_item->weapon_info, sizeof(Weapon_Info));
  872. break;
  873. }
  874. case ITEM_TYPE_RANGED:{
  875. ranged_info = new Ranged_Info;
  876. memcpy(ranged_info, old_item->ranged_info, sizeof(Ranged_Info));
  877. break;
  878. }
  879. case ITEM_TYPE_SHIELD:
  880. case ITEM_TYPE_ARMOR:{
  881. armor_info = new Armor_Info;
  882. memcpy(armor_info, old_item->armor_info, sizeof(Armor_Info));
  883. break;
  884. }
  885. case ITEM_TYPE_BAG:{
  886. bag_info = new Bag_Info;
  887. memcpy(bag_info, old_item->bag_info, sizeof(Bag_Info));
  888. break;
  889. }
  890. case ITEM_TYPE_FOOD:{
  891. food_info = new Food_Info;
  892. memcpy(food_info, old_item->food_info, sizeof(Food_Info));
  893. break;
  894. }
  895. case ITEM_TYPE_BAUBLE:{
  896. bauble_info = new Bauble_Info;
  897. memcpy(bauble_info, old_item->bauble_info, sizeof(Bauble_Info));
  898. break;
  899. }
  900. case ITEM_TYPE_SKILL:{
  901. skill_info = new Skill_Info;
  902. memcpy(skill_info, old_item->skill_info, sizeof(Skill_Info));
  903. break;
  904. }
  905. case ITEM_TYPE_THROWN:{
  906. thrown_info = new Thrown_Info;
  907. memcpy(thrown_info, old_item->thrown_info, sizeof(Thrown_Info));
  908. break;
  909. }
  910. case ITEM_TYPE_BOOK:{
  911. book_info = new Book_Info;
  912. book_info->language = old_item->book_info->language;
  913. book_info->author.data = old_item->book_info->author.data;
  914. book_info->author.size = old_item->book_info->author.size;
  915. book_info->title.data = old_item->book_info->title.data;
  916. book_info->title.size = old_item->book_info->title.size;
  917. break;
  918. }
  919. case ITEM_TYPE_HOUSE:{
  920. houseitem_info = new HouseItem_Info;
  921. memcpy(houseitem_info, old_item->houseitem_info, sizeof(HouseItem_Info));
  922. break;
  923. }
  924. case ITEM_TYPE_RECIPE:{
  925. // Recipe Book
  926. recipebook_info = new RecipeBook_Info;
  927. if (old_item->recipebook_info) {
  928. recipebook_info->uses = old_item->recipebook_info->uses;
  929. for (int32 i = 0; i < old_item->recipebook_info->recipes.size(); i++)
  930. recipebook_info->recipes.push_back(old_item->recipebook_info->recipes.at(i));
  931. }
  932. break;
  933. }
  934. case ITEM_TYPE_ADORNMENT:{
  935. adornment_info = new Adornment_Info;
  936. memcpy(adornment_info, old_item->adornment_info, sizeof(Adornment_Info));
  937. break;
  938. }
  939. case ITEM_TYPE_HOUSE_CONTAINER:{
  940. // House Containers
  941. housecontainer_info = new HouseContainer_Info;
  942. if (old_item->housecontainer_info) {
  943. housecontainer_info->broker_commission = old_item->housecontainer_info->broker_commission;
  944. housecontainer_info->fence_commission = old_item->housecontainer_info->fence_commission;
  945. housecontainer_info->allowed_types = old_item->housecontainer_info->allowed_types;
  946. housecontainer_info->num_slots = old_item->housecontainer_info->num_slots;
  947. }
  948. break;
  949. }
  950. }
  951. creator = old_item->creator;
  952. adornment = old_item->adornment;
  953. DeleteItemSets();
  954. for (int32 i = 0; i<old_item->item_sets.size(); i++){
  955. ItemSet* set = old_item->item_sets[i];
  956. if (set){
  957. ItemSet* set2 = new ItemSet;
  958. set2->item_id = set->item_id;
  959. set2->item_crc = set->item_crc;
  960. set2->item_icon = set->item_icon;
  961. set2->item_stack_size = set->item_stack_size;
  962. set2->item_list_color = set->item_list_color;
  963. item_sets.push_back(set2);
  964. }
  965. }
  966. item_stats.clear();
  967. for(int32 i=0;i<old_item->item_stats.size();i++){
  968. ItemStat* stat = old_item->item_stats[i];
  969. if(stat){
  970. ItemStat* stat2 = new ItemStat;
  971. stat2->stat_name = stat->stat_name;
  972. stat2->stat_type = stat->stat_type;
  973. stat2->stat_subtype = stat->stat_subtype;
  974. stat2->value = stat->value;
  975. stat2->stat_type_combined = stat->stat_type_combined;
  976. item_stats.push_back(stat2);
  977. }
  978. }
  979. item_string_stats.clear();
  980. for(int32 i=0;i<old_item->item_string_stats.size();i++){
  981. ItemStatString* stat = old_item->item_string_stats[i];
  982. if(stat){
  983. ItemStatString* stat2 = new ItemStatString;
  984. stat2->stat_string.data = stat->stat_string.data;
  985. stat2->stat_string.size = stat->stat_string.size;
  986. item_string_stats.push_back(stat2);
  987. }
  988. }
  989. item_level_overrides.clear();
  990. for(int32 i=0;i<old_item->item_level_overrides.size();i++){
  991. ItemLevelOverride* item_override = old_item->item_level_overrides[i];
  992. if(item_override){
  993. ItemLevelOverride* item_override2 = new ItemLevelOverride;
  994. memcpy(item_override2, item_override, sizeof(ItemLevelOverride));
  995. item_level_overrides.push_back(item_override2);
  996. }
  997. }
  998. item_effects.clear();
  999. for(int32 i=0;i<old_item->item_effects.size();i++){
  1000. ItemEffect* effect = old_item->item_effects[i];
  1001. if(effect){
  1002. ItemEffect* effect_2 = new ItemEffect;
  1003. effect_2->effect = effect->effect;
  1004. effect_2->percentage = effect->percentage;
  1005. effect_2->subbulletflag = effect->subbulletflag;
  1006. item_effects.push_back(effect_2);
  1007. }
  1008. }
  1009. book_pages.clear();
  1010. for (int32 i = 0; i < old_item->book_pages.size(); i++) {
  1011. BookPage* bookpage = old_item->book_pages[i];
  1012. if (bookpage) {
  1013. BookPage* bookpage_2 = new BookPage;
  1014. bookpage_2->page = bookpage->page;
  1015. bookpage_2->page_text.data = bookpage->page_text.data;
  1016. bookpage_2->page_text.size = bookpage->page_text.size;
  1017. bookpage_2->valign = bookpage->valign;
  1018. bookpage_2->halign = bookpage->halign;
  1019. book_pages.push_back(bookpage_2);
  1020. }
  1021. }
  1022. slot_data.clear();
  1023. slot_data = old_item->slot_data;
  1024. spell_id = old_item->spell_id;
  1025. spell_tier = old_item->spell_tier;
  1026. }
  1027. bool Item::CheckArchetypeAdvSubclass(int8 adventure_class, map<int8, int16>* adv_class_levels) {
  1028. if (adventure_class > FIGHTER && adventure_class < ANIMALIST) {
  1029. int8 check = adventure_class % 10;
  1030. if (check == 2 || check == 5 || check == 8) {
  1031. int64 adv_classes = 0;
  1032. int16 level = 0;
  1033. for (int i = adventure_class + 1; i < adventure_class + 3; i++) {
  1034. if (adv_class_levels) { //need to match levels
  1035. if (level == 0) {
  1036. if (adv_class_levels->count(i) > 0)
  1037. level = adv_class_levels->at(i);
  1038. else
  1039. return false;
  1040. }
  1041. else{
  1042. if (adv_class_levels->count(i) > 0 && adv_class_levels->at(i) != level)
  1043. return false;
  1044. }
  1045. }
  1046. else {
  1047. adv_classes = ((int64)2) << (i - 1);
  1048. if (!(generic_info.adventure_classes & adv_classes))
  1049. return false;
  1050. }
  1051. }
  1052. return true;
  1053. }
  1054. }
  1055. return false;
  1056. }
  1057. bool Item::CheckArchetypeAdvClass(int8 adventure_class, map<int8, int16>* adv_class_levels) {
  1058. if (adventure_class == 1 || adventure_class == 11 || adventure_class == 21 || adventure_class == 31) {
  1059. //if the class is an archetype class and the subclasses have access, then allow
  1060. if (CheckArchetypeAdvSubclass(adventure_class + 1, adv_class_levels) && CheckArchetypeAdvSubclass(adventure_class + 4, adv_class_levels) && CheckArchetypeAdvSubclass(adventure_class + 7, adv_class_levels)) {
  1061. if (adv_class_levels) {
  1062. int16 level = 0;
  1063. for (int i = adventure_class + 1; i <= adventure_class + 7; i += 3) {
  1064. if (adv_class_levels->count(i+1) == 0 || adv_class_levels->count(i + 2) == 0)
  1065. return false;
  1066. if(level == 0)
  1067. level = adv_class_levels->at(i+1);
  1068. if (adv_class_levels->at(i+1) != level) //already verified the classes, just need to verify the subclasses have the same levels
  1069. return false;
  1070. }
  1071. }
  1072. return true;
  1073. }
  1074. }
  1075. else if (CheckArchetypeAdvSubclass(adventure_class, adv_class_levels)) {//check archetype subclass
  1076. return true;
  1077. }
  1078. return false;
  1079. }
  1080. bool Item::CheckClass(int8 adventure_class, int8 tradeskill_class) {
  1081. int64 adv_classes = ((int64)2) << (adventure_class - 1);
  1082. int64 ts_classes = ((int64)2) << (tradeskill_class - 1);
  1083. if( ((generic_info.adventure_classes & adv_classes) || generic_info.adventure_classes == 0) && ((generic_info.tradeskill_classes & ts_classes) || generic_info.tradeskill_classes == 0) )
  1084. return true;
  1085. //check arechtype classes as last resort
  1086. return CheckArchetypeAdvClass(adventure_class);
  1087. }
  1088. bool Item::CheckLevel(int8 adventure_class, int8 tradeskill_class, int16 level) {
  1089. if ((level >= generic_info.adventure_default_level && adventure_class < 255) && (level >= generic_info.tradeskill_default_level && tradeskill_class < 255))
  1090. return true;
  1091. return false;
  1092. }
  1093. void Item::AddStat(ItemStat* in_stat){
  1094. item_stats.push_back(in_stat);
  1095. }
  1096. bool Item::HasStat(uint32 statID)
  1097. {
  1098. vector<ItemStat*>::iterator itr;
  1099. for (itr = item_stats.begin(); itr != item_stats.end(); itr++) {
  1100. if ((*itr)->stat_type_combined == statID) {
  1101. return true;
  1102. break;
  1103. }
  1104. }
  1105. return false;
  1106. }
  1107. void Item::DeleteItemSets()
  1108. {
  1109. for (int32 i = 0; i < item_sets.size(); i++){
  1110. ItemSet* set = item_sets[i];
  1111. safe_delete(set);
  1112. }
  1113. item_sets.clear();
  1114. }
  1115. void Item::AddSet(ItemSet* in_set){
  1116. item_sets.push_back(in_set);
  1117. }
  1118. void Item::AddStatString(ItemStatString* in_stat){
  1119. item_string_stats.push_back(in_stat);
  1120. }
  1121. bool Item::IsNormal(){
  1122. return generic_info.item_type == ITEM_TYPE_NORMAL;
  1123. }
  1124. bool Item::IsWeapon(){
  1125. return generic_info.item_type == ITEM_TYPE_WEAPON;
  1126. }
  1127. bool Item::IsArmor(){
  1128. return generic_info.item_type == ITEM_TYPE_ARMOR || generic_info.item_type == ITEM_TYPE_SHIELD;
  1129. }
  1130. bool Item::IsRanged(){
  1131. return generic_info.item_type == ITEM_TYPE_RANGED;
  1132. }
  1133. bool Item::IsBag(){
  1134. return generic_info.item_type == ITEM_TYPE_BAG;
  1135. }
  1136. bool Item::IsFood(){
  1137. return generic_info.item_type == ITEM_TYPE_FOOD;
  1138. }
  1139. bool Item::IsBauble(){
  1140. return generic_info.item_type == ITEM_TYPE_BAUBLE;
  1141. }
  1142. bool Item::IsSkill(){
  1143. return generic_info.item_type == ITEM_TYPE_SKILL;
  1144. }
  1145. bool Item::IsHouseItem(){
  1146. return generic_info.item_type == ITEM_TYPE_HOUSE;
  1147. }
  1148. bool Item::IsHouseContainer(){
  1149. return generic_info.item_type == ITEM_TYPE_HOUSE_CONTAINER;
  1150. }
  1151. bool Item::IsShield(){
  1152. return generic_info.item_type == ITEM_TYPE_SHIELD;
  1153. }
  1154. bool Item::IsAdornment(){
  1155. LogWrite(MISC__TODO, 1, "TODO", "Item Adornments\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1156. return generic_info.item_type == ITEM_TYPE_ADORNMENT;
  1157. }
  1158. bool Item::IsAmmo(){
  1159. return HasSlot(EQ2_AMMO_SLOT);
  1160. }
  1161. bool Item::HasAdorn0(){
  1162. if (adorn0 > 0)
  1163. return true;
  1164. return false;
  1165. }
  1166. bool Item::HasAdorn1(){
  1167. if (adorn1 > 0)
  1168. return true;
  1169. return false;
  1170. }
  1171. bool Item::HasAdorn2(){
  1172. if (adorn2 > 0)
  1173. return true;
  1174. return false;
  1175. }
  1176. bool Item::IsBook(){
  1177. return generic_info.item_type == ITEM_TYPE_BOOK;
  1178. }
  1179. bool Item::IsChainArmor(){
  1180. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 2246237129UL || generic_info.skill_req2 == 2246237129UL);
  1181. }
  1182. bool Item::IsClothArmor(){
  1183. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 3539032716UL || generic_info.skill_req2 == 3539032716UL);
  1184. }
  1185. bool Item::IsCollectable(){
  1186. return generic_info.collectable == 1;
  1187. }
  1188. bool Item::HasSlot(int8 slot, int8 slot2){
  1189. for(int32 i=0;i<slot_data.size();i++){
  1190. if(slot_data[i] == slot || slot_data[i] == slot2)
  1191. return true;
  1192. }
  1193. return false;
  1194. }
  1195. bool Item::IsCloak(){
  1196. return HasSlot(EQ2_CLOAK_SLOT);
  1197. }
  1198. bool Item::IsCrushWeapon(){
  1199. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 1;
  1200. }
  1201. bool Item::IsFoodFood(){
  1202. return generic_info.item_type == ITEM_TYPE_FOOD && food_info && food_info->type == 1;
  1203. }
  1204. bool Item::IsFoodDrink(){
  1205. return generic_info.item_type == ITEM_TYPE_FOOD && food_info && food_info->type == 0;
  1206. }
  1207. bool Item::IsJewelry(){
  1208. if(generic_info.item_type != ITEM_TYPE_ARMOR || (generic_info.skill_req1 != 2072844078 && generic_info.skill_req2 != 2072844078))
  1209. return false;
  1210. for(int32 i=0;i<slot_data.size();i++){
  1211. 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)
  1212. return true;
  1213. }
  1214. return false;
  1215. }
  1216. bool Item::IsLeatherArmor(){
  1217. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 2897193374UL || generic_info.skill_req2 == 2897193374UL);
  1218. }
  1219. bool Item::IsMisc(){
  1220. return IsNormal();
  1221. }
  1222. bool Item::IsPierceWeapon(){
  1223. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 2;
  1224. }
  1225. bool Item::IsPlateArmor(){
  1226. return generic_info.item_type == ITEM_TYPE_ARMOR && (generic_info.skill_req1 == 241174330UL || generic_info.skill_req2 == 241174330UL);
  1227. }
  1228. bool Item::IsPoison(){
  1229. LogWrite(MISC__TODO, 1, "TODO", "Separate poisons from potions\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1230. return IsBauble();
  1231. }
  1232. bool Item::IsPotion(){
  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::IsRecipeBook(){
  1237. return generic_info.item_type == ITEM_TYPE_RECIPE;
  1238. }
  1239. bool Item::IsSalesDisplay(){
  1240. LogWrite(MISC__TODO, 1, "TODO", "Item Sales Displays\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1241. return false;
  1242. }
  1243. bool Item::IsSlashWeapon(){
  1244. return generic_info.item_type == ITEM_TYPE_WEAPON && weapon_type == 0;
  1245. }
  1246. bool Item::IsSpellScroll(){
  1247. return IsSkill();
  1248. }
  1249. bool Item::IsTinkered(){
  1250. LogWrite(MISC__TODO, 1, "TODO", "Item Is Tinkered\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1251. return false;
  1252. }
  1253. bool Item::IsThrown(){
  1254. return generic_info.item_type == ITEM_TYPE_THROWN;
  1255. }
  1256. bool Item::IsHarvest() {
  1257. return generic_info.harvest == 1;
  1258. }
  1259. bool Item::IsBodyDrop() {
  1260. return generic_info.body_drop == 1;
  1261. }
  1262. bool Item::IsTradeskill(){
  1263. LogWrite(MISC__TODO, 1, "TODO", "Item Is Crafted\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1264. return false;
  1265. }
  1266. void Item::SetItemType(int8 in_type){
  1267. generic_info.item_type = in_type;
  1268. if(IsArmor() && !armor_info){
  1269. armor_info = new Armor_Info;
  1270. memset(armor_info, 0, sizeof(Armor_Info));
  1271. }
  1272. else if (IsWeapon() && !weapon_info){
  1273. weapon_info = new Weapon_Info;
  1274. memset(weapon_info, 0, sizeof(Weapon_Info));
  1275. }
  1276. else if (IsAdornment() && !adornment_info){
  1277. adornment_info = new Adornment_Info;
  1278. memset(adornment_info, 0, sizeof(Adornment_Info));
  1279. }
  1280. else if(IsRanged() && !ranged_info){
  1281. ranged_info = new Ranged_Info;
  1282. memset(ranged_info, 0, sizeof(Ranged_Info));
  1283. }
  1284. else if(IsBag() && !bag_info){
  1285. bag_info = new Bag_Info;
  1286. memset(bag_info, 0, sizeof(Bag_Info));
  1287. }
  1288. else if(IsFood() && !food_info){
  1289. food_info = new Food_Info;
  1290. memset(food_info, 0, sizeof(Food_Info));
  1291. }
  1292. else if(IsBauble() && !bauble_info){
  1293. bauble_info = new Bauble_Info;
  1294. memset(bauble_info, 0, sizeof(Bauble_Info));
  1295. }
  1296. else if(IsThrown() && !thrown_info){
  1297. thrown_info = new Thrown_Info;
  1298. memset(thrown_info, 0, sizeof(Thrown_Info));
  1299. }
  1300. else if(IsSkill() && !skill_info){
  1301. skill_info = new Skill_Info;
  1302. memset(skill_info, 0, sizeof(Skill_Info));
  1303. }
  1304. else if(IsRecipeBook() && !recipebook_info){
  1305. recipebook_info = new RecipeBook_Info;
  1306. recipebook_info->uses = 0;
  1307. }
  1308. else if(IsBook() && !book_info){
  1309. book_info = new Book_Info;
  1310. book_info->language = 0;
  1311. book_info->author.size = 0;
  1312. book_info->title.size = 0;
  1313. }
  1314. else if(IsHouseItem() && !houseitem_info){
  1315. houseitem_info = new HouseItem_Info;
  1316. memset(houseitem_info, 0, sizeof(HouseItem_Info));
  1317. }
  1318. else if(IsHouseContainer() && !housecontainer_info){
  1319. housecontainer_info = new HouseContainer_Info;
  1320. housecontainer_info->allowed_types = 0;
  1321. housecontainer_info->broker_commission = 0;
  1322. housecontainer_info->fence_commission = 0;
  1323. housecontainer_info->num_slots = 0;
  1324. }
  1325. }
  1326. bool Item::CheckFlag2(int32 flag){
  1327. int32 value = 0;
  1328. int32 flag_val = generic_info.item_flags2;
  1329. while (flag_val > 0){
  1330. if (flag_val >= FLAGS2_32768)
  1331. value = FLAGS2_32768;
  1332. else if (flag_val >= FLAGS2_16384)
  1333. value = FLAGS2_16384;
  1334. else if (flag_val >= FLAGS2_8192)
  1335. value = FLAGS2_8192;
  1336. else if (flag_val >= FLAGS2_4096)
  1337. value = FLAGS2_4096;
  1338. else if (flag_val >= FLAGS2_2048)
  1339. value = FLAGS2_2048;
  1340. else if (flag_val >= FLAGS2_1024)
  1341. value = FLAGS2_1024;
  1342. else if (flag_val >= FLAGS2_512)
  1343. value = FLAGS2_512;
  1344. else if (flag_val >= NO_SALVAGE)
  1345. value = NO_SALVAGE;
  1346. else if (flag_val >= REFINED)
  1347. value = REFINED;
  1348. else if (flag_val >= ETHERAL)
  1349. value = ETHERAL;
  1350. else if (flag_val >= NO_REPAIR)
  1351. value = NO_REPAIR;
  1352. else if (flag_val >= REFORGED)
  1353. value = REFORGED;
  1354. else if (flag_val >= UNLOCKED)
  1355. value = UNLOCKED;
  1356. else if (flag_val >= APPEARANCE_ONLY)
  1357. value = APPEARANCE_ONLY;
  1358. else if (flag_val >= HEIRLOOM)
  1359. value = HEIRLOOM;
  1360. else if (flag_val >= ORNATE)
  1361. value = ORNATE;
  1362. if (value == flag)
  1363. return true;
  1364. else
  1365. flag_val -= value;
  1366. }
  1367. return false;
  1368. }
  1369. bool Item::CheckFlag(int32 flag){
  1370. int32 value = 0;
  1371. int32 flag_val = generic_info.item_flags;
  1372. while(flag_val>0){
  1373. if (flag_val >= FLAGS_32768) //change this
  1374. value = FLAGS_32768;
  1375. else if (flag_val >= NO_TRANSMUTE) //change this
  1376. value = NO_TRANSMUTE;
  1377. else if (flag_val >= LORE_EQUIP) //change this
  1378. value = LORE_EQUIP;
  1379. else if (flag_val >= STACK_LORE) //change this
  1380. value = STACK_LORE;
  1381. else if(flag_val >= EVIL_ONLY)
  1382. value = EVIL_ONLY;
  1383. else if(flag_val >= GOOD_ONLY)
  1384. value = GOOD_ONLY;
  1385. else if(flag_val >= CRAFTED)
  1386. value = CRAFTED;
  1387. else if(flag_val >= NO_DESTROY)
  1388. value = NO_DESTROY;
  1389. else if(flag_val >= NO_ZONE)
  1390. value = NO_ZONE;
  1391. else if(flag_val >= NO_VALUE)
  1392. value = NO_VALUE;
  1393. else if(flag_val >= NO_TRADE)
  1394. value = NO_TRADE;
  1395. else if(flag_val >= TEMPORARY)
  1396. value = TEMPORARY;
  1397. else if(flag_val >= LORE)
  1398. value = LORE;
  1399. else if(flag_val >= ARTIFACT)
  1400. value = ARTIFACT;
  1401. else if(flag_val >= ATTUNEABLE)
  1402. value = ATTUNEABLE;
  1403. else if(flag_val >= ATTUNED)
  1404. value = ATTUNED;
  1405. if(value == flag)
  1406. return true;
  1407. else
  1408. flag_val -= value;
  1409. }
  1410. return false;
  1411. }
  1412. void Item::SetSlots(int32 slots){
  1413. if(slots & PRIMARY_SLOT)
  1414. AddSlot(EQ2_PRIMARY_SLOT);
  1415. if(slots & SECONDARY_SLOT)
  1416. AddSlot(EQ2_SECONDARY_SLOT);
  1417. if(slots & HEAD_SLOT)
  1418. AddSlot(EQ2_HEAD_SLOT);
  1419. if(slots & CHEST_SLOT)
  1420. AddSlot(EQ2_CHEST_SLOT);
  1421. if(slots & SHOULDERS_SLOT)
  1422. AddSlot(EQ2_SHOULDERS_SLOT);
  1423. if(slots & FOREARMS_SLOT)
  1424. AddSlot(EQ2_FOREARMS_SLOT);
  1425. if(slots & HANDS_SLOT)
  1426. AddSlot(EQ2_HANDS_SLOT);
  1427. if(slots & LEGS_SLOT)
  1428. AddSlot(EQ2_LEGS_SLOT);
  1429. if(slots & FEET_SLOT)
  1430. AddSlot(EQ2_FEET_SLOT);
  1431. if(slots & LRING_SLOT)
  1432. AddSlot(EQ2_LRING_SLOT);
  1433. if(slots & RRING_SLOT)
  1434. AddSlot(EQ2_RRING_SLOT);
  1435. if(slots & EARS_SLOT_1)
  1436. AddSlot(EQ2_EARS_SLOT_1);
  1437. if(slots & EARS_SLOT_2)
  1438. AddSlot(EQ2_EARS_SLOT_2);
  1439. if(slots & NECK_SLOT)
  1440. AddSlot(EQ2_NECK_SLOT);
  1441. if(slots & LWRIST_SLOT)
  1442. AddSlot(EQ2_LWRIST_SLOT);
  1443. if(slots & RWRIST_SLOT)
  1444. AddSlot(EQ2_RWRIST_SLOT);
  1445. if(slots & RANGE_SLOT)
  1446. AddSlot(EQ2_RANGE_SLOT);
  1447. if(slots & AMMO_SLOT)
  1448. AddSlot(EQ2_AMMO_SLOT);
  1449. if(slots & WAIST_SLOT)
  1450. AddSlot(EQ2_WAIST_SLOT);
  1451. if(slots & CLOAK_SLOT)
  1452. AddSlot(EQ2_CLOAK_SLOT);
  1453. if(slots & CHARM_SLOT_1)
  1454. AddSlot(EQ2_CHARM_SLOT_1);
  1455. if(slots & CHARM_SLOT_2)
  1456. AddSlot(EQ2_CHARM_SLOT_2);
  1457. if(slots & FOOD_SLOT)
  1458. AddSlot(EQ2_FOOD_SLOT);
  1459. if(slots & DRINK_SLOT)
  1460. AddSlot(EQ2_DRINK_SLOT);
  1461. if(slots & TEXTURES_SLOT)
  1462. AddSlot(EQ2_TEXTURES_SLOT);
  1463. }
  1464. void Item::AddStat(int8 type, int16 subtype, float value, char* name){
  1465. char item_stat_combined_string[8] = {0};
  1466. if(name && strlen(name) > 0 && type != 1){
  1467. ItemStatString* stat = new ItemStatString;
  1468. stat->stat_string.data = string(name);
  1469. stat->stat_string.size = stat->stat_string.data.length();
  1470. AddStatString(stat);
  1471. }
  1472. else{
  1473. ItemStat* stat = new ItemStat;
  1474. if(name && strlen(name) > 0)
  1475. stat->stat_name = string(name);
  1476. stat->stat_type = type;
  1477. stat->stat_subtype = subtype;
  1478. stat->value = value;
  1479. snprintf(item_stat_combined_string, 7, "%u%02u", type, subtype);
  1480. stat->stat_type_combined = atoi(item_stat_combined_string);
  1481. AddStat(stat);
  1482. }
  1483. }
  1484. void Item::AddSet(int32 item_id, int32 item_crc, int16 item_icon, int32 item_stack_size, int32 item_list_color){
  1485. ItemSet* set = new ItemSet;
  1486. set->item_id = item_id;
  1487. set->item_icon = item_icon;
  1488. set->item_crc = item_crc;
  1489. set->item_stack_size = item_stack_size;
  1490. set->item_list_color = item_list_color;
  1491. AddSet(set);
  1492. }
  1493. int16 Item::GetOverrideLevel(int8 adventure_class, int8 tradeskill_class){
  1494. int16 ret = 0;
  1495. int8 tmp_class = 0;
  1496. bool found_class = false;
  1497. for(int32 i=0;i<item_level_overrides.size();i++){
  1498. found_class = false;
  1499. if(adventure_class != 255){
  1500. tmp_class = item_level_overrides[i]->adventure_class;
  1501. if(tmp_class == PRIEST && (adventure_class >= CLERIC && adventure_class <= DEFILER))
  1502. found_class = true;
  1503. else if(tmp_class == MAGE && (adventure_class >= SORCERER && adventure_class <= NECROMANCER))
  1504. found_class = true;
  1505. else if(tmp_class == SCOUT && (adventure_class >= ROGUE && adventure_class <= ASSASSIN))
  1506. found_class = true;
  1507. else if(tmp_class == adventure_class || tmp_class == COMMONER || (tmp_class == FIGHTER && (adventure_class >= WARRIOR && adventure_class <= PALADIN)))
  1508. found_class = true;
  1509. }
  1510. else if(tradeskill_class != 255){
  1511. tmp_class = item_level_overrides[i]->tradeskill_class;
  1512. if(tmp_class == CRAFTSMAN && (tradeskill_class >= PROVISIONER && adventure_class <= CARPENTER))
  1513. found_class = true;
  1514. else if(tmp_class == OUTFITTER && (tradeskill_class >= ARMORER && tradeskill_class <= TAILOR))
  1515. found_class = true;
  1516. else if(tmp_class == SCHOLAR && (tradeskill_class >= JEWELER && tradeskill_class <= ALCHEMIST))
  1517. found_class = true;
  1518. else if(tmp_class == tradeskill_class || tmp_class == ARTISAN)
  1519. found_class = true;
  1520. }
  1521. if(found_class){
  1522. ret = item_level_overrides[i]->level;
  1523. break;
  1524. }
  1525. }
  1526. return ret;
  1527. }
  1528. void Item::serialize(PacketStruct* packet, bool show_name, Player* player, int16 packet_type, int8 subtype, bool loot_item){
  1529. int64 classes = 0;
  1530. Client *client;
  1531. int8 tmp_subtype = 0;
  1532. if (!packet || !player)
  1533. return;
  1534. client = player->GetZone()->GetClientBySpawn(player);
  1535. if (!client)
  1536. return;
  1537. if(creator.length() > 0){
  1538. packet->setSubstructSubstructDataByName("header", "info_header", "creator_flag", 1);
  1539. packet->setSubstructSubstructDataByName("header", "info_header", "creator", creator.c_str());
  1540. }
  1541. if(show_name)
  1542. packet->setSubstructSubstructDataByName("header", "info_header", "show_name", show_name);
  1543. if (packet_type == 20)
  1544. cout << "";
  1545. if(packet_type == 0)
  1546. packet->setSubstructSubstructDataByName("header", "info_header", "packettype", GetItemPacketType(packet->GetVersion()));
  1547. else
  1548. packet->setSubstructSubstructDataByName("header", "info_header", "packettype", packet_type);
  1549. packet->setSubstructSubstructDataByName("header", "info_header", "packetsubtype", subtype); // should be substype
  1550. packet->setSubstructDataByName("header_info", "footer_type", 3);
  1551. packet->setSubstructDataByName("header_info", "item_id", details.item_id);
  1552. if (!loot_item)
  1553. packet->setSubstructDataByName("header_info", "broker_item_id", details.item_id);
  1554. else
  1555. packet->setSubstructDataByName("header_info", "broker_item_id", 0xFFFFFFFFFFFFFFFF);
  1556. if(details.unique_id == 0)
  1557. packet->setSubstructDataByName("header_info", "unique_id", details.item_id);
  1558. else
  1559. packet->setSubstructDataByName("header_info", "unique_id", details.unique_id);
  1560. packet->setSubstructDataByName("header_info", "icon", details.icon);
  1561. packet->setSubstructDataByName("header_info", "tier", details.tier);
  1562. packet->setSubstructDataByName("header_info", "flags", generic_info.item_flags);
  1563. packet->setSubstructDataByName("header_info", "flags2", generic_info.item_flags2);
  1564. if(item_stats.size() > 0){
  1565. //packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size());
  1566. int8 dropstat = 0;
  1567. int8 bluemod = 0;
  1568. for (int32 i = 0; i < item_stats.size(); i++){
  1569. ItemStat* stat = item_stats[i];
  1570. if (stat->stat_type == 9){
  1571. bluemod += 1;
  1572. }
  1573. if (stat->stat_type == 6){ //Convert stats to proper client
  1574. //if (client->GetVersion() >= 63137){ //TEST
  1575. // tmp_subtype =stat->stat_subtype;
  1576. //}
  1577. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331){ //KA
  1578. tmp_subtype = world.GetItemStatKAValue(stat->stat_subtype);
  1579. }
  1580. else if (client->GetVersion() >= 57107){ //TOV
  1581. tmp_subtype = world.GetItemStatTOVValue(stat->stat_subtype);
  1582. }
  1583. else if (client->GetVersion() >= 1193){ //COE
  1584. tmp_subtype = world.GetItemStatCOEValue(stat->stat_subtype);
  1585. //tmp_subtype = stat->stat_subtype;
  1586. }
  1587. else if (client->GetVersion() >= 1096){ //DOV
  1588. tmp_subtype = world.GetItemStatDOVValue(stat->stat_subtype);
  1589. //tmp_subtype = stat->stat_subtype; //comment for normal use
  1590. }
  1591. }
  1592. else
  1593. tmp_subtype = stat->stat_subtype;
  1594. if (tmp_subtype == 255 ){
  1595. dropstat += 1;
  1596. }
  1597. }
  1598. packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size() - dropstat);
  1599. dropstat = 0;
  1600. for (int32 i = 0; i < item_stats.size(); i++) {
  1601. ItemStat* stat = item_stats[i];
  1602. if (stat->stat_type == 6){ //Convert stats to proper client
  1603. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331){ //KA
  1604. tmp_subtype = world.GetItemStatKAValue(stat->stat_subtype);
  1605. }
  1606. else if (client->GetVersion() >= 57107){ //TOV
  1607. tmp_subtype = world.GetItemStatTOVValue(stat->stat_subtype);
  1608. }
  1609. else if (client->GetVersion() >= 1193){ //COE
  1610. tmp_subtype = world.GetItemStatCOEValue(stat->stat_subtype);
  1611. //tmp_subtype = stat->stat_subtype;
  1612. }
  1613. else if (client->GetVersion() >= 1096){ //DOV
  1614. tmp_subtype = world.GetItemStatDOVValue(stat->stat_subtype); //comment out for testing
  1615. //tmp_subtype = stat->stat_subtype; //comment for normal use
  1616. }
  1617. }
  1618. else
  1619. tmp_subtype = stat->stat_subtype;
  1620. if (tmp_subtype == 255 ){
  1621. dropstat += 1;
  1622. //packet->setSubstructArrayLengthByName("header_info", "stat_count", item_stats.size()-dropstat);
  1623. }
  1624. else {
  1625. packet->setArrayDataByName("stat_type", stat->stat_type, i-dropstat);
  1626. packet->setArrayDataByName("stat_subtype", tmp_subtype, i-dropstat);
  1627. }
  1628. if (stat->stat_name.length() > 0)
  1629. packet->setArrayDataByName("stat_name", stat->stat_name.c_str(), i-dropstat);
  1630. /* SF client */
  1631. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331) {
  1632. if (stat->stat_type == 6){
  1633. packet->setArrayDataByName("value", stat->value , i - dropstat);//63119 or when diety started (this is actually the modified stat
  1634. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value (this is the unmodified stat
  1635. }
  1636. else {
  1637. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat, 0U, true);
  1638. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1639. }
  1640. }
  1641. else if (client->GetVersion() >= 1028) {
  1642. if (stat->stat_type == 6){
  1643. packet->setArrayDataByName("value", stat->value , i - dropstat);//63119 or when diety started (this is actually the infused modified stat
  1644. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value (this is the unmodified stat
  1645. }
  1646. else {
  1647. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat, 0U, true);
  1648. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1649. }
  1650. }
  1651. else{
  1652. packet->setArrayDataByName("value", (sint16)stat->value , i - dropstat);
  1653. packet->setArrayDataByName("value2", stat->value, i - dropstat);//63119 temp will be replace by modified value
  1654. }
  1655. }
  1656. }
  1657. if (item_string_stats.size() > 0 && !loot_item){
  1658. if ((client->GetVersion() >= 63119) || client->GetVersion() == 61331) {
  1659. packet->setSubstructArrayLengthByName("header_info", "mod_count", item_string_stats.size());
  1660. for (int32 i = 0; i < item_string_stats.size(); i++){
  1661. ItemStatString* stat = item_string_stats[i];
  1662. packet->setArrayDataByName("mod_string", &(stat->stat_string), i);
  1663. packet->setArrayDataByName("mod_need", 0, i);
  1664. }
  1665. }
  1666. else if (client->GetVersion() >= 1096) {
  1667. packet->setSubstructArrayLengthByName("header_info", "stat_string_count", item_string_stats.size());
  1668. for (int32 i = 0; i < item_string_stats.size(); i++){
  1669. ItemStatString* stat = item_string_stats[i];
  1670. packet->setArrayDataByName("stat_string", &(stat->stat_string), i);
  1671. }
  1672. }
  1673. }
  1674. if (item_sets.size() > 0){
  1675. packet->setArrayLengthByName("num_pieces", item_sets.size());
  1676. for (int32 i = 0; i < item_sets.size(); i++){
  1677. ItemSet* set = item_sets[i];
  1678. packet->setArrayDataByName("item_id", set->item_id, i);
  1679. packet->setArrayDataByName("item_crc", set->item_crc, i);
  1680. packet->setArrayDataByName("item_icon", set->item_icon, i);
  1681. packet->setArrayDataByName("item_unknown1", set->item_stack_size, i);
  1682. Item* item2 = master_item_list.GetItem(set->item_id);
  1683. if (item2)
  1684. packet->setArrayDataByName("item_name", item2->name.c_str(), i);
  1685. packet->setArrayDataByName("item_unknown2", set->item_list_color, i);
  1686. }
  1687. }
  1688. if(!loot_item && item_effects.size() > 0){
  1689. packet->setSubstructArrayLengthByName("footer", "num_effects", item_effects.size());
  1690. for(int32 i=0;i<item_effects.size();i++){
  1691. ItemEffect* effect = item_effects[i];
  1692. packet->setArrayDataByName("subbulletflag", effect->subbulletflag, i);
  1693. packet->setArrayDataByName("effect", &(effect->effect), i);
  1694. packet->setArrayDataByName("percentage", effect->percentage, i);
  1695. }
  1696. }
  1697. if (packet->GetVersion() < 1096) {
  1698. packet->setSubstructDataByName("header_info", "adornment_id", 0xFFFFFFFF); // Send no ID for now
  1699. packet->setSubstructDataByName("header_info", "unknown3", 0xFFFFFFFF);
  1700. }
  1701. packet->setSubstructDataByName("header_info", "unknown21", 0x00000000);
  1702. packet->setSubstructDataByName("header_info", "condition", generic_info.condition);
  1703. packet->setSubstructDataByName("header_info", "weight", generic_info.weight);
  1704. if (packet->GetVersion() <= 283) { //orig client only has one skill
  1705. if (generic_info.skill_req1 == 0 || generic_info.skill_req1 == 0xFFFFFFFF) {
  1706. if (generic_info.skill_req2 != 0 && generic_info.skill_req2 != 0xFFFFFFFF) {
  1707. packet->setSubstructDataByName("header_info", "skill_req1", generic_info.skill_req2);
  1708. }
  1709. else {
  1710. packet->setSubstructDataByName("header_info", "skill_req1", 0xFFFFFFFF);
  1711. }
  1712. }
  1713. else {
  1714. packet->setSubstructDataByName("header_info", "skill_req1", generic_info.skill_req1);
  1715. }
  1716. }
  1717. else {
  1718. if (generic_info.skill_req1 == 0)
  1719. packet->setSubstructDataByName("header_info", "skill_req1", 0xFFFFFFFF);
  1720. else
  1721. packet->setSubstructDataByName("header_info", "skill_req1", generic_info.skill_req1);
  1722. if (generic_info.skill_req2 == 0)
  1723. packet->setSubstructDataByName("header_info", "skill_req2", 0xFFFFFFFF);
  1724. else
  1725. packet->setSubstructDataByName("header_info", "skill_req2", generic_info.skill_req2);
  1726. }
  1727. if(generic_info.skill_min != 0)
  1728. packet->setSubstructDataByName("header_info", "skill_min", generic_info.skill_min);
  1729. if (client->GetVersion() <= 283) {
  1730. string flags;
  1731. if (CheckFlag(NO_TRADE))
  1732. flags += "NO-TRADE ";
  1733. if (CheckFlag(NO_VALUE))
  1734. flags += "NO-VALUE ";
  1735. if(flags.length() > 0)
  1736. packet->setSubstructDataByName("header_info", "flag_names", flags.c_str());
  1737. }
  1738. if (generic_info.adventure_classes > 0 || generic_info.tradeskill_classes > 0 || item_level_overrides.size() > 0) {
  1739. //int64 classes = 0;
  1740. int16 tmp_level = 0;
  1741. map<int8, int16> adv_class_levels;
  1742. map<int8, int16> tradeskill_class_levels;
  1743. map<int8, int16>::iterator itr;
  1744. int64 tmpVal = 0;
  1745. int8 temp = ASSASSIN;
  1746. // AoD + clients with beastlords
  1747. if (packet->GetVersion() >= 1142)
  1748. temp += 2;
  1749. // Chaneler class, get a more accurate version
  1750. if (packet->GetVersion() >= 60000)
  1751. temp += 2;
  1752. for (int32 i = 0; i <= temp; i++) {
  1753. tmpVal = (int64)pow(2.0, (double)i);
  1754. if ((generic_info.adventure_classes & tmpVal)) {
  1755. //classes += 2 << (i - 1);
  1756. classes += tmpVal;
  1757. tmp_level = GetOverrideLevel(i, 255);
  1758. if (tmp_level == 0)
  1759. adv_class_levels[i] = generic_info.adventure_default_level;
  1760. else
  1761. adv_class_levels[i] = tmp_level;
  1762. }
  1763. if (tmpVal == 0) {
  1764. if (packet->GetVersion() >= 60000)
  1765. classes = 576379072454289112;
  1766. else if (packet->GetVersion() >= 57048)
  1767. classes = 6281081087704;
  1768. else if (packet->GetVersion() >= 1142)
  1769. classes = 144095080877876952;
  1770. else
  1771. classes = 36024082983773912;
  1772. }
  1773. }
  1774. for (int i = ALCHEMIST + 1 - ARTISAN; i >= 0; i--) {
  1775. //tmpVal = 2 << i;
  1776. tmpVal = (int64)pow(2.0, (double)i);
  1777. if ((generic_info.tradeskill_classes & tmpVal)) {
  1778. classes += pow(2, (i + ARTISAN));
  1779. //classes += 2 << (i+ARTISAN-1);
  1780. tmp_level = GetOverrideLevel(i, 255);
  1781. if (tmp_level == 0)
  1782. tradeskill_class_levels[i] = generic_info.tradeskill_default_level;
  1783. else
  1784. tradeskill_class_levels[i] = tmp_level;
  1785. }
  1786. }
  1787. bool simplified_display = false;
  1788. if (client->GetVersion() <= 546) { //simplify display (if possible)
  1789. map<int8, int16> new_adv_class_levels;
  1790. for (int i = 1; i <= 31; i += 10) {
  1791. bool add_archetype = CheckArchetypeAdvClass(i, &adv_class_levels);
  1792. if (add_archetype) {
  1793. new_adv_class_levels[i] = 0;
  1794. }
  1795. else {
  1796. for (int x = 1; x <= 7; x += 3) {
  1797. if (CheckArchetypeAdvSubclass(i+x, &adv_class_levels)) {
  1798. new_adv_class_levels[i+x] = 0;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. if (new_adv_class_levels.size() > 0) {
  1804. simplified_display = true;
  1805. int8 i = 0;
  1806. for (itr = new_adv_class_levels.begin(); itr != new_adv_class_levels.end(); itr++) {
  1807. i = itr->first;
  1808. if ((i % 10) == 1) {
  1809. int16 level = 0;
  1810. for (int x = i; x < i+10; x++) {
  1811. if (adv_class_levels.count(x) > 0) {
  1812. if(level == 0)
  1813. level = adv_class_levels.at(x);
  1814. adv_class_levels.erase(x);
  1815. }
  1816. }
  1817. adv_class_levels[i] = level;
  1818. }
  1819. else {
  1820. int16 level = 0;
  1821. for (int x = i+1; x < i + 3; x++) {
  1822. if (adv_class_levels.count(x) > 0) {
  1823. if (level == 0)
  1824. level = adv_class_levels.at(x);
  1825. adv_class_levels.erase(x);
  1826. }
  1827. }
  1828. adv_class_levels[i] = level;
  1829. }
  1830. }
  1831. }
  1832. }
  1833. packet->setSubstructArrayLengthByName("header_info", "class_count", adv_class_levels.size() + tradeskill_class_levels.size());
  1834. int i = 0;
  1835. for (itr = adv_class_levels.begin(); itr != adv_class_levels.end(); itr++, i++) {
  1836. packet->setArrayDataByName("adventure_class", itr->first, i);
  1837. packet->setArrayDataByName("tradeskill_class", 255, i);
  1838. packet->setArrayDataByName("level", itr->second * 10, i);
  1839. }
  1840. for (itr = tradeskill_class_levels.begin(); itr != tradeskill_class_levels.end(); itr++, i++) {
  1841. packet->setArrayDataByName("adventure_class", 255, i);
  1842. packet->setArrayDataByName("tradeskill_class", itr->first, i);
  1843. packet->setArrayDataByName("level", itr->second, i);
  1844. }
  1845. packet->setSubstructDataByName("footer", "required_classes", classes);
  1846. }
  1847. else {
  1848. if (packet->GetVersion() >= 60000)
  1849. classes = 576379072454289112;
  1850. else if (packet->GetVersion() >= 57048)
  1851. classes = 6281081087704;
  1852. else if (packet->GetVersion() >= 1142)
  1853. classes = 144095080877876952;
  1854. else
  1855. classes = 36024082983773912;
  1856. packet->setSubstructDataByName("footer", "required_classes", classes);
  1857. }
  1858. // Is this a copy and paste error???
  1859. packet->setSubstructDataByName("footer", "required_classes2", classes);
  1860. {
  1861. if (packet->GetVersion() >= 60000)
  1862. classes = 576379072454289112;
  1863. else if (packet->GetVersion() >= 57048)
  1864. classes = 6281081087704;
  1865. else if (packet->GetVersion() >= 1142)
  1866. classes = 144095080877876952;
  1867. else
  1868. classes = 36024082983773912;
  1869. }
  1870. if (client->GetVersion() <= 283 && generic_info.adventure_default_level > 0) {
  1871. packet->setSubstructDataByName("header_info", "skill_min", (generic_info.adventure_default_level-1)*5+1);
  1872. packet->setSubstructDataByName("header_info", "skill_recommended", details.recommended_level * 5);
  1873. }
  1874. packet->setSubstructDataByName("footer", "recommended_level", details.recommended_level);
  1875. if(generic_info.adventure_default_level > 0){
  1876. packet->setSubstructDataByName("footer", "required_level", generic_info.adventure_default_level);
  1877. packet->setSubstructDataByName("footer", "footer_unknown2", 0);// remove defualt
  1878. }
  1879. else{
  1880. packet->setSubstructDataByName("footer", "required_level", generic_info.tradeskill_default_level);
  1881. packet->setSubstructDataByName("footer", "footer_unknown2", 0);//remove default
  1882. }
  1883. if(slot_data.size() > 0){
  1884. packet->setSubstructArrayLengthByName("header_info", "slot_count", slot_data.size());
  1885. for(int32 i=0;i<slot_data.size();i++){
  1886. int8 slot = slot_data[i];
  1887. if (client->GetVersion() <= 283) {
  1888. if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT) //they added a second ear slot later, adjust for only 1 original slot
  1889. slot -= 1;
  1890. else if (slot == EQ2_FOOD_SLOT)
  1891. slot = EQ2_ORIG_FOOD_SLOT;
  1892. else if(slot == EQ2_DRINK_SLOT)
  1893. slot = EQ2_ORIG_DRINK_SLOT;
  1894. }
  1895. else if (client->GetVersion() <= 546) {
  1896. if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT) //they added a second ear slot later, adjust for only 1 original slot
  1897. slot -= 1;
  1898. else if (slot == EQ2_FOOD_SLOT)
  1899. slot = EQ2_DOF_FOOD_SLOT;
  1900. else if (slot == EQ2_DRINK_SLOT)
  1901. slot = EQ2_DOF_DRINK_SLOT;
  1902. }
  1903. packet->setArrayDataByName("slot", slot, i);
  1904. }
  1905. }
  1906. if(!loot_item){
  1907. if (adornment_info)
  1908. 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);
  1909. packet->setSubstructDataByName("header", "item_type", generic_info.item_type);
  1910. switch(generic_info.item_type){
  1911. case ITEM_TYPE_WEAPON:{
  1912. if(weapon_info){
  1913. if (client->GetVersion() <= 283) {
  1914. packet->setSubstructDataByName("details", "wield_type", weapon_info->wield_type);
  1915. packet->setSubstructDataByName("details", "damage_low1", weapon_info->damage_low1);
  1916. packet->setSubstructDataByName("details", "damage_high1", weapon_info->damage_high1);
  1917. packet->setSubstructDataByName("details", "damage_low2", weapon_info->damage_low2);
  1918. packet->setSubstructDataByName("details", "damage_high2", weapon_info->damage_high2);
  1919. packet->setSubstructDataByName("details", "damage_type", weapon_type);
  1920. packet->setSubstructDataByName("details", "delay", weapon_info->delay);
  1921. }
  1922. else {
  1923. packet->setDataByName("wield_type", weapon_info->wield_type);
  1924. packet->setDataByName("damage_low1", weapon_info->damage_low1);
  1925. packet->setDataByName("damage_high1", weapon_info->damage_high1);
  1926. packet->setDataByName("damage_low2", weapon_info->damage_low2);
  1927. packet->setDataByName("damage_high2", weapon_info->damage_high2);
  1928. packet->setDataByName("damage_low3", weapon_info->damage_low3);
  1929. packet->setDataByName("damage_high3", weapon_info->damage_high3);
  1930. packet->setDataByName("damage_type", weapon_type);
  1931. packet->setDataByName("delay", weapon_info->delay);
  1932. packet->setDataByName("rating", weapon_info->rating);
  1933. }
  1934. }
  1935. break;
  1936. }
  1937. case ITEM_TYPE_RANGED:{
  1938. if(ranged_info){
  1939. if (client->GetVersion() <= 283) {
  1940. packet->setSubstructDataByName("details", "damage_low1", ranged_info->weapon_info.damage_low1);
  1941. packet->setSubstructDataByName("details", "damage_high1", ranged_info->weapon_info.damage_high1);
  1942. packet->setSubstructDataByName("details", "damage_low2", ranged_info->weapon_info.damage_low2);
  1943. packet->setSubstructDataByName("details", "damage_high2", ranged_info->weapon_info.damage_high2);
  1944. packet->setSubstructDataByName("details", "delay", ranged_info->weapon_info.delay);
  1945. packet->setSubstructDataByName("details", "range_low", ranged_info->range_low);
  1946. packet->setSubstructDataByName("details", "range_high", ranged_info->range_high);
  1947. }
  1948. else {
  1949. packet->setDataByName("damage_low1", ranged_info->weapon_info.damage_low1);
  1950. packet->setDataByName("damage_high1", ranged_info->weapon_info.damage_high1);
  1951. packet->setDataByName("damage_low2", ranged_info->weapon_info.damage_low2);
  1952. packet->setDataByName("damage_high2", ranged_info->weapon_info.damage_high2);
  1953. packet->setDataByName("damage_low3", ranged_info->weapon_info.damage_low3);
  1954. packet->setDataByName("damage_high3", ranged_info->weapon_info.damage_high3);
  1955. packet->setDataByName("delay", ranged_info->weapon_info.delay);
  1956. packet->setDataByName("range_low", ranged_info->range_low);
  1957. packet->setDataByName("range_high", ranged_info->range_high);
  1958. packet->setDataByName("rating", ranged_info->weapon_info.rating);
  1959. }
  1960. }
  1961. break;
  1962. }
  1963. case ITEM_TYPE_SHIELD:
  1964. case ITEM_TYPE_ARMOR:{
  1965. if(armor_info){
  1966. if (client->GetVersion() <= 283) {
  1967. packet->setSubstructDataByName("details", "mitigation_low", armor_info->mitigation_low);
  1968. packet->setSubstructDataByName("details", "mitigation_high", armor_info->mitigation_high);
  1969. }
  1970. else {
  1971. packet->setDataByName("mitigation_low", armor_info->mitigation_low);
  1972. packet->setDataByName("mitigation_high", armor_info->mitigation_high);
  1973. }
  1974. }
  1975. break;
  1976. }
  1977. case ITEM_TYPE_BAG:{
  1978. if(bag_info){
  1979. if (client->GetVersion() <= 283) {
  1980. if (bag_info->num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  1981. bag_info->num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  1982. packet->setSubstructDataByName("details", "num_slots", bag_info->num_slots);
  1983. packet->setSubstructDataByName("details", "weight_reduction", bag_info->weight_reduction);
  1984. }
  1985. else {
  1986. int16 free_slots = bag_info->num_slots;
  1987. if (player) {
  1988. Item* bag = player->GetPlayerItemList()->GetItemFromUniqueID(details.unique_id, true);
  1989. if (bag && bag->IsBag()) {
  1990. vector<Item*>* bag_items = player->GetPlayerItemList()->GetItemsInBag(bag);
  1991. if (bag_items->size() > bag->bag_info->num_slots) {
  1992. free_slots = 0;
  1993. packet->setArrayLengthByName("num_names", bag->bag_info->num_slots);
  1994. }
  1995. else {
  1996. free_slots = bag->bag_info->num_slots - bag_items->size();
  1997. packet->setArrayLengthByName("num_names", bag_items->size());
  1998. }
  1999. vector<Item*>::iterator itr;
  2000. int16 i = 0;
  2001. Item* tmp_bag_item = 0;
  2002. for (itr = bag_items->begin(); itr != bag_items->end(); itr++) {
  2003. tmp_bag_item = *itr;
  2004. if (tmp_bag_item && tmp_bag_item->details.slot_id < bag->bag_info->num_slots) {
  2005. packet->setArrayDataByName("item_name", tmp_bag_item->name.c_str(), i);
  2006. i++;
  2007. }
  2008. }
  2009. safe_delete(bag_items);
  2010. }
  2011. }
  2012. packet->setDataByName("num_slots", bag_info->num_slots);
  2013. packet->setDataByName("num_empty", free_slots);
  2014. packet->setDataByName("weight_reduction", bag_info->weight_reduction);
  2015. packet->setDataByName("item_score", 2);
  2016. //packet->setDataByName("unknown5", 0x1e50a86f);
  2017. //packet->setDataByName("unknown6", 0x2c17f61d);
  2018. //1 armorer
  2019. //2 weaponsmith
  2020. //4 tailor
  2021. //16 jeweler
  2022. //32 sage
  2023. //64 alchemist
  2024. //120 all scholars
  2025. //250 all craftsman
  2026. //int8 blah[] = {0x00,0x00,0x01,0x01,0xb6,0x01,0x01};
  2027. //int8 blah[] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  2028. int8 blah[] = { 0xd8,0x66,0x9b,0x6d,0xb6,0xfb,0x7f };
  2029. for (int8 i = 0; i < sizeof(blah); i++)
  2030. packet->setSubstructDataByName("footer", "footer_unknown_0", blah[i], 0, i);
  2031. }
  2032. }
  2033. break;
  2034. }
  2035. case ITEM_TYPE_FOOD:{
  2036. if(food_info && client->GetVersion() >=284){
  2037. packet->setDataByName("food_type", food_info->type);
  2038. packet->setDataByName("level", food_info->level);
  2039. packet->setDataByName("duration", food_info->duration);
  2040. }
  2041. break;
  2042. }
  2043. case ITEM_TYPE_SKILL:{
  2044. //Spell Books
  2045. if(skill_info->spell_id > 0){
  2046. Spell* spell = master_spell_list.GetSpell(skill_info->spell_id, skill_info->spell_tier);
  2047. if(spell){
  2048. if(player && client->GetVersion() >= 284) {
  2049. packet->setSubstructDataByName("header_info", "footer_type", 0);
  2050. spell->SetPacketInformation(packet, player->GetZone()->GetClientBySpawn(player));
  2051. if (player->HasSpell(skill_info->spell_id, skill_info->spell_tier))
  2052. packet->setDataByName("scribed", 1);
  2053. else
  2054. if (packet->GetVersion() >= 927){
  2055. if (player->HasSpell(skill_info->spell_id, skill_info->spell_tier, true))
  2056. packet->setAddToPacketByName("better_version", 1);// need to confirm
  2057. }
  2058. else
  2059. packet->setAddToPacketByName("better_version", 0); //if not scribed
  2060. packet->setDataByName("require_previous", 0);
  2061. }
  2062. else {
  2063. spell->SetPacketInformation(packet);
  2064. }
  2065. //packet->setDataByName("unknown26", 0);
  2066. }
  2067. }
  2068. break;
  2069. }
  2070. case ITEM_TYPE_BAUBLE:{
  2071. if(bauble_info && client->GetVersion() >= 284){
  2072. packet->setDataByName("cast", bauble_info->cast);
  2073. packet->setDataByName("recovery", bauble_info->recovery);
  2074. packet->setDataByName("duration", bauble_info->duration);
  2075. packet->setDataByName("recast", bauble_info->recast);
  2076. packet->setDataByName("display_slot_optional", bauble_info->display_slot_optional);
  2077. packet->setDataByName("display_cast_time", bauble_info->display_cast_time);
  2078. packet->setDataByName("display_bauble_type", bauble_info->display_bauble_type);
  2079. packet->setDataByName("effect_radius", bauble_info->effect_radius);
  2080. packet->setDataByName("max_aoe_targets", bauble_info->max_aoe_targets);
  2081. packet->setDataByName("display_until_cancelled", bauble_info->display_until_cancelled);
  2082. //packet->setDataByName("item_score", 1);
  2083. }
  2084. break;
  2085. }
  2086. case ITEM_TYPE_THROWN:{
  2087. if(thrown_info && client->GetVersion() >= 284){
  2088. packet->setDataByName("range", thrown_info->range);
  2089. packet->setDataByName("damage_modifier", thrown_info->damage_modifier);
  2090. packet->setDataByName("hit_bonus", thrown_info->hit_bonus);
  2091. packet->setDataByName("damage_type", thrown_info->damage_type);
  2092. }
  2093. break;
  2094. }
  2095. case ITEM_TYPE_HOUSE:{
  2096. if(houseitem_info && client->GetVersion() >= 284){
  2097. packet->setDataByName("status_rent_reduction", houseitem_info->status_rent_reduction);
  2098. packet->setDataByName("coin_rent_reduction", houseitem_info->coin_rent_reduction);
  2099. packet->setDataByName("house_only", houseitem_info->house_only);
  2100. }
  2101. break;
  2102. }
  2103. case ITEM_TYPE_BOOK:{
  2104. if(book_info && client->GetVersion() >= 284){
  2105. packet->setDataByName("language", book_info->language);
  2106. packet->setMediumStringByName("author", book_info->author.data.c_str());
  2107. packet->setMediumStringByName("title", book_info->title.data.c_str());
  2108. }
  2109. if (packet->GetVersion() <= 1096) packet->setDataByName("item_type", 13);
  2110. break;
  2111. }
  2112. case ITEM_TYPE_RECIPE:{
  2113. // Recipe Books
  2114. if(recipebook_info){
  2115. packet->setArrayLengthByName("num_recipes", recipebook_info->recipes.size());
  2116. for(int32 i = 0; i < recipebook_info->recipes.size(); i++){
  2117. packet->setArrayDataByName("recipe_name", recipebook_info->recipes.at(i).c_str(), i);
  2118. Recipe* recipe = master_recipe_list.GetRecipeByName(recipebook_info->recipes.at(i).c_str());
  2119. if (recipe) {
  2120. packet->setArrayDataByName("recipe_id", recipe->GetID(), i);
  2121. packet->setArrayDataByName("recipe_icon", recipe->GetIcon(), i);
  2122. }
  2123. }
  2124. packet->setDataByName("uses", recipebook_info->uses);
  2125. if(player->GetRecipeBookList()->HasRecipeBook(details.item_id))
  2126. packet->setDataByName("scribed", 1);
  2127. else
  2128. packet->setDataByName("scribed", 0);
  2129. }
  2130. break;
  2131. }
  2132. case ITEM_TYPE_ADORNMENT:{
  2133. //Adornements
  2134. if (client->GetVersion() >= 284) {
  2135. packet->setDataByName("item_types", adornment_info->item_types);
  2136. packet->setDataByName("duration", adornment_info->duration); // need to calcualte for remaining duration
  2137. packet->setDataByName("slot_type", adornment_info->slot_type);
  2138. packet->setDataByName("footer_set_name", "test footer set name");
  2139. packet->setArrayLengthByName("footer_set_bonus_list_count", 1);// list of the bonus items
  2140. packet->setArrayDataByName("footer_set_bonus_items_needed", 2, 0); //this is nember of items needed for granteing that stat //name,value,array
  2141. packet->setSubArrayLengthByName("footer_set_bonus_stats_count", 2, 0);//name,value,array,subarray
  2142. packet->setSubArrayDataByName("set_stat_type", 5, 0, 0);
  2143. packet->setSubArrayDataByName("set_stat_subtype", 1, 0, 0);
  2144. packet->setSubArrayDataByName("set_value", 25000, 0, 0);
  2145. }
  2146. }
  2147. case ITEM_TYPE_HOUSE_CONTAINER:{
  2148. //House Containers
  2149. if(housecontainer_info && client->GetVersion() >= 284){
  2150. packet->setDataByName("allowed_types", housecontainer_info->allowed_types);
  2151. packet->setDataByName("num_slots", housecontainer_info->num_slots);
  2152. packet->setDataByName("broker_commission", housecontainer_info->broker_commission);
  2153. packet->setDataByName("fence_commission", housecontainer_info->fence_commission);
  2154. }
  2155. }
  2156. }
  2157. }
  2158. LogWrite(MISC__TODO, 1, "TODO", "Item Set information\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  2159. if (IsBauble()) {
  2160. packet->setSubstructDataByName("footer", "stack_size", stack_count);
  2161. }
  2162. else {
  2163. packet->setSubstructDataByName("footer", "stack_size", stack_count);
  2164. }
  2165. packet->setSubstructDataByName("footer", "collectable", generic_info.collectable);
  2166. packet->setSubstructDataByName("footer", "status_item", sell_status);
  2167. LogWrite(MISC__TODO, 1, "TODO", "Set collection_needed information properly\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  2168. packet->setSubstructDataByName("footer", "collection_needed", player->GetCollectionList()->NeedsItem(this) ? 1 : 0);
  2169. if(generic_info.offers_quest_id > 0){
  2170. Quest* quest = master_quest_list.GetQuest(generic_info.offers_quest_id, false);
  2171. if(quest){
  2172. packet->setSubstructDataByName("footer", "offers_quest", quest->GetName());
  2173. packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));
  2174. }
  2175. }
  2176. if(generic_info.part_of_quest_id > 0){
  2177. Quest* quest = master_quest_list.GetQuest(generic_info.part_of_quest_id, false);
  2178. if(quest){
  2179. packet->setSubstructDataByName("footer", "part_of_quest", quest->GetName());
  2180. packet->setSubstructDataByName("footer", "quest_color", player->GetArrowColor(quest->GetQuestLevel()));
  2181. }
  2182. }
  2183. if(generic_info.max_charges > 0){
  2184. packet->setSubstructDataByName("footer", "charges", 1);
  2185. packet->setSubstructDataByName("footer", "total_charges", generic_info.max_charges);
  2186. packet->setSubstructDataByName("footer", "charges_left", details.count);
  2187. packet->setSubstructDataByName("footer", "display_charges", generic_info.display_charges);
  2188. }
  2189. if ((packet->GetVersion() >= 63119) || packet->GetVersion() == 61331){
  2190. if (sell_status > 0){
  2191. }
  2192. }
  2193. //packet->setSubstructDataByName("footer", "status_item", 0);
  2194. if (IsHarvest()){
  2195. packet->setSubstructDataByName("footer", "crafting_flag", 1);
  2196. }
  2197. // Set these to 0 for now
  2198. if(packet->GetVersion() >= 1188){
  2199. packet->setSubstructDataByName("footer", "locked_flag", 0);
  2200. packet->setSubstructDataByName("footer", "account_retricted", 0);
  2201. }
  2202. // Adorns, set all to FF for now
  2203. if (packet->GetVersion() >= 1096) {// changed to 1096 for dov from 1188
  2204. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 0);
  2205. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 1);
  2206. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 2);
  2207. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 3);
  2208. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 4);
  2209. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 5);
  2210. }
  2211. 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
  2212. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 6);
  2213. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 7);
  2214. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 8);
  2215. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 9);
  2216. packet->setSubstructDataByName("footer", "adorn_slots", 0xFF, 0, 10);
  2217. }
  2218. packet->setSubstructDataByName("footer", "name", name.c_str());
  2219. packet->setSubstructDataByName("footer", "description", description.c_str());
  2220. LogWrite(ITEM__PACKET, 0, "Items", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  2221. //packet->PrintPacket();
  2222. #if EQDEBUG >= 9
  2223. packet->PrintPacket();
  2224. #endif
  2225. }
  2226. PacketStruct* Item::PrepareItem(int16 version, bool merchant_item, bool loot_item){
  2227. PacketStruct* packet = 0;
  2228. if(loot_item && version > 546)
  2229. packet = configReader.getStruct("WS_LootItemGeneric", version);
  2230. else{
  2231. int8 tmpType = generic_info.item_type;
  2232. if (version <= 283 && generic_info.item_type > ITEM_TYPE_RECIPE)
  2233. tmpType = 0;
  2234. switch(tmpType){
  2235. case ITEM_TYPE_WEAPON:{
  2236. if(merchant_item)
  2237. packet = configReader.getStruct("WS_MerchantItemWeapon", version);
  2238. else
  2239. packet = configReader.getStruct("WS_ItemWeapon", version);
  2240. break;
  2241. }
  2242. case ITEM_TYPE_RANGED:{
  2243. if(merchant_item)
  2244. packet = configReader.getStruct("WS_MerchantItemRange", version);
  2245. else
  2246. packet = configReader.getStruct("WS_ItemRange", version);
  2247. break;
  2248. }
  2249. case ITEM_TYPE_SHIELD:{
  2250. if (merchant_item)
  2251. packet = configReader.getStruct("WS_MerchantItemShield", version);
  2252. else
  2253. packet = configReader.getStruct("WS_ItemShield", version);
  2254. break;
  2255. }
  2256. case ITEM_TYPE_ARMOR:{
  2257. if(merchant_item)
  2258. packet = configReader.getStruct("WS_MerchantItemArmor", version);
  2259. else
  2260. packet = configReader.getStruct("WS_ItemArmor", version);
  2261. break;
  2262. }
  2263. case ITEM_TYPE_BAG:{
  2264. if(merchant_item)
  2265. packet = configReader.getStruct("WS_MerchantItemBag", version);
  2266. else
  2267. packet = configReader.getStruct("WS_ItemBag", version);
  2268. break;
  2269. }
  2270. case ITEM_TYPE_BOOK:{
  2271. if(merchant_item)
  2272. packet = configReader.getStruct("WS_MerchantItemBook", version);
  2273. else
  2274. packet = configReader.getStruct("WS_ItemBook", version);
  2275. break;
  2276. }
  2277. case ITEM_TYPE_SKILL:{
  2278. if(merchant_item)
  2279. packet = configReader.getStruct("WS_MerchantItemSkill", version);
  2280. else
  2281. packet = configReader.getStruct("WS_ItemSkill", version);
  2282. break;
  2283. }
  2284. case ITEM_TYPE_RECIPE:{
  2285. if(merchant_item)
  2286. packet = configReader.getStruct("WS_MerchantItemRecipeBook", version);
  2287. else
  2288. packet = configReader.getStruct("WS_ItemRecipeBook", version);
  2289. break;
  2290. }
  2291. case ITEM_TYPE_FOOD:{
  2292. if(merchant_item)
  2293. packet = configReader.getStruct("WS_MerchantItemFood", version);
  2294. else
  2295. packet = configReader.getStruct("WS_ItemFood", version);
  2296. break;
  2297. }
  2298. case ITEM_TYPE_BAUBLE:{
  2299. if(merchant_item)
  2300. packet = configReader.getStruct("WS_MerchantItemBauble", version);
  2301. else
  2302. packet = configReader.getStruct("WS_ItemBauble", version);
  2303. break;
  2304. }
  2305. case ITEM_TYPE_ITEMCRATE:{
  2306. if (merchant_item)
  2307. packet = configReader.getStruct("WS_MerchantItemSet", version);
  2308. else
  2309. packet = configReader.getStruct("WS_ItemSet", version);
  2310. break;
  2311. }
  2312. case ITEM_TYPE_HOUSE:{
  2313. if(merchant_item)
  2314. packet = configReader.getStruct("WS_MerchantItemHouse", version);
  2315. else
  2316. packet = configReader.getStruct("WS_ItemHouse", version);
  2317. break;
  2318. }
  2319. case ITEM_TYPE_THROWN:{
  2320. if(merchant_item)
  2321. packet = configReader.getStruct("WS_MerchantItemThrown", version);
  2322. else
  2323. packet = configReader.getStruct("WS_ItemThrown", version);
  2324. break;
  2325. }
  2326. case ITEM_TYPE_HOUSE_CONTAINER:{
  2327. if(merchant_item)
  2328. packet = configReader.getStruct("WS_MerchantItemHouseContainer", version);
  2329. else
  2330. packet = configReader.getStruct("WS_ItemHouseContainer", version);
  2331. break;
  2332. }
  2333. case ITEM_TYPE_ADORNMENT:{
  2334. if(merchant_item)
  2335. packet = configReader.getStruct("WS_MerchantAdornment", version);
  2336. else
  2337. packet = configReader.getStruct("WS_ItemAdornment", version);
  2338. break;
  2339. }
  2340. default:{
  2341. if(merchant_item)
  2342. packet = configReader.getStruct("WS_MerchantItemGeneric", version);
  2343. else
  2344. packet = configReader.getStruct("WS_ItemGeneric", version);
  2345. }
  2346. }
  2347. if (packet && loot_item)
  2348. packet->AddFlag("loot");
  2349. }
  2350. if(!packet){
  2351. LogWrite(ITEM__ERROR, 0, "Item", "Unhandled Item type: %i", (int)generic_info.item_type);
  2352. return 0;
  2353. }
  2354. return packet;
  2355. }
  2356. EQ2Packet* Item::serialize(int16 version, bool show_name, Player* player, bool include_twice, int16 packet_type, int8 subtype, bool merchant_item, bool loot_item){
  2357. PacketStruct* packet = PrepareItem(version, merchant_item, loot_item);
  2358. if(!packet)
  2359. return 0;
  2360. if (version <= 546) {
  2361. include_twice = false;
  2362. packet_type = 0;
  2363. }
  2364. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false)
  2365. serialize(packet, show_name, player, packet_type, 0x80, loot_item);
  2366. else
  2367. serialize(packet, show_name, player, packet_type, 0, loot_item);
  2368. if(merchant_item)
  2369. packet->setSubstructDataByName("header_info", "unique_id", 0xFFFFFFFF);
  2370. string* generic_string_data = packet->serializeString();
  2371. //packet->PrintPacket();
  2372. //LogWrite(ITEM__DEBUG, 9, "Items", "generic_string_data:");
  2373. //DumpPacket((uchar*)generic_string_data->c_str(), generic_string_data->length());
  2374. int32 size = generic_string_data->length();
  2375. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false)
  2376. size = (size*2)-13;
  2377. uchar* out_data = new uchar[size+1];
  2378. uchar* out_ptr = out_data;
  2379. memcpy(out_ptr, (uchar*)generic_string_data->c_str(), generic_string_data->length());
  2380. out_ptr += generic_string_data->length();
  2381. if(include_twice && IsBag() == false && IsBauble() == false && IsFood() == false){
  2382. memcpy(out_ptr, (uchar*)generic_string_data->c_str() + 13, generic_string_data->length() -13);
  2383. }
  2384. int32 size2 = size;
  2385. if (version <= 283) {
  2386. uchar* out_ptr2 = out_data;
  2387. if (size2 >= 0xFF) {
  2388. size2 -= 3;
  2389. out_ptr2[0] = 0xFF;
  2390. out_ptr2 += sizeof(int8);
  2391. memcpy(out_ptr2, &size2, sizeof(int16));
  2392. }
  2393. else {
  2394. size2 -= 1;
  2395. out_ptr2[0] = size2;
  2396. }
  2397. }
  2398. else {
  2399. size2 -= 4;
  2400. memcpy(out_data, &size2, sizeof(int32));
  2401. }
  2402. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, out_data, size);
  2403. //DumpPacket(outapp);
  2404. safe_delete(packet);
  2405. safe_delete_array(out_data);
  2406. return outapp;
  2407. }
  2408. void Item::SetAppearance(ItemAppearance* appearance){
  2409. SetAppearance(appearance->type, appearance->red, appearance->green, appearance->blue, appearance->highlight_red, appearance->highlight_green, appearance->highlight_blue);
  2410. }
  2411. void Item::SetAppearance(int16 type, int8 red, int8 green, int8 blue, int8 highlight_red, int8 highlight_green, int8 highlight_blue){
  2412. generic_info.appearance_id = type;
  2413. generic_info.appearance_red = red;
  2414. generic_info.appearance_green = green;
  2415. generic_info.appearance_blue = blue;
  2416. generic_info.appearance_highlight_red = highlight_red;
  2417. generic_info.appearance_highlight_green = highlight_green;
  2418. generic_info.appearance_highlight_blue = highlight_blue;
  2419. }
  2420. void Item::AddEffect(string effect, int8 percentage, int8 subbulletflag){
  2421. ItemEffect* item_effect = new ItemEffect;
  2422. item_effect->subbulletflag = subbulletflag;
  2423. item_effect->effect.data = effect;
  2424. item_effect->effect.size = effect.length();
  2425. item_effect->percentage = percentage;
  2426. item_effects.push_back(item_effect);
  2427. }
  2428. void Item::AddBookPage(int8 page, string page_text, int8 valign, int8 halign) {
  2429. BookPage * bookpage = new BookPage;
  2430. bookpage->page = page;
  2431. bookpage->page_text.data = page_text;
  2432. bookpage->page_text.size = page_text.length();
  2433. bookpage->valign = valign;
  2434. bookpage->halign = halign;
  2435. book_pages.push_back(bookpage);
  2436. }
  2437. void Item::AddLevelOverride(ItemLevelOverride* level_override){
  2438. AddLevelOverride(level_override->adventure_class, level_override->tradeskill_class, level_override->level);
  2439. }
  2440. void Item::AddLevelOverride(int8 adventure_class, int8 tradeskill_class, int16 level){
  2441. ItemLevelOverride* item_override = new ItemLevelOverride;
  2442. item_override->adventure_class = adventure_class;
  2443. item_override->tradeskill_class = tradeskill_class;
  2444. item_override->level = level;
  2445. item_level_overrides.push_back(item_override);
  2446. }
  2447. void Item::AddSlot(int8 slot_id){
  2448. slot_data.push_back(slot_id);
  2449. }
  2450. void Item::SetWeaponType(int8 type){
  2451. weapon_type = type;
  2452. }
  2453. int8 Item::GetWeaponType(){
  2454. return weapon_type;
  2455. }
  2456. int32 Item::GetMaxSellValue(){
  2457. return max_sell_value;
  2458. }
  2459. void Item::SetMaxSellValue(int32 val){
  2460. max_sell_value = val;
  2461. }
  2462. void Item::SetItemScript(string name){
  2463. item_script = name;
  2464. }
  2465. const char* Item::GetItemScript(){
  2466. if(item_script.length() > 0)
  2467. return item_script.c_str();
  2468. return 0;
  2469. }
  2470. int32 Item::CalculateRepairCost() {
  2471. if (generic_info.condition == 100)
  2472. return 0;
  2473. float repair_cost = (float)generic_info.adventure_default_level * (10.0 - ((float)generic_info.condition * 0.1));
  2474. if (details.tier == ITEM_TAG_LEGENDARY)
  2475. repair_cost *= 4;
  2476. else if (details.tier == ITEM_TAG_FABLED)
  2477. repair_cost *= 8;
  2478. else if (details.tier == ITEM_TAG_MYTHICAL)
  2479. repair_cost *= 12;
  2480. return (int32)repair_cost;
  2481. }
  2482. PlayerItemList::PlayerItemList(){
  2483. packet_count = 0;
  2484. xor_packet = 0;
  2485. orig_packet = 0;
  2486. MPlayerItems.SetName("PlayerItemList::MPlayerItems");
  2487. }
  2488. PlayerItemList::~PlayerItemList(){
  2489. safe_delete_array(xor_packet);
  2490. safe_delete_array(orig_packet);
  2491. map<sint32, map<int16, Item*> >::iterator bag_iter;
  2492. map<int16, Item*>::iterator itr;
  2493. for(bag_iter = items.begin(); bag_iter != items.end(); bag_iter++){
  2494. for(itr = bag_iter->second.begin(); itr != bag_iter->second.end(); itr++){
  2495. safe_delete(itr->second);
  2496. }
  2497. bag_iter->second.clear();
  2498. }
  2499. items.clear();
  2500. while (!overflowItems.empty()){
  2501. safe_delete(overflowItems.back());
  2502. overflowItems.pop_back();
  2503. }
  2504. }
  2505. map<int32, Item*>* PlayerItemList::GetAllItems(){
  2506. map<int32, Item*>* ret = new map<int32, Item*>;
  2507. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2508. ret->insert(indexed_items.begin(), indexed_items.end());
  2509. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2510. return ret;
  2511. }
  2512. Item* PlayerItemList::GetItemFromIndex(int32 index){
  2513. Item* ret = 0;
  2514. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2515. if(indexed_items.count(index) > 0)
  2516. ret = indexed_items[index];
  2517. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2518. return ret;
  2519. }
  2520. Item* PlayerItemList::GetItem(sint32 bag_slot, int16 slot){
  2521. Item* ret = 0;
  2522. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2523. if(items.count(bag_slot) > 0 && items[bag_slot].count(slot) > 0)
  2524. ret = items[bag_slot][slot];
  2525. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2526. return ret;
  2527. }
  2528. void PlayerItemList::AddItem(Item* item){ //is called with a slot already set
  2529. //quick check to verify item
  2530. if(!item)
  2531. return;
  2532. else{
  2533. if(item->details.inv_slot_id != 0){
  2534. Item* bag = GetItemFromUniqueID(item->details.inv_slot_id, true);
  2535. if(bag && bag->IsBag()){
  2536. if(item->details.slot_id > bag->details.num_slots){
  2537. LogWrite(ITEM__ERROR, 0, "Item", "Error Adding Item: Invalid slot for item unique id: %u", item->details.unique_id);
  2538. safe_delete(item);
  2539. return;
  2540. }
  2541. }
  2542. }
  2543. }
  2544. int32 max_index = indexed_items.size();
  2545. int32 new_index = 0;
  2546. map<int32, Item*>::iterator itr;
  2547. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2548. for(itr = indexed_items.begin();itr != indexed_items.end(); itr++){
  2549. if(itr->first > max_index) //just grab the highest index val for next loop
  2550. max_index = itr->first;
  2551. }
  2552. for(int32 i=0;i<max_index;i++){
  2553. if(!indexed_items[i]){
  2554. new_index = i;
  2555. break;
  2556. }
  2557. }
  2558. if(new_index == 0 && max_index > 0)
  2559. new_index = max_index;
  2560. indexed_items[new_index] = item;
  2561. items[item->details.inv_slot_id][item->details.slot_id] = item;
  2562. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2563. }
  2564. Item* PlayerItemList::GetBag(int8 inventory_slot, bool lock){
  2565. Item* bag = 0;
  2566. if(lock)
  2567. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2568. if(items.count(0) > 0 && items[0].count(inventory_slot) > 0 && items[0][inventory_slot]->IsBag())
  2569. bag = items[0][inventory_slot];
  2570. if(lock)
  2571. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2572. return bag;
  2573. }
  2574. Item* PlayerItemList::GetBankBag(int8 inventory_slot, bool lock){
  2575. Item* bag = 0;
  2576. if(lock)
  2577. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2578. if(items.count(-3) > 0 && items[-3].count(inventory_slot) > 0 && items[-3][inventory_slot]->IsBag())
  2579. bag = items[-3][inventory_slot];
  2580. if(lock)
  2581. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2582. return bag;
  2583. }
  2584. int16 PlayerItemList::GetNumberOfFreeSlots(){
  2585. int16 count = 0;
  2586. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2587. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2588. if(items.count(i) == 0)
  2589. count++;
  2590. }
  2591. Item* bag = 0;
  2592. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2593. bag = GetBag(i, false);
  2594. if(bag && bag->details.num_slots > 0){
  2595. if(items.count(bag->details.bag_id) > 0){
  2596. for(int16 x=0;x<bag->details.num_slots;x++){
  2597. if(items[bag->details.bag_id].count(x) == 0)
  2598. count++;
  2599. }
  2600. }
  2601. else
  2602. count += bag->bag_info->num_slots; //if the bag hasnt been used yet, add all the free slots
  2603. }
  2604. }
  2605. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2606. return count;
  2607. }
  2608. bool PlayerItemList::HasFreeBagSlot(){
  2609. bool ret = false;
  2610. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2611. if(items.count(0) > 0){
  2612. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2613. if(items[0].count(i) == 0){
  2614. ret = true;
  2615. break;
  2616. }
  2617. }
  2618. }
  2619. else
  2620. ret = true;
  2621. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2622. return ret;
  2623. }
  2624. bool PlayerItemList::HasFreeSlot(){
  2625. bool ret = false;
  2626. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2627. if(items.count(0) > 0){
  2628. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2629. if(items[0].count(i) == 0){
  2630. ret = true;
  2631. break;
  2632. }
  2633. }
  2634. }
  2635. else
  2636. ret = true;
  2637. if(!ret){ //inventory slots full, check bags
  2638. Item* bag = 0;
  2639. for(int8 i=0;!ret && i<NUM_INV_SLOTS;i++){
  2640. bag = GetBag(i, false);
  2641. if(bag && bag->details.num_slots > 0){
  2642. if(items.count(bag->details.bag_id) > 0){
  2643. for(int16 x=0;x<bag->details.num_slots;x++){
  2644. if(items[bag->details.bag_id].count(x) == 0){
  2645. ret = true;
  2646. break;
  2647. }
  2648. }
  2649. }
  2650. else{ //if the bag hasnt been used yet, then all slots are free
  2651. ret = true;
  2652. break;
  2653. }
  2654. }
  2655. }
  2656. }
  2657. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2658. return ret;
  2659. }
  2660. bool PlayerItemList::GetFirstFreeBankSlot(sint32* bag_id, sint16* slot) {
  2661. bool ret = false;
  2662. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2663. if (items.count(-3) > 0) {
  2664. for (int8 i = 0; i < NUM_BANK_SLOTS; i++) {
  2665. if (items[-3].count(i) == 0) {
  2666. *bag_id = -3;
  2667. *slot = i;
  2668. ret = true;
  2669. break;
  2670. }
  2671. }
  2672. }
  2673. else {
  2674. *bag_id = -3;
  2675. *slot = 0;
  2676. ret = true;
  2677. }
  2678. if(!ret) {
  2679. // Inventory slots were full so check bags
  2680. Item* bag = 0;
  2681. for(int8 i = 0; !ret && i < NUM_BANK_SLOTS; i++) {
  2682. // Check to see if the item in the inventory slot is a bag and it has slots
  2683. bag = GetBankBag(i, false);
  2684. if(bag && bag->details.num_slots > 0) {
  2685. // Item was a bag so lets loop through the slots and try to find an empty one
  2686. if(items.count(bag->details.bag_id) > 0) {
  2687. for(int16 x = 0; x < bag->details.num_slots; x++) {
  2688. if(items[bag->details.bag_id].count(x) == 0) {
  2689. // Found a free slot, get the bag id of this bag
  2690. *bag_id = bag->details.bag_id;
  2691. // Get the slot
  2692. *slot = x;
  2693. ret = true;
  2694. break;
  2695. }
  2696. }
  2697. }
  2698. else {
  2699. //if the bag hasnt been used yet, then all slots are free, so set the bag_id to this bag
  2700. // and the slot to 0 (the first slot)
  2701. *bag_id = bag->details.bag_id;
  2702. *slot = 0;
  2703. ret = true;
  2704. break;
  2705. }
  2706. }
  2707. }
  2708. }
  2709. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2710. return ret;
  2711. }
  2712. bool PlayerItemList::GetFirstFreeSlot(sint32* bag_id, sint16* slot) {
  2713. // Mostly copy and paste from the above function
  2714. bool ret = false;
  2715. // Try to place the item in the normal inventory slots first
  2716. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2717. if(items.count(0) > 0){
  2718. for(int8 i=0; i < NUM_INV_SLOTS; i++) {
  2719. if(items[0].count(i) == 0) {
  2720. // Found an empty slot, store the slot id and set the return value
  2721. *bag_id = 0;
  2722. *slot = i;
  2723. ret = true;
  2724. break;
  2725. }
  2726. }
  2727. }
  2728. else {
  2729. // no items in the players inventory, set it to the first slot
  2730. *bag_id = 0;
  2731. *slot = 0;
  2732. ret = true;
  2733. }
  2734. if(!ret) {
  2735. // Inventory slots were full so check bags
  2736. Item* bag = 0;
  2737. for(int8 i = 0; !ret && i < NUM_INV_SLOTS; i++) {
  2738. // Check to see if the item in the inventory slot is a bag and it has slots
  2739. bag = GetBag(i, false);
  2740. if(bag && bag->details.num_slots > 0) {
  2741. // Item was a bag so lets loop through the slots and try to find an empty one
  2742. if(items.count(bag->details.bag_id) > 0) {
  2743. for(int16 x = 0; x < bag->details.num_slots; x++) {
  2744. if(items[bag->details.bag_id].count(x) == 0) {
  2745. // Found a free slot, get the bag id of this bag
  2746. *bag_id = bag->details.bag_id;
  2747. // Get the slot
  2748. *slot = x;
  2749. ret = true;
  2750. break;
  2751. }
  2752. }
  2753. }
  2754. else {
  2755. //if the bag hasnt been used yet, then all slots are free, so set the bag_id to this bag
  2756. // and the slot to 0 (the first slot)
  2757. *bag_id = bag->details.bag_id;
  2758. *slot = 0;
  2759. ret = true;
  2760. break;
  2761. }
  2762. }
  2763. }
  2764. }
  2765. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2766. return ret;
  2767. }
  2768. Item* PlayerItemList::CanStack(Item* item, bool include_bank){
  2769. if(!item)
  2770. return 0;
  2771. Item* ret = 0;
  2772. map<sint32, map<int16, Item*> >::iterator itr;
  2773. map<int16, Item*>::iterator slot_itr;
  2774. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2775. for(itr = items.begin(); itr != items.end(); itr++){
  2776. if(include_bank || (!include_bank && itr->first >= 0)){
  2777. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  2778. 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)){
  2779. ret = slot_itr->second;
  2780. break;
  2781. }
  2782. }
  2783. }
  2784. if(ret)
  2785. break;
  2786. }
  2787. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2788. return ret;
  2789. }
  2790. void PlayerItemList::Stack(Item* orig_item, Item* item){
  2791. if(!orig_item || !item)
  2792. return;
  2793. orig_item->details.count += item->details.count;
  2794. orig_item->save_needed = true;
  2795. }
  2796. bool PlayerItemList::AssignItemToFreeSlot(Item* item){
  2797. if(item){
  2798. Item* orig_item = CanStack(item);
  2799. if(orig_item){
  2800. Stack(orig_item, item);
  2801. return true;
  2802. }
  2803. bool use_bag_freeslot = false;
  2804. if(item->IsBag())
  2805. use_bag_freeslot = HasFreeBagSlot();
  2806. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2807. if(!use_bag_freeslot){
  2808. Item* bag = 0;
  2809. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2810. bag = GetBag(i, false);
  2811. if(bag && bag->details.num_slots > 0){
  2812. for(int16 x=0;x<bag->details.num_slots;x++){
  2813. if(items[bag->details.bag_id].count(x) == 0){
  2814. item->details.inv_slot_id = bag->details.bag_id;
  2815. item->details.slot_id = x;
  2816. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2817. AddItem(item);
  2818. return true;
  2819. }
  2820. }
  2821. }
  2822. }
  2823. }
  2824. //bags full, check inventory slots
  2825. for(int8 i=0;i<NUM_INV_SLOTS;i++){
  2826. if(items[0].count(i) == 0){
  2827. item->details.inv_slot_id = 0;
  2828. item->details.slot_id = i;
  2829. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2830. AddItem(item);
  2831. return true;
  2832. }
  2833. }
  2834. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2835. }
  2836. return false;
  2837. }
  2838. void PlayerItemList::RemoveItem(Item* item, bool delete_item){
  2839. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2840. if(items.count(item->details.inv_slot_id) > 0 && items[item->details.inv_slot_id].count(item->details.slot_id) > 0){
  2841. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2842. indexed_items[item->details.index] = 0;
  2843. }
  2844. if(item->IsBag() && item->details.inv_slot_id == 0 && item->details.slot_id < NUM_INV_SLOTS && items.count(item->details.bag_id) > 0){
  2845. map<int16, Item*>::iterator itr;
  2846. for(itr = items[item->details.bag_id].begin(); itr != items[item->details.bag_id].end(); itr++){
  2847. indexed_items[itr->second->details.index] = 0;
  2848. if(delete_item){
  2849. safe_delete(itr->second);
  2850. }
  2851. }
  2852. items.erase(item->details.bag_id);
  2853. }
  2854. if(delete_item){
  2855. safe_delete(item);
  2856. }
  2857. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2858. }
  2859. void PlayerItemList::DestroyItem(int16 index){
  2860. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2861. Item* item = indexed_items[index];
  2862. map<int16, Item*>::iterator itr;
  2863. 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
  2864. map<int16, Item*>* tmp_map = &(items[(sint32)item->details.bag_id]);
  2865. for(itr = tmp_map->begin(); itr != tmp_map->end(); itr++){
  2866. indexed_items[itr->second->details.index] = 0;
  2867. if(itr->second != item){
  2868. safe_delete(itr->second);
  2869. }
  2870. }
  2871. items.erase(item->details.bag_id);
  2872. }
  2873. if(items.count(item->details.inv_slot_id) > 0 && items[item->details.inv_slot_id].count(item->details.slot_id) > 0)
  2874. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2875. indexed_items[index] = 0;
  2876. safe_delete(item);
  2877. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2878. }
  2879. void PlayerItemList::MoveItem(Item* item, sint32 inv_slot, int16 slot, bool erase_old){
  2880. if(erase_old && items.count(item->details.inv_slot_id) > 0)
  2881. items[item->details.inv_slot_id].erase(item->details.slot_id);
  2882. items[inv_slot][slot] = item;
  2883. item->details.inv_slot_id = inv_slot;
  2884. item->details.slot_id = slot;
  2885. item->save_needed = true;
  2886. }
  2887. int16 PlayerItemList::GetNumberOfItems(){
  2888. int16 ret = 0;
  2889. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2890. if(items.size() > 0){
  2891. map<sint32, map<int16, Item*> >::iterator itr;
  2892. sint32 bag_id = 0;
  2893. for(itr = items.begin(); itr != items.end(); itr++){
  2894. bag_id = itr->first;
  2895. if(items.count(bag_id) > 0)
  2896. ret += items[bag_id].size();
  2897. }
  2898. }
  2899. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2900. return ret;
  2901. }
  2902. bool PlayerItemList::MoveItem(sint32 to_bag_id, int16 from_index, sint8 to, int8 charges){
  2903. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  2904. Item* item_from = indexed_items[from_index];
  2905. Item* item_to = 0;
  2906. if(item_from){
  2907. if(to_bag_id > 0){ //bag item
  2908. Item* bag = GetItemFromUniqueID(to_bag_id, true, false);
  2909. if(bag && bag->details.num_slots > to)
  2910. item_to = items[to_bag_id][to];
  2911. else{
  2912. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2913. return false;
  2914. }
  2915. }
  2916. else
  2917. item_to = items[to_bag_id][to];
  2918. if(charges > 0) {
  2919. if (item_to && item_from->details.item_id == item_to->details.item_id){
  2920. if(item_to->details.count > 0 && item_to->details.count < item_to->stack_count){
  2921. int32 total_tmp_price = 0;
  2922. if((item_to->details.count + item_from->details.count) <= item_to->stack_count){
  2923. total_tmp_price = (item_to->GetMaxSellValue()*item_to->details.count) + (item_from->GetMaxSellValue()*item_from->details.count);
  2924. item_to->details.count += item_from->details.count;
  2925. indexed_items[from_index] = 0;
  2926. items[item_from->details.inv_slot_id].erase(item_from->details.slot_id);
  2927. item_from->needs_deletion = true;
  2928. item_to->save_needed = true;
  2929. }
  2930. else{
  2931. int8 diff = item_to->stack_count - item_to->details.count;
  2932. total_tmp_price = (item_to->GetMaxSellValue()*item_to->details.count) + (item_from->GetMaxSellValue()*diff);
  2933. item_to->details.count = item_to->stack_count;
  2934. item_from->details.count -= diff;
  2935. item_to->save_needed = true;
  2936. }
  2937. item_to->SetMaxSellValue(total_tmp_price/item_to->details.count);
  2938. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2939. return true;
  2940. }
  2941. }
  2942. else {
  2943. if (item_from->details.count == charges) {
  2944. if (item_to)
  2945. MoveItem(item_to, item_from->details.inv_slot_id, item_from->details.slot_id);
  2946. MoveItem(item_from, to_bag_id, to, item_to ? false:true);
  2947. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2948. }
  2949. else {
  2950. if (item_to) {
  2951. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2952. return false;
  2953. }
  2954. item_from->details.count -= charges;
  2955. Item* new_item = new Item(master_item_list.GetItem(item_from->details.item_id));
  2956. new_item->details.count = charges;
  2957. new_item->details.slot_id = to;
  2958. new_item->details.inv_slot_id = to_bag_id;
  2959. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2960. new_item->save_needed = true;
  2961. AddItem(new_item);
  2962. if (item_from->details.count == 0)
  2963. RemoveItem(item_from);
  2964. }
  2965. return true;
  2966. }
  2967. }
  2968. else if(item_to && item_to->IsBag() && item_to->details.num_slots > 0){
  2969. // if item we are moving is a bag
  2970. if (item_from->IsBag() && item_from->details.num_slots > 0) {
  2971. for (int8 i = 0; i < item_from->details.num_slots; i++) {
  2972. // if there is something in the bag return, can't put bags with items into other bags
  2973. if (items[item_from->details.bag_id].count(i) != 0) {
  2974. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2975. return false;
  2976. }
  2977. }
  2978. }
  2979. if(items.count(item_to->details.bag_id) > 0){
  2980. for(int8 i=0;i<item_to->details.num_slots;i++){
  2981. if(items[item_to->details.bag_id].count(i) == 0){
  2982. MoveItem(item_from, item_to->details.bag_id, i);
  2983. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2984. return true;
  2985. }
  2986. }
  2987. }
  2988. else{
  2989. MoveItem(item_from, item_to->details.bag_id, 0);
  2990. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2991. return true;
  2992. }
  2993. }
  2994. if (item_to)
  2995. MoveItem(item_to, item_from->details.inv_slot_id, item_from->details.slot_id);
  2996. MoveItem(item_from, to_bag_id, to, item_to ? false:true);
  2997. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  2998. return true;
  2999. }
  3000. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  3001. return false;
  3002. }
  3003. EQ2Packet* PlayerItemList::serialize(Player* player, int16 version){
  3004. EQ2Packet* app = 0;
  3005. PacketStruct* packet = configReader.getStruct("WS_UpdateInventory",version);
  3006. Item* item = 0;
  3007. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3008. if(packet && indexed_items.size() > 0){
  3009. int8 packet_size = 0;
  3010. int16 size = indexed_items.size();
  3011. if (overflowItems.size() > 0)
  3012. size++;
  3013. PacketStruct* packet2 = configReader.getStruct("Substruct_Item", version);
  3014. packet_size = packet2->GetTotalPacketSize();
  3015. safe_delete(packet2);
  3016. packet->setArrayLengthByName("item_count", size);
  3017. if(packet_count < size){
  3018. if(!orig_packet){
  3019. xor_packet = new uchar[packet_size * size];
  3020. orig_packet = new uchar[packet_size * size];
  3021. memset(xor_packet, 0, packet_size * size);
  3022. memset(orig_packet, 0, packet_size * size);
  3023. }
  3024. else{
  3025. uchar* tmp = new uchar[packet_size * size];
  3026. memset(tmp, 0, packet_size * size);
  3027. memcpy(tmp, orig_packet, packet_size * packet_count);
  3028. safe_delete_array(orig_packet);
  3029. orig_packet = tmp;
  3030. safe_delete_array(xor_packet);
  3031. xor_packet = new uchar[packet_size * size];
  3032. }
  3033. packet_count = size;
  3034. }
  3035. for(int16 i = 0; i < indexed_items.size(); i++){
  3036. item = indexed_items[i];
  3037. if (item && item->details.item_id > 0)
  3038. AddItemToPacket(packet, player, item, i);
  3039. }
  3040. if (overflowItems.size() > 0) {
  3041. // We have overflow items, lets get the first one
  3042. item = overflowItems.at(0);
  3043. // Lets make sure the item is valid
  3044. if (item && item->details.item_id > 0) {
  3045. // Set the slot to 6 as that is what overflow requires to work
  3046. item->details.slot_id = 6;
  3047. // now add it to the packet
  3048. AddItemToPacket(packet, player, item, size - 1, true);
  3049. }
  3050. }
  3051. LogWrite(ITEM__PACKET, 0, "Items", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  3052. #if EQDEBUG >= 9
  3053. packet->PrintPacket();
  3054. #endif
  3055. packet->setDataByName("equip_flag",0);
  3056. app = packet->serializeCountPacket(version, 1, orig_packet, xor_packet);
  3057. DumpPacket(app);
  3058. safe_delete(packet);
  3059. }
  3060. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3061. return app;
  3062. }
  3063. void PlayerItemList::AddItemToPacket(PacketStruct* packet, Player* player, Item* item, int16 i, bool overflow){
  3064. Client *client;
  3065. int8 tmp_subtype = 0;
  3066. if (!packet || !player)
  3067. return;
  3068. client = player->GetZone()->GetClientBySpawn(player);
  3069. if (!client)
  3070. return;
  3071. int32 menu_data = 3;
  3072. if(item->slot_data.size() > 0)
  3073. menu_data -= ITEM_MENU_TYPE_GENERIC;
  3074. if (item->details.num_slots > 0) {
  3075. if (packet->GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  3076. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  3077. menu_data += ITEM_MENU_TYPE_BAG;
  3078. if (item->details.num_free_slots == item->details.num_slots)
  3079. menu_data += ITEM_MENU_TYPE_EMPTY_BAG;
  3080. }
  3081. if (item->details.item_id == 21355) {
  3082. //menu_data += ITEM_MENU_TYPE_GENERIC;
  3083. //menu_data += ITEM_MENU_TYPE_EQUIP;
  3084. menu_data += ITEM_MENU_TYPE_BOOK;
  3085. //menu_data += ITEM_MENU_TYPE_BAG;
  3086. //menu_data += ITEM_MENU_TYPE_HOUSE;
  3087. //menu_data += ITEM_MENU_TYPE_TEST12;
  3088. //menu_data += ITEM_MENU_TYPE_SCRIBE;
  3089. //menu_data += ITEM_MENU_TYPE_TEST13;
  3090. //menu_data += ITEM_MENU_TYPE_INVALID;
  3091. //menu_data += ITEM_MENU_TYPE_TEST14;
  3092. //menu_data += ITEM_MENU_TYPE_BROKEN;
  3093. }
  3094. if (item->details.item_id == 21356) {
  3095. //menu_data += ITEM_MENU_TYPE_TEST15;
  3096. menu_data += ITEM_MENU_TYPE_ATTUNED;
  3097. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  3098. menu_data += ITEM_MENU_TYPE_BOOK;
  3099. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  3100. menu_data += ITEM_MENU_TYPE_TEST1;
  3101. menu_data += ITEM_MENU_TYPE_NAMEPET;
  3102. menu_data += ITEM_MENU_TYPE_TEST2;
  3103. menu_data += ITEM_MENU_TYPE_CONSUME;
  3104. menu_data += ITEM_MENU_TYPE_USE;
  3105. }
  3106. if (item->details.item_id == 21357) {
  3107. menu_data += ITEM_MENU_TYPE_CONSUME_OFF ;
  3108. menu_data += ITEM_MENU_TYPE_TEST3 ;
  3109. menu_data += ITEM_MENU_TYPE_TEST4 ;
  3110. menu_data += ITEM_MENU_TYPE_TEST5 ;
  3111. menu_data += ITEM_MENU_TYPE_TEST6 ;
  3112. menu_data += ITEM_MENU_TYPE_TEST7 ;
  3113. menu_data += ITEM_MENU_TYPE_TEST8 ;
  3114. menu_data += ITEM_MENU_TYPE_TEST9 ;
  3115. menu_data += ITEM_MENU_TYPE_DAMAGED ;
  3116. menu_data += ITEM_MENU_TYPE_BROKEN2 ;
  3117. menu_data += ITEM_MENU_TYPE_REDEEM ;
  3118. menu_data += ITEM_MENU_TYPE_TEST10 ;
  3119. menu_data += ITEM_MENU_TYPE_UNPACK ;
  3120. }
  3121. if(item->IsSkill()){
  3122. Spell* spell = master_spell_list.GetSpell(item->skill_info->spell_id, item->skill_info->spell_tier);
  3123. if (spell && spell->ScribeAllowed(player))
  3124. menu_data += ITEM_MENU_TYPE_SCRIBE;
  3125. else
  3126. menu_data += ITEM_MENU_TYPE_INSUFFICIENT_KNOWLEDGE;
  3127. }
  3128. if(item->IsRecipeBook()){
  3129. //TODO: Add check to allow scribe
  3130. menu_data += ITEM_MENU_TYPE_SCRIBE;
  3131. }
  3132. if (item->generic_info.item_type == 10){
  3133. menu_data += ITEM_MENU_TYPE_TEST1;
  3134. menu_data += ITEM_MENU_TYPE_HOUSE;
  3135. }
  3136. if (item->generic_info.item_type == 18){
  3137. menu_data += ITEM_MENU_TYPE_UNPACK;
  3138. packet->setSubstructArrayDataByName("items", "unknown3", ITEM_MENU_TYPE2_UNPACK, 0, i);
  3139. }
  3140. if(item->generic_info.condition == 0)
  3141. menu_data += ITEM_MENU_TYPE_BROKEN;
  3142. if (client->GetVersion() <= 283){
  3143. string flags;
  3144. if (item->CheckFlag(NO_TRADE))
  3145. flags += "NO-TRADE ";
  3146. if (item->CheckFlag(NO_VALUE))
  3147. flags += "NO-VALUE ";
  3148. if (flags.length() > 0)
  3149. packet->setSubstructArrayDataByName("items", "flag_names", flags.c_str(), 0, i);
  3150. }
  3151. if (item->CheckFlag(ATTUNED) || item->CheckFlag(NO_TRADE)) {
  3152. if (client->GetVersion() <= 283)
  3153. menu_data += ORIG_ITEM_MENU_TYPE_ATTUNED;
  3154. else
  3155. menu_data += ITEM_MENU_TYPE_ATTUNED;
  3156. }
  3157. else if (item->CheckFlag(ATTUNEABLE)) {
  3158. if (client->GetVersion() <= 283)
  3159. menu_data += ORIG_ITEM_MENU_TYPE_ATTUNEABLE;
  3160. else
  3161. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  3162. }
  3163. if (item->generic_info.usable == 1)
  3164. menu_data += ITEM_MENU_TYPE_USE;
  3165. if (item->details.count > 0 && item->stack_count > 1) {
  3166. if (client->GetVersion() <= 283)
  3167. menu_data += ORIG_ITEM_MENU_TYPE_STACKABLE;
  3168. else
  3169. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  3170. }
  3171. // Added the if (overflow) so mouseover examines work properly
  3172. if (overflow)
  3173. packet->setSubstructArrayDataByName("items", "unique_id", item->details.item_id, 0, i);
  3174. else
  3175. packet->setSubstructArrayDataByName("items", "unique_id", item->details.unique_id, 0, i);
  3176. packet->setSubstructArrayDataByName("items", "bag_id", item->details.bag_id, 0, i);
  3177. packet->setSubstructArrayDataByName("items", "inv_slot_id", item->details.inv_slot_id, 0, i);
  3178. packet->setSubstructArrayDataByName("items", "menu_type", menu_data, 0, i);
  3179. if (overflow)
  3180. packet->setSubstructArrayDataByName("items", "index", 0xFFFF, 0, i);
  3181. else
  3182. packet->setSubstructArrayDataByName("items", "index", i, 0, i);
  3183. item->details.index = i;
  3184. packet->setSubstructArrayDataByName("items", "icon", item->details.icon, 0, i);
  3185. packet->setSubstructArrayDataByName("items", "slot_id", item->details.slot_id, 0, i);
  3186. if (client->GetVersion() <= 1208) {
  3187. packet->setSubstructArrayDataByName("items", "count", (std::min)(item->details.count, (int16)255), 0, i);
  3188. }
  3189. else
  3190. packet->setSubstructArrayDataByName("items", "count", item->details.count, 0, i);
  3191. //packet->setSubstructArrayDataByName("items", "unknown4", 5, 0, i);
  3192. // need item level
  3193. packet->setSubstructArrayDataByName("items", "item_level", item->details.recommended_level , 0, i);
  3194. packet->setSubstructArrayDataByName("items", "tier", item->details.tier, 0, i);
  3195. packet->setSubstructArrayDataByName("items", "num_slots", item->details.num_slots, 0, i);
  3196. // need empty slots
  3197. packet->setSubstructArrayDataByName("items", "item_id", item->details.item_id, 0, i);
  3198. //need broker id
  3199. packet->setSubstructArrayDataByName("items", "name", item->name.c_str(), 0, i);
  3200. }
  3201. bool PlayerItemList::AddOverflowItem(Item* item) {
  3202. bool ret = false;
  3203. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  3204. if (item && item->details.item_id > 0 && overflowItems.size() < 255) {
  3205. item->details.slot_id = 6;
  3206. item->details.inv_slot_id = -2;
  3207. overflowItems.push_back(item);
  3208. ret = true;
  3209. }
  3210. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  3211. return ret;
  3212. }
  3213. Item* PlayerItemList::GetOverflowItem() {
  3214. return overflowItems.at(0);
  3215. }
  3216. void PlayerItemList::RemoveOverflowItem(Item* item) {
  3217. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  3218. vector<Item*>::iterator itr = std::find(overflowItems.begin(), overflowItems.end(), item);
  3219. overflowItems.erase(itr);
  3220. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  3221. }
  3222. vector<Item*>* PlayerItemList::GetOverflowItemList() {
  3223. vector<Item*>* ret = new vector<Item*>;
  3224. MPlayerItems.writelock(__FUNCTION__, __LINE__);
  3225. vector<Item*>::iterator itr= ret->begin();
  3226. ret->insert(itr, overflowItems.begin(), overflowItems.end());
  3227. MPlayerItems.releasewritelock(__FUNCTION__, __LINE__);
  3228. return ret;
  3229. }
  3230. bool PlayerItemList::HasItem(int32 id, bool include_bank){
  3231. map<sint32, map<int16, Item*> >::iterator itr;
  3232. map<int16, Item*>::iterator slot_itr;
  3233. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3234. for(itr = items.begin(); itr != items.end(); itr++){
  3235. if(include_bank || (!include_bank && itr->first >= 0)){
  3236. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  3237. if(slot_itr->second && slot_itr->second->details.item_id == id){
  3238. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3239. return true;
  3240. }
  3241. }
  3242. }
  3243. }
  3244. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3245. return false;
  3246. }
  3247. bool PlayerItemList::SharedBankAddAllowed(Item* item){
  3248. if(!item || item->CheckFlag(NO_TRADE))
  3249. return false;
  3250. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3251. if(item->IsBag() && items.count(item->details.bag_id) > 0){
  3252. map<int16, Item*>::iterator itr;
  3253. for(itr = items[item->details.bag_id].begin(); itr != items[item->details.bag_id].end(); itr++){
  3254. if(itr->second->CheckFlag(NO_TRADE)){
  3255. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3256. return false;
  3257. }
  3258. }
  3259. }
  3260. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3261. return true;
  3262. }
  3263. vector<Item*>* PlayerItemList::GetItemsFromBagID(sint32 bag_id){
  3264. vector<Item*>* ret = new vector<Item*>;
  3265. if(items.count(bag_id) > 0){
  3266. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3267. map<int16, Item*>::iterator itr;
  3268. map<int16, Item*>::iterator itr2;
  3269. Item* item = 0;
  3270. for(itr = items[bag_id].begin(); itr != items[bag_id].end(); itr++){
  3271. item = itr->second;
  3272. if(item)
  3273. ret->push_back(item);
  3274. }
  3275. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3276. }
  3277. return ret;
  3278. }
  3279. vector<Item*>* PlayerItemList::GetItemsInBag(Item* bag){
  3280. vector<Item*>* ret_items = new vector<Item*>;
  3281. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3282. if(bag && bag->IsBag() && items.count(bag->details.bag_id) > 0){
  3283. map<int16, Item*>::iterator itr;
  3284. for(itr = items[bag->details.bag_id].begin(); itr != items[bag->details.bag_id].end(); itr++){
  3285. ret_items->push_back(itr->second);
  3286. }
  3287. }
  3288. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3289. return ret_items;
  3290. }
  3291. Item* PlayerItemList::GetItemFromID(int32 id, int8 count, bool include_bank, bool lock){
  3292. //first check for an exact count match
  3293. map<sint32, map<int16, Item*> >::iterator itr;
  3294. map<int16, Item*>::iterator slot_itr;
  3295. if(lock)
  3296. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3297. for(itr = items.begin(); itr != items.end(); itr++){
  3298. if(include_bank || (!include_bank && itr->first >= 0)){
  3299. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  3300. if(slot_itr->second && slot_itr->second->details.item_id == id && (count == 0 || slot_itr->second->details.count == count)){
  3301. if(lock)
  3302. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3303. return slot_itr->second;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. //couldn't find an exact match, look for closest
  3309. Item* closest = 0;
  3310. for(itr = items.begin(); itr != items.end(); itr++){
  3311. if(include_bank || (!include_bank && itr->first >= 0)){
  3312. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  3313. 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))
  3314. closest = slot_itr->second;
  3315. }
  3316. }
  3317. }
  3318. if(lock)
  3319. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3320. return closest;
  3321. }
  3322. Item* PlayerItemList::GetItemFromUniqueID(int32 id, bool include_bank, bool lock){
  3323. map<sint32, map<int16, Item*> >::iterator itr;
  3324. map<int16, Item*>::iterator slot_itr;
  3325. if(lock)
  3326. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3327. for(itr = items.begin(); itr != items.end(); itr++){
  3328. if(include_bank || (!include_bank && itr->first >= 0)){
  3329. for(slot_itr=itr->second.begin();slot_itr!=itr->second.end(); slot_itr++){
  3330. if(slot_itr->second && slot_itr->second->details.unique_id == id){
  3331. if(lock)
  3332. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3333. return slot_itr->second;
  3334. }
  3335. }
  3336. }
  3337. }
  3338. if(lock)
  3339. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3340. return 0;
  3341. }
  3342. bool PlayerItemList::HasFreeBankSlot() {
  3343. bool ret = false;
  3344. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3345. if (items[-3].size() < 12) //12 slots in the bank
  3346. ret = true;
  3347. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3348. return ret;
  3349. }
  3350. int8 PlayerItemList::FindFreeBankSlot() {
  3351. int8 ret = 0;
  3352. MPlayerItems.readlock(__FUNCTION__, __LINE__);
  3353. for (int8 i = 0; i < 12; i++) { //12 slots in the bank
  3354. if (items[-3].count(i) == 0) {
  3355. ret = i;
  3356. break;
  3357. }
  3358. }
  3359. MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  3360. return ret;
  3361. }
  3362. EquipmentItemList::EquipmentItemList(){
  3363. orig_packet = 0;
  3364. xor_packet = 0;
  3365. for(int8 i=0;i<NUM_SLOTS;i++)
  3366. items[i] = 0;
  3367. MEquipmentItems.SetName("EquipmentItemList::MEquipmentItems");
  3368. }
  3369. EquipmentItemList::EquipmentItemList(const EquipmentItemList& list){
  3370. orig_packet = 0;
  3371. xor_packet = 0;
  3372. for(int8 i=0;i<NUM_SLOTS;i++)
  3373. items[i] = 0;
  3374. MEquipmentItems.SetName("EquipmentItemList::MEquipmentItems");
  3375. }
  3376. EquipmentItemList::~EquipmentItemList(){
  3377. for(int8 i=0;i<NUM_SLOTS;i++)
  3378. safe_delete(items[i]);
  3379. safe_delete_array(orig_packet);
  3380. safe_delete_array(xor_packet);
  3381. }
  3382. bool EquipmentItemList::AddItem(int8 slot, Item* item){
  3383. if(item){
  3384. MEquipmentItems.lock();
  3385. Item* curItem = GetItem(slot);
  3386. if (curItem) // existing item in slot
  3387. {
  3388. MEquipmentItems.unlock();
  3389. return false;
  3390. }
  3391. SetItem(slot, item, true);
  3392. if (item->details.unique_id == 0) {
  3393. GetItem(slot)->details.unique_id = MasterItemList::NextUniqueID();
  3394. if (item->IsBag())
  3395. item->details.bag_id = item->details.unique_id;
  3396. }
  3397. MEquipmentItems.unlock();
  3398. return true;
  3399. }
  3400. return false;
  3401. }
  3402. int8 EquipmentItemList::GetNumberOfItems(){
  3403. int8 ret = 0;
  3404. MEquipmentItems.lock();
  3405. for(int8 i=0;i<NUM_SLOTS;i++){
  3406. if(items[i])
  3407. ret++;
  3408. }
  3409. MEquipmentItems.unlock();
  3410. return ret;
  3411. }
  3412. void EquipmentItemList::SetItem(int8 slot_id, Item* item, bool locked){
  3413. if(!locked)
  3414. MEquipmentItems.lock();
  3415. item->details.inv_slot_id = 0;
  3416. item->details.slot_id = slot_id;
  3417. item->details.index = slot_id;
  3418. items[slot_id] = item;
  3419. if(!locked)
  3420. MEquipmentItems.unlock();
  3421. }
  3422. vector<Item*>* EquipmentItemList::GetAllEquippedItems(){
  3423. vector<Item*>* ret = new vector<Item*>;
  3424. MEquipmentItems.lock();
  3425. for(int8 i=0;i<NUM_SLOTS;i++){
  3426. if(items[i])
  3427. ret->push_back(items[i]);
  3428. }
  3429. MEquipmentItems.unlock();
  3430. return ret;
  3431. }
  3432. Item* EquipmentItemList::GetItem(int8 slot_id){
  3433. return items[slot_id];
  3434. }
  3435. EQ2Packet* EquipmentItemList::serialize(int16 version, Player* player){
  3436. EQ2Packet* app = 0;
  3437. Item* item = 0;
  3438. PacketStruct* packet = configReader.getStruct("WS_UpdateInventory", version);
  3439. if(packet){
  3440. int8 packet_size = 0;
  3441. PacketStruct* packet2 = configReader.getStruct("Substruct_Item", version);
  3442. packet_size = packet2->GetTotalPacketSize();
  3443. safe_delete(packet2);
  3444. int8 num_slots = NUM_SLOTS;
  3445. if (version <= 564)
  3446. num_slots = 22;
  3447. packet->setArrayLengthByName("item_count", num_slots);
  3448. if(!orig_packet){
  3449. xor_packet = new uchar[packet_size* num_slots];
  3450. orig_packet = new uchar[packet_size* num_slots];
  3451. memset(xor_packet, 0, packet_size* num_slots);
  3452. memset(orig_packet, 0, packet_size* num_slots);
  3453. }
  3454. MEquipmentItems.lock();
  3455. int32 menu_data = 3;
  3456. for(int16 i=0;i<NUM_SLOTS;i++){
  3457. menu_data = 3;
  3458. item = items[i];
  3459. if(item && item->details.item_id > 0){
  3460. if(item->slot_data.size() > 0)
  3461. menu_data -= ITEM_MENU_TYPE_GENERIC;
  3462. if (item->details.num_slots > 0) {
  3463. if (packet->GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  3464. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  3465. menu_data += ITEM_MENU_TYPE_BAG;
  3466. if (item->details.num_free_slots == item->details.num_slots)
  3467. menu_data += ITEM_MENU_TYPE_EMPTY_BAG;
  3468. }
  3469. if(item->IsSkill())
  3470. menu_data += ITEM_MENU_TYPE_SCRIBE;
  3471. if(item->generic_info.condition == 0)
  3472. menu_data += ITEM_MENU_TYPE_BROKEN2;
  3473. else if (item->generic_info.condition <= 20)
  3474. menu_data += ITEM_MENU_TYPE_DAMAGED;
  3475. if (item->CheckFlag(ATTUNED) || item->CheckFlag(NO_TRADE)) {
  3476. if (version <= 283)
  3477. menu_data += ORIG_ITEM_MENU_TYPE_ATTUNED;
  3478. else
  3479. menu_data += ITEM_MENU_TYPE_ATTUNED;
  3480. }
  3481. else if (item->CheckFlag(ATTUNEABLE)) {
  3482. if (version <= 283)
  3483. menu_data += ORIG_ITEM_MENU_TYPE_ATTUNEABLE;
  3484. else
  3485. menu_data += ITEM_MENU_TYPE_ATTUNEABLE;
  3486. }
  3487. if (item->generic_info.usable == 1)
  3488. menu_data += ITEM_MENU_TYPE_USE;
  3489. if (item->IsFood())
  3490. {
  3491. if (version <= 283) {
  3492. if (item->IsFoodDrink())
  3493. menu_data += ORIG_ITEM_MENU_TYPE_DRINK;
  3494. else
  3495. menu_data += ORIG_ITEM_MENU_TYPE_FOOD;
  3496. }
  3497. else {
  3498. menu_data += ITEM_MENU_TYPE_CONSUME;
  3499. if (player && ((item->IsFoodFood() && player->get_character_flag(CF_FOOD_AUTO_CONSUME)) || (item->IsFoodDrink() && player->get_character_flag(CF_DRINK_AUTO_CONSUME))))
  3500. menu_data += ITEM_MENU_TYPE_CONSUME_OFF;
  3501. }
  3502. }
  3503. packet->setSubstructArrayDataByName("items", "unique_id", item->details.unique_id, 0, i);
  3504. packet->setSubstructArrayDataByName("items", "bag_id", item->details.bag_id, 0, i);
  3505. packet->setSubstructArrayDataByName("items", "inv_slot_id", item->details.inv_slot_id, 0, i);
  3506. if (item->details.count > 0 && item->stack_count > 1) {
  3507. if (version <= 283)
  3508. menu_data += ORIG_ITEM_MENU_TYPE_STACKABLE;
  3509. else
  3510. menu_data += ITEM_MENU_TYPE_DISPLAY_CHARGES;
  3511. }
  3512. packet->setSubstructArrayDataByName("items", "menu_type", menu_data, 0, i);
  3513. packet->setSubstructArrayDataByName("items", "icon", item->details.icon, 0, i);
  3514. packet->setSubstructArrayDataByName("items", "slot_id", item->details.slot_id, 0, i);
  3515. packet->setSubstructArrayDataByName("items", "count", item->details.count, 0, i);
  3516. // item level needed here
  3517. packet->setSubstructArrayDataByName("items", "tier", item->details.tier, 0, i);
  3518. packet->setSubstructArrayDataByName("items", "num_slots", item->details.num_slots, 0, i);
  3519. //empty slots needed here
  3520. packet->setSubstructArrayDataByName("items", "item_id", item->details.item_id, 0, i);
  3521. //broker id needed here
  3522. packet->setSubstructArrayDataByName("items", "name", item->name.c_str(), 0, i);
  3523. //packet->setSubstructArrayDataByName("items", "unknown4", 10, 0, i);
  3524. item->details.index = i;
  3525. }
  3526. packet->setSubstructArrayDataByName("items", "index", i, 0, i);
  3527. }
  3528. MEquipmentItems.unlock();
  3529. packet->setDataByName("equip_flag", 1);
  3530. app = packet->serializeCountPacket(version, 1, orig_packet, xor_packet);
  3531. safe_delete(packet);
  3532. }
  3533. return app;
  3534. }
  3535. ItemStatsValues* EquipmentItemList::CalculateEquipmentBonuses(Entity* entity){
  3536. ItemStatsValues* stats = new ItemStatsValues;
  3537. memset(stats, 0, sizeof(ItemStatsValues));
  3538. entity->GetInfoStruct()->set_mitigation_base(0);
  3539. MEquipmentItems.lock();
  3540. for(int8 i=0;i<NUM_SLOTS;i++){
  3541. if(items[i] && items[i]->details.item_id > 0){
  3542. master_item_list.CalculateItemBonuses(items[i], entity, stats);
  3543. if (items[i]->armor_info && !items[i]->IsShield())
  3544. entity->GetInfoStruct()->add_mitigation_base(items[i]->armor_info->mitigation_high);
  3545. }
  3546. }
  3547. MEquipmentItems.unlock();
  3548. return stats;
  3549. }
  3550. bool EquipmentItemList::HasItem(int32 id){
  3551. MEquipmentItems.lock();
  3552. for(int8 i=0;i<NUM_SLOTS;i++){
  3553. if(items[i] && items[i]->details.item_id == id){
  3554. MEquipmentItems.unlock();
  3555. return true;
  3556. }
  3557. }
  3558. MEquipmentItems.unlock();
  3559. return false;
  3560. }
  3561. void EquipmentItemList::RemoveItem(int8 slot, bool delete_item){
  3562. if(slot < NUM_SLOTS){
  3563. MEquipmentItems.lock();
  3564. if(delete_item){
  3565. safe_delete(items[slot]);
  3566. }
  3567. items[slot] = 0;
  3568. MEquipmentItems.unlock();
  3569. }
  3570. }
  3571. Item* EquipmentItemList::GetItemFromUniqueID(int32 item_id){
  3572. MEquipmentItems.lock();
  3573. for(int8 i=0;i<NUM_SLOTS;i++){
  3574. if(items[i] && items[i]->details.unique_id == item_id){
  3575. MEquipmentItems.unlock();
  3576. return items[i];
  3577. }
  3578. }
  3579. MEquipmentItems.unlock();
  3580. return 0;
  3581. }
  3582. Item* EquipmentItemList::GetItemFromItemID(int32 item_id) {
  3583. Item* item = 0;
  3584. MEquipmentItems.lock();
  3585. for(int8 i = 0; i < NUM_SLOTS; i++) {
  3586. if(items[i] && items[i]->details.item_id == item_id) {
  3587. item = items[i];
  3588. break;
  3589. }
  3590. }
  3591. MEquipmentItems.unlock();
  3592. return item;
  3593. }
  3594. bool EquipmentItemList::CanItemBeEquippedInSlot(Item* tmp, int8 slot){
  3595. MEquipmentItems.lock();
  3596. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3597. if(tmp->slot_data[i] == slot){
  3598. MEquipmentItems.unlock();
  3599. return true;
  3600. }
  3601. }
  3602. MEquipmentItems.unlock();
  3603. return false;
  3604. }
  3605. bool EquipmentItemList::CheckEquipSlot(Item* tmp, int8 slot){
  3606. MEquipmentItems.lock();
  3607. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3608. if(tmp->slot_data[i] == slot){
  3609. Item* tmp_item = GetItem(tmp->slot_data[i]);
  3610. if(!tmp_item || tmp_item->details.item_id == 0){
  3611. MEquipmentItems.unlock();
  3612. return true;
  3613. }
  3614. }
  3615. }
  3616. MEquipmentItems.unlock();
  3617. return false;
  3618. }
  3619. int8 EquipmentItemList::GetFreeSlot(Item* tmp, int8 slot_id){
  3620. int8 slot = 0;
  3621. MEquipmentItems.lock();
  3622. for(int8 i=0;tmp && i<tmp->slot_data.size();i++){
  3623. slot = tmp->slot_data[i];
  3624. if(slot_id == 255 || slot == slot_id){
  3625. Item* tmp_item = GetItem(slot);
  3626. if(!tmp_item || tmp_item->details.item_id == 0){
  3627. MEquipmentItems.unlock();
  3628. return slot;
  3629. }
  3630. }
  3631. }
  3632. MEquipmentItems.unlock();
  3633. return 255;
  3634. }
  3635. int8 EquipmentItemList::GetSlotByItem(Item* item) {
  3636. int8 slot = 255;
  3637. for (int8 i = 0; i < NUM_SLOTS; i++) {
  3638. if (items[i] && items[i] == item) {
  3639. slot = i;
  3640. break;
  3641. }
  3642. }
  3643. return slot;
  3644. }
  3645. string Item::CreateItemLink(int16 client_Version, bool bUseUniqueID) {
  3646. ostringstream ss;
  3647. if(client_Version > 546)
  3648. ss << "\\aITEM " << details.item_id << ' ' << (bUseUniqueID ? details.unique_id : 0) << ':' << name << "\\/a";
  3649. else {
  3650. if(bUseUniqueID)
  3651. ss << "\\aITEM " << details.item_id << ' ' << details.unique_id << ':' << name << "\\/a";
  3652. else
  3653. ss << "\\aITEM " << details.item_id << ' ' << name << ':' << name << "\\/a";
  3654. }
  3655. return ss.str();
  3656. }
  3657. int32 MasterItemList::GetItemStatIDByName(std::string name)
  3658. {
  3659. boost::to_lower(name);
  3660. map<std::string, int32>::iterator itr = mappedItemStatsStrings.find(name.c_str());
  3661. if(itr != mappedItemStatsStrings.end())
  3662. return itr->second;
  3663. return 0xFFFFFFFF;
  3664. }
  3665. std::string MasterItemList::GetItemStatNameByID(int32 id)
  3666. {
  3667. map<int32, std::string>::iterator itr = mappedItemStatTypeIDs.find(id);
  3668. if(itr != mappedItemStatTypeIDs.end())
  3669. return itr->second;
  3670. return std::string("");
  3671. }