Items.cpp 141 KB

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