9
3

Items.cpp 125 KB

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