Items.cpp 134 KB

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