Items.cpp 143 KB

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