Items.cpp 132 KB

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