Items.cpp 121 KB

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