Items.cpp 148 KB

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