Items.cpp 111 KB

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