Items.cpp 128 KB

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