Player.cpp 257 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329
  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 "Player.h"
  17. #include "../common/MiscFunctions.h"
  18. #include "World.h"
  19. #include "WorldDatabase.h"
  20. #include <math.h>
  21. #include "classes.h"
  22. #include "LuaInterface.h"
  23. #include "../common/Log.h"
  24. #include "Rules/Rules.h"
  25. #include "Titles.h"
  26. #include "Languages.h"
  27. #include "SpellProcess.h"
  28. #include <algorithm>
  29. #include <regex>
  30. #include "ClientPacketFunctions.h"
  31. extern Classes classes;
  32. extern WorldDatabase database;
  33. extern World world;
  34. extern ConfigReader configReader;
  35. extern MasterSkillList master_skill_list;
  36. extern MasterSpellList master_spell_list;
  37. extern MasterQuestList master_quest_list;
  38. extern Variables variables;
  39. extern LuaInterface* lua_interface;
  40. extern MasterItemList master_item_list;
  41. extern RuleManager rule_manager;
  42. extern MasterTitlesList master_titles_list;
  43. extern MasterLanguagesList master_languages_list;
  44. Player::Player(){
  45. tutorial_step = 0;
  46. char_id = 0;
  47. group = 0;
  48. appearance.pos.grid_id = 0;
  49. spawn_index = 1;
  50. info = 0;
  51. movement_packet = 0;
  52. fully_logged_in = false;
  53. last_movement_activity = 0;
  54. //speed = 0;
  55. packet_num = 0;
  56. range_attack = false;
  57. old_movement_packet = 0;
  58. charsheet_changed = false;
  59. quickbar_updated = false;
  60. custNPC = false;
  61. spawn_tmp_vis_xor_packet = 0;
  62. spawn_tmp_pos_xor_packet = 0;
  63. spawn_tmp_info_xor_packet = 0;
  64. pending_collection_reward = 0;
  65. pos_packet_speed = 0;
  66. LogWrite(MISC__TODO, 1, "TODO", "Add player commands here\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  67. appearance.display_name = 1;
  68. appearance.show_command_icon = 1;
  69. appearance.player_flag = 1;
  70. appearance.targetable = 1;
  71. appearance.show_level = 1;
  72. spell_count = 0;
  73. spell_orig_packet = 0;
  74. spell_xor_packet = 0;
  75. resurrecting = false;
  76. spawn_id = 1;
  77. spawn_type = 4;
  78. player_spawn_id_map[1] = this;
  79. player_spawn_reverse_id_map[this] = 1;
  80. MPlayerQuests.SetName("Player::MPlayerQuests");
  81. test_time = 0;
  82. returning_from_ld = false;
  83. away_message = "Sorry, I am A.F.K. (Away From Keyboard)";
  84. AddSecondaryEntityCommand("Inspect", 10000, "inspect_player", "", 0, 0);
  85. AddSecondaryEntityCommand("Who", 10000, "who", "", 0, 0);
  86. // commented out commands a player canNOT use on themselves... move these to Client::HandleVerbRequest()?
  87. //AddSecondaryEntityCommand("Assist", 10, "assist", "", 0, 0);
  88. //AddSecondaryEntityCommand("Duel", 10, "duel", "", 0, 0);
  89. //AddSecondaryEntityCommand("Duel Bet", 10, "duelbet", "", 0, 0);
  90. //AddSecondaryEntityCommand("Trade", 10, "trade", "", 0, 0);
  91. is_tracking = false;
  92. guild = 0;
  93. following = false;
  94. combat_target = 0;
  95. InitXPTable();
  96. pending_deletion = false;
  97. spawn_vis_struct = 0;
  98. spawn_pos_struct = 0;
  99. spawn_info_struct = 0;
  100. spawn_header_struct = 0;
  101. spawn_footer_struct = 0;
  102. widget_footer_struct = 0;
  103. sign_footer_struct = 0;
  104. pos_xor_size = 0;
  105. info_xor_size = 0;
  106. vis_xor_size = 0;
  107. pos_mutex.SetName("Player::pos_mutex");
  108. vis_mutex.SetName("Player::vis_mutex");
  109. info_mutex.SetName("Player::info_mutex");
  110. index_mutex.SetName("Player::index_mutex");
  111. spawn_mutex.SetName("Player::spawn_mutex");
  112. m_playerSpawnQuestsRequired.SetName("Player::player_spawn_quests_required");
  113. m_playerSpawnHistoryRequired.SetName("Player::player_spawn_history_required");
  114. gm_vision = false;
  115. SetSaveSpellEffects(true);
  116. reset_mentorship = false;
  117. all_spells_locked = false;
  118. current_language_id = 0;
  119. active_reward = false;
  120. }
  121. Player::~Player(){
  122. SetSaveSpellEffects(true);
  123. DeleteSpellEffects();
  124. for(int32 i=0;i<spells.size();i++){
  125. safe_delete(spells[i]);
  126. }
  127. for(int32 i=0;i<quickbar_items.size();i++){
  128. safe_delete(quickbar_items[i]);
  129. }
  130. map<int32, vector<int32>*>::iterator itr;
  131. for (itr = player_spawn_quests_required.begin(); itr != player_spawn_quests_required.end(); itr++){
  132. safe_delete(itr->second);
  133. }
  134. for (itr = player_spawn_history_required.begin(); itr != player_spawn_history_required.end(); itr++){
  135. safe_delete(itr->second);
  136. }
  137. map<int8, map<int8, vector<HistoryData*> > >::iterator itr1;
  138. map<int8, vector<HistoryData*> >::iterator itr2;
  139. vector<HistoryData*>::iterator itr3;
  140. // Type
  141. for (itr1 = m_characterHistory.begin(); itr1 != m_characterHistory.end(); itr1++) {
  142. // Sub type
  143. for (itr2 = itr1->second.begin(); itr2 != itr1->second.end(); itr2++) {
  144. // vector of data
  145. for (itr3 = itr2->second.begin(); itr3 != itr2->second.end(); itr3++) {
  146. safe_delete(*itr3);
  147. }
  148. }
  149. }
  150. mLUAHistory.writelock();
  151. map<int32, LUAHistory*>::iterator itr4;
  152. for (itr4 = m_charLuaHistory.begin(); itr4 != m_charLuaHistory.end(); itr4++) {
  153. safe_delete(itr4->second);
  154. }
  155. m_charLuaHistory.clear();
  156. mLUAHistory.releasewritelock();
  157. safe_delete_array(movement_packet);
  158. safe_delete_array(old_movement_packet);
  159. safe_delete_array(spawn_tmp_info_xor_packet);
  160. safe_delete_array(spawn_tmp_vis_xor_packet);
  161. safe_delete_array(spawn_tmp_pos_xor_packet);
  162. safe_delete_array(spell_xor_packet);
  163. safe_delete_array(spell_orig_packet);
  164. DestroyQuests();
  165. WritePlayerStatistics();
  166. RemovePlayerStatistics();
  167. DeleteMail();
  168. world.RemoveLottoPlayer(GetCharacterID());
  169. safe_delete(info);
  170. index_mutex.writelock(__FUNCTION__, __LINE__);
  171. player_spawn_reverse_id_map.clear();
  172. player_spawn_id_map.clear();
  173. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  174. info_mutex.writelock(__FUNCTION__, __LINE__);
  175. spawn_info_packet_list.clear();
  176. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  177. vis_mutex.writelock(__FUNCTION__, __LINE__);
  178. spawn_vis_packet_list.clear();
  179. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  180. pos_mutex.writelock(__FUNCTION__, __LINE__);
  181. spawn_pos_packet_list.clear();
  182. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  183. safe_delete(spawn_header_struct);
  184. safe_delete(spawn_footer_struct);
  185. safe_delete(sign_footer_struct);
  186. safe_delete(widget_footer_struct);
  187. safe_delete(spawn_info_struct);
  188. safe_delete(spawn_vis_struct);
  189. safe_delete(spawn_pos_struct);
  190. ClearPendingSelectableItemRewards(0, true);
  191. ClearPendingItemRewards();
  192. }
  193. EQ2Packet* Player::serialize(Player* player, int16 version){
  194. return spawn_serialize(player, version);
  195. }
  196. EQ2Packet* Player::Move(float x, float y, float z, int16 version, float heading){
  197. PacketStruct* packet = configReader.getStruct("WS_MoveClient", version);
  198. if(packet){
  199. packet->setDataByName("x", x);
  200. packet->setDataByName("y", y);
  201. packet->setDataByName("z", z);
  202. packet->setDataByName("unknown", 1); // 1 seems to force the client to re-render the zone at the new location
  203. packet->setDataByName("location", 0xFFFFFFFF); //added in 869
  204. if (heading != -1.0f)
  205. packet->setDataByName("heading", heading);
  206. EQ2Packet* outapp = packet->serialize();
  207. safe_delete(packet);
  208. return outapp;
  209. }
  210. return 0;
  211. }
  212. void Player::DestroyQuests(){
  213. MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  214. map<int32, Quest*>::iterator itr;
  215. for(itr = completed_quests.begin(); itr != completed_quests.end(); itr++){
  216. safe_delete(itr->second);
  217. }
  218. completed_quests.clear();
  219. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  220. safe_delete(itr->second);
  221. }
  222. player_quests.clear();
  223. for(itr = pending_quests.begin(); itr != pending_quests.end(); itr++){
  224. safe_delete(itr->second);
  225. }
  226. pending_quests.clear();
  227. MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  228. }
  229. PlayerInfo* Player::GetPlayerInfo(){
  230. if(info == 0)
  231. info = new PlayerInfo(this);
  232. return info;
  233. }
  234. void PlayerInfo::CalculateXPPercentages(){
  235. int32 xp_needed = info_struct->get_xp_needed();
  236. if(xp_needed > 0){
  237. float percentage = ((double)info_struct->get_xp() / xp_needed) * 1000;
  238. info_struct->set_xp_yellow((int16)percentage);
  239. info_struct->set_xp_blue((int16)(percentage-info_struct->get_xp_yellow())*1000);
  240. info_struct->set_xp_blue_vitality_bar(0);
  241. info_struct->set_xp_yellow_vitality_bar(0);
  242. if(player->GetXPVitality() > 0){
  243. float vitality_total = player->GetXPVitality()*10 + percentage;
  244. vitality_total -= ((int)(percentage/100)*100);
  245. if(vitality_total < 100){ //10%
  246. info_struct->set_xp_blue_vitality_bar(info_struct->get_xp_blue() + (int16)(player->GetXPVitality() *10));
  247. }
  248. else
  249. info_struct->set_xp_yellow_vitality_bar(info_struct->get_xp_yellow() + (int16)(player->GetXPVitality() *10));
  250. }
  251. }
  252. }
  253. void PlayerInfo::CalculateTSXPPercentages(){
  254. int32 ts_xp_needed = info_struct->get_ts_xp_needed();
  255. if(ts_xp_needed > 0){
  256. float percentage = ((double)info_struct->get_ts_xp() / ts_xp_needed) * 1000;
  257. info_struct->set_tradeskill_exp_yellow((int16)percentage);
  258. info_struct->set_tradeskill_exp_blue((int16)((percentage - info_struct->get_tradeskill_exp_yellow()) * 1000));
  259. /*info_struct->xp_blue_vitality_bar = 0;
  260. info_struct->xp_yellow_vitality_bar = 0;
  261. if(player->GetXPVitality() > 0){
  262. float vitality_total = player->GetXPVitality()*10 + percentage;
  263. vitality_total -= ((int)(percentage/100)*100);
  264. if(vitality_total < 100){ //10%
  265. info_struct->xp_blue_vitality_bar = info_struct->xp_blue + (int16)(player->GetXPVitality() *10);
  266. }
  267. else
  268. info_struct->xp_yellow_vitality_bar = info_struct->xp_yellow + (int16)(player->GetXPVitality() *10);
  269. }*/
  270. }
  271. }
  272. void PlayerInfo::SetHouseZone(int32 id){
  273. house_zone_id = id;
  274. }
  275. void PlayerInfo::SetBindZone(int32 id){
  276. bind_zone_id = id;
  277. }
  278. void PlayerInfo::SetBindX(float x){
  279. bind_x = x;
  280. }
  281. void PlayerInfo::SetBindY(float y){
  282. bind_y = y;
  283. }
  284. void PlayerInfo::SetBindZ(float z){
  285. bind_z = z;
  286. }
  287. void PlayerInfo::SetBindHeading(float heading){
  288. bind_heading = heading;
  289. }
  290. int32 PlayerInfo::GetHouseZoneID(){
  291. return house_zone_id;
  292. }
  293. int32 PlayerInfo::GetBindZoneID(){
  294. return bind_zone_id;
  295. }
  296. float PlayerInfo::GetBindZoneX(){
  297. return bind_x;
  298. }
  299. float PlayerInfo::GetBindZoneY(){
  300. return bind_y;
  301. }
  302. float PlayerInfo::GetBindZoneZ(){
  303. return bind_z;
  304. }
  305. float PlayerInfo::GetBindZoneHeading(){
  306. return bind_heading;
  307. }
  308. PacketStruct* PlayerInfo::serialize2(int16 version){
  309. player->CalculateBonuses();
  310. PacketStruct* packet = configReader.getStruct("WS_CharacterSheet", version);
  311. if(packet){
  312. //TODO: 2021 FIX THIS CASTING
  313. char deity[32];
  314. strncpy(deity, info_struct->get_deity().c_str(), 32);
  315. packet->setDataByName("deity", deity);
  316. char name[40];
  317. strncpy(name, info_struct->get_name().c_str(), 40);
  318. packet->setDataByName("character_name", name);
  319. packet->setDataByName("race", info_struct->get_race());
  320. packet->setDataByName("gender", info_struct->get_gender());
  321. packet->setDataByName("class1", info_struct->get_class1());
  322. packet->setDataByName("class2", info_struct->get_class2());
  323. packet->setDataByName("class3", info_struct->get_class3());
  324. packet->setDataByName("tradeskill_class1", info_struct->get_tradeskill_class1());
  325. packet->setDataByName("tradeskill_class2", info_struct->get_tradeskill_class2());
  326. packet->setDataByName("tradeskill_class3", info_struct->get_tradeskill_class3());
  327. packet->setDataByName("level", info_struct->get_level());
  328. packet->setDataByName("effective_level", info_struct->get_effective_level() != 0 ? info_struct->get_effective_level() : info_struct->get_level());
  329. packet->setDataByName("tradeskill_level", info_struct->get_tradeskill_level());
  330. packet->setDataByName("account_age_base", info_struct->get_account_age_base());
  331. // for(int8 i=0;i<19;i++)
  332. // {
  333. // packet->setDataByName("account_age_bonus", info_struct->get_account_age_bonus(i));
  334. // }
  335. //
  336. packet->setDataByName("current_hp", player->GetHP());
  337. packet->setDataByName("max_hp",player-> GetTotalHP());
  338. packet->setDataByName("base_hp", player->GetTotalHPBase());
  339. float bonus_health = floor( (float)(info_struct->get_sta() * player->CalculateBonusMod()));
  340. packet->setDataByName("bonus_health", bonus_health);
  341. packet->setDataByName("stat_bonus_health", player->CalculateBonusMod());
  342. packet->setDataByName("current_power", player->GetPower());
  343. packet->setDataByName("max_power", player->GetTotalPower());
  344. packet->setDataByName("base_power", player->GetTotalPowerBase());
  345. packet->setDataByName("bonus_power", floor( (float)(player->GetPrimaryStat() * player->CalculateBonusMod())));
  346. packet->setDataByName("stat_bonus_power", player->CalculateBonusMod());
  347. packet->setDataByName("conc_used", info_struct->get_cur_concentration());
  348. packet->setDataByName("conc_max", info_struct->get_max_concentration());
  349. packet->setDataByName("attack", info_struct->get_cur_attack());
  350. packet->setDataByName("attack_base", info_struct->get_attack_base());
  351. packet->setDataByName("absorb", info_struct->get_absorb());
  352. packet->setDataByName("mitigation_skill1", info_struct->get_mitigation_skill1());
  353. packet->setDataByName("mitigation_skill2", info_struct->get_mitigation_skill2());
  354. packet->setDataByName("mitigation_skill3", info_struct->get_mitigation_skill3());
  355. CalculateXPPercentages();
  356. packet->setDataByName("exp_yellow", info_struct->get_xp_yellow());
  357. packet->setDataByName("exp_blue", info_struct->get_xp_blue());
  358. packet->setDataByName("tradeskill_exp_yellow", info_struct->get_tradeskill_exp_yellow());
  359. packet->setDataByName("tradeskill_exp_blue", info_struct->get_tradeskill_exp_blue());
  360. packet->setDataByName("flags", info_struct->get_flags());
  361. packet->setDataByName("flags2", info_struct->get_flags2());
  362. packet->setDataByName("avoidance_pct", (int16)info_struct->get_avoidance_display()*10.0f);//avoidance_pct 192 = 19.2% // confirmed DoV
  363. packet->setDataByName("avoidance_base", (int16)info_struct->get_avoidance_base()*10.0f); // confirmed DoV
  364. packet->setDataByName("avoidance", info_struct->get_cur_avoidance());
  365. packet->setDataByName("base_avoidance_pct", info_struct->get_base_avoidance_pct());// confirmed DoV
  366. float parry_pct = info_struct->get_parry(); // client works off of int16, but we use floats to track the actual x/100%
  367. packet->setDataByName("parry",(int16)(parry_pct*10.0f));// confirmed DoV
  368. float block_pct = info_struct->get_block()*10.0f;
  369. packet->setDataByName("block", (int16)block_pct);// confirmed DoV
  370. packet->setDataByName("uncontested_block", info_struct->get_uncontested_block());// confirmed DoV
  371. packet->setDataByName("str", info_struct->get_str());
  372. packet->setDataByName("sta", info_struct->get_sta());
  373. packet->setDataByName("agi", info_struct->get_agi());
  374. packet->setDataByName("wis", info_struct->get_wis());
  375. packet->setDataByName("int", info_struct->get_intel());
  376. packet->setDataByName("str_base", info_struct->get_str_base());
  377. packet->setDataByName("sta_base", info_struct->get_sta_base());
  378. packet->setDataByName("agi_base", info_struct->get_agi_base());
  379. packet->setDataByName("wis_base", info_struct->get_wis_base());
  380. packet->setDataByName("int_base", info_struct->get_intel_base());
  381. packet->setDataByName("mitigation_cur", info_struct->get_cur_mitigation());
  382. packet->setDataByName("mitigation_max", info_struct->get_max_mitigation());
  383. packet->setDataByName("mitigation_base", info_struct->get_mitigation_base());
  384. packet->setDataByName("heat", info_struct->get_heat());
  385. packet->setDataByName("cold", info_struct->get_cold());
  386. packet->setDataByName("magic", info_struct->get_magic());
  387. packet->setDataByName("mental", info_struct->get_mental());
  388. packet->setDataByName("divine", info_struct->get_divine());
  389. packet->setDataByName("disease", info_struct->get_disease());
  390. packet->setDataByName("poison", info_struct->get_poison());
  391. packet->setDataByName("heat_base", info_struct->get_heat_base());
  392. packet->setDataByName("cold_base", info_struct->get_cold_base());
  393. packet->setDataByName("magic_base", info_struct->get_magic_base());
  394. packet->setDataByName("mental_base", info_struct->get_mental_base());
  395. packet->setDataByName("divine_base", info_struct->get_divine_base());
  396. packet->setDataByName("disease_base", info_struct->get_disease_base());
  397. packet->setDataByName("poison_base", info_struct->get_poison_base());
  398. packet->setDataByName("mitigation_cur2", info_struct->get_cur_mitigation());
  399. packet->setDataByName("mitigation_max2", info_struct->get_max_mitigation());
  400. packet->setDataByName("mitigation_base2", info_struct->get_mitigation_base());
  401. packet->setDataByName("coins_copper", info_struct->get_coin_copper());
  402. packet->setDataByName("coins_silver", info_struct->get_coin_silver());
  403. packet->setDataByName("coins_gold", info_struct->get_coin_gold());
  404. packet->setDataByName("coins_plat", info_struct->get_coin_plat());
  405. packet->setDataByName("weight", info_struct->get_weight());
  406. packet->setDataByName("max_weight", info_struct->get_max_weight());
  407. char pet_name[32];
  408. strncpy(pet_name, info_struct->get_pet_name().c_str(), 32);
  409. packet->setDataByName("pet_name", pet_name);
  410. packet->setDataByName("status_points", info_struct->get_status_points());
  411. if(bind_zone_id > 0){
  412. string bind_name = database.GetZoneName(bind_zone_id);
  413. if (bind_name.length() > 0)
  414. packet->setDataByName("bind_zone", bind_name.c_str());
  415. }
  416. else
  417. packet->setDataByName("bind_zone", "None");
  418. if(house_zone_id > 0){
  419. string house_name = database.GetZoneName(house_zone_id);
  420. if (house_name.length() > 0)
  421. packet->setDataByName("house_zone", house_name.c_str());
  422. }
  423. else
  424. packet->setDataByName("house_zone", "None");
  425. //packet->setDataByName("account_age_base", 14);
  426. packet->setDataByName("hp_regen", info_struct->get_hp_regen());
  427. packet->setDataByName("power_regen", info_struct->get_power_regen());
  428. /*packet->setDataByName("unknown11", -1, 0);
  429. packet->setDataByName("unknown11", -1, 1);
  430. packet->setDataByName("unknown13", 201, 0);
  431. packet->setDataByName("unknown13", 201, 1);
  432. packet->setDataByName("unknown13", 234, 2);
  433. packet->setDataByName("unknown13", 201, 3);
  434. packet->setDataByName("unknown13", 214, 4);
  435. packet->setDataByName("unknown13", 234, 5);
  436. packet->setDataByName("unknown13", 234, 6);
  437. packet->setDataByName("unknown14", 78);
  438. */
  439. packet->setDataByName("adventure_exp_vitality", (int16)(player->GetXPVitality() *10));
  440. //packet->setDataByName("unknown15b", 9911);
  441. packet->setDataByName("unknown15a", 78);
  442. packet->setDataByName("xp_yellow_vitality_bar", info_struct->get_xp_yellow_vitality_bar());
  443. packet->setDataByName("xp_blue_vitality_bar", info_struct->get_xp_blue_vitality_bar());
  444. packet->setDataByName("tradeskill_exp_vitality", 100);
  445. packet->setDataByName("unknown15c", 200);
  446. //packet->setDataByName("unknown15", 100, 10);
  447. packet->setDataByName("unknown18", 16880, 1);
  448. /*packet->setDataByName("unknown19", 1);
  449. packet->setDataByName("unknown19", 3, 1);
  450. packet->setDataByName("unknown19", 1074301064, 2);
  451. packet->setDataByName("unknown19", 1, 3);
  452. packet->setDataByName("unknown19", 3, 4);
  453. packet->setDataByName("unknown19", 1074301064, 5);
  454. packet->setDataByName("unknown19", 6, 6);
  455. packet->setDataByName("unknown19", 14, 7);
  456. packet->setDataByName("unknown19", 1083179008, 8);*/
  457. player->SetGroupInformation(packet);
  458. packet->setDataByName("unknown20", 1, 107);
  459. packet->setDataByName("unknown20", 1, 108);
  460. packet->setDataByName("unknown20", 1, 109);
  461. packet->setDataByName("unknown20", 1, 110);
  462. packet->setDataByName("unknown20", 1, 111);
  463. //packet->setDataByName("unknown20b", 255);
  464. //packet->setDataByName("unknown20b", 255, 1);
  465. //packet->setDataByName("unknown20b", 255, 2);
  466. packet->setDataByName("unknown11", 123);
  467. packet->setDataByName("unknown11", 234, 1);
  468. //packet->setDataByName("in_combat", 32768);
  469. //make name flash red
  470. /*packet->setDataByName("unknown20", 8);
  471. packet->setDataByName("unknown20", 38, 70);
  472. packet->setDataByName("unknown20", 17, 77);
  473. packet->setDataByName("unknown20", 1, 112); //melee stats and such
  474. packet->setDataByName("unknown20", 1, 113);
  475. packet->setDataByName("unknown20", 1, 114);
  476. packet->setDataByName("unknown20", 1, 115);
  477. packet->setDataByName("unknown20", 4294967295, 309);
  478. packet->setDataByName("unknown22", 2, 4);
  479. packet->setDataByName("unknown23", 2, 29);
  480. */
  481. //packet->setDataByName("unknown20b", 1, i); // pet bar in here
  482. // for(int i=0;i<19;i++)
  483. // packet->setDataByName("unknown7", 257, i);
  484. //packet->setDataByName("unknown21", info_struct->rain, 2);
  485. packet->setDataByName("rain", info_struct->get_rain());
  486. packet->setDataByName("rain2", info_struct->get_wind()); //-102.24);
  487. /*packet->setDataByName("unknown22", 3, 4);
  488. packet->setDataByName("unknown23", 3, 161);
  489. packet->setDataByName("unknown20", 103);
  490. packet->setDataByName("unknown20", 1280, 70);
  491. packet->setDataByName("unknown20", 9, 71);
  492. packet->setDataByName("unknown20", 5, 72);
  493. packet->setDataByName("unknown20", 4294967271, 73);
  494. packet->setDataByName("unknown20", 5, 75);
  495. packet->setDataByName("unknown20", 1051, 77);
  496. packet->setDataByName("unknown20", 3, 78);
  497. packet->setDataByName("unknown20", 6, 104);
  498. packet->setDataByName("unknown20", 1, 105);
  499. packet->setDataByName("unknown20", 20, 106);
  500. packet->setDataByName("unknown20", 3, 107);
  501. packet->setDataByName("unknown20", 1, 108);
  502. packet->setDataByName("unknown20", 1, 109);
  503. packet->setDataByName("unknown20", 4278190080, 494);
  504. packet->setDataByName("unknown20b", 255);
  505. packet->setDataByName("unknown20b", 255, 1);
  506. packet->setDataByName("unknown20b", 255, 2);
  507. packet->setDataByName("unknown20", 50, 75);
  508. */
  509. //packet->setDataByName("rain2", -102.24);
  510. for(int i=0;i<45;i++){
  511. if(i < 30){
  512. packet->setSubstructDataByName("maintained_effects", "name", info_struct->maintained_effects[i].name, i, 0);
  513. packet->setSubstructDataByName("maintained_effects", "target", info_struct->maintained_effects[i].target, i, 0);
  514. packet->setSubstructDataByName("maintained_effects", "spell_id", info_struct->maintained_effects[i].spell_id, i, 0);
  515. packet->setSubstructDataByName("maintained_effects", "slot_pos", info_struct->maintained_effects[i].slot_pos, i, 0);
  516. packet->setSubstructDataByName("maintained_effects", "icon", info_struct->maintained_effects[i].icon, i, 0);
  517. packet->setSubstructDataByName("maintained_effects", "icon_type", info_struct->maintained_effects[i].icon_backdrop, i, 0);
  518. packet->setSubstructDataByName("maintained_effects", "conc_used", info_struct->maintained_effects[i].conc_used, i, 0);
  519. packet->setSubstructDataByName("maintained_effects", "unknown3", 1, i, 0);
  520. packet->setSubstructDataByName("maintained_effects", "total_time", info_struct->maintained_effects[i].total_time, i, 0);
  521. packet->setSubstructDataByName("maintained_effects", "expire_timestamp", info_struct->maintained_effects[i].expire_timestamp, i, 0);
  522. }
  523. else if(version < 942)//version 942 added 15 additional spell effect slots
  524. break;
  525. packet->setSubstructDataByName("spell_effects", "spell_id", info_struct->spell_effects[i].spell_id, i, 0);
  526. if(info_struct->spell_effects[i].spell_id > 0 && info_struct->spell_effects[i].spell_id < 0xFFFFFFFF)
  527. packet->setSubstructDataByName("spell_effects", "unknown2", 514, i, 0);
  528. packet->setSubstructDataByName("spell_effects", "total_time", info_struct->spell_effects[i].total_time, i, 0);
  529. packet->setSubstructDataByName("spell_effects", "expire_timestamp", info_struct->spell_effects[i].expire_timestamp, i, 0);
  530. packet->setSubstructDataByName("spell_effects", "icon", info_struct->spell_effects[i].icon, i, 0);
  531. packet->setSubstructDataByName("spell_effects", "icon_type", info_struct->spell_effects[i].icon_backdrop, i, 0);
  532. }
  533. return packet;
  534. }
  535. return 0;
  536. }
  537. EQ2Packet* PlayerInfo::serialize3(PacketStruct* packet, int16 version){
  538. if(packet){
  539. string* data = packet->serializeString();
  540. int32 size = data->length();
  541. //DumpPacket((uchar*)data->c_str(), size);
  542. uchar* tmp = new uchar[size];
  543. if(!changes){
  544. orig_packet = new uchar[size];
  545. changes = new uchar[size];
  546. memcpy(orig_packet, (uchar*)data->c_str(), size);
  547. size = Pack(tmp, (uchar*)data->c_str(), size, size, version);
  548. }
  549. else{
  550. memcpy(changes, (uchar*)data->c_str(), size);
  551. Encode(changes, orig_packet, size);
  552. size = Pack(tmp, changes, size, size, version);
  553. //cout << "INFO HERE:\n";
  554. //DumpPacket(tmp, size);
  555. }
  556. EQ2Packet* ret_packet = new EQ2Packet(OP_UpdateCharacterSheetMsg, tmp, size+4);
  557. safe_delete_array(tmp);
  558. safe_delete(packet);
  559. return ret_packet;
  560. }
  561. return 0;
  562. }
  563. void PlayerInfo::SetAccountAge(int16 age){
  564. info_struct->set_account_age_base(age);
  565. }
  566. EQ2Packet* PlayerInfo::serialize(int16 version, int16 modifyPos, int32 modifyValue) {
  567. player->CalculateBonuses();
  568. /* info_struct->heat = 15;
  569. info_struct->heat_base = 13;
  570. info_struct->divine = 14;
  571. info_struct->divine_base = 11;
  572. info_struct->cur_attack = 5;
  573. info_struct->attack_base = 5;
  574. info_struct->coin_copper = 1;
  575. info_struct->coin_silver = 2;
  576. info_struct->coin_gold = 3;
  577. info_struct->coin_plat = 4;*/
  578. int8 blah1 = 90;
  579. int8 blah2 = 120;
  580. /*for (int i = 0; i < 12; i++) {
  581. info_struct->maintained_effects[i].icon = 8+i;
  582. info_struct->maintained_effects[i].icon_backdrop = 315+i;
  583. strcpy(info_struct->maintained_effects[i].name, "Testing Spell");
  584. info_struct->maintained_effects[i].spell_id = 3000+i;
  585. info_struct->maintained_effects[i].slot_pos = i;
  586. info_struct->maintained_effects[i].expire_timestamp = Timer::GetCurrentTime2() + 72000;
  587. if(i<2)
  588. info_struct->maintained_effects[i].conc_used = 1;
  589. info_struct->maintained_effects[i].total_time = 60+i;
  590. }*/
  591. PacketStruct* packet = configReader.getStruct("WS_CharacterSheet", version);
  592. /*for (int i = 0; i < 1; i++) {
  593. info_struct->spell_effects[i].icon = 303;
  594. info_struct->spell_effects[i].icon_backdrop = 317;
  595. info_struct->spell_effects[i].spell_id = 8308;
  596. info_struct->spell_effects[i].expire_timestamp = Timer::GetCurrentTime2() + 72000;
  597. if (i < 5)
  598. packet->setSubstructDataByName("spell_effects", "cancellable", 1, i);
  599. }*/
  600. //0-69, locked screen movement
  601. //30-69 normal movement
  602. //10-30 normal movement
  603. //for (int i = 5; i < 10; i++)
  604. //packet->setDataByName("unknown19", 1+i, i);
  605. //Sleep(5000);
  606. if (packet) {
  607. char name[40];
  608. strncpy(name,info_struct->get_name().c_str(),40);
  609. packet->setDataByName("character_name", name);
  610. // packet->setDataByName("unknown_1_1_MJ", 99);//unknown_1_1_MJ
  611. packet->setDataByName("race", info_struct->get_race());
  612. packet->setDataByName("gender", info_struct->get_gender());
  613. packet->setDataByName("exiled", 0); // need exiled data
  614. packet->setDataByName("class1", info_struct->get_class1());
  615. packet->setDataByName("class2", info_struct->get_class2());
  616. packet->setDataByName("class3", info_struct->get_class3());
  617. packet->setDataByName("tradeskill_class1", info_struct->get_tradeskill_class1());
  618. packet->setDataByName("tradeskill_class2", info_struct->get_tradeskill_class2());
  619. packet->setDataByName("tradeskill_class3", info_struct->get_tradeskill_class3());
  620. packet->setDataByName("level", info_struct->get_level());
  621. packet->setDataByName("effective_level", info_struct->get_effective_level() != 0 ? info_struct->get_effective_level() : info_struct->get_level());
  622. packet->setDataByName("tradeskill_level", info_struct->get_tradeskill_level());
  623. // packet->setDataByName("unknown_1_2_MJ", 98); //unknown_1_2_MJ
  624. packet->setDataByName("account_age_base", info_struct->get_account_age_base());
  625. //TODO: 2021 FIX THIS CASTING
  626. for (int8 i = 0; i < 19; i++)
  627. packet->setDataByName("account_age_bonus", 0);
  628. //TODO: 2021 FIX THIS CASTING
  629. char deity[32];
  630. strncpy(deity, info_struct->get_deity().c_str(), 32);
  631. packet->setDataByName("deity", deity);
  632. packet->setDataByName("last_name", player->GetLastName());
  633. // packet->setDataByName("unknown_1_3_MJ", 97);//unknown_1_3_MJ
  634. packet->setDataByName("current_hp", player->GetHP());
  635. packet->setDataByName("max_hp", player->GetTotalHP());
  636. packet->setDataByName("base_hp", player->GetTotalHPBase());
  637. packet->setDataByName("current_power", player->GetPower());
  638. packet->setDataByName("max_power", player->GetTotalPower());
  639. packet->setDataByName("base_power", player->GetTotalPowerBase());
  640. packet->setDataByName("conc_used", info_struct->get_cur_concentration());
  641. packet->setDataByName("conc_max", info_struct->get_max_concentration());
  642. packet->setDataByName("hp_regen", player->GetInfoStruct()->get_hp_regen());
  643. packet->setDataByName("power_regen", player->GetInfoStruct()->get_power_regen());
  644. // packet->setDataByName("unknown_1_4a_MJ", 96); //-1// was unknown11
  645. // packet->setDataByName("unknown_1_4b_MJ", 96); //-1
  646. packet->setDataByName("stat_bonus_health", player->CalculateBonusMod());//bonus health and bonus power getting same value?
  647. packet->setDataByName("stat_bonus_power", player->CalculateBonusMod());//bonus health and bonus power getting same value?
  648. float bonus_health = floor((float)(info_struct->get_sta() * player->CalculateBonusMod()));
  649. packet->setDataByName("bonus_health", bonus_health);
  650. packet->setDataByName("bonus_power", floor((float)(player->GetPrimaryStat() * player->CalculateBonusMod())));
  651. packet->setDataByName("stat_bonus_damage", 95); //stat_bonus_damage
  652. packet->setDataByName("mitigation_cur", info_struct->get_cur_mitigation());// confirmed DoV
  653. packet->setDataByName("mitigation_base", info_struct->get_mitigation_base());// confirmed DoV
  654. packet->setDataByName("mitigation_pct_pve", info_struct->get_mitigation_pve()); // % calculation Mitigation % vs PvE 392 = 39.2%// confirmed DoV
  655. packet->setDataByName("mitigation_pct_pvp", info_struct->get_mitigation_pvp()); // % calculation Mitigation % vs PvP 559 = 55.9%// confirmed DoV
  656. packet->setDataByName("toughness", 0);//toughness// confirmed DoV
  657. packet->setDataByName("toughness_resist_dmg_pvp", 0);//toughness_resist_dmg_pvp 73 = 7300% // confirmed DoV
  658. packet->setDataByName("avoidance_pct", (int16)info_struct->get_avoidance_display()*10.0f);//avoidance_pct 192 = 19.2% // confirmed DoV
  659. packet->setDataByName("avoidance_base", (int16)info_struct->get_avoidance_base()*10.0f); // confirmed DoV
  660. packet->setDataByName("avoidance", info_struct->get_cur_avoidance());
  661. // packet->setDataByName("unknown_1096_1_MJ", 90);//unknown_1096_1_MJ
  662. packet->setDataByName("base_avoidance_pct", info_struct->get_base_avoidance_pct());// confirmed DoV
  663. // packet->setDataByName("unknown_1096_2_MJ", 89);//unknown_1096_2_MJ
  664. float parry_pct = info_struct->get_parry(); // client works off of int16, but we use floats to track the actual x/100%
  665. packet->setDataByName("parry",(int16)(parry_pct*10.0f));// confirmed DoV
  666. // packet->setDataByName("unknown_1096_3_MJ", 88);//unknown_1096_3_MJ
  667. float block_pct = info_struct->get_block()*10.0f;
  668. packet->setDataByName("block", (int16)block_pct);// confirmed DoV
  669. // packet->setDataByName("unknown_1096_4_MJ", 87);//unknown_1096_4_MJ
  670. packet->setDataByName("uncontested_block", info_struct->get_uncontested_block());// confirmed DoV
  671. // packet->setDataByName("unknown_1096_5_MJ", 86);//unknown_1096_5_MJ
  672. packet->setDataByName("str", info_struct->get_str());// confirmed DoV
  673. packet->setDataByName("sta", info_struct->get_sta());// confirmed DoV
  674. packet->setDataByName("agi", info_struct->get_agi());// confirmed DoV
  675. packet->setDataByName("wis", info_struct->get_wis());// confirmed DoV
  676. packet->setDataByName("int", info_struct->get_intel());// confirmed DoV
  677. packet->setDataByName("str_base", info_struct->get_str_base()); // confirmed DoV
  678. packet->setDataByName("sta_base", info_struct->get_sta_base());// confirmed DoV
  679. packet->setDataByName("agi_base", info_struct->get_agi_base());// confirmed DoV
  680. packet->setDataByName("wis_base", info_struct->get_wis_base());// confirmed DoV
  681. packet->setDataByName("int_base", info_struct->get_intel_base());// confirmed DoV
  682. // packet->setDataByName("unknown_1096_6_MJ", 86);//unknown_1096_6_MJ
  683. if (version <= 996) {
  684. packet->setDataByName("heat", info_struct->get_heat());
  685. packet->setDataByName("cold", info_struct->get_cold());
  686. packet->setDataByName("magic", info_struct->get_magic());
  687. packet->setDataByName("mental", info_struct->get_mental());
  688. packet->setDataByName("divine", info_struct->get_divine());
  689. packet->setDataByName("disease", info_struct->get_disease());
  690. packet->setDataByName("poison", info_struct->get_poison());
  691. packet->setDataByName("heat_base", info_struct->get_heat_base());
  692. packet->setDataByName("cold_base", info_struct->get_cold_base());
  693. packet->setDataByName("magic_base", info_struct->get_magic_base());
  694. packet->setDataByName("mental_base", info_struct->get_mental_base());
  695. packet->setDataByName("divine_base", info_struct->get_divine_base());
  696. packet->setDataByName("disease_base", info_struct->get_disease_base());
  697. packet->setDataByName("poison_base", info_struct->get_poison_base());
  698. }
  699. else {
  700. packet->setDataByName("elemental", info_struct->get_heat());// confirmed DoV
  701. packet->setDataByName("noxious", info_struct->get_poison());// confirmed DoV
  702. packet->setDataByName("arcane", info_struct->get_magic());// confirmed DoV
  703. // packet->setDataByName("unknown_1096_7_MJ", 85);//unknown_1096_7_MJ
  704. packet->setDataByName("elemental_base", info_struct->get_elemental_base());// confirmed DoV
  705. packet->setDataByName("noxious_base", info_struct->get_noxious_base());// confirmed DoV
  706. packet->setDataByName("arcane_base", info_struct->get_arcane_base());// confirmed DoV
  707. }
  708. // packet->setDataByName("unknown_1096_8_MJ", 205);//unknown_1096_8_MJ
  709. packet->setDataByName("elemental_absorb_pve", 0); //210 = 21.0% confirmed DoV
  710. packet->setDataByName("noxious_absorb_pve", 0);//210 = 21.0% confirmed DoV
  711. packet->setDataByName("arcane_absorb_pve", 0);//210 = 21.0% confirmed DoV
  712. // packet->setDataByName("unknown_1096_9_MJ", 240);//unknown_1096_9_MJ
  713. packet->setDataByName("elemental_absorb_pvp", 0);//210 = 21.0% confirmed DoV
  714. packet->setDataByName("noxious_absorb_pvp", 0);//210 = 21.0% confirmed DoV
  715. packet->setDataByName("arcane_absorb_pvp", 0);//210 = 21.0% confirmed DoV
  716. // packet->setDataByName("unknown_1096_10_MJ", 280);//unknown_1096_10_MJ
  717. packet->setDataByName("elemental_dmg_reduction", 0);// confirmed DoV
  718. packet->setDataByName("noxious_dmg_reduction", 0);// confirmed DoV
  719. packet->setDataByName("arcane_dmg_reduction", 0);// confirmed DoV
  720. // packet->setDataByName("unknown_1096_11_MJ", 320);//unknown_1096_11_MJ
  721. packet->setDataByName("elemental_dmg_reduction_pct", 0);//210 = 21.0% confirmed DoV
  722. packet->setDataByName("noxious_dmg_reduction_pct", 0);//210 = 21.0% confirmed DoV
  723. packet->setDataByName("arcane_dmg_reduction_pct", 0);//210 = 21.0% confirmed DoV
  724. CalculateXPPercentages();
  725. packet->setDataByName("current_adv_xp", info_struct->get_xp()); // confirmed DoV
  726. packet->setDataByName("needed_adv_xp", info_struct->get_xp_needed());// confirmed DoV
  727. if(version >= 60114)
  728. {
  729. // AoM ends up the debt_adv_xp field is the percentage of xp to the next level needed to advance out of debt (WHYY CANT THIS JUST BE A PERCENTAGE LIKE DOV!)
  730. float currentPctOfLevel = (float)info_struct->get_xp() / (float)info_struct->get_xp_needed();
  731. float neededPctAdvanceOutOfDebt = currentPctOfLevel + (info_struct->get_xp_debt() / 100.0f);
  732. packet->setDataByName("debt_adv_xp", neededPctAdvanceOutOfDebt);
  733. }
  734. else
  735. {
  736. packet->setDataByName("exp_debt", (int16)(info_struct->get_xp_debt()/10.0f));//95= 9500% //confirmed DoV
  737. }
  738. packet->setDataByName("current_trade_xp", info_struct->get_ts_xp());// confirmed DoV
  739. packet->setDataByName("needed_trade_xp", info_struct->get_ts_xp_needed());// confirmed DoV
  740. packet->setDataByName("debt_trade_xp", 0);//95= 9500% //confirmed DoV
  741. packet->setDataByName("server_bonus", 0);//confirmed DoV
  742. packet->setDataByName("adventure_vet_bonus", 145);//confirmed DoV
  743. packet->setDataByName("tradeskill_vet_bonus", 123);//confirmed DoV
  744. packet->setDataByName("recruit_friend", 110);// 110 = 11000% //confirmed DoV
  745. packet->setDataByName("recruit_friend_bonus", 0);//confirmed DoV
  746. packet->setDataByName("adventure_vitality", (int16)(player->GetXPVitality() * 10)); // a %%
  747. packet->setDataByName("adventure_vitality_yellow_arrow", info_struct->get_xp_yellow_vitality_bar()); //change info_struct to match struct
  748. packet->setDataByName("adventure_vitality_blue_arrow", info_struct->get_xp_blue_vitality_bar()); //change info_struct to match struct
  749. packet->setDataByName("tradeskill_vitality", 300); //300 = 30%
  750. packet->setDataByName("tradeskill_vitality_purple_arrow", 0);// dov confirmed
  751. packet->setDataByName("tradeskill_vitality_blue_arrow", 0);// dov confirmed
  752. packet->setDataByName("mentor_bonus", 50);//mentor_bonus //this converts wrong says mentor bonus enabled but earning 0
  753. packet->setDataByName("assigned_aa", player->GetAssignedAA());
  754. packet->setDataByName("max_aa", rule_manager.GetGlobalRule(R_Player, MaxAA)->GetInt16());
  755. packet->setDataByName("unassigned_aa", player->GetUnassignedAA()); // dov confirmed
  756. packet->setDataByName("aa_green_bar", 0);// dov confirmed
  757. packet->setDataByName("adv_xp_to_aa_xp_slider", 0); // aa slider max // dov confirmed
  758. packet->setDataByName("adv_xp_to_aa_xp_max", 100); // aa slider position // dov confirmed
  759. packet->setDataByName("aa_blue_bar", 0);// dov confirmed
  760. packet->setDataByName("bonus_achievement_xp", 0); // dov confirmed
  761. // packet->setDataByName("unknown_1096_12_MJ", 90);
  762. packet->setDataByName("items_found", 62);// dov confirmed
  763. packet->setDataByName("named_npcs_killed", 192);// dov confirmed
  764. packet->setDataByName("quests_completed", 670);// dov confirmed
  765. packet->setDataByName("exploration_events", 435);// dov confirmed
  766. packet->setDataByName("completed_collections", 144);// dov confirmed
  767. packet->setDataByName("unknown_1096_13_MJ", 80);//unknown_1096_13_MJ
  768. packet->setDataByName("unknown_1096_14_MJ", 50);//unknown_1096_14_MJ
  769. packet->setDataByName("coins_copper", info_struct->get_coin_copper());// dov confirmed
  770. packet->setDataByName("coins_silver", info_struct->get_coin_silver());// dov confirmed
  771. packet->setDataByName("coins_gold", info_struct->get_coin_gold());// dov confirmed
  772. packet->setDataByName("coins_plat", info_struct->get_coin_plat());// dov confirmed
  773. //packet->setDataByName("unknown_1096_15_MJ", 50);//unknown_1096_15_MJ
  774. //////Spell Effects go here, but are below
  775. //////Dettrimental effects go here, but are below
  776. packet->setDataByName("trauma_count", 45);// added with spells leave here for testing//dov confirmed
  777. packet->setDataByName("arcane_count", 255);// added with spells leave here for testing//dov confirmed
  778. packet->setDataByName("noxious_count", 47);// added with spells leave here for testing//dov confirmed
  779. packet->setDataByName("elemental_count", 255);// added with spells leave here for testing//dov confirmed
  780. packet->setDataByName("curse_count", 49);// added with spells leave here for testing//dov confirmed
  781. // packet->setDataByName("unknown_1096_17_MJ", 30);//unknown_1096_17_MJ
  782. //////Maintained effects go here, but are below
  783. Skill* skill = player->GetSkillByName("Swimming", false);
  784. float breath_modifier = rule_manager.GetGlobalRule(R_Player, SwimmingSkillMinBreathLength)->GetFloat();
  785. if(skill) {
  786. int32 max_val = 450;
  787. if(skill->max_val > 0)
  788. max_val = skill->max_val;
  789. float diff = (float)(skill->current_val + player->GetStat(ITEM_STAT_SWIMMING)) / (float)max_val;
  790. float max_breath_mod = rule_manager.GetGlobalRule(R_Player, SwimmingSkillMaxBreathLength)->GetFloat();
  791. float diff_mod = max_breath_mod * diff;
  792. if(diff_mod > max_breath_mod)
  793. breath_modifier = max_breath_mod;
  794. else if(diff_mod > breath_modifier)
  795. breath_modifier = diff_mod;
  796. }
  797. packet->setDataByName("breath", breath_modifier);
  798. //packet->setDataByName("unknown_1096_18_MJ", 1000);//16880
  799. packet->setDataByName("melee_pri_dmg_min", player->GetPrimaryWeaponMinDamage());// dov confirmed
  800. packet->setDataByName("melee_pri_dmg_max", player->GetPrimaryWeaponMaxDamage());// dov confirmed
  801. packet->setDataByName("melee_sec_dmg_min", player->GetSecondaryWeaponMinDamage());// dov confirmed
  802. packet->setDataByName("melee_sec_dmg_max", player->GetSecondaryWeaponMaxDamage());// dov confirmed // this is off when using 2 handed weapon
  803. packet->setDataByName("ranged_dmg_min", player->GetRangedWeaponMinDamage());// dov confirmed
  804. packet->setDataByName("ranged_dmg_max", player->GetRangedWeaponMaxDamage());// dov confirmed
  805. if (info_struct->get_attackspeed() > 0) {
  806. packet->setDataByName("melee_pri_delay", (((float)player->GetPrimaryWeaponDelay() * 1.33) / player->CalculateAttackSpeedMod()) * .001);// dov confirmed
  807. packet->setDataByName("melee_sec_delay", (((float)player->GetSecondaryWeaponDelay() * 1.33) / player->CalculateAttackSpeedMod()) * .001);// dov confirmed
  808. packet->setDataByName("ranged_delay", (((float)player->GetRangeWeaponDelay() * 1.33) / player->CalculateAttackSpeedMod()) * .001);// dov confirmed
  809. }
  810. else {
  811. packet->setDataByName("melee_pri_delay", (float)player->GetPrimaryWeaponDelay() * .001);// dov confirmed
  812. packet->setDataByName("melee_sec_delay", (float)player->GetSecondaryWeaponDelay() * .001);// dov confirmed
  813. packet->setDataByName("ranged_delay", (float)player->GetRangeWeaponDelay() * .001);// dov confirmed
  814. }
  815. //packet->setDataByName("unknown_1096_18_MJ", 99);//unknown_1096_19a_MJ
  816. //packet->setDataByName("unknown_1096_18_MJ", 98);//unknown_1096_19b_MJ
  817. //packet->setDataByName("unknown_1096_18_MJ", 97);//unknown_1096_19c_MJ
  818. //packet->setDataByName("unknown_1096_18_MJ", 96);//unknown_1096_19d_MJ
  819. packet->setDataByName("ability_mod_pve", info_struct->get_ability_modifier());// dov confirmed
  820. packet->setDataByName("base_melee_crit", 85);//85 = 8500% dov confirmed
  821. packet->setDataByName("base_spell_crit", 84);// dov confirmed
  822. packet->setDataByName("base_taunt_crit", 83);// dov confirmed
  823. packet->setDataByName("base_heal_crit", 82);// dov confirmed
  824. packet->setDataByName("flags", info_struct->get_flags());
  825. packet->setDataByName("flags2", info_struct->get_flags2());
  826. if (version == 546) {
  827. if (player->get_character_flag(CF_ANONYMOUS))
  828. packet->setDataByName("flags_anonymous", 1);
  829. if (player->get_character_flag(CF_ROLEPLAYING))
  830. packet->setDataByName("flags_roleplaying", 1);
  831. if (player->get_character_flag(CF_AFK))
  832. packet->setDataByName("flags_afk", 1);
  833. if (player->get_character_flag(CF_LFG))
  834. packet->setDataByName("flags_lfg", 1);
  835. if (player->get_character_flag(CF_LFW))
  836. packet->setDataByName("flags_lfw", 1);
  837. if (!player->get_character_flag(CF_HIDE_HOOD) && !player->get_character_flag(CF_HIDE_HELM))
  838. packet->setDataByName("flags_show_hood", 1);
  839. if (player->get_character_flag(CF_SHOW_ILLUSION))
  840. packet->setDataByName("flags_show_illusion_form", 1);
  841. if (player->get_character_flag(CF_ALLOW_DUEL_INVITES))
  842. packet->setDataByName("flags_show_duel_invites", 1);
  843. if (player->get_character_flag(CF_ALLOW_TRADE_INVITES))
  844. packet->setDataByName("flags_show_trade_invites", 1);
  845. if (player->get_character_flag(CF_ALLOW_GROUP_INVITES))
  846. packet->setDataByName("flags_show_group_invites", 1);
  847. if (player->get_character_flag(CF_ALLOW_RAID_INVITES))
  848. packet->setDataByName("flags_show_raid_invites", 1);
  849. if (player->get_character_flag(CF_ALLOW_GUILD_INVITES))
  850. packet->setDataByName("flags_show_guild_invites", 1);
  851. }
  852. //unknown_1096_20_MJ
  853. //unknown_1096_21_MJ
  854. //unknown_1096_22_MJ
  855. //unknown_1096_23_MJ
  856. packet->setDataByName("haste", info_struct->get_haste());// dov confirmed
  857. //unknown_1096_24_MJ
  858. //unknown_1096_25_MJ
  859. //unknown_1096_26_MJ
  860. packet->setDataByName("drunk", info_struct->get_drunk());// dov confirmed
  861. //unknown_1096_27_MJ
  862. packet->setDataByName("hate_mod", info_struct->get_hate_mod());// dov confirmed
  863. packet->setDataByName("adventure_effects_bonus", 55);// NEED an adventure_effects_bonus// dov confirmed
  864. packet->setDataByName("tradeskill_effects_bonus", 56);// NEED an tradeskill_effects_bonus// dov confirmed
  865. //unknown_1096_28_MJ
  866. packet->setDataByName("dps", info_struct->get_dps());// dov confirmed
  867. //unknown_1096_29_MJ
  868. packet->setDataByName("melee_ae", info_struct->get_melee_ae());// dov confirmed
  869. packet->setDataByName("multi_attack", info_struct->get_multi_attack());// dov confirmed
  870. packet->setDataByName("spell_multi_attack", info_struct->get_spell_multi_attack());// dov confirmed
  871. //unknown_1096_30_MJ
  872. packet->setDataByName("block_chance", info_struct->get_block_chance());// dov confirmed
  873. //unknown_1096_31_MJ
  874. packet->setDataByName("crit_chance", info_struct->get_crit_chance());// dov confirmed
  875. //unknown_1096_32_MJ
  876. packet->setDataByName("crit_bonus", info_struct->get_crit_bonus());// dov confirmed
  877. packet->setDataByName("potency", info_struct->get_potency());//info_struct->get_potency);// dov confirmed
  878. //unknown_1096_33_MJ
  879. packet->setDataByName("reuse_speed", info_struct->get_reuse_speed());// dov confirmed
  880. packet->setDataByName("recovery_speed", info_struct->get_recovery_speed());// dov confirmed
  881. packet->setDataByName("casting_speed", info_struct->get_casting_speed());// dov confirmed
  882. packet->setDataByName("spell_reuse_speed", info_struct->get_spell_reuse_speed());// dov confirmed
  883. //unknown_1096_34_MJ
  884. packet->setDataByName("strikethrough", info_struct->get_strikethrough());//dov confirmed
  885. //unknown_1096_35_MJ
  886. packet->setDataByName("accuracy", info_struct->get_accuracy());//dov confirmed
  887. //unknown_1096_36_MJ
  888. packet->setDataByName("critical_mit", info_struct->get_critical_mitigation());//dov /confirmed
  889. //unknown_1096_37_MJ
  890. //toughness_resist_crit_pvp
  891. //unknown_1096_38_MJ
  892. ((Entity*)player)->MStats.lock();
  893. packet->setDataByName("durability_mod", player->stats[ITEM_STAT_DURABILITY_MOD]);// dov confirmed
  894. packet->setDataByName("durability_add", player->stats[ITEM_STAT_DURABILITY_ADD]);// dov confirmed
  895. packet->setDataByName("progress_mod", player->stats[ITEM_STAT_PROGRESS_MOD]);// dov confirmed
  896. packet->setDataByName("progress_add", player->stats[ITEM_STAT_PROGRESS_ADD]);// dov confirmed
  897. packet->setDataByName("success_mod", player->stats[ITEM_STAT_SUCCESS_MOD]);// dov confirmed
  898. packet->setDataByName("crit_success_mod", player->stats[ITEM_STAT_CRIT_SUCCESS_MOD]);// dov confirmed
  899. ((Entity*)player)->MStats.unlock();
  900. //unknown_1096_39_MJ
  901. /////GRoup Members
  902. //unknown_1096_40_MJ
  903. //unknown_1096_41_MJ
  904. if (version <= 283 && info_struct->get_pet_id() == 0xFFFFFFFF)
  905. packet->setDataByName("pet_id", 0);
  906. else {
  907. packet->setDataByName("pet_id", info_struct->get_pet_id());
  908. char pet_name[32];
  909. strncpy(pet_name, info_struct->get_pet_name().c_str(), 32);
  910. packet->setDataByName("pet_name", pet_name);
  911. }
  912. //unknown_1096_42_MJ
  913. packet->setDataByName("pet_health_pct", info_struct->get_pet_health_pct());
  914. packet->setDataByName("pet_power_pct", info_struct->get_pet_power_pct());
  915. //unknown_1096_43_MJ
  916. packet->setDataByName("pet_movement", info_struct->get_pet_movement());
  917. packet->setDataByName("pet_behavior", info_struct->get_pet_behavior());
  918. packet->setDataByName("rain", info_struct->get_rain());
  919. packet->setDataByName("rain2", info_struct->get_wind()); //-102.24);
  920. packet->setDataByName("status_points", info_struct->get_status_points());
  921. packet->setDataByName("guild_status", 888888);
  922. //unknown_1096_44_MJ
  923. if (house_zone_id > 0){
  924. string house_name = database.GetZoneName(house_zone_id);
  925. if(house_name.length() > 0)
  926. packet->setDataByName("house_zone", house_name.c_str());
  927. }
  928. else
  929. packet->setDataByName("house_zone", "None");
  930. //unknown_1096_45_MJ
  931. if (bind_zone_id > 0){
  932. string bind_name = database.GetZoneName(bind_zone_id);
  933. if(bind_name.length() > 0)
  934. packet->setDataByName("bind_zone", bind_name.c_str());
  935. }
  936. else
  937. packet->setDataByName("bind_zone", "None");
  938. ((Entity*)player)->MStats.lock();
  939. packet->setDataByName("rare_harvest_chance", player->stats[ITEM_STAT_RARE_HARVEST_CHANCE]);
  940. packet->setDataByName("max_crafting", player->stats[ITEM_STAT_MAX_CRAFTING]);
  941. packet->setDataByName("component_refund", player->stats[ITEM_STAT_COMPONENT_REFUND]);
  942. packet->setDataByName("ex_durability_mod", player->stats[ITEM_STAT_EX_DURABILITY_MOD]);
  943. packet->setDataByName("ex_durability_add", player->stats[ITEM_STAT_EX_DURABILITY_ADD]);
  944. packet->setDataByName("ex_crit_success_mod", player->stats[ITEM_STAT_EX_CRIT_SUCCESS_MOD]);
  945. packet->setDataByName("ex_crit_failure_mod", player->stats[ITEM_STAT_EX_CRIT_FAILURE_MOD]);
  946. packet->setDataByName("ex_progress_mod", player->stats[ITEM_STAT_EX_PROGRESS_MOD]);
  947. packet->setDataByName("ex_progress_add", player->stats[ITEM_STAT_EX_PROGRESS_ADD]);
  948. packet->setDataByName("ex_success_mod", player->stats[ITEM_STAT_EX_SUCCESS_MOD]);
  949. ((Entity*)player)->MStats.unlock();
  950. packet->setDataByName("flurry", info_struct->get_flurry());
  951. packet->setDataByName("unknown153", 153);
  952. packet->setDataByName("bountiful_harvest", 0); // need bountiful harvest
  953. packet->setDataByName("unknown156", 156);
  954. packet->setDataByName("unknown157", 157);
  955. packet->setDataByName("unknown159", 159);
  956. packet->setDataByName("unknown160", 160);
  957. packet->setDataByName("unknown163", 163);
  958. packet->setDataByName("unknown168", 168);
  959. packet->setDataByName("decrease_falling_dmg", 169);
  960. info_struct->set_max_weight(200);
  961. //packet->setDataByName("auto_attack", 1);
  962. //492
  963. if (version <= 546) {
  964. packet->setDataByName("exp_yellow", info_struct->get_xp_yellow() / 10);
  965. packet->setDataByName("exp_blue", info_struct->get_xp_blue()/10);
  966. }
  967. else {
  968. packet->setDataByName("exp_yellow", info_struct->get_xp_yellow());
  969. packet->setDataByName("exp_blue", info_struct->get_xp_blue());
  970. }
  971. if (version <= 546) {
  972. packet->setDataByName("tradeskill_exp_yellow", info_struct->get_tradeskill_exp_yellow() / 10);
  973. packet->setDataByName("tradeskill_exp_blue", info_struct->get_tradeskill_exp_blue() / 10);
  974. }
  975. else {
  976. packet->setDataByName("tradeskill_exp_yellow", info_struct->get_tradeskill_exp_yellow());
  977. packet->setDataByName("tradeskill_exp_blue", info_struct->get_tradeskill_exp_blue());
  978. }
  979. packet->setDataByName("attack", info_struct->get_cur_attack());
  980. packet->setDataByName("attack_base", info_struct->get_attack_base());
  981. packet->setDataByName("absorb", info_struct->get_absorb());
  982. packet->setDataByName("mitigation_skill1", info_struct->get_mitigation_skill1());
  983. packet->setDataByName("mitigation_skill2", info_struct->get_mitigation_skill2());
  984. packet->setDataByName("mitigation_skill3", info_struct->get_mitigation_skill3());
  985. packet->setDataByName("mitigation_max", info_struct->get_max_mitigation());
  986. packet->setDataByName("savagery", 250);
  987. packet->setDataByName("max_savagery", 500);
  988. packet->setDataByName("savagery_level", 1);
  989. packet->setDataByName("max_savagery_level", 5);
  990. packet->setDataByName("dissonance", 5000);
  991. packet->setDataByName("max_dissonance", 10000);
  992. packet->setDataByName("mitigation_cur2", info_struct->get_cur_mitigation());
  993. packet->setDataByName("mitigation_max2", info_struct->get_max_mitigation());
  994. packet->setDataByName("mitigation_base2", info_struct->get_mitigation_base());
  995. packet->setDataByName("weight", info_struct->get_weight());
  996. packet->setDataByName("max_weight", info_struct->get_max_weight());
  997. packet->setDataByName("unknownint32a", 777777);
  998. packet->setDataByName("unknownint32b", 666666);
  999. packet->setDataByName("mitigation2_cur", 2367);
  1000. packet->setDataByName("uncontested_riposte", info_struct->get_uncontested_riposte());
  1001. packet->setDataByName("uncontested_dodge", info_struct->get_uncontested_dodge());
  1002. packet->setDataByName("uncontested_parry", info_struct->get_uncontested_parry()); //????
  1003. packet->setDataByName("uncontested_riposte_pve", 0); //????
  1004. packet->setDataByName("uncontested_parry_pve", 0); //????
  1005. packet->setDataByName("total_prestige_points", player->GetPrestigeAA());
  1006. packet->setDataByName("unassigned_prestige_points", player->GetUnassignedPretigeAA());
  1007. packet->setDataByName("total_tradeskill_points", player->GetTradeskillAA());
  1008. packet->setDataByName("unassigned_tradeskill_points", player->GetUnassignedTradeskillAA());
  1009. packet->setDataByName("total_tradeskill_prestige_points", player->GetTradeskillPrestigeAA());
  1010. packet->setDataByName("unassigned_tradeskill_prestige_points", player->GetUnassignedTradeskillPrestigeAA());
  1011. /*packet->setDataByName("unknown13", 201, 0);
  1012. packet->setDataByName("unknown13", 201, 1);
  1013. packet->setDataByName("unknown13", 234, 2);
  1014. packet->setDataByName("unknown13", 201, 3);
  1015. packet->setDataByName("unknown13", 214, 4);
  1016. packet->setDataByName("unknown13", 234, 5);
  1017. packet->setDataByName("unknown13", 234, 6);
  1018. packet->setDataByName("unknown14", 78);
  1019. */
  1020. //packet->setDataByName("unknown23", 1, 146);
  1021. //packet->setDataByName("unknown24", 0xFF, 42);
  1022. //packet->setDataByName("unknown24", 0xFF, 46);
  1023. // unknown14c = percent aa exp to next level
  1024. packet->setDataByName("unknown14d", 100, 0);
  1025. packet->setDataByName("unknown20", 1084227584, 72);
  1026. //packet->setDataByName("unknown16", 0xFFFFFFFF, 4);
  1027. //packet->setDataByName("unknown15b", 9911);
  1028. packet->setDataByName("unknown15c", 200);
  1029. //packet->setDataByName("unknown15", 100, 10);
  1030. /*packet->setDataByName("unknown19", 1);
  1031. packet->setDataByName("unknown19", 3, 1);
  1032. packet->setDataByName("unknown19", 1074301064, 2);
  1033. packet->setDataByName("unknown19", 1, 3);
  1034. packet->setDataByName("unknown19", 3, 4);
  1035. packet->setDataByName("unknown19", 1074301064, 5);
  1036. packet->setDataByName("unknown19", 6, 6);
  1037. packet->setDataByName("unknown19", 14, 7);
  1038. packet->setDataByName("unknown19", 1083179008, 8);*/
  1039. player->SetGroupInformation(packet);
  1040. //packet->setDataByName("unknown20", 1, 107);
  1041. //packet->setDataByName("unknown20", 1, 108);
  1042. //packet->setDataByName("unknown20", 1, 109);
  1043. //packet->setDataByName("unknown20", 1, 110);
  1044. //packet->setDataByName("unknown20", 1, 111);
  1045. //packet->setDataByName("unknown20b", 255);
  1046. //packet->setDataByName("unknown20b", 255, 1);
  1047. //packet->setDataByName("unknown20b", 255, 2);
  1048. //packet->setDataByName("in_combat", 32768);
  1049. //make name flash red
  1050. /*packet->setDataByName("unknown20", 8);
  1051. packet->setDataByName("unknown20", 38, 70);
  1052. packet->setDataByName("unknown20", 17, 77);
  1053. packet->setDataByName("unknown20", 1, 112); //melee stats and such
  1054. packet->setDataByName("unknown20", 1, 113);
  1055. packet->setDataByName("unknown20", 1, 114);
  1056. packet->setDataByName("unknown20", 1, 115);
  1057. packet->setDataByName("unknown20", 4294967295, 309);
  1058. packet->setDataByName("unknown22", 2, 4);
  1059. packet->setDataByName("unknown23", 2, 29);
  1060. */
  1061. //packet->setDataByName("unknown20b", 1, i); // pet bar in here
  1062. // for(int i=0;i<19;i++)
  1063. // packet->setDataByName("unknown7", 257, i);
  1064. //packet->setDataByName("unknown21", info_struct->rain, 2);
  1065. /*packet->setDataByName("unknown22", 3, 4);
  1066. packet->setDataByName("unknown23", 3, 161);
  1067. packet->setDataByName("unknown20", 103);
  1068. packet->setDataByName("unknown20", 1280, 70);
  1069. packet->setDataByName("unknown20", 9, 71);
  1070. packet->setDataByName("unknown20", 5, 72);
  1071. packet->setDataByName("unknown20", 4294967271, 73);
  1072. packet->setDataByName("unknown20", 5, 75);
  1073. packet->setDataByName("unknown20", 1051, 77);
  1074. packet->setDataByName("unknown20", 3, 78);
  1075. packet->setDataByName("unknown20", 6, 104);
  1076. packet->setDataByName("unknown20", 1, 105);
  1077. packet->setDataByName("unknown20", 20, 106);
  1078. packet->setDataByName("unknown20", 3, 107);
  1079. packet->setDataByName("unknown20", 1, 108);
  1080. packet->setDataByName("unknown20", 1, 109);
  1081. packet->setDataByName("unknown20", 4278190080, 494);
  1082. packet->setDataByName("unknown20b", 255);
  1083. packet->setDataByName("unknown20b", 255, 1);
  1084. packet->setDataByName("unknown20b", 255, 2);
  1085. packet->setDataByName("unknown20", 50, 75);
  1086. */
  1087. /*packet->setDataByName("unknown199a", 843);// 25);
  1088. //packet->setDataByName("unknown199b", 844);// 30);
  1089. //packet->setDataByName("unknown199c", 845);// 45);
  1090. //packet->setDataByName("unknown199d", 846);// 55);
  1091. packet->setDataByName("unknown37", 537);
  1092. packet->setDataByName("unknown38", 538);
  1093. packet->setDataByName("unknown39", 539);
  1094. packet->setDataByName("unknown40", 540);
  1095. packet->setDataByName("unknown41", 541);
  1096. packet->setDataByName("unknown42", 542);
  1097. packet->setDataByName("unknown43", 543);
  1098. packet->setDataByName("unknown44", 544);
  1099. packet->setDataByName("ability_mod_pvp", 542);
  1100. packet->setDataByName("unknown43", 543);
  1101. packet->setDataByName("unknown44", 544);
  1102. packet->setDataByName("unknown45", 645);
  1103. packet->setDataByName("unknown46", 646);
  1104. packet->setDataByName("unknown47", 647);
  1105. packet->setDataByName("unknown48", 648);
  1106. packet->setDataByName("unknown49", 649);
  1107. packet->setDataByName("unknown50", 650);
  1108. packet->setDataByName("unknown51", 651);
  1109. packet->setDataByName("unknown52", 652);
  1110. packet->setDataByName("unknown53", 653);
  1111. packet->setDataByName("unknown54", 654);
  1112. packet->setDataByName("unknown55", 655);
  1113. packet->setDataByName("unknown56", 656);
  1114. packet->setDataByName("unknown57", 657);
  1115. packet->setDataByName("unknown58", 658);
  1116. packet->setDataByName("unknown59", 659);
  1117. packet->setDataByName("unknown60", 660);
  1118. */
  1119. packet->setDataByName("in_combat_movement_speed", 125);
  1120. packet->setDataByName("increase_max_power", 127);
  1121. packet->setDataByName("increase_max_power2", 128);
  1122. //129 does not exist
  1123. /* packet->setDataByName("unknown130", 130);
  1124. packet->setDataByName("unknown132", 132);
  1125. packet->setDataByName("unknown133", 133);
  1126. packet->setDataByName("unknown137", 137);
  1127. packet->setDataByName("unknown138", 138);
  1128. packet->setDataByName("unknown139", 139);
  1129. packet->setDataByName("unknown141", 141);
  1130. packet->setDataByName("unknown142", 142);
  1131. packet->setDataByName("unknown144", 144);
  1132. packet->setDataByName("unknown147", 147);
  1133. packet->setDataByName("unknown148", 148);
  1134. packet->setDataByName("unknown170", 170);
  1135. packet->setDataByName("unknown171", 171);
  1136. packet->setDataByName("unknown172", 172);
  1137. packet->setDataByName("unknown173", 173);
  1138. packet->setDataByName("unknown174", 174);
  1139. packet->setDataByName("unknown175", 175);
  1140. packet->setDataByName("unknown176", 176);
  1141. packet->setDataByName("unknown177", 177);
  1142. packet->setDataByName("loot_coin", 178);
  1143. packet->setDataByName("mitigation_increase", 179);
  1144. packet->setDataByName("unknown180", 180);
  1145. packet->setDataByName("unknown182", 182);
  1146. packet->setDataByName("unknown184", 184);
  1147. packet->setDataByName("unknown185", 185);
  1148. packet->setDataByName("unknown186", 186);
  1149. packet->setDataByName("unknown187", 187);
  1150. packet->setDataByName("unknown188", 188);
  1151. packet->setDataByName("unknown189", 189);
  1152. packet->setDataByName("unknown190", 190);
  1153. packet->setDataByName("unknown191", 191);
  1154. packet->setDataByName("unknown192", 192);
  1155. packet->setDataByName("unknown193", 193);
  1156. packet->setDataByName("unknown194", 194);
  1157. packet->setDataByName("unknown195", 195);
  1158. packet->setDataByName("unknown196", 196);
  1159. packet->setDataByName("unknown197", 197);
  1160. packet->setDataByName("unknown198", 198);
  1161. packet->setDataByName("unknown199", 199);
  1162. packet->setDataByName("unknown200", 200);
  1163. packet->setDataByName("unknown201", 201);
  1164. packet->setDataByName("unknown202", 202);
  1165. packet->setDataByName("unknown203", 203);
  1166. packet->setDataByName("unknown204", 204);
  1167. packet->setDataByName("unknown205", 205);
  1168. packet->setDataByName("unknown206", 206);
  1169. packet->setDataByName("unknown207", 207);
  1170. packet->setDataByName("unknown208", 208);
  1171. packet->setDataByName("unknown209", 209);
  1172. packet->setDataByName("unknown210", 210);
  1173. packet->setDataByName("unknown211", 211);
  1174. packet->setDataByName("unknown212", 212);
  1175. packet->setDataByName("unknown213", 213);
  1176. packet->setDataByName("unknown214", 214);
  1177. packet->setDataByName("unknown215", 215);
  1178. packet->setDataByName("unknown216", 216);
  1179. packet->setDataByName("unknown217", 217);
  1180. packet->setDataByName("unknown218", 218);
  1181. packet->setDataByName("unknown219", 219);
  1182. packet->setDataByName("unknown220", 220);
  1183. packet->setDataByName("unknown221", 221);
  1184. packet->setDataByName("unknown222", 222);
  1185. packet->setDataByName("unknown223", 223);
  1186. packet->setDataByName("unknown224", 224);
  1187. packet->setDataByName("unknown225", 225);
  1188. packet->setDataByName("unknown226", 226);
  1189. packet->setDataByName("unknown227", 227);
  1190. packet->setDataByName("unknown228", 228);
  1191. packet->setDataByName("unknown229", 229);
  1192. packet->setDataByName("unknown230", 230);
  1193. packet->setDataByName("unknown231", 231);
  1194. packet->setDataByName("unknown232", 232);
  1195. packet->setDataByName("unknown233", 233);
  1196. packet->setDataByName("unknown234", 234);
  1197. packet->setDataByName("unknown235", 235);
  1198. packet->setDataByName("unknown236", 236);
  1199. packet->setDataByName("unknown237", 237);
  1200. packet->setDataByName("unknown238", 238);
  1201. packet->setDataByName("unknown239", 239);
  1202. packet->setDataByName("unknown240", 240);
  1203. // Tradeskill stats
  1204. packet->setDataByName("unknown383", 383);
  1205. packet->setDataByName("unknown384", 384);
  1206. packet->setDataByName("unknown385", 385);
  1207. packet->setDataByName("unknown386", 386);
  1208. packet->setDataByName("unknown387", 387);
  1209. packet->setDataByName("unknown388", 388);
  1210. packet->setDataByName("unknown389", 389);
  1211. packet->setDataByName("unknown390", 390);
  1212. packet->setDataByName("unknown391", 391);
  1213. packet->setDataByName("unknown392", 392);
  1214. packet->setDataByName("unknown393", 393);
  1215. packet->setDataByName("unknown394", 394);
  1216. packet->setDataByName("unknown395", 395);
  1217. packet->setDataByName("unknown396", 396);
  1218. packet->setDataByName("unknown397", 397);
  1219. packet->setDataByName("unknown398", 398);
  1220. */
  1221. packet->setDataByName("vision", info_struct->get_vision());
  1222. packet->setDataByName("breathe_underwater", info_struct->get_breathe_underwater());
  1223. int32 expireTimestamp = 0;
  1224. Spawn* maintained_target = 0;
  1225. player->GetSpellEffectMutex()->readlock(__FUNCTION__, __LINE__);
  1226. player->GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  1227. for (int i = 0; i < 45; i++) {
  1228. if (i < 30) {
  1229. maintained_target = player->GetZone()->GetSpawnByID(info_struct->maintained_effects[i].target);
  1230. packet->setSubstructDataByName("maintained_effects", "name", info_struct->maintained_effects[i].name, i, 0);
  1231. if (maintained_target)
  1232. packet->setSubstructDataByName("maintained_effects", "target", player->GetIDWithPlayerSpawn(maintained_target), i, 0);
  1233. packet->setSubstructDataByName("maintained_effects", "target_type", info_struct->maintained_effects[i].target_type, i, 0);
  1234. packet->setSubstructDataByName("maintained_effects", "spell_id", info_struct->maintained_effects[i].spell_id, i, 0);
  1235. packet->setSubstructDataByName("maintained_effects", "slot_pos", info_struct->maintained_effects[i].slot_pos, i, 0);
  1236. packet->setSubstructDataByName("maintained_effects", "icon", info_struct->maintained_effects[i].icon, i, 0);
  1237. packet->setSubstructDataByName("maintained_effects", "icon_type", info_struct->maintained_effects[i].icon_backdrop, i, 0);
  1238. packet->setSubstructDataByName("maintained_effects", "conc_used", info_struct->maintained_effects[i].conc_used, i, 0);
  1239. packet->setSubstructDataByName("maintained_effects", "unknown3", 1, i, 0);
  1240. packet->setSubstructDataByName("maintained_effects", "total_time", info_struct->maintained_effects[i].total_time, i, 0);
  1241. expireTimestamp = info_struct->maintained_effects[i].expire_timestamp;
  1242. if (expireTimestamp == 0xFFFFFFFF)
  1243. expireTimestamp = 0;
  1244. packet->setSubstructDataByName("maintained_effects", "expire_timestamp", expireTimestamp, i, 0);
  1245. }
  1246. else if (version < 942)//version 942 added 15 additional spell effect slots
  1247. break;
  1248. packet->setSubstructDataByName("spell_effects", "spell_id", info_struct->spell_effects[i].spell_id, i, 0);
  1249. /*if(info_struct->spell_effects[i].spell_id > 0 && info_struct->spell_effects[i].spell_id < 0xFFFFFFFF)
  1250. packet->setSubstructDataByName("spell_effects", "unknown2", 514, i, 0);*/
  1251. packet->setSubstructDataByName("spell_effects", "total_time", info_struct->spell_effects[i].total_time, i, 0);
  1252. expireTimestamp = info_struct->spell_effects[i].expire_timestamp;
  1253. if (expireTimestamp == 0xFFFFFFFF)
  1254. expireTimestamp = 0;
  1255. packet->setSubstructDataByName("spell_effects", "expire_timestamp", expireTimestamp, i, 0);
  1256. packet->setSubstructDataByName("spell_effects", "icon", info_struct->spell_effects[i].icon, i, 0);
  1257. packet->setSubstructDataByName("spell_effects", "icon_type", info_struct->spell_effects[i].icon_backdrop, i, 0);
  1258. if(info_struct->spell_effects[i].spell && info_struct->spell_effects[i].spell->spell && info_struct->spell_effects[i].spell->spell->GetSpellData()->friendly_spell == 1)
  1259. packet->setSubstructDataByName("spell_effects", "cancellable", 1, i);
  1260. }
  1261. player->GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  1262. player->GetSpellEffectMutex()->releasereadlock(__FUNCTION__, __LINE__);
  1263. int8 det_count = 0;
  1264. //Send detriment counts as 255 if all dets of that type are incurable
  1265. det_count = player->GetTraumaCount();
  1266. if (det_count > 0) {
  1267. if (!player->HasCurableDetrimentType(DET_TYPE_TRAUMA))
  1268. det_count = 255;
  1269. }
  1270. packet->setDataByName("trauma_count", det_count);
  1271. det_count = player->GetArcaneCount();
  1272. if (det_count > 0) {
  1273. if (!player->HasCurableDetrimentType(DET_TYPE_ARCANE))
  1274. det_count = 255;
  1275. }
  1276. packet->setDataByName("arcane_count", det_count);
  1277. det_count = player->GetNoxiousCount();
  1278. if (det_count > 0) {
  1279. if (!player->HasCurableDetrimentType(DET_TYPE_NOXIOUS))
  1280. det_count = 255;
  1281. }
  1282. packet->setDataByName("noxious_count", det_count);
  1283. det_count = player->GetElementalCount();
  1284. if (det_count > 0) {
  1285. if (!player->HasCurableDetrimentType(DET_TYPE_ELEMENTAL))
  1286. det_count = 255;
  1287. }
  1288. packet->setDataByName("elemental_count", det_count);
  1289. det_count = player->GetCurseCount();
  1290. if (det_count > 0) {
  1291. if (!player->HasCurableDetrimentType(DET_TYPE_CURSE))
  1292. det_count = 255;
  1293. }
  1294. packet->setDataByName("curse_count", det_count);
  1295. player->GetDetrimentMutex()->readlock(__FUNCTION__, __LINE__);
  1296. vector<DetrimentalEffects>* det_list = player->GetDetrimentalSpellEffects();
  1297. DetrimentalEffects det;
  1298. int32 i = 0;
  1299. for (i = 0; i < det_list->size(); i++) {
  1300. det = det_list->at(i);
  1301. packet->setSubstructDataByName("detrimental_spell_effects", "spell_id", det.spell_id, i);
  1302. packet->setSubstructDataByName("detrimental_spell_effects", "total_time", det.total_time, i);
  1303. packet->setSubstructDataByName("detrimental_spell_effects", "icon", det.icon, i);
  1304. packet->setSubstructDataByName("detrimental_spell_effects", "icon_type", det.icon_backdrop, i);
  1305. expireTimestamp = det.expire_timestamp;
  1306. if (expireTimestamp == 0xFFFFFFFF)
  1307. expireTimestamp = 0;
  1308. packet->setSubstructDataByName("detrimental_spell_effects", "expire_timestamp", expireTimestamp, i);
  1309. packet->setSubstructDataByName("detrimental_spell_effects", "unknown2", 2, i);
  1310. if (i == 30) {
  1311. if (version < 942)
  1312. break;
  1313. }
  1314. else if (i == 45)
  1315. break;
  1316. }
  1317. if (version < 942) {
  1318. while (i < 30) {
  1319. packet->setSubstructDataByName("detrimental_spell_effects", "spell_id", 0xFFFFFFFF, i);
  1320. i++;
  1321. }
  1322. }
  1323. else {
  1324. while (i < 45) {
  1325. packet->setSubstructDataByName("detrimental_spell_effects", "spell_id", 0xFFFFFFFF, i);
  1326. i++;
  1327. }
  1328. }
  1329. player->GetDetrimentMutex()->releasereadlock(__FUNCTION__, __LINE__);
  1330. // disabling as not in use right now
  1331. //packet->setDataByName("spirit_rank", 2);
  1332. //packet->setDataByName("spirit", 1);
  1333. //packet->setDataByName("spirit_progress", .67);
  1334. packet->setDataByName("combat_exp_enabled", 1);
  1335. /*for (int i = 0; i < 12; i++) {
  1336. packet->setSubstructDataByName("spell_effects", "spell_id", i + 1, i);
  1337. if (i % 2 == 0)
  1338. packet->setSubstructDataByName("spell_effects", "cancellable", 1, i);
  1339. }*/
  1340. int testa = 0x41;
  1341. int testb = 0x41;
  1342. //160-330
  1343. //0-250 (160-250) //top down view
  1344. //250-290 nothing
  1345. //290-330 //blocked view
  1346. //310-330 nothing
  1347. //1168: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 41 41 41 | .............AAA
  1348. //1184: 42 41 43 41 44 41 45 00 - 00 00 00 00 00 00 00 00 | BACADAE......... //blocked view
  1349. //1184: 00 41 41 41 42 41 43 00 - 00 00 00 00 00 00 00 00 | .AAABAC......... //blocked view
  1350. //1184: 00 41 41 41 41 00 00 00 - 00 00 00 00 00 00 00 00 | .AAAA........... //blocked view
  1351. //1184: 00 41 41 00 00 00 00 00 - 00 00 00 00 00 00 00 00 | .AA............. //blocked view
  1352. //1184: 00 41 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 | .AA............. //blocked view
  1353. //1184: 41 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 | .AA............. //blocked view 293
  1354. //1168: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 41 | ...............A //blocked view 292
  1355. //packet->setDataByName("screen_blur", 0); //1168: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 41 00 //blurred view
  1356. //packet->setDataByName("unknown18", testa, 295);
  1357. //packet->setDataByName("unknown18", testa, 296);
  1358. //packet->setDataByName("unknown18", testa, 297);
  1359. //300 pet junk
  1360. //492
  1361. /*for (int i = 300; i < 360; i++) {
  1362. packet->setDataByName("unknown19", testa, i);
  1363. testa++;
  1364. //packet->setDataByName("unknown19", 0xc3, i+1);
  1365. }*/
  1366. /*packet->setDataByName("pet_id", 5);
  1367. packet->setDataByName("pet_name", "Blah");
  1368. packet->setDataByName("pet_hp", .9);
  1369. packet->setDataByName("pet_power", .8);*/
  1370. /*packet->setDataByName("test7", 0x3f);
  1371. packet->setDataByName("test8", 0xc3);
  1372. packet->setDataByName("unknown17", 12);
  1373. packet->setDataByName("unknown17", 12, 1);
  1374. packet->setDataByName("unknown17", 12, 2);
  1375. packet->setDataByName("unknown17", 12, 3);*/
  1376. string* data = packet->serializeString();
  1377. int32 size = data->length();
  1378. /*uchar blah[] = { 0x31,0x02,0x00,0x00,0xff,0x4f,0x77,0x6b,0x65,0x65,0x63,0x65,0x87,0x61
  1379. ,0x67,0x68,0x1b,0x83,0x04,0x01,0x13,0x95,0x02,0x02,0x01,0x88,0x01,0x91,0x30,0x30
  1380. ,0xa2,0x01,0x30,0x84,0x30,0x8a,0x38,0x38,0xf0,0x17,0x01,0x17,0x9f,0x01,0x17,0x01
  1381. ,0x17,0x01,0x0a,0xd5,0x10,0x14,0x18,0x14,0xaa,0x14,0x10,0x14,0x95,0x18,0x14,0x14
  1382. ,0x09,0xd1,0x08,0x08,0x06,0x82,0x06,0x1a,0xd1,0x28,0x28,0x1e,0x8a,0x1e,0x01,0x1f
  1383. ,0x81,0x13,0x09,0x91,0x01,0x50,0x15,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff
  1384. ,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f
  1385. ,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff
  1386. ,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff
  1387. ,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f
  1388. ,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff
  1389. ,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff
  1390. ,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f
  1391. ,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff
  1392. ,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff
  1393. ,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x07,0x8f
  1394. ,0xff,0xff,0xff,0xff,0x07,0x8f,0xff,0xff,0xff,0xff,0x47,0x8f,0xff,0xff,0xff,0xff
  1395. ,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff
  1396. ,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f
  1397. ,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff
  1398. ,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86
  1399. ,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff
  1400. ,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff
  1401. ,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48
  1402. ,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff
  1403. ,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff
  1404. ,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff
  1405. ,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f
  1406. ,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff
  1407. ,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86
  1408. ,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff
  1409. ,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff
  1410. ,0xff,0xff,0xff,0x86,0xff,0xff,0x48,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x48
  1411. ,0x8f,0xff,0xff,0xff,0xff,0x86,0xff,0xff,0x0a,0x83,0xf0,0x41,0x7f,0x7f,0x7f,0x7f
  1412. ,0x3a,0xff,0xff,0xff,0xff,0xff,0x4e,0x6f,0x20,0x87,0x50,0x65,0x74,0x2d,0x9f,0x3f
  1413. ,0xc3,0x94,0xcb,0xc2,0x08,0x81,0x02 };*/
  1414. //size = sizeof(blah);
  1415. //packet->PrintPacket();
  1416. uchar* tmp = new uchar[size];
  1417. bool reverse = version > 283;
  1418. if (!changes) {
  1419. orig_packet = new uchar[size];
  1420. changes = new uchar[size];
  1421. memcpy(orig_packet, (uchar*)data->c_str(), size);
  1422. //DumpPacket(orig_packet, size);
  1423. size = Pack(tmp, orig_packet, size, size, version, reverse);
  1424. }
  1425. else {
  1426. memcpy(changes, (uchar*)data->c_str(), size);
  1427. if (modifyPos > 0) {
  1428. uchar* ptr2 = (uchar*)changes;
  1429. ptr2 += modifyPos - 1;
  1430. if (modifyValue > 0xFFFF) {
  1431. memcpy(ptr2, (uchar*)&modifyValue, 4);
  1432. }
  1433. else if (modifyValue > 0xFF) {
  1434. memcpy(ptr2, (uchar*)&modifyValue, 2);
  1435. }
  1436. else
  1437. memcpy(ptr2, (uchar*)&modifyValue, 1);
  1438. }
  1439. /*if (player->GetTempVariable("offset").length() > 0){
  1440. changes[atoul(player->GetTempVariable("offset").c_str())] = 0xF4;
  1441. changes[atoul(player->GetTempVariable("offset").c_str()) + 1] = 0x01;
  1442. }*/
  1443. Encode(changes, orig_packet, size);
  1444. if (modifyPos > 0) {
  1445. uchar* ptr2 = (uchar*)orig_packet;
  1446. if (modifyPos > 64)
  1447. ptr2 += modifyPos - 64;
  1448. int16 tmpsize = modifyPos + 128;
  1449. if (tmpsize > size)
  1450. tmpsize = size;
  1451. //DumpPacket(ptr2, tmpsize - modifyPos);
  1452. }
  1453. size = Pack(tmp, changes, size, size, version, reverse);
  1454. //DumpPacket(tmp, size);
  1455. }
  1456. if (version >= 546)
  1457. {
  1458. PacketStruct* control_packet = configReader.getStruct("WS_SetControlGhost", version);
  1459. if (control_packet) {
  1460. control_packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1461. control_packet->setDataByName("speed", player->GetSpeed());
  1462. control_packet->setDataByName("air_speed", player->GetAirSpeed());
  1463. control_packet->setDataByName("size", 0.51);
  1464. Client* client = player->GetZone()->GetClientBySpawn(player);
  1465. if (client)
  1466. client->QueuePacket(control_packet->serialize());
  1467. safe_delete(control_packet);
  1468. }
  1469. }
  1470. EQ2Packet* ret_packet = new EQ2Packet(OP_UpdateCharacterSheetMsg, tmp, size);
  1471. safe_delete(packet);
  1472. safe_delete_array(tmp);
  1473. return ret_packet;
  1474. }
  1475. return 0;
  1476. }
  1477. EQ2Packet* PlayerInfo::serializePet(int16 version) {
  1478. PacketStruct* packet = configReader.getStruct("WS_CharacterPet", version);
  1479. if(packet) {
  1480. Spawn* pet = 0;
  1481. pet = player->GetPet();
  1482. if (!pet)
  1483. pet = player->GetCharmedPet();
  1484. if (pet) {
  1485. packet->setDataByName("current_hp", pet->GetHP());
  1486. packet->setDataByName("max_hp", pet->GetTotalHP());
  1487. packet->setDataByName("base_hp", pet->GetTotalHPBase());
  1488. packet->setDataByName("current_power", pet->GetPower());
  1489. packet->setDataByName("max_power", pet->GetTotalPower());
  1490. packet->setDataByName("base_power", pet->GetTotalPowerBase());
  1491. packet->setDataByName("spawn_id", info_struct->get_pet_id());
  1492. packet->setDataByName("spawn_id2", info_struct->get_pet_id());
  1493. char pet_name[32];
  1494. strncpy(pet_name, info_struct->get_pet_name().c_str(), 32);
  1495. packet->setDataByName("name", pet_name);
  1496. packet->setDataByName("no_pet", pet_name);
  1497. if (version >= 57000) {
  1498. packet->setDataByName("current_power3", pet->GetPower());
  1499. packet->setDataByName("max_power3", pet->GetTotalPower());
  1500. packet->setDataByName("health_pct_tooltip", (double)info_struct->get_pet_health_pct());
  1501. packet->setDataByName("health_pct_bar", (double)info_struct->get_pet_health_pct());
  1502. }
  1503. else {
  1504. packet->setDataByName("health_pct_tooltip", info_struct->get_pet_health_pct());
  1505. packet->setDataByName("health_pct_bar", info_struct->get_pet_health_pct());
  1506. }
  1507. packet->setDataByName("power_pct_tooltip", info_struct->get_pet_power_pct());
  1508. packet->setDataByName("power_pct_bar", info_struct->get_pet_power_pct());
  1509. packet->setDataByName("unknown5", 255); // Hate % maybe
  1510. packet->setDataByName("movement", info_struct->get_pet_movement());
  1511. packet->setDataByName("behavior", info_struct->get_pet_behavior());
  1512. }
  1513. else {
  1514. packet->setDataByName("current_hp", 0);
  1515. packet->setDataByName("max_hp", 0);
  1516. packet->setDataByName("base_hp", 0);
  1517. packet->setDataByName("current_power", 0);
  1518. packet->setDataByName("max_power", 0);
  1519. packet->setDataByName("base_power", 0);
  1520. packet->setDataByName("spawn_id", 0);
  1521. packet->setDataByName("spawn_id2", 0xFFFFFFFF);
  1522. packet->setDataByName("name", "");
  1523. packet->setDataByName("no_pet", "No Pet");
  1524. packet->setDataByName("health_pct_tooltip", 0);
  1525. packet->setDataByName("health_pct_bar", 0);
  1526. packet->setDataByName("power_pct_tooltip", 0);
  1527. packet->setDataByName("power_pct_bar", 0);
  1528. packet->setDataByName("unknown5", 0);
  1529. packet->setDataByName("movement", 0);
  1530. packet->setDataByName("behavior", 0);
  1531. }
  1532. string* data = packet->serializeString();
  1533. int32 size = data->length();
  1534. uchar* tmp = new uchar[size];
  1535. // if this is the first time sending this packet create the buffers
  1536. if(!pet_changes){
  1537. pet_orig_packet = new uchar[size];
  1538. pet_changes = new uchar[size];
  1539. // copy the packet into the pet_orig_packet so we can xor against it in the future
  1540. memcpy(pet_orig_packet, (uchar*)data->c_str(), size);
  1541. // pack the packet, result ends up in tmp
  1542. size = Pack(tmp, (uchar*)data->c_str(), size, size, version);
  1543. }
  1544. else{
  1545. // copy the packet into pet_changes
  1546. memcpy(pet_changes, (uchar*)data->c_str(), size);
  1547. // XOR's the packet to the original, stores the new packet in the orig packet (will xor against that for the next update)
  1548. // puts the xor packet into pet_changes.
  1549. Encode(pet_changes, pet_orig_packet, size);
  1550. // Pack the pet_changes packet, will put the packed size at the start, result ends up in tmp
  1551. size = Pack(tmp, pet_changes, size, size, version);
  1552. }
  1553. // Create the packet that we will send
  1554. EQ2Packet* ret_packet = new EQ2Packet(OP_CharacterPet, tmp, size+4);
  1555. // Clean up
  1556. safe_delete_array(tmp);
  1557. safe_delete(packet);
  1558. // Return the packet that will be sent to the client
  1559. return ret_packet;
  1560. }
  1561. return 0;
  1562. }
  1563. bool Player::DamageEquippedItems(int8 amount, Client* client) {
  1564. bool ret = false;
  1565. int8 item_type;
  1566. Item* item = 0;
  1567. equipment_list.MEquipmentItems.readlock(__FUNCTION__, __LINE__);
  1568. for(int8 i=0;i<NUM_SLOTS;i++){
  1569. item = equipment_list.items[i];
  1570. if(item) {
  1571. item_type = item->generic_info.item_type;
  1572. if (item->details.item_id > 0 && item_type != ITEM_TYPE_FOOD && item_type != ITEM_TYPE_BAUBLE && item_type != ITEM_TYPE_THROWN &&
  1573. !item->CheckFlag2(INDESTRUCTABLE)){
  1574. ret = true;
  1575. if((item->generic_info.condition - amount) > 0)
  1576. item->generic_info.condition -= amount;
  1577. else
  1578. item->generic_info.condition = 0;
  1579. item->save_needed = true;
  1580. if (client)
  1581. client->QueuePacket(item->serialize(client->GetVersion(), false, this));
  1582. }
  1583. }
  1584. }
  1585. equipment_list.MEquipmentItems.releasereadlock(__FUNCTION__, __LINE__);
  1586. return ret;
  1587. }
  1588. int8 Player::ConvertSlotToClient(int8 slot, int16 version) {
  1589. if (version <= 283) {
  1590. if (slot == EQ2_FOOD_SLOT)
  1591. slot = EQ2_ORIG_FOOD_SLOT;
  1592. else if (slot == EQ2_DRINK_SLOT)
  1593. slot = EQ2_ORIG_DRINK_SLOT;
  1594. else if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT)
  1595. slot -= 1;
  1596. }
  1597. else if (version <= 546) {
  1598. if (slot == EQ2_FOOD_SLOT)
  1599. slot = EQ2_DOF_FOOD_SLOT;
  1600. else if (slot == EQ2_DRINK_SLOT)
  1601. slot = EQ2_DOF_DRINK_SLOT;
  1602. else if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT)
  1603. slot -= 1;
  1604. }
  1605. return slot;
  1606. }
  1607. int8 Player::ConvertSlotFromClient(int8 slot, int16 version) {
  1608. if (version <= 283) {
  1609. if (slot == EQ2_ORIG_FOOD_SLOT)
  1610. slot = EQ2_FOOD_SLOT;
  1611. else if (slot == EQ2_ORIG_DRINK_SLOT)
  1612. slot = EQ2_DRINK_SLOT;
  1613. else if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT)
  1614. slot += 1;
  1615. }
  1616. else if (version <= 546) {
  1617. if (slot == EQ2_DOF_FOOD_SLOT)
  1618. slot = EQ2_FOOD_SLOT;
  1619. else if (slot == EQ2_DOF_DRINK_SLOT)
  1620. slot = EQ2_DRINK_SLOT;
  1621. else if (slot > EQ2_EARS_SLOT_1 && slot <= EQ2_WAIST_SLOT)
  1622. slot += 1;
  1623. }
  1624. return slot;
  1625. }
  1626. vector<EQ2Packet*> Player::UnequipItem(int16 index, sint32 bag_id, int8 slot, int16 version, int8 appearance_type, bool send_item_updates) {
  1627. vector<EQ2Packet*> packets;
  1628. EquipmentItemList* equipList = &equipment_list;
  1629. if(appearance_type)
  1630. equipList = &appearance_equipment_list;
  1631. if(index >= NUM_SLOTS) {
  1632. LogWrite(PLAYER__ERROR, 0, "Player", "%u index is out of range for equip items, bag_id: %i, slot: %u, version: %u, appearance: %u", index, bag_id, slot, version, appearance_type);
  1633. return packets;
  1634. }
  1635. equipList->MEquipmentItems.readlock(__FUNCTION__, __LINE__);
  1636. Item* item = equipList->items[index];
  1637. equipList->MEquipmentItems.releasereadlock(__FUNCTION__, __LINE__);
  1638. if (item && bag_id == -999) {
  1639. int8 old_slot = item->details.slot_id;
  1640. if (item_list.AssignItemToFreeSlot(item)) {
  1641. if(appearance_type)
  1642. database.DeleteItem(GetCharacterID(), item, "APPEARANCE");
  1643. else
  1644. database.DeleteItem(GetCharacterID(), item, "EQUIPPED");
  1645. if (item->GetItemScript() && lua_interface)
  1646. lua_interface->RunItemScript(item->GetItemScript(), "unequipped", item, this);
  1647. const char* zone_script = world.GetZoneScript(GetZone()->GetZoneID());
  1648. if (zone_script && lua_interface)
  1649. lua_interface->RunZoneScript(zone_script, "item_unequipped", GetZone(), this, item->details.item_id, item->name.c_str(), 0, item->details.unique_id);
  1650. item->save_needed = true;
  1651. EQ2Packet* outapp = item_list.serialize(this, version);
  1652. if (outapp) {
  1653. packets.push_back(outapp);
  1654. packets.push_back(item->serialize(version, false));
  1655. EQ2Packet* bag_packet = SendBagUpdate(item->details.inv_slot_id, version);
  1656. if (bag_packet)
  1657. packets.push_back(bag_packet);
  1658. }
  1659. equipList->RemoveItem(index);
  1660. SetEquippedItemAppearances();
  1661. packets.push_back(equipList->serialize(version, this));
  1662. SetCharSheetChanged(true);
  1663. SetEquipment(0, old_slot);
  1664. }
  1665. else {
  1666. PacketStruct* packet = configReader.getStruct("WS_DisplayText", version);
  1667. if (packet) {
  1668. packet->setDataByName("color", CHANNEL_COLOR_YELLOW);
  1669. packet->setMediumStringByName("text", "Unable to unequip item: no free inventory locations.");
  1670. packet->setDataByName("unknown02", 0x00ff);
  1671. packets.push_back(packet->serialize());
  1672. safe_delete(packet);
  1673. }
  1674. }
  1675. }
  1676. else if (item) {
  1677. Item* to_item = 0;
  1678. if(appearance_type && slot == 255)
  1679. {
  1680. sint16 tmpSlot = 0;
  1681. item_list.GetFirstFreeSlot(&bag_id, &tmpSlot);
  1682. if(tmpSlot >= 0 && tmpSlot < 255)
  1683. slot = tmpSlot;
  1684. else
  1685. bag_id = 0;
  1686. }
  1687. item_list.MPlayerItems.readlock(__FUNCTION__, __LINE__);
  1688. if (item_list.items.count(bag_id) > 0 && item_list.items[bag_id][BASE_EQUIPMENT].count(slot) > 0)
  1689. to_item = item_list.items[bag_id][BASE_EQUIPMENT][slot];
  1690. bool canEquipToSlot = false;
  1691. if (to_item && equipList->CanItemBeEquippedInSlot(to_item, ConvertSlotFromClient(item->details.slot_id, version))) {
  1692. canEquipToSlot = true;
  1693. }
  1694. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1695. if (canEquipToSlot) {
  1696. equipList->RemoveItem(index);
  1697. if(item->details.appearance_type)
  1698. database.DeleteItem(GetCharacterID(), item, "APPEARANCE");
  1699. else
  1700. database.DeleteItem(GetCharacterID(), item, "EQUIPPED");
  1701. database.DeleteItem(GetCharacterID(), to_item, "NOT-EQUIPPED");
  1702. if (item->GetItemScript() && lua_interface)
  1703. lua_interface->RunItemScript(item->GetItemScript(), "unequipped", item, this);
  1704. if (to_item->GetItemScript() && lua_interface)
  1705. lua_interface->RunItemScript(to_item->GetItemScript(), "equipped", to_item, this);
  1706. item_list.RemoveItem(to_item);
  1707. equipList->SetItem(item->details.slot_id, to_item);
  1708. to_item->save_needed = true;
  1709. packets.push_back(to_item->serialize(version, false));
  1710. SetEquipment(to_item);
  1711. item->details.inv_slot_id = bag_id;
  1712. item->details.slot_id = slot;
  1713. item->details.appearance_type = 0;
  1714. if(item_list.AddItem(item)) {
  1715. item->save_needed = true;
  1716. SetEquippedItemAppearances();
  1717. // SerializeItemPackets serves item and equipList in opposite order is why we don't use that function here..
  1718. packets.push_back(item->serialize(version, false));
  1719. packets.push_back(equipList->serialize(version, this));
  1720. packets.push_back(item_list.serialize(this, version));
  1721. }
  1722. else {
  1723. LogWrite(PLAYER__ERROR, 0, "Player", "failed to add item to item_list during UnequipItem, index %u, bag id %i, slot %u, version %u, appearance type %u", index, bag_id, slot, version, appearance_type);
  1724. }
  1725. }
  1726. else if (to_item && to_item->IsBag() && to_item->details.num_slots > 0) {
  1727. bool free_slot = false;
  1728. for (int8 i = 0; i < to_item->details.num_slots; i++) {
  1729. item_list.MPlayerItems.readlock(__FUNCTION__, __LINE__);
  1730. int32 count = item_list.items[to_item->details.bag_id][appearance_type].count(i);
  1731. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1732. if (count == 0) {
  1733. SetEquipment(0, item->details.slot_id);
  1734. if(item->details.appearance_type)
  1735. database.DeleteItem(GetCharacterID(), item, "APPEARANCE");
  1736. else
  1737. database.DeleteItem(GetCharacterID(), item, "EQUIPPED");
  1738. if (item->GetItemScript() && lua_interface)
  1739. lua_interface->RunItemScript(item->GetItemScript(), "unequipped", item, this);
  1740. equipList->RemoveItem(index);
  1741. item->details.inv_slot_id = to_item->details.bag_id;
  1742. item->details.slot_id = i;
  1743. item->details.appearance_type = to_item->details.appearance_type;
  1744. SerializeItemPackets(equipList, &packets, item, version, to_item);
  1745. free_slot = true;
  1746. break;
  1747. }
  1748. }
  1749. if (!free_slot) {
  1750. PacketStruct* packet = configReader.getStruct("WS_DisplayText", version);
  1751. if (packet) {
  1752. packet->setDataByName("color", CHANNEL_COLOR_YELLOW);
  1753. packet->setMediumStringByName("text", "Unable to unequip item: no free space in the bag.");
  1754. packet->setDataByName("unknown02", 0x00ff);
  1755. packets.push_back(packet->serialize());
  1756. safe_delete(packet);
  1757. }
  1758. }
  1759. }
  1760. else if (to_item) {
  1761. PacketStruct* packet = configReader.getStruct("WS_DisplayText", version);
  1762. if (packet) {
  1763. packet->setDataByName("color", CHANNEL_COLOR_YELLOW);
  1764. packet->setMediumStringByName("text", "Unable to swap items: that item cannot be equipped there.");
  1765. packet->setDataByName("unknown02", 0x00ff);
  1766. packets.push_back(packet->serialize());
  1767. safe_delete(packet);
  1768. }
  1769. }
  1770. else {
  1771. if ((bag_id == 0 && slot < NUM_INV_SLOTS) || (bag_id == -3 && slot < NUM_BANK_SLOTS) || (bag_id == -4 && slot < NUM_SHARED_BANK_SLOTS)) {
  1772. if (bag_id == -4 && item->CheckFlag(NO_TRADE)) {
  1773. PacketStruct* packet = configReader.getStruct("WS_DisplayText", version);
  1774. if (packet) {
  1775. packet->setDataByName("color", CHANNEL_COLOR_YELLOW);
  1776. packet->setMediumStringByName("text", "Unable to unequip item: that item cannot be traded.");
  1777. packet->setDataByName("unknown02", 0x00ff);
  1778. packets.push_back(packet->serialize());
  1779. safe_delete(packet);
  1780. }
  1781. }
  1782. else {
  1783. // need to check if appearance slot vs equipped
  1784. SetEquipment(0, item->details.slot_id);
  1785. if(item->details.appearance_type)
  1786. database.DeleteItem(GetCharacterID(), item, "APPEARANCE");
  1787. else
  1788. database.DeleteItem(GetCharacterID(), item, "EQUIPPED");
  1789. if (item->GetItemScript() && lua_interface)
  1790. lua_interface->RunItemScript(item->GetItemScript(), "unequipped", item, this);
  1791. equipList->RemoveItem(index);
  1792. item->details.inv_slot_id = bag_id;
  1793. item->details.slot_id = slot;
  1794. item->details.appearance_type = 0;
  1795. SerializeItemPackets(equipList, &packets, item, version);
  1796. }
  1797. }
  1798. else {
  1799. Item* bag = item_list.GetItemFromUniqueID(bag_id, true);
  1800. if (bag && bag->IsBag() && slot < bag->details.num_slots) {
  1801. SetEquipment(0, item->details.slot_id);
  1802. if(item->details.appearance_type)
  1803. database.DeleteItem(GetCharacterID(), item, "APPEARANCE");
  1804. else
  1805. database.DeleteItem(GetCharacterID(), item, "EQUIPPED");
  1806. if (item->GetItemScript() && lua_interface)
  1807. lua_interface->RunItemScript(item->GetItemScript(), "unequipped", item, this);
  1808. equipList->RemoveItem(index);
  1809. item->details.inv_slot_id = bag_id;
  1810. item->details.slot_id = slot;
  1811. item->details.appearance_type = 0;
  1812. SerializeItemPackets(equipList, &packets, item, version);
  1813. }
  1814. }
  1815. }
  1816. Item* bag = item_list.GetItemFromUniqueID(bag_id, true);
  1817. if (bag && bag->IsBag())
  1818. packets.push_back(bag->serialize(version, false, this));
  1819. }
  1820. if(send_item_updates)
  1821. {
  1822. GetClient()->UpdateSentSpellList();
  1823. GetClient()->ClearSentSpellList();
  1824. }
  1825. return packets;
  1826. }
  1827. map<int32, Item*>* Player::GetItemList(){
  1828. return item_list.GetAllItems();
  1829. }
  1830. vector<Item*>* Player::GetEquippedItemList(){
  1831. return equipment_list.GetAllEquippedItems();
  1832. }
  1833. vector<Item*>* Player::GetAppearanceEquippedItemList(){
  1834. return appearance_equipment_list.GetAllEquippedItems();
  1835. }
  1836. EQ2Packet* Player::SendBagUpdate(int32 bag_unique_id, int16 version){
  1837. Item* bag = 0;
  1838. if(bag_unique_id > 0)
  1839. bag = item_list.GetItemFromUniqueID(bag_unique_id, true);
  1840. if(bag && bag->IsBag())
  1841. return bag->serialize(version, false, this);
  1842. return 0;
  1843. }
  1844. void Player::SetEquippedItemAppearances(){
  1845. vector<Item*>* items = GetEquipmentList()->GetAllEquippedItems();
  1846. vector<Item*>* appearance_items = GetAppearanceEquipmentList()->GetAllEquippedItems();
  1847. if(items){
  1848. for(int32 i=0;i<items->size();i++)
  1849. SetEquipment(items->at(i));
  1850. // just have appearance items brute force replace the slots after the fact
  1851. for(int32 i=0;i<appearance_items->size();i++)
  1852. SetEquipment(appearance_items->at(i));
  1853. }
  1854. safe_delete(items);
  1855. safe_delete(appearance_items);
  1856. info_changed = true;
  1857. GetZone()->SendSpawnChanges(this);
  1858. }
  1859. EQ2Packet* Player::SwapEquippedItems(int8 slot1, int8 slot2, int16 version, int16 equip_type){
  1860. EquipmentItemList* equipList = &equipment_list;
  1861. // right now client seems to pass 3 for this? Not sure why when other fields has appearance equipment as type 1
  1862. if(equip_type == 3)
  1863. equipList = &appearance_equipment_list;
  1864. equipList->MEquipmentItems.readlock(__FUNCTION__, __LINE__);
  1865. Item* item_from = equipList->items[slot1];
  1866. Item* item_to = equipList->items[slot2];
  1867. equipList->MEquipmentItems.releasereadlock(__FUNCTION__, __LINE__);
  1868. if(item_from && equipList->CanItemBeEquippedInSlot(item_from, slot2)){
  1869. if(item_to){
  1870. if(!equipList->CanItemBeEquippedInSlot(item_to, slot1))
  1871. return 0;
  1872. }
  1873. equipList->MEquipmentItems.writelock(__FUNCTION__, __LINE__);
  1874. equipList->items[slot1] = nullptr;
  1875. equipList->MEquipmentItems.releasewritelock(__FUNCTION__, __LINE__);
  1876. equipList->SetItem(slot2, item_from);
  1877. if(item_to)
  1878. {
  1879. equipList->SetItem(slot1, item_to);
  1880. item_to->save_needed = true;
  1881. }
  1882. item_from->save_needed = true;
  1883. if (GetClient())
  1884. {
  1885. //EquipmentItemList* equipList = &equipment_list;
  1886. //if(appearance_type)
  1887. // equipList = &appearance_equipment_list;
  1888. if(item_to)
  1889. GetClient()->QueuePacket(item_to->serialize(version, false, this));
  1890. GetClient()->QueuePacket(item_from->serialize(version, false, this));
  1891. GetClient()->QueuePacket(item_list.serialize(this, version));
  1892. }
  1893. return equipList->serialize(version, this);
  1894. }
  1895. return 0;
  1896. }
  1897. bool Player::CanEquipItem(Item* item) {
  1898. if (item) {
  1899. Client* client = GetZone()->GetClientBySpawn(this);
  1900. if (client) {
  1901. if (item->CheckFlag(EVIL_ONLY) && GetAlignment() != ALIGNMENT_EVIL) {
  1902. client->Message(0, "%s requires an evil race.", item->name.c_str());
  1903. }
  1904. else if (item->CheckFlag(GOOD_ONLY) && GetAlignment() != ALIGNMENT_GOOD) {
  1905. client->Message(0, "%s requires a good race.", item->name.c_str());
  1906. }
  1907. else if (item->IsArmor() || item->IsWeapon() || item->IsFood() || item->IsRanged() || item->IsShield() || item->IsBauble() || item->IsAmmo() || item->IsThrown()) {
  1908. if ((item->generic_info.skill_req1 == 0 || item->generic_info.skill_req1 == 0xFFFFFFFF || skill_list.HasSkill(item->generic_info.skill_req1)) && (item->generic_info.skill_req2 == 0 || item->generic_info.skill_req2 == 0xFFFFFFFF || skill_list.HasSkill(item->generic_info.skill_req2))) {
  1909. int16 override_level = item->GetOverrideLevel(GetAdventureClass(), GetTradeskillClass());
  1910. if (override_level > 0 && override_level <= GetLevel())
  1911. return true;
  1912. if (item->CheckClass(GetAdventureClass(), GetTradeskillClass()))
  1913. if (item->CheckLevel(GetAdventureClass(), GetTradeskillClass(), GetLevel()))
  1914. return true;
  1915. else
  1916. client->Message(CHANNEL_COLOR_RED, "You must be at least level %u to equip %s.", item->generic_info.adventure_default_level, item->CreateItemLink(client->GetVersion()).c_str());
  1917. else
  1918. client->Message(CHANNEL_COLOR_RED, "Your class may not equip %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1919. }
  1920. else
  1921. client->SimpleMessage(0, "You lack the skill required to equip this item.");
  1922. }
  1923. else
  1924. client->Message(0, "Item %s isn't equipable.", item->name.c_str());
  1925. }
  1926. }
  1927. return false;
  1928. }
  1929. vector<EQ2Packet*> Player::EquipItem(int16 index, int16 version, int8 appearance_type, int8 slot_id) {
  1930. EquipmentItemList* equipList = &equipment_list;
  1931. if(appearance_type)
  1932. equipList = &appearance_equipment_list;
  1933. vector<EQ2Packet*> packets;
  1934. item_list.MPlayerItems.readlock(__FUNCTION__, __LINE__);
  1935. if (item_list.indexed_items.count(index) == 0) {
  1936. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1937. return packets;
  1938. }
  1939. Item* item = item_list.indexed_items[index];
  1940. int8 orig_slot_id = slot_id;
  1941. slot_id = ConvertSlotFromClient(slot_id, version);
  1942. if (item) {
  1943. if(orig_slot_id == 255 && item->CheckFlag2(APPEARANCE_ONLY)) {
  1944. appearance_type = 1;
  1945. equipList = &appearance_equipment_list;
  1946. }
  1947. if (slot_id != 255 && !item->HasSlot(slot_id)) {
  1948. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1949. return packets;
  1950. }
  1951. int8 slot = equipList->GetFreeSlot(item, slot_id);
  1952. bool canEquip = CanEquipItem(item);
  1953. int32 conflictSlot = 0;
  1954. if(canEquip && !appearance_type && item->CheckFlag2(APPEARANCE_ONLY))
  1955. {
  1956. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1957. GetClient()->SimpleMessage(CHANNEL_COLOR_RED, "This item is for appearance slots only.");
  1958. return packets;
  1959. }
  1960. else if(canEquip && (conflictSlot = equipList->CheckSlotConflict(item)) > 0) {
  1961. bool abort = true;
  1962. switch(conflictSlot) {
  1963. case LORE:
  1964. GetClient()->SimpleMessage(CHANNEL_COLOR_RED, "Lore conflict, cannot equip this item.");
  1965. break;
  1966. case LORE_EQUIP:
  1967. GetClient()->SimpleMessage(CHANNEL_COLOR_RED, "You already have this item equipped, you cannot equip another.");
  1968. break;
  1969. case STACK_LORE:
  1970. GetClient()->SimpleMessage(CHANNEL_COLOR_RED, "Cannot equip as it exceeds lore stack.");
  1971. break;
  1972. default:
  1973. abort = false;
  1974. break;
  1975. }
  1976. if(abort) {
  1977. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1978. return packets;
  1979. }
  1980. }
  1981. else if (canEquip && item->CheckFlag(ATTUNEABLE)) {
  1982. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", version);
  1983. char text[255];
  1984. sprintf(text, "%s must be attuned before it can be equipped. Would you like to attune it now?", item->name.c_str());
  1985. char accept_command[25];
  1986. sprintf(accept_command, "attune_inv %i 1 0 -1", index);
  1987. packet->setDataByName("text", text);
  1988. packet->setDataByName("accept_text", "Attune");
  1989. packet->setDataByName("accept_command", accept_command);
  1990. packet->setDataByName("cancel_text", "Cancel");
  1991. // No clue if we even need the following 2 unknowns, just added them so the packet matches what live sends
  1992. packet->setDataByName("max_length", 50);
  1993. packet->setDataByName("unknown4", 1);
  1994. packets.push_back(packet->serialize());
  1995. safe_delete(packet);
  1996. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  1997. return packets;
  1998. }
  1999. if (canEquip && slot == 255)
  2000. {
  2001. if (slot_id == 255)
  2002. slot = item->slot_data.at(0);
  2003. else
  2004. slot = slot_id;
  2005. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2006. packets = UnequipItem(slot, item->details.inv_slot_id, item->details.slot_id, version, appearance_type, false);
  2007. // grab player items lock again and assure item still present
  2008. item_list.MPlayerItems.readlock(__FUNCTION__, __LINE__);
  2009. if (item_list.indexed_items.count(index) == 0) {
  2010. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2011. return packets;
  2012. }
  2013. // If item is a 2handed weapon and something is in the secondary, unequip the secondary
  2014. if (item->IsWeapon() && item->weapon_info->wield_type == ITEM_WIELD_TYPE_TWO_HAND && equipList->GetItem(EQ2_SECONDARY_SLOT) != 0) {
  2015. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2016. vector<EQ2Packet*> tmp_packets = UnequipItem(EQ2_SECONDARY_SLOT, -999, 0, version, appearance_type, false);
  2017. //packets.reserve(packets.size() + tmp_packets.size());
  2018. packets.insert(packets.end(), tmp_packets.begin(), tmp_packets.end());
  2019. }
  2020. else {
  2021. // release for delete item / scripting etc
  2022. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2023. }
  2024. }
  2025. else if (canEquip && slot < 255) {
  2026. // If item is a 2handed weapon and something is in the secondary, unequip the secondary
  2027. if (item->IsWeapon() && item->weapon_info->wield_type == ITEM_WIELD_TYPE_TWO_HAND && equipList->GetItem(EQ2_SECONDARY_SLOT) != 0) {
  2028. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2029. vector<EQ2Packet*> tmp_packets = UnequipItem(EQ2_SECONDARY_SLOT, -999, 0, version, appearance_type, false);
  2030. //packets.reserve(packets.size() + tmp_packets.size());
  2031. packets.insert(packets.end(), tmp_packets.begin(), tmp_packets.end());
  2032. }
  2033. else {
  2034. // release for delete item / scripting etc
  2035. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2036. }
  2037. database.DeleteItem(GetCharacterID(), item, "NOT-EQUIPPED");
  2038. if (item->GetItemScript() && lua_interface)
  2039. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, this);
  2040. item_list.RemoveItem(item);
  2041. equipList->SetItem(ConvertSlotToClient(slot, version), item);
  2042. item->save_needed = true;
  2043. packets.push_back(item->serialize(version, false));
  2044. SetEquipment(item);
  2045. const char* zone_script = world.GetZoneScript(GetZone()->GetZoneID());
  2046. if (zone_script && lua_interface)
  2047. lua_interface->RunZoneScript(zone_script, "item_equipped", GetZone(), this, item->details.item_id, item->name.c_str(), 0, item->details.unique_id);
  2048. int32 bag_id = item->details.inv_slot_id;
  2049. if (item->generic_info.condition == 0) {
  2050. Client* client = GetZone()->GetClientBySpawn(this);
  2051. if (client) {
  2052. LogWrite(MISC__TODO, 1, "TODO", "Send popup text in red 'Some of your equipment is broken!'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  2053. client->Message(CHANNEL_COLOR_RED, "Your %s is worn out and will not be effective until repaired.", item->CreateItemLink(client->GetVersion(), true).c_str());
  2054. }
  2055. }
  2056. SetEquippedItemAppearances();
  2057. packets.push_back(equipList->serialize(version, this));
  2058. EQ2Packet* outapp = item_list.serialize(this, version);
  2059. if (outapp) {
  2060. packets.push_back(outapp);
  2061. EQ2Packet* bag_packet = SendBagUpdate(bag_id, version);
  2062. if (bag_packet)
  2063. packets.push_back(bag_packet);
  2064. }
  2065. SetCharSheetChanged(true);
  2066. }
  2067. else {
  2068. // clear items lock
  2069. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2070. }
  2071. }
  2072. else {
  2073. // clear items lock
  2074. item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
  2075. }
  2076. client->UpdateSentSpellList();
  2077. client->ClearSentSpellList();
  2078. return packets;
  2079. }
  2080. bool Player::AddItem(Item* item, AddItemType type) {
  2081. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2082. int16 lore_stack_count = 0;
  2083. if (item && item->details.item_id > 0) {
  2084. if( ((conflictItemList = item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2085. (conflictequipmentList = equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2086. (conflictAppearanceEquipmentList = appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2087. switch(type)
  2088. {
  2089. case AddItemType::BUY_FROM_BROKER:
  2090. client->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "You already own this item and cannot have another.");
  2091. break;
  2092. default:
  2093. client->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "You cannot obtain %s due to lore conflict.", item->name.c_str());
  2094. break;
  2095. }
  2096. return false;
  2097. }
  2098. else if(conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE ||
  2099. conflictAppearanceEquipmentList == STACK_LORE) {
  2100. switch(type)
  2101. {
  2102. default:
  2103. client->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "You already have one stack of the LORE item: %s.", item->name.c_str());
  2104. break;
  2105. }
  2106. return false;
  2107. }
  2108. else if (item_list.AssignItemToFreeSlot(item)) {
  2109. item->save_needed = true;
  2110. return true;
  2111. }
  2112. else if (item_list.AddOverflowItem(item))
  2113. return true;
  2114. }
  2115. return false;
  2116. }
  2117. bool Player::AddItemToBank(Item* item) {
  2118. if (item && item->details.item_id > 0) {
  2119. sint32 bag = -3;
  2120. sint16 slot = -1;
  2121. if (item_list.GetFirstFreeBankSlot(&bag, &slot)) {
  2122. item->details.inv_slot_id = bag;
  2123. item->details.slot_id = slot;
  2124. item->save_needed = true;
  2125. return item_list.AddItem(item);
  2126. }
  2127. else if (item_list.AddOverflowItem(item))
  2128. return true;
  2129. }
  2130. return false;
  2131. }
  2132. EQ2Packet* Player::SendInventoryUpdate(int16 version) {
  2133. // assure any inventory updates are reflected in sell window
  2134. if(GetClient() && GetClient()->GetMerchantTransaction())
  2135. GetClient()->SendSellMerchantList();
  2136. return item_list.serialize(this, version);
  2137. }
  2138. void Player::UpdateInventory(int32 bag_id) {
  2139. EQ2Packet* outapp = client->GetPlayer()->SendInventoryUpdate(client->GetVersion());
  2140. client->QueuePacket(outapp);
  2141. outapp = client->GetPlayer()->SendBagUpdate(bag_id, client->GetVersion());
  2142. if (outapp)
  2143. client->QueuePacket(outapp);
  2144. }
  2145. EQ2Packet* Player::MoveInventoryItem(sint32 to_bag_id, int16 from_index, int8 new_slot, int8 charges, int8 appearance_type, bool* item_deleted, int16 version) {
  2146. Item* item = item_list.GetItemFromIndex(from_index);
  2147. int8 result = item_list.MoveItem(to_bag_id, from_index, new_slot, appearance_type, charges);
  2148. if (result == 1) {
  2149. if (item) {
  2150. if (!item->needs_deletion)
  2151. item->save_needed = true;
  2152. else if (item->needs_deletion) {
  2153. database.DeleteItem(GetCharacterID(), item, 0);
  2154. client->GetPlayer()->item_list.DestroyItem(from_index);
  2155. client->GetPlayer()->UpdateInventory(to_bag_id);
  2156. if(item_deleted)
  2157. *item_deleted = true;
  2158. }
  2159. }
  2160. return item_list.serialize(this, version);
  2161. }
  2162. else {
  2163. PacketStruct* packet = configReader.getStruct("WS_DisplayText", version);
  2164. if (packet) {
  2165. packet->setDataByName("color", CHANNEL_COLOR_YELLOW);
  2166. packet->setMediumStringByName("text", "Could not move item to that location.");
  2167. packet->setDataByName("unknown02", 0x00ff);
  2168. EQ2Packet* outapp = packet->serialize();
  2169. safe_delete(packet);
  2170. return outapp;
  2171. }
  2172. }
  2173. return 0;
  2174. }
  2175. int32 Player::GetCoinsCopper(){
  2176. return GetInfoStruct()->get_coin_copper();
  2177. }
  2178. int32 Player::GetCoinsSilver(){
  2179. return GetInfoStruct()->get_coin_silver();
  2180. }
  2181. int32 Player::GetCoinsGold(){
  2182. return GetInfoStruct()->get_coin_gold();
  2183. }
  2184. int32 Player::GetCoinsPlat(){
  2185. return GetInfoStruct()->get_coin_plat();
  2186. }
  2187. int32 Player::GetBankCoinsCopper(){
  2188. return GetInfoStruct()->get_bank_coin_copper();
  2189. }
  2190. int32 Player::GetBankCoinsSilver(){
  2191. return GetInfoStruct()->get_bank_coin_silver();
  2192. }
  2193. int32 Player::GetBankCoinsGold(){
  2194. return GetInfoStruct()->get_bank_coin_gold();
  2195. }
  2196. int32 Player::GetBankCoinsPlat(){
  2197. return GetInfoStruct()->get_bank_coin_plat();
  2198. }
  2199. int32 Player::GetStatusPoints(){
  2200. return GetInfoStruct()->get_status_points();
  2201. }
  2202. vector<QuickBarItem*>* Player::GetQuickbar(){
  2203. return &quickbar_items;
  2204. }
  2205. bool Player::UpdateQuickbarNeeded(){
  2206. return quickbar_updated;
  2207. }
  2208. void Player::ResetQuickbarNeeded(){
  2209. quickbar_updated = false;
  2210. }
  2211. void Player::AddQuickbarItem(int32 bar, int32 slot, int32 type, int16 icon, int16 icon_type, int32 id, int8 tier, int32 unique_id, const char* text, bool update){
  2212. RemoveQuickbarItem(bar, slot, false);
  2213. QuickBarItem* ability = new QuickBarItem;
  2214. ability->deleted = false;
  2215. ability->hotbar = bar;
  2216. ability->slot = slot;
  2217. ability->type = type;
  2218. ability->icon = icon;
  2219. ability->tier = tier;
  2220. ability->icon_type = icon_type;
  2221. ability->id = id;
  2222. if(unique_id == 0)
  2223. unique_id = database.NextUniqueHotbarID();
  2224. ability->unique_id = unique_id;
  2225. if(type == QUICKBAR_TEXT_CMD && text){
  2226. ability->text.data = string(text);
  2227. ability->text.size = ability->text.data.length();
  2228. }
  2229. else
  2230. ability->text.size = 0;
  2231. quickbar_items.push_back(ability);
  2232. if(update)
  2233. quickbar_updated = true;
  2234. }
  2235. void Player::RemoveQuickbarItem(int32 bar, int32 slot, bool update){
  2236. vector<QuickBarItem*>::iterator itr;
  2237. QuickBarItem* qbi = 0;
  2238. for(itr=quickbar_items.begin();itr!=quickbar_items.end();itr++){
  2239. qbi = *itr;
  2240. if(qbi && qbi->deleted == false && qbi->hotbar == bar && qbi->slot == slot){
  2241. qbi->deleted = true;
  2242. break;
  2243. }
  2244. }
  2245. if(update)
  2246. quickbar_updated = true;
  2247. }
  2248. void Player::ClearQuickbarItems(){
  2249. quickbar_items.clear();
  2250. }
  2251. EQ2Packet* Player::GetQuickbarPacket(int16 version){
  2252. PacketStruct* packet = configReader.getStruct("WS_QuickBarInit", version);
  2253. if(packet){
  2254. vector<QuickBarItem*>::iterator itr;
  2255. packet->setArrayLengthByName("num_abilities", quickbar_items.size());
  2256. int16 i=0;
  2257. for(itr=quickbar_items.begin();itr != quickbar_items.end(); itr++){
  2258. QuickBarItem* ability = *itr;
  2259. if(!ability || ability->deleted)
  2260. continue;
  2261. packet->setArrayDataByName("hotbar", ability->hotbar, i);
  2262. packet->setArrayDataByName("slot", ability->slot, i);
  2263. packet->setArrayDataByName("type", ability->type, i);
  2264. packet->setArrayDataByName("icon", ability->icon, i);
  2265. packet->setArrayDataByName("icon_type", ability->icon_type, i);
  2266. packet->setArrayDataByName("id", ability->id, i);
  2267. packet->setArrayDataByName("unique_id", ability->tier, i);
  2268. packet->setArrayDataByName("text", &ability->text, i);
  2269. i++;
  2270. }
  2271. EQ2Packet* app = packet->serialize();
  2272. safe_delete(packet);
  2273. return app;
  2274. }
  2275. return 0;
  2276. }
  2277. void Player::AddSpellBookEntry(int32 spell_id, int8 tier, sint32 slot, int32 type, int32 timer, bool save_needed){
  2278. SpellBookEntry* spell = new SpellBookEntry;
  2279. spell->status = 169;
  2280. spell->slot = slot;
  2281. spell->spell_id = spell_id;
  2282. spell->type = type;
  2283. spell->tier = tier;
  2284. spell->timer = timer;
  2285. spell->save_needed = save_needed;
  2286. spell->recast = 0;
  2287. spell->recast_available = 0;
  2288. spell->player = this;
  2289. spell->visible = true;
  2290. spell->in_use = false;
  2291. spell->in_remiss = false;
  2292. MSpellsBook.lock();
  2293. spells.push_back(spell);
  2294. MSpellsBook.unlock();
  2295. if (type == SPELL_BOOK_TYPE_NOT_SHOWN)
  2296. AddPassiveSpell(spell_id, tier);
  2297. }
  2298. void Player::RemoveSpellBookEntry(int32 spell_id, bool remove_passives_from_list){
  2299. MSpellsBook.lock();
  2300. vector<SpellBookEntry*>::iterator itr;
  2301. SpellBookEntry* spell = 0;
  2302. for(itr = spells.begin(); itr != spells.end(); itr++){
  2303. spell = *itr;
  2304. if(spell->spell_id == spell_id){
  2305. if (spell->type == SPELL_BOOK_TYPE_NOT_SHOWN)
  2306. RemovePassive(spell->spell_id, spell->tier, remove_passives_from_list);
  2307. spells.erase(itr);
  2308. break;
  2309. }
  2310. }
  2311. MSpellsBook.unlock();
  2312. }
  2313. void Player::ResortSpellBook(int32 sort_by, int32 order, int32 pattern, int32 maxlvl_only, int32 book_type)
  2314. {
  2315. //sort_by : 0 - alpha, 1 - level, 2 - category
  2316. //order : 0 - ascending, 1 - descending
  2317. //pattern : 0 - zigzag, 1 - down, 2 - across
  2318. MSpellsBook.lock();
  2319. std::vector<SpellBookEntry*> sort_spells(spells);
  2320. if (!maxlvl_only)
  2321. {
  2322. switch (sort_by)
  2323. {
  2324. case 0:
  2325. if (!order)
  2326. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByName);
  2327. else
  2328. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByNameReverse);
  2329. break;
  2330. case 1:
  2331. if (!order)
  2332. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByLevel);
  2333. else
  2334. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByLevelReverse);
  2335. break;
  2336. case 2:
  2337. if (!order)
  2338. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByCategory);
  2339. else
  2340. stable_sort(sort_spells.begin(), sort_spells.end(), SortSpellEntryByCategoryReverse);
  2341. break;
  2342. }
  2343. }
  2344. vector<SpellBookEntry*>::iterator itr;
  2345. SpellBookEntry* spell = 0;
  2346. map<string, SpellBookEntry*> tmpSpells;
  2347. vector<SpellBookEntry*> resultSpells;
  2348. int32 i = 0;
  2349. int8 page_book_count = 0;
  2350. int32 last_start_point = 0;
  2351. for (itr = sort_spells.begin(); itr != sort_spells.end(); itr++) {
  2352. spell = *itr;
  2353. if (spell->type != book_type)
  2354. continue;
  2355. if (maxlvl_only)
  2356. {
  2357. Spell* actual_spell = 0;
  2358. actual_spell = master_spell_list.GetSpell(spell->spell_id, spell->tier);
  2359. std::regex re("^(.*?)(\\s(I{1,}[VX]{0,}|V{1,}[IVX]{0,})|X{1,}[IVX]{0,})$");
  2360. std::string output = std::regex_replace(string(actual_spell->GetName()), re, "$1", std::regex_constants::format_no_copy);
  2361. if ( output.size() < 1 )
  2362. output = string(actual_spell->GetName());
  2363. map<string, SpellBookEntry*>::iterator tmpItr = tmpSpells.find(output);
  2364. if (tmpItr != tmpSpells.end())
  2365. {
  2366. Spell* tmpSpell = master_spell_list.GetSpell(tmpItr->second->spell_id, tmpItr->second->tier);
  2367. if (actual_spell->GetLevelRequired(this) > tmpSpell->GetLevelRequired(this))
  2368. {
  2369. tmpItr->second->visible = false;
  2370. tmpItr->second->slot = 0xFFFF;
  2371. std::vector<SpellBookEntry*>::iterator it;
  2372. it = find(resultSpells.begin(), resultSpells.end(), (SpellBookEntry*)tmpItr->second);
  2373. if (it != resultSpells.end())
  2374. resultSpells.erase(it);
  2375. tmpSpells.erase(tmpItr);
  2376. }
  2377. else
  2378. continue; // leave as-is we have the newer spell
  2379. }
  2380. spell->visible = true;
  2381. tmpSpells.insert(make_pair(output, spell));
  2382. resultSpells.push_back(spell);
  2383. }
  2384. spell->slot = i;
  2385. Spell* tmpspell = 0;
  2386. tmpspell = master_spell_list.GetSpell(spell->spell_id, spell->tier);
  2387. GetSpellBookSlotSort(pattern, &i, &page_book_count, &last_start_point);
  2388. } // end for loop for setting slots
  2389. if (maxlvl_only)
  2390. {
  2391. switch (sort_by)
  2392. {
  2393. case 0:
  2394. if (!order)
  2395. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByName);
  2396. else
  2397. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByNameReverse);
  2398. break;
  2399. case 1:
  2400. if (!order)
  2401. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByLevel);
  2402. else
  2403. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByLevelReverse);
  2404. break;
  2405. case 2:
  2406. if (!order)
  2407. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByCategory);
  2408. else
  2409. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByCategoryReverse);
  2410. break;
  2411. }
  2412. i = 0;
  2413. page_book_count = 0;
  2414. last_start_point = 0;
  2415. vector<SpellBookEntry*>::iterator tmpItr;
  2416. for (tmpItr = resultSpells.begin(); tmpItr != resultSpells.end(); tmpItr++) {
  2417. ((SpellBookEntry*)*tmpItr)->slot = i;
  2418. GetSpellBookSlotSort(pattern, &i, &page_book_count, &last_start_point);
  2419. }
  2420. }
  2421. MSpellsBook.unlock();
  2422. }
  2423. bool Player::SortSpellEntryByName(SpellBookEntry* s1, SpellBookEntry* s2)
  2424. {
  2425. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2426. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2427. if (!spell1 || !spell2)
  2428. return false;
  2429. return (string(spell1->GetName()) < string(spell2->GetName()));
  2430. }
  2431. bool Player::SortSpellEntryByCategory(SpellBookEntry* s1, SpellBookEntry* s2)
  2432. {
  2433. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2434. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2435. if (!spell1 || !spell2)
  2436. return false;
  2437. return (spell1->GetSpellIconBackdrop() < spell2->GetSpellIconBackdrop());
  2438. }
  2439. bool Player::SortSpellEntryByLevel(SpellBookEntry* s1, SpellBookEntry* s2)
  2440. {
  2441. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2442. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2443. if (!spell1 || !spell2)
  2444. return false;
  2445. int16 lvl1 = spell1->GetLevelRequired(s1->player);
  2446. int16 lvl2 = spell2->GetLevelRequired(s2->player);
  2447. if (lvl1 == 0xFFFF)
  2448. lvl1 = 0;
  2449. if (lvl2 == 0xFFFF)
  2450. lvl2 = 0;
  2451. return (lvl1 < lvl2);
  2452. }
  2453. bool Player::SortSpellEntryByNameReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2454. {
  2455. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2456. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2457. if (!spell1 || !spell2)
  2458. return false;
  2459. return (string(spell2->GetName()) < string(spell1->GetName()));
  2460. }
  2461. bool Player::SortSpellEntryByCategoryReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2462. {
  2463. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2464. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2465. if (!spell1 || !spell2)
  2466. return false;
  2467. return (spell2->GetSpellIconBackdrop() < spell1->GetSpellIconBackdrop());
  2468. }
  2469. bool Player::SortSpellEntryByLevelReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2470. {
  2471. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2472. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2473. if (!spell1 || !spell2)
  2474. return false;
  2475. int16 lvl1 = spell1->GetLevelRequired(s1->player);
  2476. int16 lvl2 = spell2->GetLevelRequired(s2->player);
  2477. if (lvl1 == 0xFFFF)
  2478. lvl1 = 0;
  2479. if (lvl2 == 0xFFFF)
  2480. lvl2 = 0;
  2481. return (lvl2 < lvl1);
  2482. }
  2483. int8 Player::GetSpellSlot(int32 spell_id){
  2484. MSpellsBook.lock();
  2485. vector<SpellBookEntry*>::iterator itr;
  2486. SpellBookEntry* spell = 0;
  2487. for(itr = spells.begin(); itr != spells.end(); itr++){
  2488. spell = *itr;
  2489. if(spell->spell_id == spell_id)
  2490. {
  2491. int8 slot = spell->slot;
  2492. MSpellsBook.unlock();
  2493. return slot;
  2494. }
  2495. }
  2496. MSpellsBook.unlock();
  2497. return 0;
  2498. }
  2499. void Player::AddSkill(int32 skill_id, int16 current_val, int16 max_val, bool save_needed){
  2500. Skill* master_skill = master_skill_list.GetSkill(skill_id);
  2501. if (master_skill) {
  2502. Skill* skill = new Skill(master_skill);
  2503. skill->current_val = current_val;
  2504. skill->previous_val = current_val;
  2505. skill->max_val = max_val;
  2506. if (save_needed)
  2507. skill->save_needed = true;
  2508. skill_list.AddSkill(skill);
  2509. }
  2510. }
  2511. void Player::RemovePlayerSkill(int32 skill_id, bool save) {
  2512. Skill* skill = skill_list.GetSkill(skill_id);
  2513. if (skill)
  2514. RemoveSkillFromDB(skill, save);
  2515. }
  2516. void Player::RemoveSkillFromDB(Skill* skill, bool save) {
  2517. skill_list.RemoveSkill(skill);
  2518. if (save)
  2519. database.DeleteCharacterSkill(GetCharacterID(), skill);
  2520. }
  2521. int16 Player::GetSpellSlotMappingCount(){
  2522. int16 ret = 0;
  2523. MSpellsBook.lock();
  2524. for(int32 i=0;i<spells.size();i++){
  2525. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2526. if(spell->slot >= 0 && spell->spell_id > 0)
  2527. ret++;
  2528. }
  2529. MSpellsBook.unlock();
  2530. return ret;
  2531. }
  2532. int8 Player::GetSpellTier(int32 id){
  2533. int8 ret = 0;
  2534. MSpellsBook.lock();
  2535. for(int32 i=0;i<spells.size();i++){
  2536. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2537. if(spell->spell_id == id){
  2538. ret = spell->tier;
  2539. break;
  2540. }
  2541. }
  2542. MSpellsBook.unlock();
  2543. return ret;
  2544. }
  2545. int16 Player::GetSpellPacketCount(){
  2546. int16 ret = 0;
  2547. MSpellsBook.lock();
  2548. for(int32 i=0;i<spells.size();i++){
  2549. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2550. if(spell->spell_id > 0)
  2551. ret++;
  2552. }
  2553. MSpellsBook.unlock();
  2554. return ret;
  2555. }
  2556. void Player::LockAllSpells() {
  2557. vector<SpellBookEntry*>::iterator itr;
  2558. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2559. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2560. if ((*itr)->type != SPELL_BOOK_TYPE_TRADESKILL)
  2561. RemoveSpellStatus((*itr), SPELL_STATUS_LOCK, false);
  2562. }
  2563. all_spells_locked = true;
  2564. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2565. }
  2566. void Player::UnlockAllSpells(bool modify_recast, Spell* exception) {
  2567. vector<SpellBookEntry*>::iterator itr;
  2568. int32 exception_spell_id = 0;
  2569. if (exception)
  2570. exception_spell_id = exception->GetSpellID();
  2571. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2572. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2573. MaintainedEffects* effect = 0;
  2574. if((effect = GetMaintainedSpell((*itr)->spell_id)) && effect->spell->spell->GetSpellData()->duration_until_cancel)
  2575. continue;
  2576. if ((*itr)->in_use == false &&
  2577. (((*itr)->spell_id != exception_spell_id ||
  2578. (*itr)->timer > 0 && (*itr)->timer != exception->GetSpellData()->linked_timer)
  2579. && (*itr)->type != SPELL_BOOK_TYPE_TRADESKILL))
  2580. AddSpellStatus((*itr), SPELL_STATUS_LOCK, modify_recast);
  2581. else if((*itr)->in_remiss)
  2582. {
  2583. AddSpellStatus((*itr), SPELL_STATUS_LOCK);
  2584. (*itr)->in_remiss = false;
  2585. }
  2586. }
  2587. all_spells_locked = false;
  2588. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2589. }
  2590. void Player::LockSpell(Spell* spell, int16 recast) {
  2591. vector<SpellBookEntry*>::iterator itr;
  2592. SpellBookEntry* spell2;
  2593. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2594. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2595. spell2 = *itr;
  2596. if (spell2->spell_id == spell->GetSpellID() || (spell->GetSpellData()->linked_timer > 0 && spell->GetSpellData()->linked_timer == spell2->timer))
  2597. {
  2598. spell2->in_use = true;
  2599. RemoveSpellStatus(spell2, SPELL_STATUS_LOCK, true, recast);
  2600. }
  2601. else if(spell2->in_use)
  2602. RemoveSpellStatus(spell2, SPELL_STATUS_LOCK, false, 0);
  2603. }
  2604. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2605. }
  2606. void Player::UnlockSpell(Spell* spell) {
  2607. if (spell->GetStayLocked())
  2608. return;
  2609. vector<SpellBookEntry*>::iterator itr;
  2610. SpellBookEntry* spell2;
  2611. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2612. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2613. spell2 = *itr;
  2614. if (spell2->spell_id == spell->GetSpellID() || (spell->GetSpellData()->linked_timer > 0 && spell->GetSpellData()->linked_timer == spell2->timer))
  2615. {
  2616. spell2->in_use = false;
  2617. if(all_spells_locked)
  2618. spell2->in_remiss = true;
  2619. else
  2620. AddSpellStatus(spell2, SPELL_STATUS_LOCK);
  2621. }
  2622. }
  2623. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2624. }
  2625. void Player::LockTSSpells() {
  2626. vector<SpellBookEntry*>::iterator itr;
  2627. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2628. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2629. if ((*itr)->type == SPELL_BOOK_TYPE_TRADESKILL)
  2630. RemoveSpellStatus(*itr, SPELL_STATUS_LOCK);
  2631. }
  2632. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2633. // Unlock all other types
  2634. UnlockAllSpells();
  2635. }
  2636. void Player::UnlockTSSpells() {
  2637. vector<SpellBookEntry*>::iterator itr;
  2638. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2639. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2640. if ((*itr)->type == SPELL_BOOK_TYPE_TRADESKILL)
  2641. AddSpellStatus(*itr, SPELL_STATUS_LOCK);
  2642. }
  2643. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2644. // Lock all other types
  2645. LockAllSpells();
  2646. }
  2647. void Player::QueueSpell(Spell* spell) {
  2648. vector<SpellBookEntry*>::iterator itr;
  2649. SpellBookEntry* spell2;
  2650. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2651. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2652. spell2 = *itr;
  2653. if (spell2->spell_id == spell->GetSpellID())
  2654. AddSpellStatus(spell2, SPELL_STATUS_QUEUE, false);
  2655. }
  2656. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2657. }
  2658. void Player::UnQueueSpell(Spell* spell) {
  2659. vector<SpellBookEntry*>::iterator itr;
  2660. SpellBookEntry* spell2;
  2661. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2662. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2663. spell2 = *itr;
  2664. if (spell2->spell_id == spell->GetSpellID())
  2665. RemoveSpellStatus(spell2, SPELL_STATUS_QUEUE, false);
  2666. }
  2667. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2668. }
  2669. vector<Spell*> Player::GetSpellBookSpellsByTimer(int32 timerID) {
  2670. vector<Spell*> ret;
  2671. vector<SpellBookEntry*>::iterator itr;
  2672. MSpellsBook.readlock(__FUNCTION__, __LINE__);
  2673. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2674. if ((*itr)->timer == timerID)
  2675. ret.push_back(master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier));
  2676. }
  2677. MSpellsBook.releasereadlock(__FUNCTION__, __LINE__);
  2678. return ret;
  2679. }
  2680. void Player::ModifySpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2681. if (modify_recast) {
  2682. spell->recast = recast;
  2683. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2684. }
  2685. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2686. spell->status += value; // use set/remove spell status now
  2687. }
  2688. }
  2689. void Player::AddSpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2690. if (modify_recast) {
  2691. spell->recast = recast;
  2692. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2693. }
  2694. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2695. spell->status = spell->status | value;
  2696. }
  2697. }
  2698. void Player::RemoveSpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2699. if (modify_recast) {
  2700. spell->recast = recast;
  2701. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2702. }
  2703. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2704. spell->status = spell->status & ~value;
  2705. }
  2706. }
  2707. void Player::SetSpellStatus(Spell* spell, int8 status){
  2708. MSpellsBook.lock();
  2709. vector<SpellBookEntry*>::iterator itr;
  2710. SpellBookEntry* spell2 = 0;
  2711. for(itr = spells.begin(); itr != spells.end(); itr++){
  2712. spell2 = *itr;
  2713. if(spell2->spell_id == spell->GetSpellData()->id){
  2714. spell2->status = spell2->status | status;
  2715. break;
  2716. }
  2717. }
  2718. MSpellsBook.unlock();
  2719. }
  2720. vector<SpellBookEntry*>* Player::GetSpellsSaveNeeded(){
  2721. vector<SpellBookEntry*>* ret = 0;
  2722. vector<SpellBookEntry*>::iterator itr;
  2723. MSpellsBook.lock();
  2724. SpellBookEntry* spell = 0;
  2725. for(itr = spells.begin(); itr != spells.end(); itr++){
  2726. spell = *itr;
  2727. if(spell->save_needed){
  2728. if(!ret)
  2729. ret = new vector<SpellBookEntry*>;
  2730. ret->push_back(spell);
  2731. }
  2732. }
  2733. MSpellsBook.unlock();
  2734. return ret;
  2735. }
  2736. int16 Player::GetTierUp(int16 tier)
  2737. {
  2738. switch(tier)
  2739. {
  2740. case 0:
  2741. break;
  2742. case 7:
  2743. case 9:
  2744. tier -= 2;
  2745. break;
  2746. default:
  2747. tier -= 1;
  2748. break;
  2749. }
  2750. return tier;
  2751. }
  2752. bool Player::HasSpell(int32 spell_id, int8 tier, bool include_higher_tiers, bool include_possible_scribe){
  2753. bool ret = false;
  2754. vector<SpellBookEntry*>::iterator itr;
  2755. MSpellsBook.lock();
  2756. SpellBookEntry* spell = 0;
  2757. for(itr = spells.begin(); itr != spells.end(); itr++){
  2758. spell = *itr;
  2759. if(spell->spell_id == spell_id && (tier == 255 || spell->tier == tier || (include_higher_tiers && spell->tier > tier) || (include_possible_scribe && tier <= spell->tier))){
  2760. ret = true;
  2761. break;
  2762. }
  2763. }
  2764. MSpellsBook.unlock();
  2765. return ret;
  2766. }
  2767. sint32 Player::GetFreeSpellBookSlot(int32 type){
  2768. sint32 ret = 0;
  2769. MSpellsBook.lock();
  2770. vector<SpellBookEntry*>::iterator itr;
  2771. SpellBookEntry* spell = 0;
  2772. for(itr = spells.begin(); itr != spells.end(); itr++){
  2773. spell = *itr;
  2774. if(spell->type == type && spell->slot > ret) //get last slot (add 1 to it on return)
  2775. ret = spell->slot;
  2776. }
  2777. MSpellsBook.unlock();
  2778. return ret+1;
  2779. }
  2780. SpellBookEntry* Player::GetSpellBookSpell(int32 spell_id){
  2781. MSpellsBook.lock();
  2782. vector<SpellBookEntry*>::iterator itr;
  2783. SpellBookEntry* ret = 0;
  2784. SpellBookEntry* spell = 0;
  2785. for(itr = spells.begin(); itr != spells.end(); itr++){
  2786. spell = *itr;
  2787. if(spell->spell_id == spell_id){
  2788. ret = spell;
  2789. break;
  2790. }
  2791. }
  2792. MSpellsBook.unlock();
  2793. return ret;
  2794. }
  2795. vector<int32> Player::GetSpellBookSpellIDBySkill(int32 skill_id) {
  2796. vector<int32> ret;
  2797. MSpellsBook.readlock(__FUNCTION__, __LINE__);
  2798. vector<SpellBookEntry*>::iterator itr;
  2799. Spell* spell = 0;
  2800. for(itr = spells.begin(); itr != spells.end(); itr++){
  2801. spell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  2802. if(spell && spell->GetSpellData()->mastery_skill == skill_id)
  2803. ret.push_back(spell->GetSpellData()->id);
  2804. }
  2805. MSpellsBook.releasereadlock(__FUNCTION__, __LINE__);
  2806. return ret;
  2807. }
  2808. EQ2Packet* Player::GetSpellSlotMappingPacket(int16 version){
  2809. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", version);
  2810. if(packet){
  2811. int16 count = GetSpellSlotMappingCount();
  2812. int16 ptr = 0;
  2813. if(count > 0){
  2814. packet->setArrayLengthByName("spell_count", count);
  2815. MSpellsBook.lock();
  2816. for(int32 i=0;i<spells.size();i++){
  2817. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2818. if(spell->slot < 0 || spell->spell_id == 0)
  2819. continue;
  2820. packet->setArrayDataByName("spell_id", spell->spell_id, ptr);
  2821. packet->setArrayDataByName("slot_id", (int16)spell->slot, ptr);
  2822. ptr++;
  2823. }
  2824. MSpellsBook.unlock();
  2825. EQ2Packet* ret = packet->serialize();
  2826. safe_delete(packet);
  2827. return ret;
  2828. }
  2829. safe_delete(packet);
  2830. }
  2831. return 0;
  2832. }
  2833. EQ2Packet* Player::GetSpellBookUpdatePacket(int16 version) {
  2834. PacketStruct* packet = configReader.getStruct("WS_UpdateSpellBook", version);
  2835. EQ2Packet* ret = 0;
  2836. if (packet) {
  2837. Spell* spell = 0;
  2838. SpellBookEntry* spell_entry = 0;
  2839. int16 count = GetSpellPacketCount();
  2840. int16 ptr = 0;
  2841. // Get the packet size
  2842. PacketStruct* packet2 = configReader.getStruct("SubStruct_UpdateSpellBook", version);
  2843. int32 total_bytes = packet2->GetTotalPacketSize();
  2844. safe_delete(packet2);
  2845. packet->setArrayLengthByName("spell_count", count);
  2846. if (count > 0) {
  2847. if (count > spell_count) {
  2848. uchar* tmp = 0;
  2849. if (spell_orig_packet) {
  2850. tmp = new uchar[count * total_bytes];
  2851. memset(tmp, 0, total_bytes * count);
  2852. memcpy(tmp, spell_orig_packet, spell_count * total_bytes);
  2853. safe_delete_array(spell_orig_packet);
  2854. safe_delete_array(spell_xor_packet);
  2855. spell_orig_packet = tmp;
  2856. }
  2857. else {
  2858. spell_orig_packet = new uchar[count * total_bytes];
  2859. memset(spell_orig_packet, 0, total_bytes * count);
  2860. }
  2861. spell_xor_packet = new uchar[count * total_bytes];
  2862. memset(spell_xor_packet, 0, count * total_bytes);
  2863. }
  2864. spell_count = count;
  2865. MSpellsBook.lock();
  2866. for (int32 i = 0; i < spells.size(); i++) {
  2867. spell_entry = (SpellBookEntry*)spells[i];
  2868. if (spell_entry->spell_id == 0)
  2869. continue;
  2870. spell = master_spell_list.GetSpell(spell_entry->spell_id, spell_entry->tier);
  2871. if (spell) {
  2872. if (spell_entry->recast_available == 0 || Timer::GetCurrentTime2() > spell_entry->recast_available) {
  2873. packet->setSubstructArrayDataByName("spells", "available", 1, 0, ptr);
  2874. }
  2875. packet->setSubstructArrayDataByName("spells", "spell_id", spell_entry->spell_id, 0, ptr);
  2876. packet->setSubstructArrayDataByName("spells", "type", spell_entry->type, 0, ptr);
  2877. packet->setSubstructArrayDataByName("spells", "recast_available", spell_entry->recast_available, 0, ptr);
  2878. packet->setSubstructArrayDataByName("spells", "recast_time", spell_entry->recast, 0, ptr);
  2879. packet->setSubstructArrayDataByName("spells", "status", spell_entry->status, 0, ptr);
  2880. packet->setSubstructArrayDataByName("spells", "icon", (spell->GetSpellIcon() * -1) - 1, 0, ptr);
  2881. packet->setSubstructArrayDataByName("spells", "icon_type", spell->GetSpellIconBackdrop(), 0, ptr);
  2882. packet->setSubstructArrayDataByName("spells", "icon2", spell->GetSpellIconHeroicOp(), 0, ptr);
  2883. packet->setSubstructArrayDataByName("spells", "unique_id", (spell_entry->tier + 1) * -1, 0, ptr); //this is actually GetSpellNameCrc(spell->GetName()), but hijacking it for spell tier
  2884. packet->setSubstructArrayDataByName("spells", "charges", 255, 0, ptr);
  2885. // Beastlord and Channeler spell support
  2886. if (spell->GetSpellData()->savage_bar == 1)
  2887. packet->setSubstructArrayDataByName("spells", "unknown6", 32, 0, ptr); // advantages
  2888. else if (spell->GetSpellData()->savage_bar == 2)
  2889. packet->setSubstructArrayDataByName("spells", "unknown6", 64, 0, ptr); // primal
  2890. else if (spell->GetSpellData()->savage_bar == 3) {
  2891. packet->setSubstructArrayDataByName("spells", "unknown6", 6, 1, ptr); // 6 = channeler
  2892. // Slot req for channelers
  2893. // bitmask for slots 1 = slot 1, 2 = slot 2, 4 = slot 3, 8 = slot 4, 16 = slot 5, 32 = slot 6, 64 = slot 7, 128 = slot 8
  2894. packet->setSubstructArrayDataByName("spells", "savage_bar_slot", spell->GetSpellData()->savage_bar_slot, 0, ptr);
  2895. }
  2896. ptr++;
  2897. }
  2898. }
  2899. MSpellsBook.unlock();
  2900. }
  2901. ret = packet->serializeCountPacket(version, 0, spell_orig_packet, spell_xor_packet);
  2902. //packet->PrintPacket();
  2903. //DumpPacket(ret);
  2904. safe_delete(packet);
  2905. }
  2906. return ret;
  2907. }
  2908. PlayerInfo::~PlayerInfo(){
  2909. RemoveOldPackets();
  2910. }
  2911. PlayerInfo::PlayerInfo(Player* in_player){
  2912. orig_packet = 0;
  2913. changes = 0;
  2914. pet_orig_packet = 0;
  2915. pet_changes = 0;
  2916. player = in_player;
  2917. info_struct = player->GetInfoStruct();
  2918. info_struct->set_name(std::string(player->GetName()));
  2919. info_struct->set_deity(std::string("None"));
  2920. info_struct->set_class1(classes.GetBaseClass(player->GetAdventureClass()));
  2921. info_struct->set_class2(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  2922. info_struct->set_class3(player->GetAdventureClass());
  2923. info_struct->set_race(player->GetRace());
  2924. info_struct->set_gender(player->GetGender());
  2925. info_struct->set_level(player->GetLevel());
  2926. info_struct->set_tradeskill_level(player->GetTSLevel()); // JA: added 2011.07.22 to address TODO below
  2927. info_struct->set_tradeskill_class1(classes.GetTSBaseClass(player->GetTradeskillClass()));
  2928. info_struct->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(player->GetTradeskillClass()));
  2929. info_struct->set_tradeskill_class3(player->GetTradeskillClass());
  2930. LogWrite(MISC__TODO, 1, "TODO", "Fix info_struct.tradeskill_level = player->GetArtLevel();\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  2931. for(int i=0;i<45;i++){
  2932. if(i<30){
  2933. info_struct->maintained_effects[i].spell_id = 0xFFFFFFFF;
  2934. info_struct->maintained_effects[i].icon = 0xFFFF;
  2935. info_struct->maintained_effects[i].spell = nullptr;
  2936. }
  2937. info_struct->spell_effects[i].spell_id = 0xFFFFFFFF;
  2938. info_struct->spell_effects[i].spell = nullptr;
  2939. }
  2940. house_zone_id = 0;
  2941. bind_zone_id = 0;
  2942. bind_x = 0;
  2943. bind_y = 0;
  2944. bind_z = 0;
  2945. bind_heading = 0;
  2946. boat_x_offset = 0;
  2947. boat_y_offset = 0;
  2948. boat_z_offset = 0;
  2949. boat_spawn = 0;
  2950. }
  2951. MaintainedEffects* Player::GetFreeMaintainedSpellSlot(){
  2952. MaintainedEffects* ret = 0;
  2953. InfoStruct* info = GetInfoStruct();
  2954. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2955. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2956. if(info->maintained_effects[i].spell_id == 0xFFFFFFFF){
  2957. ret = &info->maintained_effects[i];
  2958. ret->spell_id = 0;
  2959. ret->slot_pos = i;
  2960. break;
  2961. }
  2962. }
  2963. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2964. return ret;
  2965. }
  2966. MaintainedEffects* Player::GetMaintainedSpell(int32 id){
  2967. MaintainedEffects* ret = 0;
  2968. InfoStruct* info = GetInfoStruct();
  2969. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2970. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2971. if(info->maintained_effects[i].spell_id == id){
  2972. ret = &info->maintained_effects[i];
  2973. break;
  2974. }
  2975. }
  2976. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2977. return ret;
  2978. }
  2979. MaintainedEffects* Player::GetMaintainedSpellBySlot(int8 slot){
  2980. MaintainedEffects* ret = 0;
  2981. InfoStruct* info = GetInfoStruct();
  2982. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2983. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2984. if(info->maintained_effects[i].slot_pos == slot){
  2985. ret = &info->maintained_effects[i];
  2986. break;
  2987. }
  2988. }
  2989. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2990. return ret;
  2991. }
  2992. MaintainedEffects* Player::GetMaintainedSpells() {
  2993. return GetInfoStruct()->maintained_effects;
  2994. }
  2995. SpellEffects* Player::GetFreeSpellEffectSlot(){
  2996. SpellEffects* ret = 0;
  2997. InfoStruct* info = GetInfoStruct();
  2998. GetSpellEffectMutex()->readlock(__FUNCTION__, __LINE__);
  2999. for(int i=0;i<45;i++){
  3000. if(info->spell_effects[i].spell_id == 0xFFFFFFFF){
  3001. ret = &info->spell_effects[i];
  3002. ret->spell_id = 0;
  3003. break;
  3004. }
  3005. }
  3006. GetSpellEffectMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3007. return ret;
  3008. }
  3009. SpellEffects* Player::GetSpellEffects() {
  3010. return GetInfoStruct()->spell_effects;
  3011. }
  3012. // call inside info_mutex
  3013. void Player::ClearRemovalTimers(){
  3014. map<int32, SpawnQueueState*>::iterator itr;
  3015. for(itr = spawn_state_list.begin(); itr != spawn_state_list.end();) {
  3016. SpawnQueueState* sr = itr->second;
  3017. itr = spawn_state_list.erase(itr);
  3018. safe_delete(sr);
  3019. }
  3020. }
  3021. void Player::ClearEverything(){
  3022. index_mutex.writelock(__FUNCTION__, __LINE__);
  3023. player_spawn_id_map.clear();
  3024. player_spawn_reverse_id_map.clear();
  3025. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3026. map<int32, vector<int32>*>::iterator itr;
  3027. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  3028. for (itr = player_spawn_quests_required.begin(); itr != player_spawn_quests_required.end(); itr++){
  3029. safe_delete(itr->second);
  3030. }
  3031. player_spawn_quests_required.clear();
  3032. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  3033. m_playerSpawnHistoryRequired.writelock(__FUNCTION__, __LINE__);
  3034. for (itr = player_spawn_history_required.begin(); itr != player_spawn_history_required.end(); itr++){
  3035. safe_delete(itr->second);
  3036. }
  3037. player_spawn_history_required.clear();
  3038. m_playerSpawnHistoryRequired.releasewritelock(__FUNCTION__, __LINE__);
  3039. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3040. ClearRemovalTimers();
  3041. spawn_packet_sent.clear();
  3042. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3043. info_mutex.writelock(__FUNCTION__, __LINE__);
  3044. spawn_info_packet_list.clear();
  3045. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3046. vis_mutex.writelock(__FUNCTION__, __LINE__);
  3047. spawn_vis_packet_list.clear();
  3048. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3049. pos_mutex.writelock(__FUNCTION__, __LINE__);
  3050. spawn_pos_packet_list.clear();
  3051. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3052. }
  3053. bool Player::IsFullyLoggedIn() {
  3054. return fully_logged_in;
  3055. }
  3056. void Player::SetFullyLoggedIn(bool val) {
  3057. fully_logged_in = val;
  3058. }
  3059. bool Player::IsResurrecting(){
  3060. return resurrecting;
  3061. }
  3062. void Player::SetResurrecting(bool val){
  3063. resurrecting = val;
  3064. }
  3065. void Player::AddMaintainedSpell(LuaSpell* luaspell){
  3066. if(!luaspell)
  3067. return;
  3068. Spell* spell = luaspell->spell;
  3069. MaintainedEffects* effect = GetFreeMaintainedSpellSlot();
  3070. int32 target_type = 0;
  3071. Spawn* spawn = 0;
  3072. if(effect){
  3073. GetMaintainedMutex()->writelock(__FUNCTION__, __LINE__);
  3074. strcpy(effect->name, spell->GetSpellData()->name.data.c_str());
  3075. effect->target = luaspell->initial_target;
  3076. spawn = luaspell->caster->GetZone()->GetSpawnByID(luaspell->initial_target);
  3077. if (spawn){
  3078. if (spawn == this)
  3079. target_type = 0;
  3080. else if (GetPet() == spawn || GetCharmedPet() == spawn)
  3081. target_type = 1;
  3082. else
  3083. target_type = 2;
  3084. }
  3085. effect->target_type = target_type;
  3086. effect->spell = luaspell;
  3087. if(!luaspell->slot_pos)
  3088. luaspell->slot_pos = effect->slot_pos;
  3089. effect->spell_id = spell->GetSpellData()->id;
  3090. LogWrite(PLAYER__DEBUG, 5, "Player", "AddMaintainedSpell Spell ID: %u, req concentration: %u", spell->GetSpellData()->id, spell->GetSpellData()->req_concentration);
  3091. effect->icon = spell->GetSpellData()->icon;
  3092. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  3093. effect->conc_used = spell->GetSpellData()->req_concentration;
  3094. effect->total_time = spell->GetSpellDuration()/10;
  3095. effect->tier = spell->GetSpellData()->tier;
  3096. if (spell->GetSpellData()->duration_until_cancel)
  3097. effect->expire_timestamp = 0xFFFFFFFF;
  3098. else
  3099. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  3100. GetMaintainedMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3101. charsheet_changed = true;
  3102. }
  3103. }
  3104. void Player::AddSpellEffect(LuaSpell* luaspell, int32 override_expire_time){
  3105. if(!luaspell || !luaspell->caster)
  3106. return;
  3107. Spell* spell = luaspell->spell;
  3108. SpellEffects* old_effect = GetSpellEffect(spell->GetSpellID(), luaspell->caster);
  3109. SpellEffects* effect = 0;
  3110. if (old_effect){
  3111. GetZone()->RemoveTargetFromSpell(old_effect->spell, this);
  3112. RemoveSpellEffect(old_effect->spell);
  3113. }
  3114. effect = GetFreeSpellEffectSlot();
  3115. if(effect){
  3116. GetSpellEffectMutex()->writelock(__FUNCTION__, __LINE__);
  3117. effect->spell = luaspell;
  3118. effect->spell_id = spell->GetSpellData()->id;
  3119. effect->caster = luaspell->caster;
  3120. effect->total_time = spell->GetSpellDuration()/10;
  3121. if (spell->GetSpellData()->duration_until_cancel)
  3122. effect->expire_timestamp = 0xFFFFFFFF;
  3123. else if(override_expire_time)
  3124. effect->expire_timestamp = Timer::GetCurrentTime2() + override_expire_time;
  3125. else
  3126. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  3127. effect->icon = spell->GetSpellData()->icon;
  3128. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  3129. effect->tier = spell->GetSpellTier();
  3130. GetSpellEffectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3131. charsheet_changed = true;
  3132. if(luaspell->caster && luaspell->caster->IsPlayer() && luaspell->caster != this)
  3133. {
  3134. GetClient()->TriggerSpellSave();
  3135. ((Player*)luaspell->caster)->GetClient()->TriggerSpellSave();
  3136. }
  3137. }
  3138. }
  3139. void Player::RemoveMaintainedSpell(LuaSpell* luaspell){
  3140. if(!luaspell)
  3141. return;
  3142. bool found = false;
  3143. Client* client = GetZone()->GetClientBySpawn(this);
  3144. LuaSpell* old_spell = 0;
  3145. LuaSpell* current_spell = 0;
  3146. GetMaintainedMutex()->writelock(__FUNCTION__, __LINE__);
  3147. for(int i=0;i<30;i++){
  3148. // If we already found the spell then we are bumping all other up one so there are no gaps in the ui
  3149. // This check needs to be first so found can never be true on the first iteration (i = 0)
  3150. if (found) {
  3151. old_spell = GetInfoStruct()->maintained_effects[i - 1].spell;
  3152. current_spell = GetInfoStruct()->maintained_effects[i].spell;
  3153. //Update the maintained window uses_remaining and damage_remaining values
  3154. if (current_spell && current_spell->num_triggers > 0)
  3155. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, current_spell->num_triggers, 0);
  3156. else if (current_spell && current_spell->damage_remaining > 0)
  3157. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, current_spell->damage_remaining, 1);
  3158. else if (old_spell && old_spell->had_triggers)
  3159. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, 0, 0);
  3160. else if (old_spell && old_spell->had_dmg_remaining)
  3161. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, 0, 1);
  3162. GetInfoStruct()->maintained_effects[i].slot_pos = i - 1;
  3163. GetInfoStruct()->maintained_effects[i - 1] = GetInfoStruct()->maintained_effects[i];
  3164. if (current_spell)
  3165. current_spell->slot_pos = i - 1;
  3166. }
  3167. // Compare spells, if we found a match set the found flag
  3168. if(GetInfoStruct()->maintained_effects[i].spell == luaspell)
  3169. found = true;
  3170. }
  3171. // if we found the spell in the array then we need to flag the char sheet as changed and set the last element to empty
  3172. if (found) {
  3173. memset(&GetInfoStruct()->maintained_effects[29], 0, sizeof(MaintainedEffects));
  3174. GetInfoStruct()->maintained_effects[29].spell_id = 0xFFFFFFFF;
  3175. GetInfoStruct()->maintained_effects[29].icon = 0xFFFF;
  3176. GetInfoStruct()->maintained_effects[29].spell = nullptr;
  3177. charsheet_changed = true;
  3178. }
  3179. GetMaintainedMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3180. }
  3181. void Player::RemoveSpellEffect(LuaSpell* spell){
  3182. bool found = false;
  3183. GetSpellEffectMutex()->writelock(__FUNCTION__, __LINE__);
  3184. for(int i=0;i<45;i++){
  3185. if (found) {
  3186. GetInfoStruct()->spell_effects[i-1] = GetInfoStruct()->spell_effects[i];
  3187. }
  3188. if(GetInfoStruct()->spell_effects[i].spell == spell)
  3189. found = true;
  3190. }
  3191. if (found) {
  3192. memset(&GetInfoStruct()->spell_effects[44], 0, sizeof(SpellEffects));
  3193. GetInfoStruct()->spell_effects[44].spell_id = 0xFFFFFFFF;
  3194. changed = true;
  3195. info_changed = true;
  3196. AddChangedZoneSpawn();
  3197. charsheet_changed = true;
  3198. }
  3199. GetSpellEffectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3200. }
  3201. bool Player::HasActiveMaintainedSpell(Spell* spell, Spawn* target){
  3202. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  3203. for(int i=0;i<30;i++){
  3204. if (GetInfoStruct()->maintained_effects[i].spell_id == spell->GetSpellData()->id){
  3205. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3206. return true;
  3207. }
  3208. }
  3209. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3210. return false;
  3211. }
  3212. bool Player::HasActiveSpellEffect(Spell* spell, Spawn* target){
  3213. return false;
  3214. }
  3215. void Player::PrepareIncomingMovementPacket(int32 len, uchar* data, int16 version)
  3216. {
  3217. if(GetClient() && GetClient()->IsReloadingZone())
  3218. return;
  3219. LogWrite(PLAYER__DEBUG, 7, "Player", "Enter: %s", __FUNCTION__); // trace
  3220. // XML structs may be to slow to use in this portion of the code as a single
  3221. // client sends a LOT of these packets when they are moving. I have commented
  3222. // out all the code for xml structs, to switch to it just uncomment
  3223. // the code and comment the 2 if/else if/else blocks, both have a comment
  3224. // above them to let you know wich ones they are.
  3225. //PacketStruct* update = configReader.getStruct("WS_PlayerPosUpdate", version);
  3226. int16 total_bytes; // = update->GetTotalPacketSize();
  3227. // Comment out this if/else if/else block if you switch to xml structs
  3228. if (version >= 1144)
  3229. total_bytes = sizeof(Player_Update1144);
  3230. else if (version >= 1096)
  3231. total_bytes = sizeof(Player_Update1096);
  3232. else if (version <= 283)
  3233. total_bytes = sizeof(Player_Update283);
  3234. else
  3235. total_bytes = sizeof(Player_Update);
  3236. if (!movement_packet)
  3237. movement_packet = new uchar[total_bytes];
  3238. else if (!old_movement_packet)
  3239. old_movement_packet = new uchar[total_bytes];
  3240. if (movement_packet && old_movement_packet)
  3241. memcpy(old_movement_packet, movement_packet, total_bytes);
  3242. bool reverse = version > 283;
  3243. Unpack(len, data, movement_packet, total_bytes, 0, reverse);
  3244. if (!movement_packet || !old_movement_packet)
  3245. return;
  3246. Decode(movement_packet, old_movement_packet, total_bytes);
  3247. //update->LoadPacketData(movement_packet, total_bytes);
  3248. int32 activity; // = update->getType_int32_ByName("activity");
  3249. int32 grid_id; // = update->getType_int32_ByName("grid_location");
  3250. float direction1; // = update->getType_float_ByName("direction1");
  3251. float direction2; // = update->getType_float_ByName("direction2");;
  3252. float speed; // = update->getType_float_ByName("speed");;
  3253. float side_speed;
  3254. float x; // = update->getType_float_ByName("x");;
  3255. float y; // = update->getType_float_ByName("y");;
  3256. float z; // = update->getType_float_ByName("z");;
  3257. float x_speed;
  3258. float y_speed;
  3259. float z_speed;
  3260. // comment out this if/else if/else block if you use xml structs
  3261. if (version >= 1144) {
  3262. Player_Update1144* update = (Player_Update1144*)movement_packet;
  3263. activity = update->activity;
  3264. grid_id = update->grid_location;
  3265. direction1 = update->direction1;
  3266. direction2 = update->direction2;
  3267. speed = update->speed;
  3268. side_speed = update->side_speed;
  3269. x = update->x;
  3270. y = update->y;
  3271. z = update->z;
  3272. x_speed = update->speed_x;
  3273. y_speed = update->speed_y;
  3274. z_speed = update->speed_z;
  3275. SetPitch(180 + update->pitch);
  3276. }
  3277. else if (version >= 1096) {
  3278. Player_Update1096* update = (Player_Update1096*)movement_packet;
  3279. activity = update->activity;
  3280. grid_id = update->grid_location;
  3281. direction1 = update->direction1;
  3282. direction2 = update->direction2;
  3283. speed = update->speed;
  3284. side_speed = update->side_speed;
  3285. x = update->x;
  3286. y = update->y;
  3287. z = update->z;
  3288. x_speed = update->speed_x;
  3289. y_speed = update->speed_y;
  3290. z_speed = update->speed_z;
  3291. SetPitch(180 + update->pitch);
  3292. }
  3293. else if (version <= 283) {
  3294. Player_Update283* update = (Player_Update283*)movement_packet;
  3295. activity = update->activity;
  3296. grid_id = update->grid_location;
  3297. direction1 = update->direction1;
  3298. direction2 = update->direction2;
  3299. speed = update->speed;
  3300. side_speed = update->side_speed;
  3301. x = update->x;
  3302. y = update->y;
  3303. z = update->z;
  3304. x_speed = update->speed_x;
  3305. y_speed = update->speed_y;
  3306. z_speed = update->speed_z;
  3307. if (update->pitch != 0)
  3308. SetPitch(180 + update->pitch);
  3309. }
  3310. else {
  3311. Player_Update* update = (Player_Update*)movement_packet;
  3312. activity = update->activity;
  3313. grid_id = update->grid_location;
  3314. direction1 = update->direction1;
  3315. direction2 = update->direction2;
  3316. speed = update->speed;
  3317. side_speed = update->side_speed;
  3318. x = update->x;
  3319. y = update->y;
  3320. z = update->z;
  3321. x_speed = update->speed_x;
  3322. y_speed = update->speed_y;
  3323. z_speed = update->speed_z;
  3324. appearance.pos.X2 = update->orig_x;
  3325. appearance.pos.Y2 = update->orig_y;
  3326. appearance.pos.Z2 = update->orig_z;
  3327. appearance.pos.X3 = update->orig_x2;
  3328. appearance.pos.Y3 = update->orig_y2;
  3329. appearance.pos.Z3 = update->orig_z2;
  3330. SetPitch(180 + update->pitch);
  3331. }
  3332. SetHeading((sint16)(direction1 * 64), (sint16)(direction2 * 64));
  3333. if (activity != last_movement_activity) {
  3334. switch(activity) {
  3335. case UPDATE_ACTIVITY_RUNNING:
  3336. case UPDATE_ACTIVITY_RUNNING_AOM:
  3337. case UPDATE_ACTIVITY_IN_WATER_ABOVE:
  3338. case UPDATE_ACTIVITY_IN_WATER_BELOW:
  3339. case UPDATE_ACTIVITY_MOVE_WATER_ABOVE_AOM:
  3340. case UPDATE_ACTIVITY_MOVE_WATER_BELOW_AOM: {
  3341. if(GetZone() && GetZone()->GetDrowningVictim(this))
  3342. GetZone()->RemoveDrowningVictim(this);
  3343. break;
  3344. }
  3345. case UPDATE_ACTIVITY_DROWNING:
  3346. case UPDATE_ACTIVITY_DROWNING2:
  3347. case UPDATE_ACTIVITY_DROWNING_AOM:
  3348. case UPDATE_ACTIVITY_DROWNING2_AOM: {
  3349. if(GetZone() && !GetInvulnerable()) {
  3350. GetZone()->AddDrowningVictim(this);
  3351. }
  3352. break;
  3353. }
  3354. case UPDATE_ACTIVITY_JUMPING:
  3355. case UPDATE_ACTIVITY_JUMPING_AOM:
  3356. case UPDATE_ACTIVITY_FALLING:
  3357. case UPDATE_ACTIVITY_FALLING_AOM: {
  3358. if(GetInitialState() != 1024) {
  3359. SetInitialState(1024);
  3360. }
  3361. else if(GetInitialState() == 1024) {
  3362. if(activity == UPDATE_ACTIVITY_JUMPING_AOM) {
  3363. SetInitialState(UPDATE_ACTIVITY_JUMPING_AOM);
  3364. }
  3365. else {
  3366. SetInitialState(16512);
  3367. }
  3368. }
  3369. break;
  3370. }
  3371. }
  3372. last_movement_activity = activity;
  3373. }
  3374. //Player is riding a lift, update lift XYZ offsets and the lift's spawn pointer
  3375. if (activity & UPDATE_ACTIVITY_RIDING_BOAT) {
  3376. Spawn* boat = 0;
  3377. float boat_x = x;
  3378. float boat_y = y;
  3379. float boat_z = z;
  3380. if (GetBoatSpawn() == 0 && GetZone()) {
  3381. boat = GetZone()->GetClosestTransportSpawn(GetX(), GetY(), GetZ());
  3382. SetBoatSpawn(boat);
  3383. if(boat)
  3384. {
  3385. LogWrite(PLAYER__DEBUG, 0, "Player", "Set Player %s (%u) on Boat: %s",
  3386. GetName(), GetCharacterID(), boat ? boat->GetName() : "notset");
  3387. boat->AddRailPassenger(GetCharacterID());
  3388. GetZone()->CallSpawnScript(boat, SPAWN_SCRIPT_BOARD, this);
  3389. }
  3390. }
  3391. if (boat || (GetBoatSpawn() && GetZone())) {
  3392. if (!boat)
  3393. boat = GetZone()->GetSpawnByID(GetBoatSpawn());
  3394. if (boat && boat->IsWidget() && ((Widget*)boat)->GetMultiFloorLift()) {
  3395. boat_x -= boat->GetX();
  3396. boat_y -= boat->GetY();
  3397. boat_z -= boat->GetZ();
  3398. //appearance.pos.grid_id = grid_id;
  3399. }
  3400. }
  3401. SetBoatX(boat_x);
  3402. SetBoatY(boat_y);
  3403. SetBoatZ(boat_z);
  3404. pos_packet_speed = speed;
  3405. grid_id = appearance.pos.grid_id;
  3406. }
  3407. else if (GetBoatSpawn() > 0 && !lift_cooldown.Enabled())
  3408. {
  3409. lift_cooldown.Start(100, true);
  3410. }
  3411. else if(lift_cooldown.Check())
  3412. {
  3413. if(GetBoatSpawn())
  3414. {
  3415. Spawn* boat = GetZone()->GetSpawnByID(GetBoatSpawn());
  3416. if(boat)
  3417. {
  3418. LogWrite(PLAYER__DEBUG, 0, "Player", "Remove Player %s (%u) from Boat: %s",
  3419. GetName(), GetCharacterID(), boat ? boat->GetName() : "notset");
  3420. boat->RemoveRailPassenger(GetCharacterID());
  3421. GetZone()->CallSpawnScript(boat, SPAWN_SCRIPT_DEBOARD, this);
  3422. }
  3423. }
  3424. SetBoatSpawn(0);
  3425. lift_cooldown.Disable();
  3426. }
  3427. if (!IsResurrecting() && !GetBoatSpawn())
  3428. {
  3429. if (!IsRooted() && !IsMezzedOrStunned()) {
  3430. SetX(x);
  3431. SetY(y);
  3432. SetZ(z);
  3433. SetSpeedX(x_speed);
  3434. SetSpeedY(y_speed);
  3435. SetSpeedZ(z_speed);
  3436. SetSideSpeed(side_speed);
  3437. pos_packet_speed = speed;
  3438. }
  3439. else {
  3440. SetSpeedX(0);
  3441. SetSpeedY(0);
  3442. SetSpeedZ(0);
  3443. SetSideSpeed(0);
  3444. pos_packet_speed = 0;
  3445. }
  3446. }
  3447. if (appearance.pos.grid_id != grid_id)
  3448. {
  3449. LogWrite(PLAYER__DEBUG, 0, "Player", "%s left grid %u and entered grid %u", appearance.name, appearance.pos.grid_id, grid_id);
  3450. const char* zone_script = world.GetZoneScript(GetZone()->GetZoneID());
  3451. if (zone_script && lua_interface)
  3452. {
  3453. lua_interface->RunZoneScript(zone_script, "enter_location", GetZone(), this, grid_id);
  3454. lua_interface->RunZoneScript(zone_script, "leave_location", GetZone(), this, appearance.pos.grid_id);
  3455. }
  3456. appearance.pos.grid_id = grid_id;
  3457. }
  3458. if (activity == UPDATE_ACTIVITY_IN_WATER_ABOVE || activity == UPDATE_ACTIVITY_IN_WATER_BELOW) {
  3459. if (MakeRandomFloat(0, 100) < 25 && InWater())
  3460. GetSkillByName("Swimming", true);
  3461. }
  3462. // don't have to uncomment the print packet but you MUST uncomment the safe_delete() for xml structs
  3463. //update->PrintPacket();
  3464. //safe_delete(update);
  3465. LogWrite(PLAYER__DEBUG, 7, "Player", "Exit: %s", __FUNCTION__); // trace
  3466. }
  3467. int16 Player::GetLastMovementActivity(){
  3468. return last_movement_activity;
  3469. }
  3470. void Player::AddSpawnInfoPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3471. spawn_info_packet_list[spawn_id] = string((char*)packet, packet_size);
  3472. }
  3473. void Player::AddSpawnPosPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3474. spawn_pos_packet_list[spawn_id] = string((char*)packet, packet_size);
  3475. }
  3476. uchar* Player::GetSpawnPosPacketForXOR(int32 spawn_id){
  3477. uchar* ret = 0;
  3478. if(spawn_pos_packet_list.count(spawn_id) == 1)
  3479. ret = (uchar*)spawn_pos_packet_list[spawn_id].c_str();
  3480. return ret;
  3481. }
  3482. uchar* Player::GetSpawnInfoPacketForXOR(int32 spawn_id){
  3483. uchar* ret = 0;
  3484. if(spawn_info_packet_list.count(spawn_id) == 1)
  3485. ret = (uchar*)spawn_info_packet_list[spawn_id].c_str();
  3486. return ret;
  3487. }
  3488. void Player::AddSpawnVisPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3489. spawn_vis_packet_list[spawn_id] = string((char*)packet, packet_size);
  3490. }
  3491. uchar* Player::GetSpawnVisPacketForXOR(int32 spawn_id){
  3492. uchar* ret = 0;
  3493. if(spawn_vis_packet_list.count(spawn_id) == 1)
  3494. ret = (uchar*)spawn_vis_packet_list[spawn_id].c_str();
  3495. return ret;
  3496. }
  3497. uchar* Player::GetTempInfoPacketForXOR(){
  3498. return spawn_tmp_info_xor_packet;
  3499. }
  3500. uchar* Player::GetTempVisPacketForXOR(){
  3501. return spawn_tmp_vis_xor_packet;
  3502. }
  3503. uchar* Player::GetTempPosPacketForXOR(){
  3504. return spawn_tmp_pos_xor_packet;
  3505. }
  3506. uchar* Player::SetTempInfoPacketForXOR(int16 size){
  3507. spawn_tmp_info_xor_packet = new uchar[size];
  3508. info_xor_size = size;
  3509. return spawn_tmp_info_xor_packet;
  3510. }
  3511. uchar* Player::SetTempVisPacketForXOR(int16 size){
  3512. spawn_tmp_vis_xor_packet = new uchar[size];
  3513. vis_xor_size = size;
  3514. return spawn_tmp_vis_xor_packet;
  3515. }
  3516. uchar* Player::SetTempPosPacketForXOR(int16 size){
  3517. spawn_tmp_pos_xor_packet = new uchar[size];
  3518. pos_xor_size = size;
  3519. return spawn_tmp_pos_xor_packet;
  3520. }
  3521. bool Player::CheckPlayerInfo(){
  3522. return info != 0;
  3523. }
  3524. bool Player::SetSpawnSentState(Spawn* spawn, SpawnState state) {
  3525. bool val = true;
  3526. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3527. int16 index = GetIndexForSpawn(spawn);
  3528. if(index > 0 && (state == SpawnState::SPAWN_STATE_SENDING)) {
  3529. LogWrite(PLAYER__WARNING, 0, "Player", "Spawn ALREADY INDEXED for Player %s (%u). Spawn %s (index %u) attempted to state %u.",
  3530. GetName(), GetCharacterID(), spawn->GetName(), index, state);
  3531. if(GetClient()->IsReloadingZone()) {
  3532. spawn_packet_sent.insert(make_pair(spawn->GetID(), state));
  3533. val = false;
  3534. }
  3535. // we don't do anything this spawn is already populated by the player
  3536. }
  3537. else {
  3538. LogWrite(PLAYER__DEBUG, 0, "Player", "Spawn for Player %s (%u). Spawn %s (index %u) in state %u.",
  3539. GetName(), GetCharacterID(), spawn->GetName(), index, state);
  3540. map<int32,int8>::iterator itr = spawn_packet_sent.find(spawn->GetID());
  3541. if(itr != spawn_packet_sent.end())
  3542. itr->second = state;
  3543. else
  3544. spawn_packet_sent.insert(make_pair(spawn->GetID(), state));
  3545. if(state == SPAWN_STATE_SENT_WAIT) {
  3546. map<int32,SpawnQueueState*>::iterator state_itr;
  3547. if((state_itr = spawn_state_list.find(spawn->GetID())) != spawn_state_list.end()) {
  3548. safe_delete(state_itr->second);
  3549. spawn_state_list.erase(state_itr);
  3550. }
  3551. SpawnQueueState* removal = new SpawnQueueState;
  3552. removal->index_id = index;
  3553. removal->spawn_state_timer = Timer(500, true);
  3554. removal->spawn_state_timer.Start();
  3555. spawn_state_list.insert(make_pair(spawn->GetID(),removal));
  3556. }
  3557. else if(state == SpawnState::SPAWN_STATE_REMOVING &&
  3558. spawn_state_list.count(spawn->GetID()) == 0) {
  3559. SpawnQueueState* removal = new SpawnQueueState;
  3560. removal->index_id = index;
  3561. removal->spawn_state_timer = Timer(1000, true);
  3562. removal->spawn_state_timer.Start();
  3563. spawn_state_list.insert(make_pair(spawn->GetID(),removal));
  3564. }
  3565. }
  3566. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3567. return val;
  3568. }
  3569. void Player::CheckSpawnStateQueue() {
  3570. if(!GetClient()->IsReadyForUpdates())
  3571. return;
  3572. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3573. map<int32, SpawnQueueState*>::iterator itr;
  3574. for(itr = spawn_state_list.begin(); itr != spawn_state_list.end();) {
  3575. if(itr->second->spawn_state_timer.Check()) {
  3576. map<int32, int8>::iterator sent_itr = spawn_packet_sent.find(itr->first);
  3577. LogWrite(PLAYER__DEBUG, 0, "Player", "Spawn for Player %s (%u). Spawn index %u in state %u.",
  3578. GetName(), GetCharacterID(), itr->second->index_id, sent_itr->second);
  3579. switch(sent_itr->second) {
  3580. case SpawnState::SPAWN_STATE_SENT_WAIT: {
  3581. sent_itr->second = SpawnState::SPAWN_STATE_SENT;
  3582. SpawnQueueState* sr = itr->second;
  3583. itr = spawn_state_list.erase(itr);
  3584. safe_delete(sr);
  3585. break;
  3586. }
  3587. case SpawnState::SPAWN_STATE_REMOVING: {
  3588. if(itr->first == GetID() && GetClient()->IsReloadingZone()) {
  3589. itr->second->spawn_state_timer.Disable();
  3590. continue;
  3591. }
  3592. if(itr->second->index_id) {
  3593. PacketStruct* packet = packet = configReader.getStruct("WS_DestroyGhostCmd", GetClient()->GetVersion());
  3594. packet->setDataByName("spawn_index", itr->second->index_id);
  3595. packet->setDataByName("delete", 1);
  3596. GetClient()->QueuePacket(packet->serialize());
  3597. safe_delete(packet);
  3598. }
  3599. sent_itr->second = SpawnState::SPAWN_STATE_REMOVING_SLEEP;
  3600. itr++;
  3601. break;
  3602. }
  3603. case SpawnState::SPAWN_STATE_REMOVING_SLEEP: {
  3604. map<int32, int8>::iterator sent_itr = spawn_packet_sent.find(itr->first);
  3605. sent_itr->second = SpawnState::SPAWN_STATE_REMOVED;
  3606. SpawnQueueState* sr = itr->second;
  3607. itr = spawn_state_list.erase(itr);
  3608. safe_delete(sr);
  3609. break;
  3610. }
  3611. default: {
  3612. // reset
  3613. itr->second->spawn_state_timer.Disable();
  3614. break;
  3615. }
  3616. }
  3617. }
  3618. else
  3619. itr++;
  3620. }
  3621. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3622. }
  3623. bool Player::WasSentSpawn(int32 spawn_id){
  3624. if(GetID() == spawn_id)
  3625. return true;
  3626. bool ret = false;
  3627. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3628. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3629. if(itr != spawn_packet_sent.end() && itr->second == SpawnState::SPAWN_STATE_SENT) {
  3630. ret = true;
  3631. }
  3632. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3633. return ret;
  3634. }
  3635. bool Player::IsSendingSpawn(int32 spawn_id){
  3636. bool ret = false;
  3637. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3638. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3639. if(itr != spawn_packet_sent.end() && (itr->second == SpawnState::SPAWN_STATE_SENDING || itr->second == SPAWN_STATE_SENT_WAIT)) {
  3640. ret = true;
  3641. }
  3642. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3643. return ret;
  3644. }
  3645. bool Player::IsRemovingSpawn(int32 spawn_id){
  3646. bool ret = false;
  3647. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3648. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3649. if(itr != spawn_packet_sent.end() &&
  3650. (itr->second == SpawnState::SPAWN_STATE_REMOVING || itr->second == SpawnState::SPAWN_STATE_REMOVING_SLEEP)) {
  3651. ret = true;
  3652. }
  3653. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3654. return ret;
  3655. }
  3656. PlayerSkillList* Player::GetSkills(){
  3657. return &skill_list;
  3658. }
  3659. void Player::InCombat(bool val, bool range) {
  3660. if (val)
  3661. GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() | (1 << (range?CF_RANGED_AUTO_ATTACK:CF_AUTO_ATTACK)));
  3662. else
  3663. GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() & ~(1 << (range?CF_RANGED_AUTO_ATTACK:CF_AUTO_ATTACK)));
  3664. bool changeCombatState = false;
  3665. if((in_combat && !val) || (!in_combat && val))
  3666. changeCombatState = true;
  3667. in_combat = val;
  3668. if(in_combat)
  3669. AddIconValue(64);
  3670. else
  3671. RemoveIconValue(64);
  3672. if(changeCombatState)
  3673. SetRegenValues(GetInfoStruct()->get_effective_level());
  3674. charsheet_changed = true;
  3675. info_changed = true;
  3676. }
  3677. void Player::SetCharSheetChanged(bool val){
  3678. charsheet_changed = val;
  3679. }
  3680. bool Player::GetCharSheetChanged(){
  3681. return charsheet_changed;
  3682. }
  3683. bool Player::AdventureXPEnabled(){
  3684. return (GetInfoStruct()->get_flags() & (1 << CF_COMBAT_EXPERIENCE_ENABLED));
  3685. }
  3686. bool Player::TradeskillXPEnabled() {
  3687. // TODO: need to identify the flag to togle tradeskill xp
  3688. return true;
  3689. }
  3690. void Player::set_character_flag(int flag){
  3691. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3692. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3693. if (flag > CF_MAXIMUM_FLAG) return;
  3694. if (flag < 32) GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() | (1 << flag));
  3695. else GetInfoStruct()->set_flags2(GetInfoStruct()->get_flags2() | (1 << (flag - 32)));
  3696. charsheet_changed = true;
  3697. info_changed = true;
  3698. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3699. }
  3700. void Player::reset_character_flag(int flag){
  3701. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3702. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3703. if (flag > CF_MAXIMUM_FLAG) return;
  3704. if (flag < 32)
  3705. {
  3706. int8 origflag = GetInfoStruct()->get_flags();
  3707. GetInfoStruct()->set_flags(origflag &= ~(1 << flag));
  3708. }
  3709. else
  3710. {
  3711. int8 flag2 = GetInfoStruct()->get_flags2();
  3712. GetInfoStruct()->set_flags2(flag2 &= ~(1 << (flag - 32)));
  3713. }
  3714. charsheet_changed = true;
  3715. info_changed = true;
  3716. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3717. }
  3718. void Player::toggle_character_flag(int flag){
  3719. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3720. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3721. if (flag > CF_MAXIMUM_FLAG) return;
  3722. if (flag < 32)
  3723. {
  3724. int32 origflag = GetInfoStruct()->get_flags();
  3725. GetInfoStruct()->set_flags(origflag ^= (1 << flag));
  3726. }
  3727. else
  3728. {
  3729. int32 flag2 = GetInfoStruct()->get_flags2();
  3730. GetInfoStruct()->set_flags2(flag2 ^= (1 << (flag - 32)));
  3731. }
  3732. charsheet_changed = true;
  3733. info_changed = true;
  3734. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3735. }
  3736. bool Player::get_character_flag(int flag){
  3737. bool ret = false;
  3738. if (flag > CF_MAXIMUM_FLAG){
  3739. LogWrite(PLAYER__DEBUG, 0, "Player", "Player::get_character_flag error: attempted to check flag %i", flag);
  3740. return ret;
  3741. }
  3742. if (flag < 32) ret = ((GetInfoStruct()->get_flags()) >> flag & 1);
  3743. else ret = ((GetInfoStruct()->get_flags2()) >> (flag - 32) & 1);
  3744. return ret;
  3745. }
  3746. float Player::GetXPVitality(){
  3747. return GetInfoStruct()->get_xp_vitality();
  3748. }
  3749. float Player::GetTSXPVitality() {
  3750. return GetInfoStruct()->get_tradeskill_xp_vitality();
  3751. }
  3752. bool Player::DoubleXPEnabled(){
  3753. return GetInfoStruct()->get_xp_vitality() > 0;
  3754. }
  3755. void Player::SetCharacterID(int32 new_id){
  3756. char_id = new_id;
  3757. }
  3758. int32 Player::GetCharacterID(){
  3759. return char_id;
  3760. }
  3761. float Player::CalculateXP(Spawn* victim){
  3762. if(AdventureXPEnabled() == false || !victim)
  3763. return 0;
  3764. float multiplier = 0;
  3765. float zone_xp_modifier = 1; // let's be safe!!
  3766. if( GetZone()->GetXPModifier() != 0 ) {
  3767. zone_xp_modifier = GetZone()->GetXPModifier();
  3768. LogWrite(PLAYER__DEBUG, 5, "XP", "Zone XP Modifier = %.2f", zone_xp_modifier);
  3769. }
  3770. switch(GetArrowColor(victim->GetLevel())){
  3771. case ARROW_COLOR_GRAY:
  3772. LogWrite(PLAYER__DEBUG, 5, "XP", "Gray Arrow = No XP");
  3773. return 0.0f;
  3774. break;
  3775. case ARROW_COLOR_GREEN:
  3776. multiplier = 3.25;
  3777. LogWrite(PLAYER__DEBUG, 5, "XP", "Green Arrow Multiplier = %.2f", multiplier);
  3778. break;
  3779. case ARROW_COLOR_BLUE:
  3780. multiplier = 3.5;
  3781. LogWrite(PLAYER__DEBUG, 5, "XP", "Blue Arrow Multiplier = %.2f", multiplier);
  3782. break;
  3783. case ARROW_COLOR_WHITE:
  3784. multiplier = 4;
  3785. LogWrite(PLAYER__DEBUG, 5, "XP", "White Arrow Multiplier = %.2f", multiplier);
  3786. break;
  3787. case ARROW_COLOR_YELLOW:
  3788. multiplier = 4.25;
  3789. LogWrite(PLAYER__DEBUG, 5, "XP", "Yellow Arrow Multiplier = %.2f", multiplier);
  3790. break;
  3791. case ARROW_COLOR_ORANGE:
  3792. multiplier = 4.5;
  3793. LogWrite(PLAYER__DEBUG, 5, "XP", "Orange Arrow Multiplier = %.2f", multiplier);
  3794. break;
  3795. case ARROW_COLOR_RED:
  3796. multiplier = 6;
  3797. LogWrite(PLAYER__DEBUG, 5, "XP", "Red Arrow Multiplier = %.2f", multiplier);
  3798. break;
  3799. }
  3800. float total = multiplier * 8;
  3801. LogWrite(PLAYER__DEBUG, 5, "XP", "Multiplier * 8 = %.2f", total);
  3802. if(victim->GetEncounterLevel() > 6) { // no need to multiply by 1 if this is a normal mob
  3803. total *= (victim->GetEncounterLevel() - 5);
  3804. LogWrite(PLAYER__DEBUG, 5, "XP", "Encounter > 6, total = %.2f", total);
  3805. }
  3806. else if(victim->GetEncounterLevel() <= 5) {
  3807. total /= (7 - victim->GetEncounterLevel()); //1 down mobs are worth half credit, 2 down worth .25, etc
  3808. LogWrite(PLAYER__DEBUG, 5, "XP", "Encounter <= 5, total = %.2f", total);
  3809. }
  3810. if(victim->GetHeroic() > 1) {
  3811. total *= victim->GetHeroic();
  3812. LogWrite(PLAYER__DEBUG, 5, "XP", "Heroic, total = %.2f", total);
  3813. }
  3814. if(DoubleXPEnabled()) {
  3815. LogWrite(PLAYER__DEBUG, 5, "XP", "Calculating Double XP!");
  3816. float percent = (((float)(total))/GetNeededXP()) *100;
  3817. LogWrite(PLAYER__DEBUG, 5, "XP", "Percent of total / XP Needed * 100, percent = %.2f", percent);
  3818. float xp_vitality = GetXPVitality();
  3819. if(xp_vitality >= percent) {
  3820. GetInfoStruct()->set_xp_vitality(xp_vitality - percent);
  3821. total *= 2;
  3822. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality >= Percent, total = %.2f", total);
  3823. }
  3824. else {
  3825. total += ((GetXPVitality() / percent) *2)*total;
  3826. GetInfoStruct()->set_xp_vitality(0);
  3827. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality < Percent, total = %.2f", total);
  3828. }
  3829. }
  3830. LogWrite(PLAYER__DEBUG, 5, "XP", "Final total = %.2f", (total * world.GetXPRate() * zone_xp_modifier));
  3831. return total * world.GetXPRate() * zone_xp_modifier;
  3832. }
  3833. float Player::CalculateTSXP(int8 level){
  3834. if(TradeskillXPEnabled() == false)
  3835. return 0;
  3836. float multiplier = 0;
  3837. float zone_xp_modifier = 1; // let's be safe!!
  3838. if( GetZone()->GetXPModifier() != 0 ) {
  3839. zone_xp_modifier = GetZone()->GetXPModifier();
  3840. LogWrite(PLAYER__DEBUG, 5, "XP", "Zone XP Modifier = %.2f", zone_xp_modifier);
  3841. }
  3842. sint16 diff = level - GetTSLevel();
  3843. if(GetTSLevel() < 10)
  3844. diff *= 3;
  3845. else if(GetTSLevel() <= 20)
  3846. diff *= 2;
  3847. if(diff >= 9)
  3848. multiplier = 6;
  3849. else if(diff >= 5)
  3850. multiplier = 4.5;
  3851. else if(diff >= 1)
  3852. multiplier = 4.25;
  3853. else if(diff == 0)
  3854. multiplier = 4;
  3855. else if(diff <= -11)
  3856. multiplier = 0;
  3857. else if(diff <= -6)
  3858. multiplier = 3.25;
  3859. else //if(diff < 0)
  3860. multiplier = 3.5;
  3861. float total = multiplier * 8;
  3862. LogWrite(PLAYER__DEBUG, 5, "XP", "Multiplier * 8 = %.2f", total);
  3863. if(DoubleXPEnabled()) {
  3864. LogWrite(PLAYER__DEBUG, 5, "XP", "Calculating Double XP!");
  3865. float percent = (((float)(total))/GetNeededTSXP()) *100;
  3866. LogWrite(PLAYER__DEBUG, 5, "XP", "Percent of total / XP Needed * 100, percent = %.2f", percent);
  3867. float ts_xp_vitality = GetTSXPVitality();
  3868. if(ts_xp_vitality >= percent) {
  3869. GetInfoStruct()->set_tradeskill_xp_vitality(ts_xp_vitality - percent);
  3870. total *= 2;
  3871. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality >= Percent, total = %.2f", total);
  3872. }
  3873. else {
  3874. total += ((GetTSXPVitality() / percent) *2)*total;
  3875. GetInfoStruct()->set_tradeskill_xp_vitality(0);
  3876. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality < Percent, total = %.2f", total);
  3877. }
  3878. }
  3879. LogWrite(PLAYER__DEBUG, 5, "XP", "Final total = %.2f", (total * world.GetXPRate() * zone_xp_modifier));
  3880. return total * world.GetXPRate() * zone_xp_modifier;
  3881. }
  3882. void Player::CalculateOfflineDebtRecovery(int32 unix_timestamp)
  3883. {
  3884. float xpDebt = GetXPDebt();
  3885. // not a real timestamp to work with
  3886. if(unix_timestamp < 1 || xpDebt == 0.0f)
  3887. return;
  3888. uint32 diff = (Timer::GetCurrentTime2() - unix_timestamp)/1000;
  3889. float recoveryDebtPercentage = rule_manager.GetGlobalRule(R_Combat, ExperienceDebtRecoveryPercent)->GetFloat()/100.0f;
  3890. int32 recoveryPeriodSeconds = rule_manager.GetGlobalRule(R_Combat, ExperienceDebtRecoveryPeriod)->GetInt32();
  3891. if(recoveryDebtPercentage == 0.0f || recoveryPeriodSeconds < 1)
  3892. return;
  3893. float periodsPassed = (float)diff/(float)recoveryPeriodSeconds;
  3894. // not enough time passed to calculate debt xp recovered
  3895. if(periodsPassed < 1.0f)
  3896. return;
  3897. float debtToSubtract = xpDebt * ((recoveryDebtPercentage*periodsPassed)/100.0f);
  3898. if(debtToSubtract >= xpDebt)
  3899. GetInfoStruct()->set_xp_debt(0.0f);
  3900. else
  3901. GetInfoStruct()->set_xp_debt(xpDebt - debtToSubtract);
  3902. }
  3903. void Player::SetNeededXP(int32 val){
  3904. GetInfoStruct()->set_xp_needed(val);
  3905. }
  3906. void Player::SetNeededXP(){
  3907. //GetInfoStruct()->xp_needed = GetLevel() * 100;
  3908. // Get xp needed to get to the next level
  3909. int16 level = GetLevel() + 1;
  3910. // If next level is beyond what we have in the map multiply the last value we have by how many levels we are over plus one
  3911. if (level > 95)
  3912. SetNeededXP(m_levelXPReq[95] * ((level - 95) + 1));
  3913. else
  3914. SetNeededXP(m_levelXPReq[level]);
  3915. }
  3916. void Player::SetXP(int32 val){
  3917. GetInfoStruct()->set_xp(val);
  3918. }
  3919. void Player::SetNeededTSXP(int32 val) {
  3920. GetInfoStruct()->set_ts_xp_needed(val);
  3921. }
  3922. void Player::SetNeededTSXP() {
  3923. GetInfoStruct()->set_ts_xp_needed(GetTSLevel() * 100);
  3924. }
  3925. void Player::SetTSXP(int32 val) {
  3926. GetInfoStruct()->set_ts_xp(val);
  3927. }
  3928. float Player::GetXPDebt(){
  3929. return GetInfoStruct()->get_xp_debt();
  3930. }
  3931. int32 Player::GetNeededXP(){
  3932. return GetInfoStruct()->get_xp_needed();
  3933. }
  3934. int32 Player::GetXP(){
  3935. return GetInfoStruct()->get_xp();
  3936. }
  3937. int32 Player::GetNeededTSXP() {
  3938. return GetInfoStruct()->get_ts_xp_needed();
  3939. }
  3940. int32 Player::GetTSXP() {
  3941. return GetInfoStruct()->get_ts_xp();
  3942. }
  3943. bool Player::AddXP(int32 xp_amount){
  3944. MStats.lock();
  3945. xp_amount += (int32)(((float)xp_amount) * stats[ITEM_STAT_COMBATEXPMOD]) / 100;
  3946. MStats.unlock();
  3947. if(GetInfoStruct()->get_xp_debt())
  3948. {
  3949. float expRatioToDebt = rule_manager.GetGlobalRule(R_Combat, ExperienceToDebt)->GetFloat()/100.0f;
  3950. int32 amountToTakeFromDebt = (int32)((float)expRatioToDebt * (float)xp_amount);
  3951. int32 amountRequiredClearDebt = (GetInfoStruct()->get_xp_debt()/100.0f) * xp_amount;
  3952. if(amountToTakeFromDebt > amountRequiredClearDebt)
  3953. {
  3954. GetInfoStruct()->set_xp_debt(0.0f);
  3955. if(amountRequiredClearDebt > xp_amount)
  3956. xp_amount = 0;
  3957. else
  3958. xp_amount -= amountRequiredClearDebt;
  3959. }
  3960. else
  3961. {
  3962. float amountRemovedPct = ((float)amountToTakeFromDebt/(float)amountRequiredClearDebt);
  3963. GetInfoStruct()->set_xp_debt(GetInfoStruct()->get_xp_debt()-amountRemovedPct);
  3964. if(amountToTakeFromDebt > xp_amount)
  3965. xp_amount = 0;
  3966. else
  3967. xp_amount -= amountToTakeFromDebt;
  3968. }
  3969. }
  3970. // used up in xp debt
  3971. if(!xp_amount)
  3972. return true;
  3973. float current_xp_percent = ((float)GetXP()/(float)GetNeededXP())*100;
  3974. float miniding_min_percent = ((int)(current_xp_percent/10)+1)*10;
  3975. while((xp_amount + GetXP()) >= GetNeededXP()){
  3976. if (!CheckLevelStatus(GetLevel() + 1)) {
  3977. GetZone()->GetClientBySpawn(this)->SimpleMessage(CHANNEL_COLOR_RED, "You do not have the required status to level up anymore!");
  3978. return false;
  3979. }
  3980. xp_amount -= GetNeededXP() - GetXP();
  3981. SetLevel(GetLevel() + 1);
  3982. }
  3983. SetXP(GetXP() + xp_amount);
  3984. GetPlayerInfo()->CalculateXPPercentages();
  3985. current_xp_percent = ((float)GetXP()/(float)GetNeededXP())*100;
  3986. if(current_xp_percent >= miniding_min_percent){
  3987. SetHP(GetTotalHP());
  3988. SetPower(GetTotalPower());
  3989. GetZone()->SendCastSpellPacket(332, this, this); //send mini level up spell effect
  3990. }
  3991. return true;
  3992. }
  3993. bool Player::AddTSXP(int32 xp_amount){
  3994. MStats.lock();
  3995. xp_amount += ((xp_amount)*stats[ITEM_STAT_TRADESKILLEXPMOD]) / 100;
  3996. MStats.unlock();
  3997. float current_xp_percent = ((float)GetTSXP()/(float)GetNeededTSXP())*100;
  3998. float miniding_min_percent = ((int)(current_xp_percent/10)+1)*10;
  3999. while((xp_amount + GetTSXP()) >= GetNeededTSXP()){
  4000. if (!CheckLevelStatus(GetTSLevel() + 1)) {
  4001. GetZone()->GetClientBySpawn(this)->SimpleMessage(CHANNEL_COLOR_RED, "You do not have the required status to level up anymore!");
  4002. return false;
  4003. }
  4004. xp_amount -= GetNeededTSXP() - GetTSXP();
  4005. SetTSLevel(GetTSLevel() + 1);
  4006. SetTSXP(0);
  4007. SetNeededTSXP();
  4008. }
  4009. SetTSXP(GetTSXP() + xp_amount);
  4010. GetPlayerInfo()->CalculateXPPercentages();
  4011. current_xp_percent = ((float)GetTSXP()/(float)GetNeededTSXP())*100;
  4012. if(current_xp_percent >= miniding_min_percent){
  4013. SetHP(GetTotalHP());
  4014. SetPower(GetTotalPower());
  4015. }
  4016. if (GetTradeskillClass() == 0){
  4017. SetTradeskillClass(1);
  4018. GetInfoStruct()->set_tradeskill_class1(1);
  4019. GetInfoStruct()->set_tradeskill_class2(1);
  4020. GetInfoStruct()->set_tradeskill_class3(1);
  4021. }
  4022. return true;
  4023. }
  4024. void Player::CalculateLocation(){
  4025. if(GetSpeed() > 0 ){
  4026. if(GetHeading() >= 270 && GetHeading() <= 360){
  4027. SetX(GetX() + (GetSpeed()*.5)*((360-GetHeading())/90));
  4028. SetZ(GetZ() - (GetSpeed()*.5)*((GetHeading()-270)/90));
  4029. }
  4030. else if(GetHeading() >= 180 && GetHeading() < 270){
  4031. SetX(GetX() + (GetSpeed()*.5)*((GetHeading()-180)/90));
  4032. SetZ(GetZ() + (GetSpeed()*.5)*((270-GetHeading())/90));
  4033. }
  4034. else if(GetHeading() >= 90 && GetHeading() < 180){
  4035. SetX(GetX() - (GetSpeed()*.5)*((180-GetHeading())/90));
  4036. SetZ(GetZ() + (GetSpeed()*.5)*((GetHeading()-90)/90));
  4037. }
  4038. else if(GetHeading() >= 0 && GetHeading() < 90){
  4039. SetX(GetX() - (GetSpeed()*.5)*(GetHeading()/90));
  4040. SetZ(GetZ() - (GetSpeed()*.5)*((90-GetHeading())/90));
  4041. }
  4042. }
  4043. }
  4044. Spawn* Player::GetSpawnByIndex(int16 index){
  4045. Spawn* spawn = 0;
  4046. index_mutex.readlock(__FUNCTION__, __LINE__);
  4047. if(player_spawn_id_map.count(index) > 0)
  4048. spawn = player_spawn_id_map[index];
  4049. index_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4050. return spawn;
  4051. }
  4052. int16 Player::GetIndexForSpawn(Spawn* spawn) {
  4053. int16 val = 0;
  4054. index_mutex.readlock(__FUNCTION__, __LINE__);
  4055. if(player_spawn_reverse_id_map.count(spawn) > 0)
  4056. val = player_spawn_reverse_id_map[spawn];
  4057. index_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4058. return val;
  4059. }
  4060. bool Player::WasSpawnRemoved(Spawn* spawn){
  4061. bool wasRemoved = false;
  4062. if(IsRemovingSpawn(spawn->GetID()))
  4063. return false;
  4064. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  4065. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  4066. if(itr != spawn_packet_sent.end() && itr->second == SpawnState::SPAWN_STATE_REMOVED) {
  4067. wasRemoved = true;
  4068. }
  4069. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4070. return wasRemoved;
  4071. }
  4072. void Player::RemoveSpawn(Spawn* spawn)
  4073. {
  4074. LogWrite(PLAYER__DEBUG, 3, "Player", "Remove Spawn '%s' (%u)", spawn->GetName(), spawn->GetID());
  4075. SetSpawnSentState(spawn, SpawnState::SPAWN_STATE_REMOVING);
  4076. info_mutex.writelock(__FUNCTION__, __LINE__);
  4077. vis_mutex.writelock(__FUNCTION__, __LINE__);
  4078. pos_mutex.writelock(__FUNCTION__, __LINE__);
  4079. index_mutex.writelock(__FUNCTION__, __LINE__);
  4080. if (player_spawn_reverse_id_map[spawn] && player_spawn_id_map.count(player_spawn_reverse_id_map[spawn]) > 0)
  4081. player_spawn_id_map.erase(player_spawn_reverse_id_map[spawn]);
  4082. if (player_spawn_reverse_id_map.count(spawn) > 0)
  4083. player_spawn_reverse_id_map.erase(spawn);
  4084. if (player_spawn_id_map.count(spawn->GetID()) && player_spawn_id_map[spawn->GetID()] == spawn)
  4085. player_spawn_id_map.erase(spawn->GetID());
  4086. int32 id = spawn->GetID();
  4087. if (spawn_info_packet_list.count(id))
  4088. spawn_info_packet_list.erase(id);
  4089. if (spawn_pos_packet_list.count(id))
  4090. spawn_pos_packet_list.erase(id);
  4091. if (spawn_vis_packet_list.count(id))
  4092. spawn_vis_packet_list.erase(id);
  4093. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4094. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4095. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4096. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4097. }
  4098. vector<int32> Player::GetQuestIDs(){
  4099. vector<int32> ret;
  4100. map<int32, Quest*>::iterator itr;
  4101. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4102. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4103. if(itr->second)
  4104. ret.push_back(itr->second->GetQuestID());
  4105. }
  4106. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4107. return ret;
  4108. }
  4109. vector<Quest*>* Player::CheckQuestsItemUpdate(Item* item){
  4110. vector<Quest*>* quest_updates = 0;
  4111. map<int32, Quest*>::iterator itr;
  4112. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4113. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4114. if(itr->second && itr->second->CheckQuestItemUpdate(item->details.item_id, item->details.count)){
  4115. if(!quest_updates)
  4116. quest_updates = new vector<Quest*>();
  4117. quest_updates->push_back(itr->second);
  4118. }
  4119. }
  4120. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4121. return quest_updates;
  4122. }
  4123. void Player::CheckQuestsCraftUpdate(Item* item, int32 qty){
  4124. map<int32, Quest*>::iterator itr;
  4125. vector<Quest*>* update_list = new vector<Quest*>;
  4126. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4127. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4128. if(itr->second){
  4129. if(item && qty > 0){
  4130. if(itr->second->CheckQuestRefIDUpdate(item->details.item_id, qty)){
  4131. update_list->push_back(itr->second);
  4132. }
  4133. }
  4134. }
  4135. }
  4136. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4137. if(update_list && update_list->size() > 0){
  4138. Client* client = GetZone()->GetClientBySpawn(this);
  4139. if(client){
  4140. for(int8 i=0;i<update_list->size(); i++){
  4141. client->SendQuestUpdate(update_list->at(i));
  4142. client->SendQuestFailure(update_list->at(i));
  4143. }
  4144. }
  4145. }
  4146. update_list->clear();
  4147. safe_delete(update_list);
  4148. }
  4149. void Player::CheckQuestsHarvestUpdate(Item* item, int32 qty){
  4150. map<int32, Quest*>::iterator itr;
  4151. vector<Quest*>* update_list = new vector<Quest*>;
  4152. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4153. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4154. if(itr->second){
  4155. if(item && qty > 0){
  4156. if(itr->second->CheckQuestRefIDUpdate(item->details.item_id, qty)){
  4157. update_list->push_back(itr->second);
  4158. }
  4159. }
  4160. }
  4161. }
  4162. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4163. if(update_list && update_list->size() > 0){
  4164. Client* client = GetZone()->GetClientBySpawn(this);
  4165. if(client){
  4166. for(int8 i=0;i<update_list->size(); i++){
  4167. client->SendQuestUpdate(update_list->at(i));
  4168. client->SendQuestFailure(update_list->at(i));
  4169. }
  4170. }
  4171. }
  4172. update_list->clear();
  4173. safe_delete(update_list);
  4174. }
  4175. vector<Quest*>* Player::CheckQuestsSpellUpdate(Spell* spell) {
  4176. vector<Quest*>* quest_updates = 0;
  4177. map<int32, Quest*>::iterator itr;
  4178. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4179. for (itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4180. if (itr->second && itr->second->CheckQuestSpellUpdate(spell)) {
  4181. if (!quest_updates)
  4182. quest_updates = new vector<Quest*>();
  4183. quest_updates->push_back(itr->second);
  4184. }
  4185. }
  4186. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4187. return quest_updates;
  4188. }
  4189. PacketStruct* Player::GetQuestJournalPacket(bool all_quests, int16 version, int32 crc, int32 current_quest_id, bool updated){
  4190. PacketStruct* packet = configReader.getStruct("WS_QuestJournalUpdate", version);
  4191. Quest* quest = 0;
  4192. if(packet){
  4193. int16 total_quests_num = 0;
  4194. int16 total_completed_quests = 0;
  4195. map<int32, Quest*> total_quests = player_quests;
  4196. if(all_quests && completed_quests.size() > 0)
  4197. total_quests.insert(completed_quests.begin(), completed_quests.end());
  4198. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4199. if(total_quests.size() > 0){
  4200. map<string, int16> quest_types;
  4201. map<int32, Quest*>::iterator itr;
  4202. int16 zone_id = 0;
  4203. for(itr = total_quests.begin(); itr != total_quests.end(); itr++){
  4204. if(itr->first && itr->second){
  4205. if(current_quest_id == 0 && itr->second->GetTurnedIn() == false)
  4206. current_quest_id = itr->first;
  4207. if(itr->second->GetTurnedIn())
  4208. total_completed_quests++;
  4209. if(itr->second->GetType()){
  4210. if(quest_types.count(itr->second->GetType()) == 0){
  4211. quest_types[itr->second->GetType()] = zone_id;
  4212. zone_id++;
  4213. }
  4214. }
  4215. if(itr->second->GetZone()){
  4216. if(quest_types.count(itr->second->GetType()) == 0){
  4217. quest_types[itr->second->GetType()] = zone_id;
  4218. zone_id++;
  4219. }
  4220. }
  4221. total_quests_num++;
  4222. }
  4223. else
  4224. continue;
  4225. }
  4226. packet->setArrayLengthByName("num_quests", total_quests_num);
  4227. int16 i = 0;
  4228. for(itr = total_quests.begin(); itr != total_quests.end(); itr++){
  4229. if(i == 0 && quest_types.size() > 0){
  4230. packet->setArrayLengthByName("num_quest_zones", quest_types.size());
  4231. map<string, int16>::iterator type_itr;
  4232. int16 x = 0;
  4233. for(type_itr = quest_types.begin(); type_itr != quest_types.end(); type_itr++){
  4234. packet->setArrayDataByName("quest_zones_zone", type_itr->first.c_str(), x);
  4235. packet->setArrayDataByName("quest_zones_zone_id", type_itr->second, x);
  4236. x++;
  4237. }
  4238. }
  4239. if(itr->first == 0 || !itr->second)
  4240. continue;
  4241. if(!all_quests && !itr->second->GetUpdateRequired())
  4242. continue;
  4243. quest = itr->second;
  4244. if(!quest->GetDeleted())
  4245. packet->setArrayDataByName("active", 1, i);
  4246. packet->setArrayDataByName("name", quest->GetName(), i);
  4247. packet->setArrayDataByName("quest_type", quest->GetType(), i);
  4248. packet->setArrayDataByName("quest_zone", quest->GetZone(), i);
  4249. int8 display_status = QUEST_DISPLAY_STATUS_NORMAL;
  4250. if(itr->second->GetCompleted())
  4251. packet->setArrayDataByName("completed", 1, i);
  4252. if(itr->second->GetTurnedIn()){
  4253. packet->setArrayDataByName("turned_in", 1, i);
  4254. packet->setArrayDataByName("completed", 1, i);
  4255. packet->setArrayDataByName("visible", 1, i);
  4256. packet->setArrayDataByName("unknown3", 1, i);
  4257. display_status += QUEST_DISPLAY_STATUS_COMPLETED;
  4258. }
  4259. if (updated) {
  4260. packet->setArrayDataByName("quest_updated", 1, i);
  4261. packet->setArrayDataByName("journal_updated", 1, i);
  4262. }
  4263. packet->setArrayDataByName("quest_id", quest->GetQuestID(), i);
  4264. packet->setArrayDataByName("day", quest->GetDay(), i);
  4265. packet->setArrayDataByName("month", quest->GetMonth(), i);
  4266. packet->setArrayDataByName("year", quest->GetYear(), i);
  4267. packet->setArrayDataByName("level", quest->GetQuestLevel(), i);
  4268. int8 difficulty = 0;
  4269. string category = quest->GetType();
  4270. if(category == "Tradeskill")
  4271. difficulty = GetTSArrowColor(quest->GetQuestLevel());
  4272. else
  4273. difficulty = GetArrowColor(quest->GetQuestLevel());
  4274. packet->setArrayDataByName("difficulty", difficulty, i);
  4275. if (itr->second->GetEncounterLevel() > 4)
  4276. packet->setArrayDataByName("encounter_level", quest->GetEncounterLevel(), i);
  4277. else
  4278. packet->setArrayDataByName("encounter_level", 4, i);
  4279. if(version >= 931 && quest_types.count(quest->GetType()) > 0)
  4280. packet->setArrayDataByName("zonetype_id", quest_types[quest->GetType()], i);
  4281. if(version >= 931 && quest_types.count(quest->GetZone()) > 0)
  4282. packet->setArrayDataByName("zone_id", quest_types[quest->GetZone()], i);
  4283. if(version >= 931 && quest->GetVisible()){
  4284. if (quest->GetCompletedFlag())
  4285. display_status += QUEST_DISPLAY_STATUS_COMPLETE_FLAG;
  4286. else if (quest->IsRepeatable())
  4287. display_status += QUEST_DISPLAY_STATUS_REPEATABLE;
  4288. if (quest->GetYellowName() || quest->CheckCategoryYellow())
  4289. display_status += QUEST_DISPLAY_STATUS_YELLOW;
  4290. if (quest->IsTracked())
  4291. display_status += QUEST_DISPLAY_STATUS_CHECK;
  4292. else
  4293. display_status += QUEST_DISPLAY_STATUS_NO_CHECK;
  4294. if (quest->IsHidden() && !quest->GetTurnedIn())
  4295. display_status = QUEST_DISPLAY_STATUS_HIDDEN;
  4296. }
  4297. else
  4298. packet->setArrayDataByName("visible", quest->GetVisible(), i);
  4299. if (itr->second->IsRepeatable())
  4300. packet->setArrayDataByName("repeatable", 1, i);
  4301. packet->setArrayDataByName("display_status", display_status, i);
  4302. i++;
  4303. }
  4304. //packet->setDataByName("unknown4", 0);
  4305. packet->setDataByName("visible_quest_id", current_quest_id);
  4306. }
  4307. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4308. packet->setDataByName("player_crc", crc);
  4309. packet->setDataByName("player_name", GetName());
  4310. packet->setDataByName("used_quests", total_quests_num - total_completed_quests);
  4311. packet->setDataByName("max_quests", 75);
  4312. LogWrite(PLAYER__PACKET, 0, "Player", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  4313. #if EQDEBUG >= 9
  4314. packet->PrintPacket();
  4315. #endif
  4316. }
  4317. return packet;
  4318. }
  4319. PacketStruct* Player::GetQuestJournalPacket(Quest* quest, int16 version, int32 crc, bool updated) {
  4320. if (!quest)
  4321. return 0;
  4322. PacketStruct* packet = configReader.getStruct("WS_QuestJournalUpdate", version);
  4323. if (packet) {
  4324. packet->setArrayLengthByName("num_quests", 1);
  4325. packet->setArrayLengthByName("num_quest_zones", 1);
  4326. packet->setArrayDataByName("quest_zones_zone", quest->GetType());
  4327. packet->setArrayDataByName("quest_zones_zone_id", 0);
  4328. if(!quest->GetDeleted() && !quest->GetCompleted())
  4329. packet->setArrayDataByName("active", 1);
  4330. packet->setArrayDataByName("name", quest->GetName());
  4331. // don't see these two in the struct
  4332. packet->setArrayDataByName("quest_type", quest->GetType());
  4333. packet->setArrayDataByName("quest_zone", quest->GetZone());
  4334. int8 display_status = QUEST_DISPLAY_STATUS_NORMAL;
  4335. if(quest->GetCompleted())
  4336. packet->setArrayDataByName("completed", 1);
  4337. if(quest->GetTurnedIn()) {
  4338. packet->setArrayDataByName("turned_in", 1);
  4339. packet->setArrayDataByName("completed", 1);
  4340. packet->setArrayDataByName("visible", 1);
  4341. display_status += QUEST_DISPLAY_STATUS_COMPLETED;
  4342. }
  4343. packet->setArrayDataByName("quest_id", quest->GetQuestID());
  4344. packet->setArrayDataByName("day", quest->GetDay());
  4345. packet->setArrayDataByName("month", quest->GetMonth());
  4346. packet->setArrayDataByName("year", quest->GetYear());
  4347. packet->setArrayDataByName("level", quest->GetQuestLevel());
  4348. int8 difficulty = 0;
  4349. string category = quest->GetType();
  4350. if(category == "Tradeskill")
  4351. difficulty = GetTSArrowColor(quest->GetQuestLevel());
  4352. else
  4353. difficulty = GetArrowColor(quest->GetQuestLevel());
  4354. packet->setArrayDataByName("difficulty", difficulty);
  4355. if (quest->GetEncounterLevel() > 4)
  4356. packet->setArrayDataByName("encounter_level", quest->GetEncounterLevel());
  4357. else
  4358. packet->setArrayDataByName("encounter_level", 4);
  4359. if (version >= 931) {
  4360. packet->setArrayDataByName("zonetype_id", 0);
  4361. packet->setArrayDataByName("zone_id", 0);
  4362. }
  4363. if(version >= 931 && quest->GetVisible()){
  4364. if (quest->GetCompletedFlag())
  4365. display_status += QUEST_DISPLAY_STATUS_COMPLETE_FLAG;
  4366. else if (quest->IsRepeatable())
  4367. display_status += QUEST_DISPLAY_STATUS_REPEATABLE;
  4368. if (quest->GetYellowName() || quest->CheckCategoryYellow())
  4369. display_status += QUEST_DISPLAY_STATUS_YELLOW;
  4370. if (quest->IsTracked())
  4371. display_status += QUEST_DISPLAY_STATUS_CHECK;
  4372. else
  4373. display_status += QUEST_DISPLAY_STATUS_NO_CHECK;
  4374. if (quest->IsHidden() && !quest->GetTurnedIn())
  4375. display_status = QUEST_DISPLAY_STATUS_HIDDEN;
  4376. }
  4377. else
  4378. packet->setArrayDataByName("visible", quest->GetVisible());
  4379. if (quest->IsRepeatable())
  4380. packet->setArrayDataByName("repeatable", 1);
  4381. packet->setArrayDataByName("display_status", display_status);
  4382. if (updated) {
  4383. packet->setArrayDataByName("quest_updated", 1);
  4384. packet->setArrayDataByName("journal_updated", 1);
  4385. }
  4386. if(version >= 546)
  4387. packet->setDataByName("unknown3", 1);
  4388. packet->setDataByName("visible_quest_id", quest->GetQuestID());
  4389. packet->setDataByName("player_crc", crc);
  4390. packet->setDataByName("player_name", GetName());
  4391. packet->setDataByName("used_quests", player_quests.size());
  4392. packet->setDataByName("unknown4a", 1);
  4393. packet->setDataByName("max_quests", 75);
  4394. }
  4395. return packet;
  4396. }
  4397. Quest* Player::SetStepComplete(int32 id, int32 step){
  4398. Quest* ret = 0;
  4399. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4400. if(player_quests.count(id) > 0){
  4401. if(player_quests[id]->SetStepComplete(step))
  4402. ret = player_quests[id];
  4403. }
  4404. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4405. return ret;
  4406. }
  4407. Quest* Player::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4408. Quest* ret = 0;
  4409. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4410. if (player_quests.count(quest_id) > 0) {
  4411. if (player_quests[quest_id]->AddStepProgress(step, progress))
  4412. ret = player_quests[quest_id];
  4413. }
  4414. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4415. return ret;
  4416. }
  4417. int32 Player::GetStepProgress(int32 quest_id, int32 step_id) {
  4418. int32 ret = 0;
  4419. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4420. if (player_quests.count(quest_id) > 0)
  4421. ret = player_quests[quest_id]->GetStepProgress(step_id);
  4422. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4423. return ret;
  4424. }
  4425. void Player::RemoveQuest(int32 id, bool delete_quest){
  4426. MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  4427. if(delete_quest){
  4428. safe_delete(player_quests[id]);
  4429. }
  4430. map<int32, Quest*>::iterator itr = player_quests.find(id);
  4431. if(itr != player_quests.end()) {
  4432. player_quests.erase(itr);
  4433. }
  4434. MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  4435. SendQuestRequiredSpawns(id);
  4436. }
  4437. vector<Quest*>* Player::CheckQuestsLocationUpdate(){
  4438. vector<Quest*>* quest_updates = 0;
  4439. map<int32, Quest*>::iterator itr;
  4440. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4441. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4442. if(itr->second && itr->second->CheckQuestLocationUpdate(GetX(), GetY(), GetZ(), (GetZone() ? GetZone()->GetZoneID() : 0))){
  4443. if(!quest_updates)
  4444. quest_updates = new vector<Quest*>();
  4445. quest_updates->push_back(itr->second);
  4446. }
  4447. }
  4448. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4449. return quest_updates;
  4450. }
  4451. vector<Quest*>* Player::CheckQuestsFailures(){
  4452. vector<Quest*>* quest_failures = 0;
  4453. map<int32, Quest*>::iterator itr;
  4454. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4455. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4456. if(itr->second && itr->second->GetQuestFailures()->size() > 0){
  4457. if(!quest_failures)
  4458. quest_failures = new vector<Quest*>();
  4459. quest_failures->push_back(itr->second);
  4460. }
  4461. }
  4462. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4463. return quest_failures;
  4464. }
  4465. vector<Quest*>* Player::CheckQuestsKillUpdate(Spawn* spawn, bool update){
  4466. vector<Quest*>* quest_updates = 0;
  4467. map<int32, Quest*>::iterator itr;
  4468. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4469. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4470. if(itr->second && itr->second->CheckQuestKillUpdate(spawn, update)){
  4471. if(!quest_updates)
  4472. quest_updates = new vector<Quest*>();
  4473. quest_updates->push_back(itr->second);
  4474. }
  4475. }
  4476. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4477. return quest_updates;
  4478. }
  4479. bool Player::HasQuestUpdateRequirement(Spawn* spawn){
  4480. bool reqMet = false;
  4481. map<int32, Quest*>::iterator itr;
  4482. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4483. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4484. if(itr->second && itr->second->CheckQuestReferencedSpawns(spawn)){
  4485. reqMet = true;
  4486. break;
  4487. }
  4488. }
  4489. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4490. return reqMet;
  4491. }
  4492. vector<Quest*>* Player::CheckQuestsChatUpdate(Spawn* spawn){
  4493. vector<Quest*>* quest_updates = 0;
  4494. map<int32, Quest*>::iterator itr;
  4495. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4496. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4497. if(itr->second && itr->second->CheckQuestChatUpdate(spawn->GetDatabaseID())){
  4498. if(!quest_updates)
  4499. quest_updates = new vector<Quest*>();
  4500. quest_updates->push_back(itr->second);
  4501. }
  4502. }
  4503. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4504. return quest_updates;
  4505. }
  4506. int16 Player::GetTaskGroupStep(int32 quest_id){
  4507. Quest* quest = 0;
  4508. int16 step = 0;
  4509. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4510. if(player_quests.count(quest_id) > 0){
  4511. quest = player_quests[quest_id];
  4512. if(quest) {
  4513. step = quest->GetTaskGroupStep();
  4514. }
  4515. }
  4516. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4517. return step;
  4518. }
  4519. bool Player::GetQuestStepComplete(int32 quest_id, int32 step_id){
  4520. bool ret = false;
  4521. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4522. if(player_quests.count(quest_id) > 0){
  4523. Quest* quest = player_quests[quest_id];
  4524. if ( quest != NULL )
  4525. ret = quest->GetQuestStepCompleted(step_id);
  4526. }
  4527. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4528. return ret;
  4529. }
  4530. int16 Player::GetQuestStep(int32 quest_id){
  4531. Quest* quest = 0;
  4532. int16 step = 0;
  4533. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4534. if(player_quests.count(quest_id) > 0){
  4535. quest = player_quests[quest_id];
  4536. if(quest) {
  4537. step = quest->GetQuestStep();
  4538. }
  4539. }
  4540. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4541. return step;
  4542. }
  4543. map<int32, Quest*>* Player::GetPlayerQuests(){
  4544. return &player_quests;
  4545. }
  4546. map<int32, Quest*>* Player::GetCompletedPlayerQuests(){
  4547. return &completed_quests;
  4548. }
  4549. Quest* Player::GetAnyQuest(int32 quest_id) {
  4550. if(player_quests.count(quest_id) > 0)
  4551. return player_quests[quest_id];
  4552. if(completed_quests.count(quest_id) > 0)
  4553. return completed_quests[quest_id];
  4554. return 0;
  4555. }
  4556. Quest* Player::GetCompletedQuest(int32 quest_id){
  4557. if(completed_quests.count(quest_id) > 0)
  4558. return completed_quests[quest_id];
  4559. return 0;
  4560. }
  4561. Quest* Player::GetQuest(int32 quest_id){
  4562. if(player_quests.count(quest_id) > 0)
  4563. return player_quests[quest_id];
  4564. return 0;
  4565. }
  4566. void Player::AddCompletedQuest(Quest* quest){
  4567. completed_quests[quest->GetQuestID()] = quest;
  4568. quest->SetSaveNeeded(true);
  4569. quest->SetTurnedIn(true);
  4570. if(quest->GetCompletedDescription())
  4571. quest->SetDescription(string(quest->GetCompletedDescription()));
  4572. quest->SetUpdateRequired(true);
  4573. }
  4574. bool Player::CheckQuestRemoveFlag(Spawn* spawn){
  4575. if(current_quest_flagged.count(spawn) > 0){
  4576. current_quest_flagged.erase(spawn);
  4577. return true;
  4578. }
  4579. return false;
  4580. }
  4581. bool Player::CheckQuestRequired(Spawn* spawn){
  4582. if(spawn)
  4583. return spawn->MeetsSpawnAccessRequirements(this);
  4584. return false;
  4585. }
  4586. int8 Player::CheckQuestFlag(Spawn* spawn){
  4587. int8 ret = 0;
  4588. if (!spawn) {
  4589. LogWrite(PLAYER__ERROR, 0, "Player", "CheckQuestFlag() called with an invalid spawn");
  4590. return ret;
  4591. }
  4592. if(spawn->HasProvidedQuests()){
  4593. vector<int32>* quests = spawn->GetProvidedQuests();
  4594. Quest* quest = 0;
  4595. for(int32 i=0;i<quests->size();i++){
  4596. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4597. if(player_quests.count(quests->at(i)) > 0){
  4598. if(player_quests[quests->at(i)]->GetCompleted() && player_quests[quests->at(i)]->GetQuestReturnNPC() == spawn->GetDatabaseID()){
  4599. ret = 2;
  4600. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4601. break;
  4602. }
  4603. }
  4604. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4605. int8 flag = 0;
  4606. if (CanReceiveQuest(quests->at(i), &flag)){
  4607. if(flag) {
  4608. ret = flag;
  4609. break;
  4610. }
  4611. master_quest_list.LockQuests();
  4612. quest = master_quest_list.GetQuest(quests->at(i), false);
  4613. master_quest_list.UnlockQuests();
  4614. if(quest){
  4615. int8 color = quest->GetFeatherColor();
  4616. // purple
  4617. if (color == 1)
  4618. ret = 16;
  4619. // green
  4620. else if (color == 2)
  4621. ret = 32;
  4622. // blue
  4623. else if (color == 3)
  4624. ret = 64;
  4625. // normal
  4626. else
  4627. ret = 1;
  4628. break;
  4629. }
  4630. }
  4631. }
  4632. }
  4633. map<int32, Quest*>::iterator itr;
  4634. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4635. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4636. if(itr->second->CheckQuestChatUpdate(spawn->GetDatabaseID(), false))
  4637. ret = 2;
  4638. }
  4639. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4640. if(ret > 0)
  4641. current_quest_flagged[spawn] = true;
  4642. return ret;
  4643. }
  4644. bool Player::CanReceiveQuest(int32 quest_id, int8* ret){
  4645. bool passed = true;
  4646. int32 x;
  4647. master_quest_list.LockQuests();
  4648. Quest* quest = master_quest_list.GetQuest(quest_id, false);
  4649. master_quest_list.UnlockQuests();
  4650. if (!quest)
  4651. passed = false;
  4652. //check if quest is already completed, and not repeatable
  4653. else if (GetCompletedQuest(quest_id) && !quest->IsRepeatable())
  4654. passed = false;
  4655. //check if the player already has this quest
  4656. else if (player_quests.count(quest_id) > 0)
  4657. passed = false;
  4658. //Check Prereq Adv Levels
  4659. else if (quest->GetPrereqLevel() > GetLevel())
  4660. passed = false;
  4661. else if (quest->GetPrereqMaxLevel() > 0){
  4662. if (GetLevel() > quest->GetPrereqMaxLevel())
  4663. passed = false;
  4664. }
  4665. //Check Prereq TS Levels
  4666. else if (quest->GetPrereqTSLevel() > GetTSLevel())
  4667. passed = false;
  4668. else if (quest->GetPrereqMaxTSLevel() > 0){
  4669. if (GetTSLevel() > quest->GetPrereqMaxLevel())
  4670. passed = false;
  4671. }
  4672. // Check quest pre req
  4673. vector<int32>* prereq_quests = quest->GetPrereqQuests();
  4674. if(passed && prereq_quests && prereq_quests->size() > 0){
  4675. for(int32 x=0;x<prereq_quests->size();x++){
  4676. if(completed_quests.count(prereq_quests->at(x)) == 0){
  4677. passed = false;
  4678. break;
  4679. }
  4680. }
  4681. }
  4682. //Check Prereq Classes
  4683. vector<int8>* prereq_classes = quest->GetPrereqClasses();
  4684. if(passed && prereq_classes && prereq_classes->size() > 0){
  4685. for(int32 x=0;x<prereq_classes->size();x++){
  4686. if(prereq_classes->at(x) == GetAdventureClass()){
  4687. passed = true;
  4688. break;
  4689. }
  4690. else
  4691. passed = false;
  4692. }
  4693. }
  4694. //Check Prereq TS Classes
  4695. vector<int8>* prereq_tsclasses = quest->GetPrereqTradeskillClasses();
  4696. if(passed && prereq_tsclasses && prereq_tsclasses->size() > 0){
  4697. for( x=0;x<prereq_tsclasses->size();x++){
  4698. if(prereq_tsclasses->at(x) == GetTradeskillClass()){
  4699. passed = true;
  4700. break;
  4701. }
  4702. else
  4703. passed = false;
  4704. }
  4705. }
  4706. // Check model prereq
  4707. vector<int16>* prereq_model_types = quest->GetPrereqModelTypes();
  4708. if(passed && prereq_model_types && prereq_model_types->size() > 0){
  4709. for(x=0;x<prereq_model_types->size();x++){
  4710. if(prereq_model_types->at(x) == GetModelType()){
  4711. passed = true;
  4712. break;
  4713. }
  4714. else
  4715. passed = false;
  4716. }
  4717. }
  4718. // Check faction pre req
  4719. vector<QuestFactionPrereq>* prereq_factions = quest->GetPrereqFactions();
  4720. if(passed && prereq_factions && prereq_factions->size() > 0){
  4721. sint32 val = 0;
  4722. for(x=0;x<prereq_factions->size();x++){
  4723. val = GetFactions()->GetFactionValue(prereq_factions->at(x).faction_id);
  4724. if(val >= prereq_factions->at(x).min && (prereq_factions->at(x).max == 0 || val <= prereq_factions->at(x).max)){
  4725. passed = true;
  4726. break;
  4727. }
  4728. else
  4729. passed = false;
  4730. }
  4731. }
  4732. LogWrite(MISC__TODO, 1, "TODO", "Check prereq items\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  4733. // Check race pre req
  4734. vector<int8>* prereq_races = quest->GetPrereqRaces();
  4735. if(passed && prereq_races && prereq_races->size() > 0){
  4736. for(x=0;x<prereq_races->size();x++){
  4737. if(prereq_races->at(x) == GetRace()){
  4738. passed = true;
  4739. break;
  4740. }
  4741. else
  4742. passed = false;
  4743. }
  4744. }
  4745. int32 flag = 0;
  4746. if(lua_interface->CallQuestFunction(quest, "ReceiveQuestCriteria", this, 0xFFFFFFFF, &flag)) {
  4747. if(ret)
  4748. *ret = flag;
  4749. if(!flag) {
  4750. passed = false;
  4751. }
  4752. else {
  4753. passed = true;
  4754. }
  4755. }
  4756. return passed;
  4757. }
  4758. bool Player::ShouldSendSpawn(Spawn* spawn){
  4759. if(spawn->IsDeletedSpawn() || IsSendingSpawn(spawn->GetID()) || IsRemovingSpawn(spawn->GetID()))
  4760. return false;
  4761. else if((WasSentSpawn(spawn->GetID()) == false) && (!spawn->IsPrivateSpawn() || spawn->AllowedAccess(this)))
  4762. return true;
  4763. return false;
  4764. }
  4765. int8 Player::GetArrowColor(int8 spawn_level){
  4766. int8 color = 0;
  4767. sint16 diff = spawn_level - GetLevel();
  4768. if(GetLevel() < 10)
  4769. diff *= 3;
  4770. else if(GetLevel() <= 20)
  4771. diff *= 2;
  4772. if(diff >= 9)
  4773. color = ARROW_COLOR_RED;
  4774. else if(diff >= 5)
  4775. color = ARROW_COLOR_ORANGE;
  4776. else if(diff >= 1)
  4777. color = ARROW_COLOR_YELLOW;
  4778. else if(diff == 0)
  4779. color = ARROW_COLOR_WHITE;
  4780. else if(diff <= -11)
  4781. color = ARROW_COLOR_GRAY;
  4782. else if(diff <= -6)
  4783. color = ARROW_COLOR_GREEN;
  4784. else //if(diff < 0)
  4785. color = ARROW_COLOR_BLUE;
  4786. return color;
  4787. }
  4788. int8 Player::GetTSArrowColor(int8 level){
  4789. int8 color = 0;
  4790. sint16 diff = level - GetTSLevel();
  4791. if(GetLevel() < 10)
  4792. diff *= 3;
  4793. else if(GetLevel() <= 20)
  4794. diff *= 2;
  4795. if(diff >= 9)
  4796. color = ARROW_COLOR_RED;
  4797. else if(diff >= 5)
  4798. color = ARROW_COLOR_ORANGE;
  4799. else if(diff >= 1)
  4800. color = ARROW_COLOR_YELLOW;
  4801. else if(diff == 0)
  4802. color = ARROW_COLOR_WHITE;
  4803. else if(diff <= -11)
  4804. color = ARROW_COLOR_GRAY;
  4805. else if(diff <= -6)
  4806. color = ARROW_COLOR_GREEN;
  4807. else //if(diff < 0)
  4808. color = ARROW_COLOR_BLUE;
  4809. return color;
  4810. }
  4811. void Player::AddCoins(int64 val){
  4812. int32 tmp = 0;
  4813. UpdatePlayerStatistic(STAT_PLAYER_TOTAL_WEALTH, (GetCoinsCopper() + (GetCoinsSilver() * 100) + (GetCoinsGold() * 10000) + (GetCoinsPlat() * 1000000)) + val, true);
  4814. if(val >= 1000000){
  4815. tmp = val / 1000000;
  4816. val -= tmp*1000000;
  4817. GetInfoStruct()->add_coin_plat(tmp);
  4818. }
  4819. if(val >= 10000){
  4820. tmp = val / 10000;
  4821. val -= tmp*10000;
  4822. GetInfoStruct()->add_coin_gold(tmp);
  4823. }
  4824. if(val >= 100){
  4825. tmp = val / 100;
  4826. val -= tmp*100;
  4827. GetInfoStruct()->add_coin_silver(tmp);
  4828. }
  4829. GetInfoStruct()->add_coin_copper(val);
  4830. int32 new_copper_value = GetInfoStruct()->get_coin_copper();
  4831. if(new_copper_value >= 100){
  4832. tmp = new_copper_value/100;
  4833. GetInfoStruct()->set_coin_copper(new_copper_value - (100 * tmp));
  4834. GetInfoStruct()->add_coin_silver(tmp);
  4835. }
  4836. int32 new_silver_value = GetInfoStruct()->get_coin_silver();
  4837. if(new_silver_value >= 100){
  4838. tmp = new_silver_value/100;
  4839. GetInfoStruct()->set_coin_silver(new_silver_value - (100 * tmp));
  4840. GetInfoStruct()->add_coin_gold(tmp);
  4841. }
  4842. int32 new_gold_value = GetInfoStruct()->get_coin_gold();
  4843. if(new_gold_value >= 100){
  4844. tmp = new_gold_value/100;
  4845. GetInfoStruct()->set_coin_gold(new_gold_value - (100 * tmp));
  4846. GetInfoStruct()->add_coin_plat(tmp);
  4847. }
  4848. charsheet_changed = true;
  4849. }
  4850. bool Player::RemoveCoins(int64 val){
  4851. int64 total_coins = GetInfoStruct()->get_coin_plat()*1000000;
  4852. total_coins += GetInfoStruct()->get_coin_gold()*10000;
  4853. total_coins += GetInfoStruct()->get_coin_silver()*100;
  4854. total_coins += GetInfoStruct()->get_coin_copper();
  4855. if(total_coins >= val){
  4856. total_coins -= val;
  4857. GetInfoStruct()->set_coin_plat(0);
  4858. GetInfoStruct()->set_coin_gold(0);
  4859. GetInfoStruct()->set_coin_silver(0);
  4860. GetInfoStruct()->set_coin_copper(0);
  4861. AddCoins(total_coins);
  4862. return true;
  4863. }
  4864. return false;
  4865. }
  4866. bool Player::HasCoins(int64 val) {
  4867. int64 total_coins = GetInfoStruct()->get_coin_plat()*1000000;
  4868. total_coins += GetInfoStruct()->get_coin_gold()*10000;
  4869. total_coins += GetInfoStruct()->get_coin_silver()*100;
  4870. total_coins += GetInfoStruct()->get_coin_copper();
  4871. if(total_coins >= val)
  4872. return true;
  4873. return false;
  4874. }
  4875. bool Player::HasPendingLootItems(int32 id){
  4876. return (pending_loot_items.count(id) > 0 && pending_loot_items[id].size() > 0);
  4877. }
  4878. bool Player::HasPendingLootItem(int32 id, int32 item_id){
  4879. return (pending_loot_items.count(id) > 0 && pending_loot_items[id].count(item_id) > 0);
  4880. }
  4881. vector<Item*>* Player::GetPendingLootItems(int32 id){
  4882. vector<Item*>* ret = 0;
  4883. if(pending_loot_items.count(id) > 0){
  4884. ret = new vector<Item*>();
  4885. map<int32, bool>::iterator itr;
  4886. for(itr = pending_loot_items[id].begin(); itr != pending_loot_items[id].end(); itr++){
  4887. if(master_item_list.GetItem(itr->first))
  4888. ret->push_back(master_item_list.GetItem(itr->first));
  4889. }
  4890. }
  4891. return ret;
  4892. }
  4893. void Player::RemovePendingLootItem(int32 id, int32 item_id){
  4894. if(pending_loot_items.count(id) > 0){
  4895. pending_loot_items[id].erase(item_id);
  4896. if(pending_loot_items[id].size() == 0)
  4897. pending_loot_items.erase(id);
  4898. }
  4899. }
  4900. void Player::RemovePendingLootItems(int32 id){
  4901. if(pending_loot_items.count(id) > 0)
  4902. pending_loot_items.erase(id);
  4903. }
  4904. void Player::AddPendingLootItems(int32 id, vector<Item*>* items){
  4905. if(items){
  4906. Item* item = 0;
  4907. for(int32 i=0;i<items->size();i++){
  4908. item = items->at(i);
  4909. if(item)
  4910. pending_loot_items[id][item->details.item_id] = true;
  4911. }
  4912. }
  4913. }
  4914. void Player::AddPlayerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date) {
  4915. if (statistics.count(stat_id) == 0) {
  4916. Statistic* stat = new Statistic;
  4917. stat->stat_id = stat_id;
  4918. stat->stat_value = stat_value;
  4919. stat->stat_date = stat_date;
  4920. stat->save_needed = false;
  4921. statistics[stat_id] = stat;
  4922. }
  4923. }
  4924. void Player::UpdatePlayerStatistic(int32 stat_id, sint32 stat_value, bool overwrite) {
  4925. if (statistics.count(stat_id) == 0)
  4926. AddPlayerStatistic(stat_id, 0, 0);
  4927. Statistic* stat = statistics[stat_id];
  4928. overwrite == true ? stat->stat_value = stat_value : stat->stat_value += stat_value;
  4929. stat->stat_date = Timer::GetUnixTimeStamp();
  4930. stat->save_needed = true;
  4931. }
  4932. void Player::WritePlayerStatistics() {
  4933. map<int32, Statistic*>::iterator stat_itr;
  4934. for (stat_itr = statistics.begin(); stat_itr != statistics.end(); stat_itr++) {
  4935. Statistic* stat = stat_itr->second;
  4936. if (stat->save_needed) {
  4937. stat->save_needed = false;
  4938. database.WritePlayerStatistic(this, stat);
  4939. }
  4940. }
  4941. }
  4942. sint64 Player::GetPlayerStatisticValue(int32 stat_id) {
  4943. if (stat_id >= 0 && statistics.count(stat_id) > 0)
  4944. return statistics[stat_id]->stat_value;
  4945. return 0;
  4946. }
  4947. void Player::RemovePlayerStatistics() {
  4948. map<int32, Statistic*>::iterator stat_itr;
  4949. for (stat_itr = statistics.begin(); stat_itr != statistics.end(); stat_itr++)
  4950. safe_delete(stat_itr->second);
  4951. statistics.clear();
  4952. }
  4953. void Player::SetGroup(PlayerGroup* new_group){
  4954. group = new_group;
  4955. }
  4956. /*PlayerGroup* Player::GetGroup(){
  4957. return group;
  4958. }*/
  4959. bool Player::IsGroupMember(Entity* player) {
  4960. bool ret = false;
  4961. if (GetGroupMemberInfo() && player) {
  4962. //world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4963. ret = world.GetGroupManager()->IsInGroup(GetGroupMemberInfo()->group_id, player);
  4964. /*deque<GroupMemberInfo*>::iterator itr;
  4965. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(GetGroupMemberInfo()->group_id);
  4966. for (itr = members->begin(); itr != members->end(); itr++) {
  4967. GroupMemberInfo* gmi = *itr;
  4968. if (gmi->client && gmi->client->GetPlayer() == player) {
  4969. ret = true;
  4970. break;
  4971. }
  4972. }
  4973. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);*/
  4974. }
  4975. return ret;
  4976. }
  4977. void Player::SetGroupInformation(PacketStruct* packet){
  4978. int8 det_count = 0;
  4979. Entity* member = 0;
  4980. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4981. if (GetGroupMemberInfo()) {
  4982. PlayerGroup* group = world.GetGroupManager()->GetGroup(GetGroupMemberInfo()->group_id);
  4983. if (group)
  4984. {
  4985. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4986. deque<GroupMemberInfo*>* members = group->GetMembers();
  4987. deque<GroupMemberInfo*>::iterator itr;
  4988. GroupMemberInfo* info = 0;
  4989. int x = 0;
  4990. for (itr = members->begin(); itr != members->end(); itr++) {
  4991. info = *itr;
  4992. if (info == GetGroupMemberInfo()) {
  4993. if (info->leader)
  4994. packet->setDataByName("group_leader_id", 0xFFFFFFFF); // If this player is the group leader then fill this element with FF FF FF FF
  4995. continue;
  4996. }
  4997. else {
  4998. if (info->leader)
  4999. packet->setDataByName("group_leader_id", x); // If leader is some one else then fill with the slot number they are in
  5000. }
  5001. member = info->member;
  5002. if (member && member->GetZone() == GetZone()) {
  5003. packet->setSubstructDataByName("group_members", "unknown3", 1, x);
  5004. packet->setSubstructDataByName("group_members", "spawn_id", GetIDWithPlayerSpawn(member), x);
  5005. if (member->HasPet()) {
  5006. if (member->GetPet())
  5007. packet->setSubstructDataByName("group_members", "pet_id", GetIDWithPlayerSpawn(member->GetPet()), x);
  5008. else
  5009. packet->setSubstructDataByName("group_members", "pet_id", GetIDWithPlayerSpawn(member->GetCharmedPet()), x);
  5010. }
  5011. else
  5012. packet->setSubstructDataByName("group_members", "pet_id", 0xFFFFFFFF, x);
  5013. //Send detriment counts as 255 if all dets of that type are incurable
  5014. det_count = member->GetTraumaCount();
  5015. if (det_count > 0) {
  5016. if (!member->HasCurableDetrimentType(DET_TYPE_TRAUMA))
  5017. det_count = 255;
  5018. }
  5019. packet->setSubstructDataByName("group_members", "trauma_count", det_count, x);
  5020. det_count = member->GetArcaneCount();
  5021. if (det_count > 0) {
  5022. if (!member->HasCurableDetrimentType(DET_TYPE_ARCANE))
  5023. det_count = 255;
  5024. }
  5025. packet->setSubstructDataByName("group_members", "arcane_count", det_count, x);
  5026. det_count = member->GetNoxiousCount();
  5027. if (det_count > 0) {
  5028. if (!member->HasCurableDetrimentType(DET_TYPE_NOXIOUS))
  5029. det_count = 255;
  5030. }
  5031. packet->setSubstructDataByName("group_members", "noxious_count", det_count, x);
  5032. det_count = member->GetElementalCount();
  5033. if (det_count > 0) {
  5034. if (!member->HasCurableDetrimentType(DET_TYPE_ELEMENTAL))
  5035. det_count = 255;
  5036. }
  5037. packet->setSubstructDataByName("group_members", "elemental_count", det_count, x);
  5038. det_count = member->GetCurseCount();
  5039. if (det_count > 0) {
  5040. if (!member->HasCurableDetrimentType(DET_TYPE_CURSE))
  5041. det_count = 255;
  5042. }
  5043. packet->setSubstructDataByName("group_members", "curse_count", det_count, x);
  5044. }
  5045. else {
  5046. packet->setSubstructDataByName("group_members", "unknown3", 2, x);
  5047. packet->setSubstructDataByName("group_members", "pet_id", 0xFFFFFFFF, x);
  5048. //packet->setSubstructDataByName("group_members", "unknown5", 1, x, 1); // unknown5 > 1 = name is blue
  5049. }
  5050. packet->setSubstructDataByName("group_members", "name", info->name.c_str(), x);
  5051. packet->setSubstructDataByName("group_members", "hp_current", info->hp_current, x);
  5052. packet->setSubstructDataByName("group_members", "hp_max", info->hp_max, x);
  5053. packet->setSubstructDataByName("group_members", "power_current", info->power_current, x);
  5054. packet->setSubstructDataByName("group_members", "power_max", info->power_max, x);
  5055. packet->setSubstructDataByName("group_members", "level_current", info->level_current, x);
  5056. packet->setSubstructDataByName("group_members", "level_max", info->level_max, x);
  5057. packet->setSubstructDataByName("group_members", "zone", info->zone.c_str(), x);
  5058. packet->setSubstructDataByName("group_members", "race_id", info->race_id, x);
  5059. packet->setSubstructDataByName("group_members", "class_id", info->class_id, x);
  5060. x++;
  5061. }
  5062. }
  5063. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5064. }
  5065. //packet->PrintPacket();
  5066. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5067. }
  5068. PlayerItemList* Player::GetPlayerItemList(){
  5069. return &item_list;
  5070. }
  5071. void Player::ResetSavedSpawns(){
  5072. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  5073. ClearRemovalTimers();
  5074. spawn_packet_sent.clear();
  5075. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5076. info_mutex.writelock(__FUNCTION__, __LINE__);
  5077. spawn_info_packet_list.clear();
  5078. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5079. vis_mutex.writelock(__FUNCTION__, __LINE__);
  5080. spawn_vis_packet_list.clear();
  5081. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5082. pos_mutex.writelock(__FUNCTION__, __LINE__);
  5083. spawn_pos_packet_list.clear();
  5084. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5085. index_mutex.writelock(__FUNCTION__, __LINE__);
  5086. player_spawn_reverse_id_map.clear();
  5087. player_spawn_id_map.clear();
  5088. player_spawn_id_map[1] = this;
  5089. player_spawn_reverse_id_map[this] = 1;
  5090. spawn_index = 1;
  5091. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5092. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  5093. player_spawn_quests_required.clear();
  5094. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5095. if(info)
  5096. info->RemoveOldPackets();
  5097. safe_delete_array(movement_packet);
  5098. safe_delete_array(old_movement_packet);
  5099. }
  5100. void Player::SetReturningFromLD(bool val){
  5101. if(val && val != returning_from_ld)
  5102. {
  5103. if(GetPlayerItemList())
  5104. GetPlayerItemList()->ResetPackets();
  5105. GetEquipmentList()->ResetPackets();
  5106. GetAppearanceEquipmentList()->ResetPackets();
  5107. skill_list.ResetPackets();
  5108. safe_delete_array(spell_orig_packet);
  5109. safe_delete_array(spell_xor_packet);
  5110. spell_orig_packet=0;
  5111. spell_xor_packet=0;
  5112. spell_count = 0;
  5113. reset_character_flag(CF_IS_SITTING);
  5114. if (GetActivityStatus() & ACTIVITY_STATUS_CAMPING)
  5115. SetActivityStatus(GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  5116. if (GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD)
  5117. SetActivityStatus(GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  5118. SetTempVisualState(0);
  5119. safe_delete_array(spawn_tmp_info_xor_packet);
  5120. safe_delete_array(spawn_tmp_vis_xor_packet);
  5121. safe_delete_array(spawn_tmp_pos_xor_packet);
  5122. spawn_tmp_info_xor_packet = 0;
  5123. spawn_tmp_vis_xor_packet = 0;
  5124. spawn_tmp_pos_xor_packet = 0;
  5125. pos_xor_size = 0;
  5126. info_xor_size = 0;
  5127. vis_xor_size = 0;
  5128. index_mutex.writelock(__FUNCTION__, __LINE__);
  5129. player_spawn_id_map[1] = this;
  5130. player_spawn_reverse_id_map[this] = 1;
  5131. spawn_index = 1;
  5132. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5133. }
  5134. returning_from_ld = val;
  5135. }
  5136. bool Player::IsReturningFromLD(){
  5137. return returning_from_ld;
  5138. }
  5139. void Player::AddFriend(const char* name, bool save){
  5140. if(name){
  5141. if(save)
  5142. friend_list[name] = 1;
  5143. else
  5144. friend_list[name] = 0;
  5145. }
  5146. }
  5147. bool Player::IsFriend(const char* name){
  5148. if(name && friend_list.count(name) > 0 && friend_list[name] < 2)
  5149. return true;
  5150. return false;
  5151. }
  5152. void Player::RemoveFriend(const char* name){
  5153. if(friend_list.count(name) > 0)
  5154. friend_list[name] = 2;
  5155. }
  5156. map<string, int8>* Player::GetFriends(){
  5157. return &friend_list;
  5158. }
  5159. void Player::AddIgnore(const char* name, bool save){
  5160. if(name){
  5161. if(save)
  5162. ignore_list[name] = 1;
  5163. else
  5164. ignore_list[name] = 0;
  5165. }
  5166. }
  5167. bool Player::IsIgnored(const char* name){
  5168. if(name && ignore_list.count(name) > 0 && ignore_list[name] < 2)
  5169. return true;
  5170. return false;
  5171. }
  5172. void Player::RemoveIgnore(const char* name){
  5173. if(name && ignore_list.count(name) > 0)
  5174. ignore_list[name] = 2;
  5175. }
  5176. map<string, int8>* Player::GetIgnoredPlayers(){
  5177. return &ignore_list;
  5178. }
  5179. bool Player::CheckLevelStatus(int16 new_level) {
  5180. int16 LevelCap = rule_manager.GetGlobalRule(R_Player, MaxLevel)->GetInt16();
  5181. int16 LevelCapOverrideStatus = rule_manager.GetGlobalRule(R_Player, MaxLevelOverrideStatus)->GetInt16();
  5182. if ( (LevelCap < new_level) && (LevelCapOverrideStatus > GetZone()->GetClientBySpawn(this)->GetAdminStatus()) )
  5183. return false;
  5184. return true;
  5185. }
  5186. Skill* Player::GetSkillByName(const char* name, bool check_update){
  5187. Skill* ret = skill_list.GetSkillByName(name);
  5188. if(check_update)
  5189. {
  5190. if(skill_list.CheckSkillIncrease(ret))
  5191. CalculateBonuses();
  5192. }
  5193. return ret;
  5194. }
  5195. Skill* Player::GetSkillByID(int32 id, bool check_update){
  5196. Skill* ret = skill_list.GetSkill(id);
  5197. if(check_update)
  5198. {
  5199. if(skill_list.CheckSkillIncrease(ret))
  5200. CalculateBonuses();
  5201. }
  5202. return ret;
  5203. }
  5204. void Player::SetRangeAttack(bool val){
  5205. range_attack = val;
  5206. }
  5207. bool Player::GetRangeAttack(){
  5208. return range_attack;
  5209. }
  5210. bool Player::AddMail(Mail* mail) {
  5211. bool ret = false;
  5212. if (mail) {
  5213. mail_list.Put(mail->mail_id, mail);
  5214. ret = true;
  5215. }
  5216. return ret;
  5217. }
  5218. MutexMap<int32, Mail*>* Player::GetMail() {
  5219. return &mail_list;
  5220. }
  5221. Mail* Player::GetMail(int32 mail_id) {
  5222. Mail* mail = 0;
  5223. if (mail_list.count(mail_id) > 0)
  5224. mail = mail_list.Get(mail_id);
  5225. return mail;
  5226. }
  5227. void Player::DeleteMail(bool from_database) {
  5228. MutexMap<int32, Mail*>::iterator itr = mail_list.begin();
  5229. while (itr.Next())
  5230. DeleteMail(itr->first, from_database);
  5231. mail_list.clear();
  5232. }
  5233. void Player::DeleteMail(int32 mail_id, bool from_database) {
  5234. if (mail_list.count(mail_id) > 0) {
  5235. if (from_database)
  5236. database.DeletePlayerMail(mail_list.Get(mail_id));
  5237. mail_list.erase(mail_id);
  5238. }
  5239. }
  5240. ZoneServer* Player::GetGroupMemberInZone(int32 zone_id) {
  5241. //if ( GetGroup() == NULL )
  5242. return NULL;
  5243. /*GroupMemberInfo* info = 0;
  5244. for(int32 i=0;i<GetGroup()->members.size(); i++){
  5245. info = GetGroup()->members[i];
  5246. if(info == group_member_info)
  5247. continue;
  5248. // if the client exists, they are attached to a player,
  5249. // the player is currently in an instance, which has the same zone id (for that instance type)
  5250. if ( info->client != NULL && info->client->GetPlayer() != NULL &&
  5251. info->client->GetPlayer()->GetZone()->GetInstanceID() > 0 &&
  5252. info->client->GetPlayer()->GetZone()->GetZoneID() == zone_id )
  5253. {
  5254. return info->client->GetPlayer()->GetZone();
  5255. }
  5256. }
  5257. // no member is in an instance with this zone id
  5258. return NULL;*/
  5259. }
  5260. /* CharacterInstances */
  5261. CharacterInstances::CharacterInstances() {
  5262. m_instanceList.SetName("Mutex::m_instanceList");
  5263. }
  5264. CharacterInstances::~CharacterInstances() {
  5265. RemoveInstances();
  5266. }
  5267. void CharacterInstances::AddInstance(int32 db_id, int32 instance_id, int32 last_success_timestamp, int32 last_failure_timestamp, int32 success_lockout_time, int32 failure_lockout_time, int32 zone_id, int8 zone_instancetype, string zone_name) {
  5268. InstanceData data;
  5269. data.db_id = db_id;
  5270. data.instance_id = instance_id;
  5271. data.zone_id = zone_id;
  5272. data.zone_instance_type = zone_instancetype;
  5273. data.zone_name = zone_name;
  5274. data.last_success_timestamp = last_success_timestamp;
  5275. data.last_failure_timestamp = last_failure_timestamp;
  5276. data.success_lockout_time = success_lockout_time;
  5277. data.failure_lockout_time = failure_lockout_time;
  5278. instanceList.push_back(data);
  5279. }
  5280. void CharacterInstances::RemoveInstances() {
  5281. instanceList.clear();
  5282. }
  5283. bool CharacterInstances::RemoveInstanceByZoneID(int32 zone_id) {
  5284. vector<InstanceData>::iterator itr;
  5285. m_instanceList.writelock(__FUNCTION__, __LINE__);
  5286. for(itr = instanceList.begin(); itr != instanceList.end(); itr++) {
  5287. InstanceData* data = &(*itr);
  5288. if (data->zone_id == zone_id) {
  5289. instanceList.erase(itr);
  5290. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5291. return true;
  5292. }
  5293. }
  5294. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5295. return false;
  5296. }
  5297. bool CharacterInstances::RemoveInstanceByInstanceID(int32 instance_id) {
  5298. vector<InstanceData>::iterator itr;
  5299. m_instanceList.writelock(__FUNCTION__, __LINE__);
  5300. for(itr = instanceList.begin(); itr != instanceList.end(); itr++) {
  5301. InstanceData* data = &(*itr);
  5302. if (data->instance_id == instance_id) {
  5303. instanceList.erase(itr);
  5304. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5305. return true;
  5306. }
  5307. }
  5308. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5309. return false;
  5310. }
  5311. InstanceData* CharacterInstances::FindInstanceByZoneID(int32 zone_id) {
  5312. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5313. for(int32 i = 0; i < instanceList.size(); i++) {
  5314. InstanceData* data = &instanceList.at(i);
  5315. if (data->zone_id == zone_id) {
  5316. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5317. return data;
  5318. }
  5319. }
  5320. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5321. return 0;
  5322. }
  5323. InstanceData* CharacterInstances::FindInstanceByDBID(int32 db_id) {
  5324. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5325. for(int32 i = 0; i < instanceList.size(); i++) {
  5326. InstanceData* data = &instanceList.at(i);
  5327. if (data->db_id == db_id) {
  5328. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5329. return data;
  5330. }
  5331. }
  5332. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5333. return 0;
  5334. }
  5335. InstanceData* CharacterInstances::FindInstanceByInstanceID(int32 instance_id) {
  5336. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5337. for(int32 i = 0; i < instanceList.size(); i++) {
  5338. InstanceData* data = &instanceList.at(i);
  5339. if (data->instance_id == instance_id) {
  5340. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5341. return data;
  5342. }
  5343. }
  5344. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5345. return 0;
  5346. }
  5347. vector<InstanceData> CharacterInstances::GetLockoutInstances() {
  5348. vector<InstanceData> ret;
  5349. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5350. for (int32 i = 0; i < instanceList.size(); i++) {
  5351. InstanceData* data = &instanceList.at(i);
  5352. if (data->zone_instance_type == SOLO_LOCKOUT_INSTANCE || data->zone_instance_type == GROUP_LOCKOUT_INSTANCE || data->zone_instance_type == RAID_LOCKOUT_INSTANCE)
  5353. ret.push_back(*data);
  5354. }
  5355. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5356. return ret;
  5357. }
  5358. vector<InstanceData> CharacterInstances::GetPersistentInstances() {
  5359. vector<InstanceData> ret;
  5360. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5361. for (int32 i = 0; i < instanceList.size(); i++) {
  5362. InstanceData* data = &instanceList.at(i);
  5363. if (data->zone_instance_type == SOLO_PERSIST_INSTANCE || data->zone_instance_type == GROUP_PERSIST_INSTANCE || data->zone_instance_type == RAID_PERSIST_INSTANCE)
  5364. ret.push_back(*data);
  5365. }
  5366. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5367. return ret;
  5368. }
  5369. void CharacterInstances::ProcessInstanceTimers(Player* player) {
  5370. // Only need to check persistent instances here, lockout should be handled by zone shutting down
  5371. // Check instance id, if > 0 check timers, if timers expired set instance id to 0 and update the db `character_instance` to instance id 0,
  5372. // delete instance from `instances` if no more characters assigned to it
  5373. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5374. for (int32 i = 0; i < instanceList.size(); i++) {
  5375. InstanceData* data = &instanceList.at(i);
  5376. // Check to see if we have a valid instance and if it is persistant
  5377. if (data->instance_id > 0) {
  5378. if (data->zone_instance_type == SOLO_PERSIST_INSTANCE || data->zone_instance_type == GROUP_PERSIST_INSTANCE || data->zone_instance_type == RAID_PERSIST_INSTANCE) {
  5379. // Check max duration (last success + success time)
  5380. if (Timer::GetUnixTimeStamp() >= (data->last_success_timestamp + data->success_lockout_time)) {
  5381. // Max duration has passed, instance has expired lets remove the player from it,
  5382. // this will also delete the instace if all players have been removed from it
  5383. database.DeleteCharacterFromInstance(player->GetCharacterID(), data->instance_id);
  5384. data->instance_id = 0;
  5385. }
  5386. }
  5387. if (data->zone_instance_type == SOLO_LOCKOUT_INSTANCE || data->zone_instance_type == GROUP_LOCKOUT_INSTANCE || data->zone_instance_type == RAID_LOCKOUT_INSTANCE) {
  5388. // Need to check lockout instance ids to ensure they are still valid.
  5389. if (!database.VerifyInstanceID(player->GetCharacterID(), data->instance_id))
  5390. data->instance_id = 0;
  5391. }
  5392. }
  5393. }
  5394. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5395. /*for(int32 i=0;i<instanceList->size();i++)
  5396. {
  5397. bool valuesUpdated = false;
  5398. InstanceData data = instanceList->at(i);
  5399. if ( data.grant_reenter_time_left > 0 )
  5400. {
  5401. if ( ( data.grant_reenter_time_left - msDiff ) < 1 )
  5402. data.grant_reenter_time_left = 0;
  5403. else
  5404. data.grant_reenter_time_left -= msDiff;
  5405. valuesUpdated = true;
  5406. }
  5407. if ( data.grant_reset_time_left > 0 )
  5408. {
  5409. if ( ( data.grant_reset_time_left - msDiff ) < 1 )
  5410. data.grant_reset_time_left = 0;
  5411. else
  5412. data.grant_reset_time_left -= msDiff;
  5413. valuesUpdated = true;
  5414. }
  5415. if ( data.lockout_time > 0 )
  5416. {
  5417. if ( ( data.lockout_time - msDiff ) < 1 )
  5418. {
  5419. data.lockout_time = 0;
  5420. // this means that their timer ran out and we need to clear it from db and player
  5421. RemoveInstanceByInstanceID(data.instance_id);
  5422. database.DeleteCharacterFromInstance(player->GetCharacterID(),data.instance_id);
  5423. }
  5424. else
  5425. data.lockout_time -= msDiff;
  5426. valuesUpdated = true;
  5427. }
  5428. if ( valuesUpdated )
  5429. database.UpdateCharacterInstanceTimers(player->GetCharacterID(),data.instance_id,data.lockout_time,data.grant_reset_time_left,data.grant_reenter_time_left);
  5430. }*/
  5431. }
  5432. int32 CharacterInstances::GetInstanceCount() {
  5433. return instanceList.size();
  5434. }
  5435. void Player::SetPlayerAdventureClass(int8 new_class){
  5436. SetAdventureClass(new_class);
  5437. GetInfoStruct()->set_class1(classes.GetBaseClass(new_class));
  5438. GetInfoStruct()->set_class2(classes.GetSecondaryBaseClass(new_class));
  5439. GetInfoStruct()->set_class3(new_class);
  5440. charsheet_changed = true;
  5441. if(GetZone())
  5442. GetZone()->TriggerCharSheetTimer();
  5443. }
  5444. void Player::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  5445. GetSkills()->AddSkillBonus(spell_id, skill_id, value);
  5446. }
  5447. SkillBonus* Player::GetSkillBonus(int32 spell_id) {
  5448. return GetSkills()->GetSkillBonus(spell_id);
  5449. }
  5450. void Player::RemoveSkillBonus(int32 spell_id) {
  5451. GetSkills()->RemoveSkillBonus(spell_id);
  5452. }
  5453. bool Player::HasFreeBankSlot() {
  5454. return item_list.HasFreeBankSlot();
  5455. }
  5456. int8 Player::FindFreeBankSlot() {
  5457. return item_list.FindFreeBankSlot();
  5458. }
  5459. void Player::AddTitle(sint32 title_id, const char *name, int8 prefix, bool save_needed){
  5460. Title* new_title = new Title;
  5461. new_title->SetID(title_id);
  5462. new_title->SetName(name);
  5463. new_title->SetPrefix(prefix);
  5464. new_title->SetSaveNeeded(save_needed);
  5465. player_titles_list.Add(new_title);
  5466. }
  5467. void Player::AddAAEntry(int16 template_id, int8 tab_id, int32 aa_id, int16 order,int8 treeid) {
  5468. }
  5469. void Player::AddLanguage(int32 id, const char *name, bool save_needed){
  5470. Skill* skill = master_skill_list.GetSkillByName(name);
  5471. if(skill && !GetSkills()->HasSkill(skill->skill_id)) {
  5472. AddSkill(skill->skill_id, 1, skill->max_val, true);
  5473. }
  5474. // Check to see if the player already has the language
  5475. if (HasLanguage(id))
  5476. return;
  5477. // Doesn't already have the language so add it
  5478. Language* new_language = new Language;
  5479. new_language->SetID(id);
  5480. new_language->SetName(name);
  5481. player_languages_list.Add(new_language);
  5482. if (save_needed)
  5483. database.SaveCharacterLang(GetCharacterID(), id);
  5484. }
  5485. bool Player::HasLanguage(int32 id){
  5486. list<Language*>* languages = player_languages_list.GetAllLanguages();
  5487. list<Language*>::iterator itr;
  5488. Language* language = 0;
  5489. bool ret = false;
  5490. for(itr = languages->begin(); itr != languages->end(); itr++){
  5491. language = *itr;
  5492. if(language->GetID() == id){
  5493. ret = true;
  5494. break;
  5495. }
  5496. }
  5497. return ret;
  5498. }
  5499. bool Player::HasLanguage(const char* name){
  5500. list<Language*>* languages = player_languages_list.GetAllLanguages();
  5501. list<Language*>::iterator itr;
  5502. Language* language = 0;
  5503. bool ret = false;
  5504. for(itr = languages->begin(); itr != languages->end(); itr++){
  5505. language = *itr;
  5506. if(!strncmp(language->GetName(), name, strlen(name))){
  5507. ret = true;
  5508. break;
  5509. }
  5510. }
  5511. return ret;
  5512. }
  5513. void Player::AddPassiveSpell(int32 id, int8 tier)
  5514. {
  5515. // Add the spell to the list of passives this player currently has
  5516. // list is used for quickly going over only the passive spells the
  5517. // player has instead of going through all their spells.
  5518. passive_spells.push_back(id);
  5519. Client* client = GetZone()->GetClientBySpawn(this);
  5520. // Don not apply passives if the client is null, zoning, or reviving
  5521. if (client == NULL || client->IsZoning() || IsResurrecting())
  5522. return;
  5523. Spell* spell = 0;
  5524. spell = master_spell_list.GetSpell(id, tier);
  5525. if (spell) {
  5526. SpellProcess* spellProcess = 0;
  5527. // Get the current zones spell process
  5528. spellProcess = GetZone()->GetSpellProcess();
  5529. // Cast the spell, CastPassives() bypasses the spell queue
  5530. spellProcess->CastPassives(spell, this);
  5531. }
  5532. }
  5533. void Player::ApplyPassiveSpells()
  5534. {
  5535. Spell* spell = 0;
  5536. SpellBookEntry* spell2 = 0;
  5537. vector<int32>::iterator itr;
  5538. SpellProcess* spellProcess = 0;
  5539. spellProcess = GetZone()->GetSpellProcess();
  5540. for (itr = passive_spells.begin(); itr != passive_spells.end(); itr++)
  5541. {
  5542. spell2 = GetSpellBookSpell((*itr));
  5543. spell = master_spell_list.GetSpell(spell2->spell_id, spell2->tier);
  5544. if (spell) {
  5545. spellProcess->CastPassives(spell, this);
  5546. }
  5547. }
  5548. }
  5549. void Player::RemovePassive(int32 id, int8 tier, bool remove_from_list)
  5550. {
  5551. Spell* spell = 0;
  5552. spell = master_spell_list.GetSpell(id, tier);
  5553. if (spell) {
  5554. SpellProcess* spellProcess = 0;
  5555. spellProcess = GetZone()->GetSpellProcess();
  5556. spellProcess->CastPassives(spell, this, true);
  5557. if (remove_from_list) {
  5558. vector<int32>::iterator remove;
  5559. remove = find(passive_spells.begin(), passive_spells.end(), id);
  5560. if (remove != passive_spells.end())
  5561. passive_spells.erase(remove);
  5562. }
  5563. database.DeleteCharacterSpell(GetCharacterID(), spell->GetSpellID());
  5564. }
  5565. }
  5566. void Player::RemoveAllPassives()
  5567. {
  5568. vector<int32>::iterator itr;
  5569. for (itr = passive_spells.begin(); itr != passive_spells.end(); itr++)
  5570. RemoveSpellBookEntry((*itr), false);
  5571. passive_spells.clear();
  5572. }
  5573. void Player::ResetPetInfo() {
  5574. GetInfoStruct()->set_pet_id(0xFFFFFFFF);
  5575. GetInfoStruct()->set_pet_name(std::string("No Pet"));
  5576. GetInfoStruct()->set_pet_movement(0);
  5577. GetInfoStruct()->set_pet_behavior(0);
  5578. GetInfoStruct()->set_pet_health_pct(0.0f);
  5579. GetInfoStruct()->set_pet_power_pct(0.0f);
  5580. // Make sure the values get sent to the client
  5581. SetCharSheetChanged(true);
  5582. }
  5583. bool Player::HasRecipeBook(int32 recipe_id){
  5584. return recipebook_list.HasRecipeBook(recipe_id);
  5585. }
  5586. bool Player::DiscoveredLocation(int32 locationID) {
  5587. bool ret = false;
  5588. // No discovery type entry then return false
  5589. if (m_characterHistory.count(HISTORY_TYPE_DISCOVERY) == 0)
  5590. return false;
  5591. // Is a discovery type entry but not a location subtype return false
  5592. if (m_characterHistory[HISTORY_TYPE_DISCOVERY].count(HISTORY_SUBTYPE_LOCATION) == 0)
  5593. return false;
  5594. vector<HistoryData*>::iterator itr;
  5595. for (itr = m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].begin(); itr != m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].end(); itr++) {
  5596. if ((*itr)->Value == locationID) {
  5597. ret = true;
  5598. break;
  5599. }
  5600. }
  5601. return ret;
  5602. }
  5603. void Player::UpdatePlayerHistory(int8 type, int8 subtype, int32 value, int32 value2) {
  5604. switch (type) {
  5605. case HISTORY_TYPE_NONE:
  5606. HandleHistoryNone(subtype, value, value2);
  5607. break;
  5608. case HISTORY_TYPE_DEATH:
  5609. HandleHistoryDeath(subtype, value, value2);
  5610. break;
  5611. case HISTORY_TYPE_DISCOVERY:
  5612. HandleHistoryDiscovery(subtype, value, value2);
  5613. break;
  5614. case HISTORY_TYPE_XP:
  5615. HandleHistoryXP(subtype, value, value2);
  5616. break;
  5617. default:
  5618. // Not a valid history event so return out before trying to save into the db
  5619. return;
  5620. }
  5621. }
  5622. void Player::HandleHistoryNone(int8 subtype, int32 value, int32 value2) {
  5623. }
  5624. void Player::HandleHistoryDeath(int8 subtype, int32 value, int32 value2) {
  5625. }
  5626. void Player::HandleHistoryDiscovery(int8 subtype, int32 value, int32 value2) {
  5627. switch (subtype) {
  5628. case HISTORY_SUBTYPE_NONE:
  5629. break;
  5630. case HISTORY_SUBTYPE_ADVENTURE:
  5631. break;
  5632. case HISTORY_SUBTYPE_TRADESKILL:
  5633. break;
  5634. case HISTORY_SUBTYPE_QUEST:
  5635. break;
  5636. case HISTORY_SUBTYPE_AA:
  5637. break;
  5638. case HISTORY_SUBTYPE_ITEM:
  5639. break;
  5640. case HISTORY_SUBTYPE_LOCATION: {
  5641. HistoryData* hd = new HistoryData;
  5642. hd->Value = value;
  5643. hd->Value2 = value2;
  5644. hd->EventDate = Timer::GetUnixTimeStamp();
  5645. strcpy(hd->Location, GetZone()->GetZoneName());
  5646. m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].push_back(hd);
  5647. break;
  5648. }
  5649. default:
  5650. // Invalid subtype, default to NONE
  5651. break;
  5652. }
  5653. }
  5654. void Player::HandleHistoryXP(int8 subtype, int32 value, int32 value2) {
  5655. switch (subtype) {
  5656. case HISTORY_SUBTYPE_NONE:
  5657. break;
  5658. case HISTORY_SUBTYPE_ADVENTURE: {
  5659. HistoryData* hd = new HistoryData;
  5660. hd->Value = value;
  5661. hd->Value2 = value2;
  5662. hd->EventDate = Timer::GetUnixTimeStamp();
  5663. strcpy(hd->Location, GetZone()->GetZoneName());
  5664. m_characterHistory[HISTORY_TYPE_XP][HISTORY_SUBTYPE_ADVENTURE].push_back(hd);
  5665. }
  5666. break;
  5667. case HISTORY_SUBTYPE_TRADESKILL:
  5668. break;
  5669. case HISTORY_SUBTYPE_QUEST:
  5670. break;
  5671. case HISTORY_SUBTYPE_AA:
  5672. break;
  5673. case HISTORY_SUBTYPE_ITEM:
  5674. break;
  5675. case HISTORY_SUBTYPE_LOCATION:
  5676. break;
  5677. default:
  5678. // Invalid subtype, default to NONE
  5679. break;
  5680. }
  5681. }
  5682. void Player::LoadPlayerHistory(int8 type, int8 subtype, HistoryData* hd) {
  5683. m_characterHistory[type][subtype].push_back(hd);
  5684. }
  5685. void Player::SaveHistory() {
  5686. LogWrite(PLAYER__DEBUG, 0, "Player", "Saving History for Player: '%s'", GetName());
  5687. map<int8, map<int8, vector<HistoryData*> > >::iterator itr;
  5688. map<int8, vector<HistoryData*> >::iterator itr2;
  5689. vector<HistoryData*>::iterator itr3;
  5690. for (itr = m_characterHistory.begin(); itr != m_characterHistory.end(); itr++) {
  5691. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  5692. for (itr3 = itr2->second.begin(); itr3 != itr2->second.end(); itr3++) {
  5693. database.SaveCharacterHistory(this, itr->first, itr2->first, (*itr3)->Value, (*itr3)->Value2, (*itr3)->Location, (*itr3)->EventDate);
  5694. }
  5695. }
  5696. }
  5697. }
  5698. void Player::InitXPTable() {
  5699. m_levelXPReq[2] = 600;
  5700. m_levelXPReq[3] = 800;
  5701. m_levelXPReq[4] = 1000;
  5702. m_levelXPReq[5] = 1400;
  5703. m_levelXPReq[6] = 1800;
  5704. m_levelXPReq[7] = 2200;
  5705. m_levelXPReq[8] = 2600;
  5706. m_levelXPReq[9] = 3000;
  5707. m_levelXPReq[10] = 3400;
  5708. m_levelXPReq[11] = 3800;
  5709. m_levelXPReq[12] = 4200;
  5710. m_levelXPReq[13] = 4600;
  5711. m_levelXPReq[14] = 5000;
  5712. m_levelXPReq[15] = 5500;
  5713. m_levelXPReq[16] = 6000;
  5714. m_levelXPReq[17] = 6500;
  5715. m_levelXPReq[18] = 7000;
  5716. m_levelXPReq[19] = 7500;
  5717. m_levelXPReq[20] = 8000;
  5718. m_levelXPReq[21] = 8500;
  5719. m_levelXPReq[22] = 9000;
  5720. m_levelXPReq[23] = 9500;
  5721. m_levelXPReq[24] = 10000;
  5722. m_levelXPReq[25] = 10500;
  5723. m_levelXPReq[26] = 11000;
  5724. m_levelXPReq[27] = 11750;
  5725. m_levelXPReq[28] = 12500;
  5726. m_levelXPReq[29] = 13250;
  5727. m_levelXPReq[30] = 14000;
  5728. m_levelXPReq[31] = 14750;
  5729. m_levelXPReq[32] = 15500;
  5730. m_levelXPReq[33] = 16250;
  5731. m_levelXPReq[34] = 17000;
  5732. m_levelXPReq[35] = 17750;
  5733. m_levelXPReq[36] = 18500;
  5734. m_levelXPReq[37] = 19250;
  5735. m_levelXPReq[38] = 20000;
  5736. m_levelXPReq[39] = 20750;
  5737. m_levelXPReq[40] = 21500;
  5738. m_levelXPReq[41] = 22250;
  5739. m_levelXPReq[42] = 23000;
  5740. m_levelXPReq[43] = 24000;
  5741. m_levelXPReq[44] = 25000;
  5742. m_levelXPReq[45] = 26000;
  5743. m_levelXPReq[46] = 27000;
  5744. m_levelXPReq[47] = 28000;
  5745. m_levelXPReq[48] = 29250;
  5746. m_levelXPReq[49] = 30500;
  5747. m_levelXPReq[50] = 32000;
  5748. m_levelXPReq[51] = 33750;
  5749. m_levelXPReq[52] = 35750;
  5750. m_levelXPReq[53] = 38000;
  5751. m_levelXPReq[54] = 40500;
  5752. m_levelXPReq[55] = 42500;
  5753. m_levelXPReq[56] = 45500;
  5754. m_levelXPReq[57] = 48500;
  5755. m_levelXPReq[58] = 51500;
  5756. m_levelXPReq[59] = 54500;
  5757. m_levelXPReq[60] = 57500;
  5758. m_levelXPReq[61] = 60500;
  5759. m_levelXPReq[62] = 63500;
  5760. m_levelXPReq[63] = 66500;
  5761. m_levelXPReq[64] = 70000;
  5762. m_levelXPReq[65] = 73500;
  5763. m_levelXPReq[66] = 77000;
  5764. m_levelXPReq[67] = 80500;
  5765. m_levelXPReq[68] = 84000;
  5766. m_levelXPReq[69] = 87500;
  5767. m_levelXPReq[70] = 91000;
  5768. m_levelXPReq[71] = 94500;
  5769. m_levelXPReq[72] = 98000;
  5770. m_levelXPReq[73] = 101500;
  5771. m_levelXPReq[74] = 105000;
  5772. m_levelXPReq[75] = 108500;
  5773. m_levelXPReq[76] = 116500;
  5774. m_levelXPReq[77] = 132500;
  5775. m_levelXPReq[78] = 152500;
  5776. m_levelXPReq[79] = 172500;
  5777. m_levelXPReq[80] = 192500;
  5778. m_levelXPReq[81] = 212500;
  5779. m_levelXPReq[82] = 232500;
  5780. m_levelXPReq[83] = 252500;
  5781. m_levelXPReq[84] = 272500;
  5782. m_levelXPReq[85] = 292500;
  5783. m_levelXPReq[86] = 312500;
  5784. m_levelXPReq[87] = 332500;
  5785. m_levelXPReq[88] = 352500;
  5786. m_levelXPReq[89] = 372500;
  5787. m_levelXPReq[90] = 392500;
  5788. m_levelXPReq[91] = 863550;
  5789. m_levelXPReq[92] = 949905;
  5790. m_levelXPReq[93] = 1044895;
  5791. m_levelXPReq[94] = 1149385;
  5792. m_levelXPReq[95] = 1264323;
  5793. }
  5794. void Player::SendQuestRequiredSpawns(int32 quest_id){
  5795. bool locked = true;
  5796. m_playerSpawnQuestsRequired.readlock(__FUNCTION__, __LINE__);
  5797. if (player_spawn_quests_required.size() > 0 ) {
  5798. ZoneServer* zone = GetZone();
  5799. Client* client = zone->GetClientBySpawn(this);
  5800. if (!client){
  5801. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5802. return;
  5803. }
  5804. int xxx = player_spawn_quests_required.count(quest_id);
  5805. if (player_spawn_quests_required.count(quest_id) > 0){
  5806. vector<int32> spawns = *player_spawn_quests_required[quest_id];
  5807. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5808. Spawn* spawn = 0;
  5809. vector<int32>::iterator itr;
  5810. for (itr = spawns.begin(); itr != spawns.end();){
  5811. spawn = zone->GetSpawnByID(*itr);
  5812. if (spawn)
  5813. zone->SendSpawnChanges(spawn, client, false, true);
  5814. else {
  5815. itr = spawns.erase(itr);
  5816. continue;
  5817. }
  5818. itr++;
  5819. }
  5820. locked = false;
  5821. }
  5822. }
  5823. if (locked)
  5824. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5825. }
  5826. void Player::SendHistoryRequiredSpawns(int32 event_id){
  5827. bool locked = true;
  5828. m_playerSpawnHistoryRequired.readlock(__FUNCTION__, __LINE__);
  5829. if (player_spawn_history_required.size() > 0) {
  5830. ZoneServer* zone = GetZone();
  5831. Client* client = zone->GetClientBySpawn(this);
  5832. if (!client){
  5833. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5834. return;
  5835. }
  5836. if (player_spawn_history_required.count(event_id) > 0){
  5837. vector<int32> spawns = *player_spawn_history_required[event_id];
  5838. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5839. Spawn* spawn = 0;
  5840. vector<int32>::iterator itr;
  5841. for (itr = spawns.begin(); itr != spawns.end();){
  5842. spawn = zone->GetSpawnByID(*itr);
  5843. if (spawn)
  5844. zone->SendSpawnChanges(spawn, client, false, true);
  5845. else {
  5846. itr = spawns.erase(itr);
  5847. continue;
  5848. }
  5849. itr++;
  5850. }
  5851. locked = false;
  5852. }
  5853. }
  5854. if (locked)
  5855. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5856. }
  5857. void Player::AddQuestRequiredSpawn(Spawn* spawn, int32 quest_id){
  5858. if(!spawn || !quest_id)
  5859. return;
  5860. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  5861. if(player_spawn_quests_required.count(quest_id) == 0)
  5862. player_spawn_quests_required[quest_id] = new vector<int32>;
  5863. vector<int32>* quest_spawns = player_spawn_quests_required[quest_id];
  5864. int32 current_spawn = 0;
  5865. for(int32 i=0;i<quest_spawns->size();i++){
  5866. current_spawn = quest_spawns->at(i);
  5867. if (current_spawn == spawn->GetID()){
  5868. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5869. return;
  5870. }
  5871. }
  5872. player_spawn_quests_required[quest_id]->push_back(spawn->GetID());
  5873. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5874. }
  5875. void Player::AddHistoryRequiredSpawn(Spawn* spawn, int32 event_id){
  5876. if (!spawn || !event_id)
  5877. return;
  5878. m_playerSpawnHistoryRequired.writelock(__FUNCTION__, __LINE__);
  5879. if (player_spawn_history_required.count(event_id) == 0)
  5880. player_spawn_history_required[event_id] = new vector<int32>;
  5881. vector<int32>* history_spawns = player_spawn_history_required[event_id];
  5882. vector<int32>::iterator itr = find(history_spawns->begin(), history_spawns->end(), spawn->GetID());
  5883. if (itr == history_spawns->end())
  5884. history_spawns->push_back(spawn->GetID());
  5885. m_playerSpawnHistoryRequired.releasewritelock(__FUNCTION__, __LINE__);
  5886. }
  5887. int32 PlayerInfo::GetBoatSpawn(){
  5888. return boat_spawn;
  5889. }
  5890. void PlayerInfo::SetBoatSpawn(Spawn* spawn){
  5891. if(spawn)
  5892. boat_spawn = spawn->GetID();
  5893. else
  5894. boat_spawn = 0;
  5895. }
  5896. void PlayerInfo::RemoveOldPackets(){
  5897. safe_delete_array(changes);
  5898. safe_delete_array(orig_packet);
  5899. safe_delete_array(pet_changes);
  5900. safe_delete_array(pet_orig_packet);
  5901. changes = 0;
  5902. orig_packet = 0;
  5903. pet_changes = 0;
  5904. pet_orig_packet = 0;
  5905. }
  5906. PlayerControlFlags::PlayerControlFlags(){
  5907. MControlFlags.SetName("PlayerControlFlags::MControlFlags");
  5908. MFlagChanges.SetName("PlayerControlFlags::MFlagChanges");
  5909. flags_changed = false;
  5910. flag_changes.clear();
  5911. current_flags.clear();
  5912. }
  5913. PlayerControlFlags::~PlayerControlFlags(){
  5914. flag_changes.clear();
  5915. current_flags.clear();
  5916. }
  5917. bool PlayerControlFlags::ControlFlagsChanged(){
  5918. bool ret;
  5919. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5920. ret = flags_changed;
  5921. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5922. return ret;
  5923. }
  5924. void PlayerControlFlags::SetPlayerControlFlag(int8 param, int8 param_value, bool is_active){
  5925. if (!param || !param_value)
  5926. return;
  5927. bool active_changed = false;
  5928. MControlFlags.writelock(__FUNCTION__, __LINE__);
  5929. active_changed = (current_flags[param][param_value] != is_active);
  5930. if (active_changed){
  5931. current_flags[param][param_value] = is_active;
  5932. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5933. flag_changes[param][param_value] = is_active ? 1 : 0;
  5934. flags_changed = true;
  5935. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5936. }
  5937. MControlFlags.releasewritelock(__FUNCTION__, __LINE__);
  5938. }
  5939. void PlayerControlFlags::SendControlFlagUpdates(Client* client){
  5940. if (!client)
  5941. return;
  5942. map<int8, int8>* ptr = 0;
  5943. map<int8, map<int8, int8> >::iterator itr;
  5944. map<int8, int8>::iterator itr2;
  5945. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5946. for (itr = flag_changes.begin(); itr != flag_changes.end(); itr++){
  5947. ptr = &itr->second;
  5948. for (itr2 = ptr->begin(); itr2 != ptr->end(); itr2++){
  5949. ClientPacketFunctions::SendServerControlFlags(client, itr->first, itr2->first, itr2->second);
  5950. }
  5951. }
  5952. flag_changes.clear();
  5953. flags_changed = false;
  5954. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5955. }
  5956. bool Player::ControlFlagsChanged(){
  5957. return control_flags.ControlFlagsChanged();
  5958. }
  5959. void Player::SetPlayerControlFlag(int8 param, int8 param_value, bool is_active){
  5960. control_flags.SetPlayerControlFlag(param, param_value, is_active);
  5961. }
  5962. void Player::SendControlFlagUpdates(Client* client){
  5963. control_flags.SendControlFlagUpdates(client);
  5964. }
  5965. void Player::LoadLUAHistory(int32 event_id, LUAHistory* history) {
  5966. mLUAHistory.writelock();
  5967. if (m_charLuaHistory.count(event_id) > 0) {
  5968. LogWrite(PLAYER__ERROR, 0, "Player", "Attempted to added a dupicate event (%u) to character LUA history", event_id);
  5969. safe_delete(history);
  5970. mLUAHistory.releasewritelock();
  5971. return;
  5972. }
  5973. m_charLuaHistory.insert(make_pair(event_id,history));
  5974. mLUAHistory.releasewritelock();
  5975. }
  5976. void Player::SaveLUAHistory() {
  5977. mLUAHistory.readlock();
  5978. LogWrite(PLAYER__DEBUG, 0, "Player", "Saving LUA History for Player: '%s'", GetName());
  5979. map<int32, LUAHistory*>::iterator itr;
  5980. for (itr = m_charLuaHistory.begin(); itr != m_charLuaHistory.end(); itr++) {
  5981. if (itr->second->SaveNeeded) {
  5982. database.SaveCharacterLUAHistory(this, itr->first, itr->second->Value, itr->second->Value2);
  5983. itr->second->SaveNeeded = false;
  5984. }
  5985. }
  5986. mLUAHistory.releasereadlock();
  5987. }
  5988. void Player::UpdateLUAHistory(int32 event_id, int32 value, int32 value2) {
  5989. mLUAHistory.writelock();
  5990. LUAHistory* hd = 0;
  5991. if (m_charLuaHistory.count(event_id) > 0)
  5992. hd = m_charLuaHistory[event_id];
  5993. else {
  5994. hd = new LUAHistory;
  5995. m_charLuaHistory.insert(make_pair(event_id,hd));
  5996. }
  5997. hd->Value = value;
  5998. hd->Value2 = value2;
  5999. hd->SaveNeeded = true;
  6000. mLUAHistory.releasewritelock();
  6001. // release the mLUAHistory lock, we will maintain a readlock to avoid any further writes until we complete SendHistoryRequiredSpawns
  6002. // through Spawn::SendSpawnChanges -> Spawn::InitializeVisPacketData -> Spawn::MeetsSpawnAccessRequirements-> Player::GetLUAHistory (this was causing a deadlock)
  6003. mLUAHistory.readlock();
  6004. SendHistoryRequiredSpawns(event_id);
  6005. mLUAHistory.releasereadlock();
  6006. }
  6007. LUAHistory* Player::GetLUAHistory(int32 event_id) {
  6008. LUAHistory* ret = 0;
  6009. mLUAHistory.readlock();
  6010. if (m_charLuaHistory.count(event_id) > 0)
  6011. ret = m_charLuaHistory[event_id];
  6012. mLUAHistory.releasereadlock();
  6013. return ret;
  6014. }
  6015. bool Player::CanSeeInvis(Entity* target)
  6016. {
  6017. if (!target->IsStealthed() && !target->IsInvis())
  6018. return true;
  6019. if (target->IsStealthed() && HasSeeHideSpell())
  6020. return true;
  6021. else if (target->IsInvis() && HasSeeInvisSpell())
  6022. return true;
  6023. sint32 radius = rule_manager.GetGlobalRule(R_PVP, InvisPlayerDiscoveryRange)->GetSInt32();
  6024. if (radius == 0) // radius of 0 is always seen
  6025. return true;
  6026. // radius of -1 is never seen except through items/spells, radius > -1 means we will show the player if they get into the inner radius
  6027. else if (radius > -1 && this->GetDistance((Spawn*)target) < (float)radius)
  6028. return true;
  6029. // TODO: Implement See Invis Spells! http://cutpon.com:3000/devn00b/EQ2EMu/issues/43
  6030. Item* item = 0;
  6031. vector<Item*>* equipped_list = GetEquippedItemList();
  6032. bool seeInvis = false;
  6033. bool seeStealth = false;
  6034. for (int32 i = 0; i < equipped_list->size(); i++)
  6035. {
  6036. item = equipped_list->at(i);
  6037. seeInvis = item->HasStat(ITEM_STAT_SEEINVIS);
  6038. seeStealth = item->HasStat(ITEM_STAT_SEESTEALTH);
  6039. if (target->IsStealthed() && seeStealth)
  6040. return true;
  6041. else if (target->IsInvis() && seeInvis)
  6042. return true;
  6043. }
  6044. return false;
  6045. }
  6046. // returns true if we need to update target info due to see invis status change
  6047. bool Player::CheckChangeInvisHistory(Entity* target)
  6048. {
  6049. std::map<int32, bool>::iterator it;
  6050. it = target_invis_history.find(target->GetID());
  6051. if (it != target_invis_history.end())
  6052. {
  6053. //canSeeStatus
  6054. if (it->second)
  6055. {
  6056. if (!this->CanSeeInvis(target))
  6057. {
  6058. UpdateTargetInvisHistory(target->GetID(), false);
  6059. return true;
  6060. }
  6061. else
  6062. return false;
  6063. }
  6064. else
  6065. {
  6066. if (this->CanSeeInvis(target))
  6067. {
  6068. UpdateTargetInvisHistory(target->GetID(), true);
  6069. return true;
  6070. }
  6071. else
  6072. return false;
  6073. }
  6074. }
  6075. if (!this->CanSeeInvis(target))
  6076. UpdateTargetInvisHistory(target->GetID(), false);
  6077. else
  6078. UpdateTargetInvisHistory(target->GetID(), true);
  6079. return true;
  6080. }
  6081. void Player::UpdateTargetInvisHistory(int32 targetID, bool canSeeStatus)
  6082. {
  6083. target_invis_history[targetID] = canSeeStatus;
  6084. }
  6085. void Player::RemoveTargetInvisHistory(int32 targetID)
  6086. {
  6087. target_invis_history.erase(targetID);
  6088. }
  6089. bool Player::SetSpawnMap(Spawn* spawn)
  6090. {
  6091. if(!client->GetPlayer()->SetSpawnSentState(spawn, SpawnState::SPAWN_STATE_SENDING)) {
  6092. /*index_mutex.writelock(__FUNCTION__, __LINE__);
  6093. spawn_id += 1;
  6094. if (spawn_index == 255)
  6095. spawn_index += 1; //just so we dont have to worry about overloading
  6096. map<int32, Spawn*>::iterator itr = player_spawn_id_map.find(player_spawn_reverse_id_map[this]);
  6097. if(itr != player_spawn_id_map.end()) {
  6098. player_spawn_id_map.erase(itr);
  6099. }
  6100. player_spawn_id_map[spawn_id] = spawn;
  6101. player_spawn_reverse_id_map[this] = spawn_id;
  6102. index_mutex.releasewritelock(__FUNCTION__, __LINE__);*/
  6103. return false;
  6104. }
  6105. index_mutex.writelock(__FUNCTION__, __LINE__);
  6106. spawn_id += 1;
  6107. if (spawn_index == 255)
  6108. spawn_index += 1; //just so we dont have to worry about overloading
  6109. int32 tmp_id = spawn_id;
  6110. player_spawn_id_map[tmp_id] = spawn;
  6111. if(player_spawn_reverse_id_map.count(spawn))
  6112. player_spawn_reverse_id_map.erase(spawn);
  6113. player_spawn_reverse_id_map.insert(make_pair(spawn,tmp_id));
  6114. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6115. return true;
  6116. }
  6117. NPC* Player::InstantiateSpiritShard(float origX, float origY, float origZ, float origHeading, int32 origGridID, ZoneServer* origZone)
  6118. {
  6119. NPC* npc = new NPC();
  6120. string newName(GetName());
  6121. newName.append("'s spirit shard");
  6122. strcpy(npc->appearance.name, newName.c_str());
  6123. /*vector<EntityCommand*>* primary_command_list = zone->GetEntityCommandList(result.GetInt32(9));
  6124. vector<EntityCommand*>* secondary_command_list = zone->GetEntityCommandList(result.GetInt32(10));
  6125. if(primary_command_list){
  6126. npc->SetPrimaryCommands(primary_command_list);
  6127. npc->primary_command_list_id = result.GetInt32(9);
  6128. }
  6129. if(secondary_command_list){
  6130. npc->SetSecondaryCommands(secondary_command_list);
  6131. npc->secondary_command_list_id = result.GetInt32(10);
  6132. }*/
  6133. npc->appearance.level = GetLevel();
  6134. npc->appearance.race = GetRace();
  6135. npc->appearance.gender = GetGender();
  6136. npc->appearance.adventure_class = GetAdventureClass();
  6137. npc->appearance.model_type = GetModelType();
  6138. npc->appearance.soga_model_type = GetSogaModelType();
  6139. npc->appearance.display_name = 1;
  6140. npc->features.hair_type = GetHairType();
  6141. npc->features.hair_face_type = GetFacialHairType();
  6142. npc->features.wing_type = GetWingType();
  6143. npc->features.chest_type = GetChestType();
  6144. npc->features.legs_type = GetLegsType();
  6145. npc->features.soga_hair_type = GetSogaHairType();
  6146. npc->features.soga_hair_face_type = GetSogaFacialHairType();
  6147. npc->appearance.attackable = 0;
  6148. npc->appearance.show_level = 1;
  6149. npc->appearance.targetable = 1;
  6150. npc->appearance.show_command_icon = 1;
  6151. npc->appearance.display_hand_icon = 0;
  6152. npc->appearance.hide_hood = GetHideHood();
  6153. npc->size = GetSize();
  6154. npc->appearance.pos.collision_radius = appearance.pos.collision_radius;
  6155. npc->appearance.action_state = appearance.action_state;
  6156. npc->appearance.visual_state = 6193; // ghostly look
  6157. npc->appearance.mood_state = appearance.mood_state;
  6158. npc->appearance.emote_state = appearance.emote_state;
  6159. npc->appearance.pos.state = appearance.pos.state;
  6160. npc->appearance.activity_status = appearance.activity_status;
  6161. strncpy(npc->appearance.sub_title, appearance.sub_title, sizeof(npc->appearance.sub_title));
  6162. npc->SetPrefixTitle(GetPrefixTitle());
  6163. npc->SetSuffixTitle(GetSuffixTitle());
  6164. npc->SetLastName(GetLastName());
  6165. npc->SetX(origX);
  6166. npc->SetY(origY);
  6167. npc->SetZ(origZ);
  6168. npc->SetHeading(origHeading);
  6169. npc->SetSpawnOrigX(origX);
  6170. npc->SetSpawnOrigY(origY);
  6171. npc->SetSpawnOrigZ(origZ);
  6172. npc->SetSpawnOrigHeading(origHeading);
  6173. npc->appearance.pos.grid_id = origGridID;
  6174. const char* script = rule_manager.GetGlobalRule(R_Combat, SpiritShardSpawnScript)->GetString();
  6175. int32 dbid = database.CreateSpiritShard(newName.c_str(), GetLevel(), GetRace(), GetGender(), GetAdventureClass(), GetModelType(), GetSogaModelType(),
  6176. GetHairType(), GetFacialHairType(), GetWingType(), GetChestType(), GetLegsType(), GetSogaHairType(), GetSogaFacialHairType(), GetHideHood(),
  6177. GetSize(), npc->appearance.pos.collision_radius, npc->appearance.action_state, npc->appearance.visual_state, npc->appearance.mood_state,
  6178. npc->appearance.emote_state, npc->appearance.pos.state, npc->appearance.activity_status, npc->appearance.sub_title, GetPrefixTitle(), GetSuffixTitle(),
  6179. GetLastName(), origX, origY, origZ, origHeading, origGridID, GetCharacterID(), origZone->GetZoneID(), origZone->GetInstanceID());
  6180. npc->SetShardID(dbid);
  6181. npc->SetShardCharID(GetCharacterID());
  6182. npc->SetShardCreatedTimestamp(Timer::GetCurrentTime2());
  6183. if(script)
  6184. npc->SetSpawnScript(script);
  6185. return npc;
  6186. }
  6187. void Player::SaveSpellEffects()
  6188. {
  6189. if(stop_save_spell_effects)
  6190. {
  6191. LogWrite(PLAYER__WARNING, 0, "Player", "SaveSpellEffects called while player constructing / deconstructing!");
  6192. return;
  6193. }
  6194. SpellProcess* spellProcess = 0;
  6195. // Get the current zones spell process
  6196. spellProcess = GetZone()->GetSpellProcess();
  6197. Query savedEffects;
  6198. savedEffects.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_spell_effects where charid=%u", GetCharacterID());
  6199. savedEffects.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_spell_effect_targets where caster_char_id=%u", GetCharacterID());
  6200. InfoStruct* info = GetInfoStruct();
  6201. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  6202. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  6203. for(int i = 0; i < 45; i++) {
  6204. if(info->spell_effects[i].spell_id != 0xFFFFFFFF)
  6205. {
  6206. Spawn* spawn = nullptr;
  6207. int32 target_char_id = 0;
  6208. if(info->spell_effects[i].spell->initial_target_char_id != 0)
  6209. target_char_id = info->spell_effects[i].spell->initial_target_char_id;
  6210. else if((spawn = GetZone()->GetSpawnByID(info->spell_effects[i].spell->initial_target)) != nullptr && spawn->IsPlayer())
  6211. target_char_id = ((Player*)spawn)->GetCharacterID();
  6212. int32 timestamp = 0xFFFFFFFF;
  6213. if(!info->spell_effects[i].spell->spell->GetSpellData()->duration_until_cancel)
  6214. timestamp = info->spell_effects[i].expire_timestamp - Timer::GetCurrentTime2();
  6215. int32 caster_char_id = info->spell_effects[i].spell->initial_caster_char_id;
  6216. if(caster_char_id == 0)
  6217. continue;
  6218. Query effectSave;
  6219. effectSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT,
  6220. "insert into character_spell_effects (name, caster_char_id, target_char_id, target_type, db_effect_type, spell_id, effect_slot, slot_pos, icon, icon_backdrop, conc_used, tier, total_time, expire_timestamp, lua_file, custom_spell, charid, damage_remaining, effect_bitmask, num_triggers, had_triggers, cancel_after_triggers, crit, last_spellattack_hit, interrupted, resisted, custom_function) values ('%s', %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %f, %u, '%s', %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, '%s')",
  6221. database.getSafeEscapeString(info->spell_effects[i].spell->spell->GetName()).c_str(), caster_char_id,
  6222. target_char_id, 0 /*no target_type for spell_effects*/, DB_TYPE_SPELLEFFECTS /* db_effect_type for spell_effects */, info->spell_effects[i].spell_id, i, info->spell_effects[i].spell->slot_pos,
  6223. info->spell_effects[i].icon, info->spell_effects[i].icon_backdrop, 0 /* no conc_used for spell_effects */, info->spell_effects[i].tier,
  6224. info->spell_effects[i].total_time, timestamp, database.getSafeEscapeString(info->spell_effects[i].spell->file_name.c_str()).c_str(), info->spell_effects[i].spell->spell->IsCopiedSpell(), GetCharacterID(),
  6225. info->spell_effects[i].spell->damage_remaining, info->spell_effects[i].spell->effect_bitmask, info->spell_effects[i].spell->num_triggers, info->spell_effects[i].spell->had_triggers, info->spell_effects[i].spell->cancel_after_all_triggers,
  6226. info->spell_effects[i].spell->crit, info->spell_effects[i].spell->last_spellattack_hit, info->spell_effects[i].spell->interrupted, info->spell_effects[i].spell->resisted, (info->maintained_effects[i].expire_timestamp) == 0xFFFFFFFF ? "" : database.getSafeEscapeString(spellProcess->SpellScriptTimerCustomFunction(info->spell_effects[i].spell).c_str()).c_str());
  6227. }
  6228. if (i < NUM_MAINTAINED_EFFECTS && info->maintained_effects[i].spell_id != 0xFFFFFFFF){
  6229. Spawn* spawn = GetZone()->GetSpawnByID(info->maintained_effects[i].spell->initial_target);
  6230. int32 target_char_id = 0;
  6231. if(info->maintained_effects[i].spell->initial_target_char_id != 0)
  6232. target_char_id = info->maintained_effects[i].spell->initial_target_char_id;
  6233. else if(!info->maintained_effects[i].spell->initial_target)
  6234. target_char_id = GetCharacterID();
  6235. else if(spawn && spawn->IsPlayer())
  6236. target_char_id = ((Player*)spawn)->GetCharacterID();
  6237. else if (spawn && spawn->IsPet() && ((Entity*)spawn)->GetOwner() == (Entity*)this)
  6238. target_char_id = 0xFFFFFFFF;
  6239. int32 caster_char_id = (info->maintained_effects[i].spell->caster && info->maintained_effects[i].spell->caster->IsPlayer()) ? ((Player*)info->maintained_effects[i].spell->caster)->GetCharacterID() : 0;
  6240. int32 timestamp = 0xFFFFFFFF;
  6241. if(!info->maintained_effects[i].spell->spell->GetSpellData()->duration_until_cancel)
  6242. timestamp = info->maintained_effects[i].expire_timestamp - Timer::GetCurrentTime2();
  6243. Query effectSave;
  6244. effectSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT,
  6245. "insert into character_spell_effects (name, caster_char_id, target_char_id, target_type, db_effect_type, spell_id, effect_slot, slot_pos, icon, icon_backdrop, conc_used, tier, total_time, expire_timestamp, lua_file, custom_spell, charid, damage_remaining, effect_bitmask, num_triggers, had_triggers, cancel_after_triggers, crit, last_spellattack_hit, interrupted, resisted, custom_function) values ('%s', %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %f, %u, '%s', %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, '%s')",
  6246. database.getSafeEscapeString(info->maintained_effects[i].name).c_str(), caster_char_id, target_char_id, info->maintained_effects[i].target_type, DB_TYPE_MAINTAINEDEFFECTS /* db_effect_type for maintained_effects */, info->maintained_effects[i].spell_id, i, info->maintained_effects[i].slot_pos,
  6247. info->maintained_effects[i].icon, info->maintained_effects[i].icon_backdrop, info->maintained_effects[i].conc_used, info->maintained_effects[i].tier,
  6248. info->maintained_effects[i].total_time, timestamp, database.getSafeEscapeString(info->maintained_effects[i].spell->file_name.c_str()).c_str(), info->maintained_effects[i].spell->spell->IsCopiedSpell(), GetCharacterID(),
  6249. info->maintained_effects[i].spell->damage_remaining, info->maintained_effects[i].spell->effect_bitmask, info->maintained_effects[i].spell->num_triggers, info->maintained_effects[i].spell->had_triggers, info->maintained_effects[i].spell->cancel_after_all_triggers,
  6250. info->maintained_effects[i].spell->crit, info->maintained_effects[i].spell->last_spellattack_hit, info->maintained_effects[i].spell->interrupted, info->maintained_effects[i].spell->resisted, (info->maintained_effects[i].expire_timestamp) == 0xFFFFFFFF ? "" : database.getSafeEscapeString(spellProcess->SpellScriptTimerCustomFunction(info->maintained_effects[i].spell).c_str()).c_str());
  6251. info->maintained_effects[i].spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6252. std::string insertTargets = string("insert into character_spell_effect_targets (caster_char_id, target_char_id, target_type, db_effect_type, spell_id, effect_slot, slot_pos) values ");
  6253. bool firstTarget = true;
  6254. map<Spawn*, int8> targetsInserted;
  6255. for (int8 t = 0; t < info->maintained_effects[i].spell->targets.size(); t++) {
  6256. int32 spawn_id = info->maintained_effects[i].spell->targets.at(t);
  6257. Spawn* spawn = GetZone()->GetSpawnByID(spawn_id);
  6258. LogWrite(SPELL__DEBUG, 0, "Spell", "%s has target %u to identify for spell %s", GetName(), spawn_id, info->maintained_effects[i].spell->spell->GetName());
  6259. if(spawn && (spawn->IsPlayer() || spawn->IsPet()))
  6260. {
  6261. int32 tmpCharID = 0;
  6262. int8 type = 0;
  6263. if(targetsInserted.find(spawn) != targetsInserted.end())
  6264. continue;
  6265. if(spawn->IsPlayer())
  6266. tmpCharID = ((Player*)spawn)->GetCharacterID();
  6267. else if (spawn->IsPet() && ((Entity*)spawn)->GetOwner() == (Entity*)this)
  6268. {
  6269. tmpCharID = 0xFFFFFFFF;
  6270. }
  6271. else if(spawn->IsPet() && ((Entity*)spawn)->GetOwner() &&
  6272. ((Entity*)spawn)->GetOwner()->IsPlayer())
  6273. {
  6274. type = ((Entity*)spawn)->GetPetType();
  6275. Player* petOwner = (Player*)((Entity*)spawn)->GetOwner();
  6276. tmpCharID = petOwner->GetCharacterID();
  6277. }
  6278. if(!firstTarget)
  6279. insertTargets.append(", ");
  6280. targetsInserted.insert(make_pair(spawn, true));
  6281. LogWrite(SPELL__DEBUG, 0, "Spell", "%s has target %s (%u) added to spell %s", GetName(), spawn ? spawn->GetName() : "NA", tmpCharID, info->maintained_effects[i].spell->spell->GetName());
  6282. insertTargets.append("(" + std::to_string(caster_char_id) + ", " + std::to_string(tmpCharID) + ", " + std::to_string(type) + ", " +
  6283. std::to_string(DB_TYPE_MAINTAINEDEFFECTS) + ", " + std::to_string(info->maintained_effects[i].spell_id) + ", " + std::to_string(i) +
  6284. ", " + std::to_string(info->maintained_effects[i].slot_pos) + ")");
  6285. firstTarget = false;
  6286. }
  6287. }
  6288. multimap<int32,int8>::iterator entries;
  6289. for(entries = info->maintained_effects[i].spell->char_id_targets.begin(); entries != info->maintained_effects[i].spell->char_id_targets.end(); entries++)
  6290. {
  6291. if(!firstTarget)
  6292. insertTargets.append(", ");
  6293. LogWrite(SPELL__DEBUG, 0, "Spell", "%s has target %s (%u) added to spell %s", GetName(), spawn ? spawn->GetName() : "NA", entries->first, info->maintained_effects[i].spell->spell->GetName());
  6294. insertTargets.append("(" + std::to_string(caster_char_id) + ", " + std::to_string(entries->first) + ", " + std::to_string(entries->second) + ", " +
  6295. std::to_string(DB_TYPE_MAINTAINEDEFFECTS) + ", " + std::to_string(info->maintained_effects[i].spell_id) + ", " + std::to_string(i) +
  6296. ", " + std::to_string(info->maintained_effects[i].slot_pos) + ")");
  6297. firstTarget = false;
  6298. }
  6299. info->maintained_effects[i].spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6300. if(!firstTarget)
  6301. {
  6302. Query targetSave;
  6303. targetSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, insertTargets.c_str());
  6304. }
  6305. }
  6306. }
  6307. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  6308. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  6309. }
  6310. void Player::MentorTarget()
  6311. {
  6312. if(client->GetPlayer()->GetGroupMemberInfo() && client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id)
  6313. {
  6314. client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id = 0;
  6315. reset_mentorship = true;
  6316. client->Message(CHANNEL_COMMAND_TEXT, "You stop mentoring, and return to level %u.", client->GetPlayer()->GetLevel());
  6317. }
  6318. else if(!reset_mentorship && client->GetPlayer()->GetTarget())
  6319. {
  6320. if(client->GetPlayer()->GetTarget()->IsPlayer())
  6321. {
  6322. Player* tmpPlayer = (Player*)client->GetPlayer()->GetTarget();
  6323. if(tmpPlayer->GetGroupMemberInfo() && tmpPlayer->GetGroupMemberInfo()->mentor_target_char_id)
  6324. {
  6325. client->Message(CHANNEL_COMMAND_TEXT, "You cannot mentor %s at this time.",tmpPlayer->GetName());
  6326. return;
  6327. }
  6328. if(client->GetPlayer()->group_id > 0 && client->GetPlayer()->GetTarget()->group_id == client->GetPlayer()->group_id)
  6329. {
  6330. if(client->GetPlayer()->GetGroupMemberInfo() && !client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id && client->GetPlayer()->GetZone() == client->GetPlayer()->GetTarget()->GetZone() && client->GetPlayer()->GetTarget()->GetName() != client->GetPlayer()->GetName())
  6331. {
  6332. SetMentorStats(client->GetPlayer()->GetTarget()->GetLevel(), tmpPlayer->GetCharacterID());
  6333. client->Message(CHANNEL_COMMAND_TEXT, "You are now mentoring %s, reducing your effective level to %u.",client->GetPlayer()->GetTarget()->GetName(), client->GetPlayer()->GetTarget()->GetLevel());
  6334. }
  6335. if(client->GetPlayer()->GetTarget()->GetName() == client->GetPlayer()->GetName()) {
  6336. client->Message(CHANNEL_COMMAND_TEXT, "You cannot mentor yourself.");
  6337. }
  6338. }
  6339. }
  6340. }
  6341. }
  6342. void Player::SetMentorStats(int32 effective_level, int32 target_char_id)
  6343. {
  6344. RemoveSpells();
  6345. if(client->GetPlayer()->GetGroupMemberInfo())
  6346. client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id = target_char_id;
  6347. InfoStruct* info = GetInfoStruct();
  6348. info->set_effective_level(effective_level);
  6349. client->GetPlayer()->SetTotalHPBase(effective_level * effective_level * 2 + 40);
  6350. client->GetPlayer()->SetTotalPowerBase((sint32)(effective_level * effective_level * 2.1 + 45));
  6351. client->GetPlayer()->CalculateBonuses();
  6352. client->GetPlayer()->SetHP(GetTotalHP());
  6353. client->GetPlayer()->SetPower(GetTotalPower());
  6354. info->set_agi_base(effective_level * 2 + 15);
  6355. info->set_intel_base(effective_level * 2 + 15);
  6356. info->set_wis_base(effective_level * 2 + 15);
  6357. info->set_str_base(effective_level * 2 + 15);
  6358. info->set_sta_base(effective_level * 2 + 15);
  6359. info->set_cold_base((int16)(effective_level * 1.5 + 10));
  6360. info->set_heat_base((int16)(effective_level * 1.5 + 10));
  6361. info->set_disease_base((int16)(effective_level * 1.5 + 10));
  6362. info->set_mental_base((int16)(effective_level * 1.5 + 10));
  6363. info->set_magic_base((int16)(effective_level * 1.5 + 10));
  6364. info->set_divine_base((int16)(effective_level * 1.5 + 10));
  6365. info->set_poison_base((int16)(effective_level * 1.5 + 10));
  6366. GetClient()->ClearSentItemDetails();
  6367. if(GetClient())
  6368. {
  6369. EQ2Packet* app = GetEquipmentList()->serialize(GetClient()->GetVersion(), this);
  6370. if (app) {
  6371. GetClient()->QueuePacket(app);
  6372. }
  6373. }
  6374. GetEquipmentList()->SendEquippedItems(this);
  6375. }
  6376. void Player::SetLevel(int16 level, bool setUpdateFlags) {
  6377. if(!GetGroupMemberInfo() || GetGroupMemberInfo()->mentor_target_char_id == 0) {
  6378. GetInfoStruct()->set_effective_level(level);
  6379. }
  6380. SetInfo(&appearance.level, level, setUpdateFlags);
  6381. SetXP(0);
  6382. SetNeededXP();
  6383. }
  6384. bool Player::SerializeItemPackets(EquipmentItemList* equipList, vector<EQ2Packet*>* packets, Item* item, int16 version, Item* to_item) {
  6385. if(item_list.AddItem(item)) {
  6386. item->save_needed = true;
  6387. SetEquippedItemAppearances();
  6388. packets->push_back(equipList->serialize(version, this));
  6389. packets->push_back(item->serialize(version, false));
  6390. if(to_item)
  6391. packets->push_back(to_item->serialize(version, false, this));
  6392. packets->push_back(item_list.serialize(this, version));
  6393. return true;
  6394. }
  6395. else {
  6396. LogWrite(PLAYER__ERROR, 0, "Player", "failed to add item to item_list");
  6397. }
  6398. return false;
  6399. }
  6400. void Player::AddGMVisualFilter(int32 filter_type, int32 filter_value, char* filter_search_str, int16 visual_tag) {
  6401. if(MatchGMVisualFilter(filter_type, filter_value, filter_search_str) > 0)
  6402. return;
  6403. vis_mutex.writelock(__FUNCTION__, __LINE__);
  6404. GMTagFilter filter;
  6405. filter.filter_type = filter_type;
  6406. filter.filter_value = filter_value;
  6407. memset(filter.filter_search_criteria, 0, sizeof(filter.filter_search_criteria));
  6408. if(filter_search_str)
  6409. memcpy(&filter.filter_search_criteria, filter_search_str, strnlen(filter_search_str, sizeof(filter.filter_search_criteria)));
  6410. filter.visual_tag = visual_tag;
  6411. gm_visual_filters.push_back(filter);
  6412. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6413. }
  6414. int16 Player::MatchGMVisualFilter(int32 filter_type, int32 filter_value, char* filter_search_str, bool in_vismutex_lock) {
  6415. if(!in_vismutex_lock)
  6416. vis_mutex.readlock(__FUNCTION__, __LINE__);
  6417. int16 tag_id = 0;
  6418. vector<GMTagFilter>::iterator itr = gm_visual_filters.begin();
  6419. for(;itr != gm_visual_filters.end();itr++) {
  6420. if(itr->filter_type == filter_type && itr->filter_value == filter_value) {
  6421. if(filter_search_str && !strcasecmp(filter_search_str, itr->filter_search_criteria)) {
  6422. tag_id = itr->visual_tag;
  6423. break;
  6424. }
  6425. }
  6426. }
  6427. if(!in_vismutex_lock)
  6428. vis_mutex.releasereadlock(__FUNCTION__, __LINE__);
  6429. return tag_id;
  6430. }
  6431. void Player::ClearGMVisualFilters() {
  6432. vis_mutex.writelock(__FUNCTION__, __LINE__);
  6433. gm_visual_filters.clear();
  6434. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6435. }
  6436. int Player::GetPVPAlignment(){
  6437. int bind_zone = GetPlayerInfo()->GetBindZoneID();
  6438. int alignment = 0;
  6439. if(bind_zone && bind_zone != 0){
  6440. //0 is good.
  6441. //1 is evil.
  6442. //2 is neutral aka haven players.
  6443. switch(bind_zone){
  6444. //good zones
  6445. case 114: //Gfay
  6446. case 221: //Qeynos Harbor
  6447. case 222: //North Qeynos
  6448. case 231: //South Qeynos
  6449. case 233: //Nettleville
  6450. case 234: //Starcrest
  6451. case 235: //Graystone
  6452. case 236: //CastleView
  6453. case 237: //Willowood
  6454. case 238: //Baubbleshire
  6455. case 470: //Frostfang
  6456. case 589: //Qeynos Combined 1
  6457. case 660: //Qeynos Combined 2
  6458. alignment = 0; //good
  6459. break;
  6460. //evil zones
  6461. case 128: //East Freeport
  6462. case 134: //Big Bend
  6463. case 135: //Stonestair
  6464. case 136: //Temple St.
  6465. case 137: //Beggars Ct.
  6466. case 138: //Longshadow
  6467. case 139: //Scale Yard
  6468. case 144: //North Freeport
  6469. case 166: //South Freeport
  6470. case 168: //West Freeport
  6471. case 184: //Neriak
  6472. case 644: //BigBend2
  6473. case 645: //Stonestair2
  6474. case 646: //Temple St2
  6475. case 647: //Beggars Ct2
  6476. case 648: //LongShadow2
  6477. case 649: //Scale Yard2
  6478. alignment = 1; //evil
  6479. break;
  6480. //Neutral (MajDul?)
  6481. case 45: //haven
  6482. case 46: //MajDul
  6483. alignment = 2;
  6484. break;
  6485. default:
  6486. alignment = -1; //error
  6487. }
  6488. //return -1 (error), 0 (good), 1 (evil), or 2 (Neutral)
  6489. return alignment;
  6490. }
  6491. return -1; //error
  6492. }
  6493. void Player::GetSpellBookSlotSort(int32 pattern, int32* i, int8* page_book_count, int32* last_start_point) {
  6494. switch(pattern) {
  6495. case 1: { // down
  6496. *i = (*i) + 2;
  6497. (*page_book_count)++;
  6498. if(*page_book_count > 3) {
  6499. if(((*i) % 2) == 0) {
  6500. (*i) = (*last_start_point) + 1;
  6501. }
  6502. else {
  6503. (*last_start_point) = (*last_start_point) + 8;
  6504. (*i) = (*last_start_point);
  6505. }
  6506. (*page_book_count) = 0;
  6507. }
  6508. break;
  6509. }
  6510. case 2: { // across
  6511. (*page_book_count)++;
  6512. switch(*page_book_count) {
  6513. case 1:
  6514. case 3: {
  6515. (*i)++;
  6516. break;
  6517. }
  6518. case 2: {
  6519. (*i) = (*i) + 7;
  6520. break;
  6521. }
  6522. case 4: {
  6523. (*last_start_point) = (*last_start_point) + 2;
  6524. (*i) = (*last_start_point);
  6525. (*page_book_count) = 0;
  6526. break;
  6527. }
  6528. }
  6529. break;
  6530. }
  6531. default: { // zig-zag
  6532. (*i)++;
  6533. break;
  6534. }
  6535. }
  6536. }