Items.cpp 117 KB

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