Items.cpp 140 KB

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