Items.cpp 144 KB

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