9
3

Items.cpp 110 KB

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