Items.cpp 121 KB

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