Items.cpp 117 KB

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