Player.cpp 255 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266
  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. if (!maxlvl_only)
  2320. {
  2321. switch (sort_by)
  2322. {
  2323. case 0:
  2324. if (!order)
  2325. stable_sort(spells.begin(), spells.end(), SortSpellEntryByName);
  2326. else
  2327. stable_sort(spells.begin(), spells.end(), SortSpellEntryByNameReverse);
  2328. break;
  2329. case 1:
  2330. if (!order)
  2331. stable_sort(spells.begin(), spells.end(), SortSpellEntryByLevel);
  2332. else
  2333. stable_sort(spells.begin(), spells.end(), SortSpellEntryByLevelReverse);
  2334. break;
  2335. case 2:
  2336. if (!order)
  2337. stable_sort(spells.begin(), spells.end(), SortSpellEntryByCategory);
  2338. else
  2339. stable_sort(spells.begin(), spells.end(), SortSpellEntryByCategoryReverse);
  2340. break;
  2341. }
  2342. }
  2343. vector<SpellBookEntry*>::iterator itr;
  2344. SpellBookEntry* spell = 0;
  2345. int i = 0;
  2346. map<string, SpellBookEntry*> tmpSpells;
  2347. vector<SpellBookEntry*> resultSpells;
  2348. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2349. spell = *itr;
  2350. if (spell->type != book_type || spell->slot == -1)
  2351. continue;
  2352. if (maxlvl_only)
  2353. {
  2354. Spell* actual_spell = 0;
  2355. actual_spell = master_spell_list.GetSpell(spell->spell_id, spell->tier);
  2356. std::regex re("^(.*?)(\\s(I{1,}[VX]{0,}|V{1,}[IVX]{0,})|X{1,}[IVX]{0,})$");
  2357. std::string output = std::regex_replace(string(actual_spell->GetName()), re, "$1", std::regex_constants::format_no_copy);
  2358. if ( output.size() < 1 )
  2359. output = string(actual_spell->GetName());
  2360. map<string, SpellBookEntry*>::iterator tmpItr = tmpSpells.find(output);
  2361. if (tmpItr != tmpSpells.end())
  2362. {
  2363. Spell* tmpSpell = master_spell_list.GetSpell(tmpItr->second->spell_id, tmpItr->second->tier);
  2364. if (actual_spell->GetLevelRequired(this) > tmpSpell->GetLevelRequired(this))
  2365. {
  2366. tmpItr->second->visible = false;
  2367. tmpItr->second->slot = 0xFFFF;
  2368. std::vector<SpellBookEntry*>::iterator it;
  2369. it = find(resultSpells.begin(), resultSpells.end(), (SpellBookEntry*)tmpItr->second);
  2370. if (it != resultSpells.end())
  2371. resultSpells.erase(it);
  2372. tmpSpells.erase(tmpItr);
  2373. }
  2374. else
  2375. continue; // leave as-is we have the newer spell
  2376. }
  2377. spell->visible = true;
  2378. tmpSpells.insert(make_pair(output, spell));
  2379. resultSpells.push_back(spell);
  2380. }
  2381. spell->slot = i;
  2382. i++;
  2383. } // end for loop for setting slots
  2384. if (maxlvl_only)
  2385. {
  2386. switch (sort_by)
  2387. {
  2388. case 0:
  2389. if (!order)
  2390. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByName);
  2391. else
  2392. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByNameReverse);
  2393. break;
  2394. case 1:
  2395. if (!order)
  2396. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByLevel);
  2397. else
  2398. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByLevelReverse);
  2399. break;
  2400. case 2:
  2401. if (!order)
  2402. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByCategory);
  2403. else
  2404. stable_sort(resultSpells.begin(), resultSpells.end(), SortSpellEntryByCategoryReverse);
  2405. break;
  2406. }
  2407. i = 0;
  2408. vector<SpellBookEntry*>::iterator tmpItr;
  2409. for (tmpItr = resultSpells.begin(); tmpItr != resultSpells.end(); tmpItr++) {
  2410. ((SpellBookEntry*)*tmpItr)->slot = i;
  2411. i++;
  2412. }
  2413. }
  2414. MSpellsBook.unlock();
  2415. }
  2416. bool Player::SortSpellEntryByName(SpellBookEntry* s1, SpellBookEntry* s2)
  2417. {
  2418. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2419. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2420. if (!spell1 || !spell2)
  2421. return false;
  2422. return (string(spell1->GetName()) < string(spell2->GetName()));
  2423. }
  2424. bool Player::SortSpellEntryByCategory(SpellBookEntry* s1, SpellBookEntry* s2)
  2425. {
  2426. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2427. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2428. if (!spell1 || !spell2)
  2429. return false;
  2430. return (spell1->GetSpellIconBackdrop() < spell2->GetSpellIconBackdrop());
  2431. }
  2432. bool Player::SortSpellEntryByLevel(SpellBookEntry* s1, SpellBookEntry* s2)
  2433. {
  2434. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2435. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2436. if (!spell1 || !spell2)
  2437. return false;
  2438. int16 lvl1 = spell1->GetLevelRequired(s1->player);
  2439. int16 lvl2 = spell2->GetLevelRequired(s2->player);
  2440. if (lvl1 == 0xFFFF)
  2441. lvl1 = 0;
  2442. if (lvl2 == 0xFFFF)
  2443. lvl2 = 0;
  2444. return (lvl1 < lvl2);
  2445. }
  2446. bool Player::SortSpellEntryByNameReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2447. {
  2448. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2449. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2450. if (!spell1 || !spell2)
  2451. return false;
  2452. return (string(spell2->GetName()) < string(spell1->GetName()));
  2453. }
  2454. bool Player::SortSpellEntryByCategoryReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2455. {
  2456. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2457. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2458. if (!spell1 || !spell2)
  2459. return false;
  2460. return (spell2->GetSpellIconBackdrop() < spell1->GetSpellIconBackdrop());
  2461. }
  2462. bool Player::SortSpellEntryByLevelReverse(SpellBookEntry* s1, SpellBookEntry* s2)
  2463. {
  2464. Spell* spell1 = master_spell_list.GetSpell(s1->spell_id, s1->tier);
  2465. Spell* spell2 = master_spell_list.GetSpell(s2->spell_id, s2->tier);
  2466. if (!spell1 || !spell2)
  2467. return false;
  2468. int16 lvl1 = spell1->GetLevelRequired(s1->player);
  2469. int16 lvl2 = spell2->GetLevelRequired(s2->player);
  2470. if (lvl1 == 0xFFFF)
  2471. lvl1 = 0;
  2472. if (lvl2 == 0xFFFF)
  2473. lvl2 = 0;
  2474. return (lvl2 < lvl1);
  2475. }
  2476. int8 Player::GetSpellSlot(int32 spell_id){
  2477. MSpellsBook.lock();
  2478. vector<SpellBookEntry*>::iterator itr;
  2479. SpellBookEntry* spell = 0;
  2480. for(itr = spells.begin(); itr != spells.end(); itr++){
  2481. spell = *itr;
  2482. if(spell->spell_id == spell_id)
  2483. {
  2484. int8 slot = spell->slot;
  2485. MSpellsBook.unlock();
  2486. return slot;
  2487. }
  2488. }
  2489. MSpellsBook.unlock();
  2490. return 0;
  2491. }
  2492. void Player::AddSkill(int32 skill_id, int16 current_val, int16 max_val, bool save_needed){
  2493. Skill* master_skill = master_skill_list.GetSkill(skill_id);
  2494. if (master_skill) {
  2495. Skill* skill = new Skill(master_skill);
  2496. skill->current_val = current_val;
  2497. skill->previous_val = current_val;
  2498. skill->max_val = max_val;
  2499. if (save_needed)
  2500. skill->save_needed = true;
  2501. skill_list.AddSkill(skill);
  2502. }
  2503. }
  2504. void Player::RemovePlayerSkill(int32 skill_id, bool save) {
  2505. Skill* skill = skill_list.GetSkill(skill_id);
  2506. if (skill)
  2507. RemoveSkillFromDB(skill, save);
  2508. }
  2509. void Player::RemoveSkillFromDB(Skill* skill, bool save) {
  2510. skill_list.RemoveSkill(skill);
  2511. if (save)
  2512. database.DeleteCharacterSkill(GetCharacterID(), skill);
  2513. }
  2514. int16 Player::GetSpellSlotMappingCount(){
  2515. int16 ret = 0;
  2516. MSpellsBook.lock();
  2517. for(int32 i=0;i<spells.size();i++){
  2518. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2519. if(spell->slot >= 0 && spell->spell_id > 0)
  2520. ret++;
  2521. }
  2522. MSpellsBook.unlock();
  2523. return ret;
  2524. }
  2525. int8 Player::GetSpellTier(int32 id){
  2526. int8 ret = 0;
  2527. MSpellsBook.lock();
  2528. for(int32 i=0;i<spells.size();i++){
  2529. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2530. if(spell->spell_id == id){
  2531. ret = spell->tier;
  2532. break;
  2533. }
  2534. }
  2535. MSpellsBook.unlock();
  2536. return ret;
  2537. }
  2538. int16 Player::GetSpellPacketCount(){
  2539. int16 ret = 0;
  2540. MSpellsBook.lock();
  2541. for(int32 i=0;i<spells.size();i++){
  2542. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2543. if(spell->spell_id > 0)
  2544. ret++;
  2545. }
  2546. MSpellsBook.unlock();
  2547. return ret;
  2548. }
  2549. void Player::LockAllSpells() {
  2550. vector<SpellBookEntry*>::iterator itr;
  2551. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2552. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2553. if ((*itr)->type != SPELL_BOOK_TYPE_TRADESKILL)
  2554. RemoveSpellStatus((*itr), SPELL_STATUS_LOCK, false);
  2555. }
  2556. all_spells_locked = true;
  2557. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2558. }
  2559. void Player::UnlockAllSpells(bool modify_recast, Spell* exception) {
  2560. vector<SpellBookEntry*>::iterator itr;
  2561. int32 exception_spell_id = 0;
  2562. if (exception)
  2563. exception_spell_id = exception->GetSpellID();
  2564. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2565. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2566. MaintainedEffects* effect = 0;
  2567. if((effect = GetMaintainedSpell((*itr)->spell_id)) && effect->spell->spell->GetSpellData()->duration_until_cancel)
  2568. continue;
  2569. if ((*itr)->in_use == false &&
  2570. (((*itr)->spell_id != exception_spell_id ||
  2571. (*itr)->timer > 0 && (*itr)->timer != exception->GetSpellData()->linked_timer)
  2572. && (*itr)->type != SPELL_BOOK_TYPE_TRADESKILL))
  2573. AddSpellStatus((*itr), SPELL_STATUS_LOCK, modify_recast);
  2574. else if((*itr)->in_remiss)
  2575. {
  2576. AddSpellStatus((*itr), SPELL_STATUS_LOCK);
  2577. (*itr)->in_remiss = false;
  2578. }
  2579. }
  2580. all_spells_locked = false;
  2581. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2582. }
  2583. void Player::LockSpell(Spell* spell, int16 recast) {
  2584. vector<SpellBookEntry*>::iterator itr;
  2585. SpellBookEntry* spell2;
  2586. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2587. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2588. spell2 = *itr;
  2589. if (spell2->spell_id == spell->GetSpellID() || (spell->GetSpellData()->linked_timer > 0 && spell->GetSpellData()->linked_timer == spell2->timer))
  2590. {
  2591. spell2->in_use = true;
  2592. RemoveSpellStatus(spell2, SPELL_STATUS_LOCK, true, recast);
  2593. }
  2594. else if(spell2->in_use)
  2595. RemoveSpellStatus(spell2, SPELL_STATUS_LOCK, false, 0);
  2596. }
  2597. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2598. }
  2599. void Player::UnlockSpell(Spell* spell) {
  2600. if (spell->GetStayLocked())
  2601. return;
  2602. vector<SpellBookEntry*>::iterator itr;
  2603. SpellBookEntry* spell2;
  2604. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2605. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2606. spell2 = *itr;
  2607. if (spell2->spell_id == spell->GetSpellID() || (spell->GetSpellData()->linked_timer > 0 && spell->GetSpellData()->linked_timer == spell2->timer))
  2608. {
  2609. spell2->in_use = false;
  2610. if(all_spells_locked)
  2611. spell2->in_remiss = true;
  2612. else
  2613. AddSpellStatus(spell2, SPELL_STATUS_LOCK);
  2614. }
  2615. }
  2616. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2617. }
  2618. void Player::LockTSSpells() {
  2619. vector<SpellBookEntry*>::iterator itr;
  2620. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2621. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2622. if ((*itr)->type == SPELL_BOOK_TYPE_TRADESKILL)
  2623. RemoveSpellStatus(*itr, SPELL_STATUS_LOCK);
  2624. }
  2625. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2626. // Unlock all other types
  2627. UnlockAllSpells();
  2628. }
  2629. void Player::UnlockTSSpells() {
  2630. vector<SpellBookEntry*>::iterator itr;
  2631. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2632. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2633. if ((*itr)->type == SPELL_BOOK_TYPE_TRADESKILL)
  2634. AddSpellStatus(*itr, SPELL_STATUS_LOCK);
  2635. }
  2636. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2637. // Lock all other types
  2638. LockAllSpells();
  2639. }
  2640. void Player::QueueSpell(Spell* spell) {
  2641. vector<SpellBookEntry*>::iterator itr;
  2642. SpellBookEntry* spell2;
  2643. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2644. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2645. spell2 = *itr;
  2646. if (spell2->spell_id == spell->GetSpellID())
  2647. AddSpellStatus(spell2, SPELL_STATUS_QUEUE, false);
  2648. }
  2649. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2650. }
  2651. void Player::UnQueueSpell(Spell* spell) {
  2652. vector<SpellBookEntry*>::iterator itr;
  2653. SpellBookEntry* spell2;
  2654. MSpellsBook.writelock(__FUNCTION__, __LINE__);
  2655. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2656. spell2 = *itr;
  2657. if (spell2->spell_id == spell->GetSpellID())
  2658. RemoveSpellStatus(spell2, SPELL_STATUS_QUEUE, false);
  2659. }
  2660. MSpellsBook.releasewritelock(__FUNCTION__, __LINE__);
  2661. }
  2662. vector<Spell*> Player::GetSpellBookSpellsByTimer(int32 timerID) {
  2663. vector<Spell*> ret;
  2664. vector<SpellBookEntry*>::iterator itr;
  2665. MSpellsBook.readlock(__FUNCTION__, __LINE__);
  2666. for (itr = spells.begin(); itr != spells.end(); itr++) {
  2667. if ((*itr)->timer == timerID)
  2668. ret.push_back(master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier));
  2669. }
  2670. MSpellsBook.releasereadlock(__FUNCTION__, __LINE__);
  2671. return ret;
  2672. }
  2673. void Player::ModifySpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2674. if (modify_recast) {
  2675. spell->recast = recast;
  2676. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2677. }
  2678. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2679. spell->status += value; // use set/remove spell status now
  2680. }
  2681. }
  2682. void Player::AddSpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2683. if (modify_recast) {
  2684. spell->recast = recast;
  2685. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2686. }
  2687. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2688. spell->status = spell->status | value;
  2689. }
  2690. }
  2691. void Player::RemoveSpellStatus(SpellBookEntry* spell, sint16 value, bool modify_recast, int16 recast) {
  2692. if (modify_recast) {
  2693. spell->recast = recast;
  2694. spell->recast_available = Timer::GetCurrentTime2() + (recast * 100);
  2695. }
  2696. if (modify_recast || spell->recast_available <= Timer::GetCurrentTime2() || value == 4) {
  2697. spell->status = spell->status & ~value;
  2698. }
  2699. }
  2700. void Player::SetSpellStatus(Spell* spell, int8 status){
  2701. MSpellsBook.lock();
  2702. vector<SpellBookEntry*>::iterator itr;
  2703. SpellBookEntry* spell2 = 0;
  2704. for(itr = spells.begin(); itr != spells.end(); itr++){
  2705. spell2 = *itr;
  2706. if(spell2->spell_id == spell->GetSpellData()->id){
  2707. spell2->status = spell2->status | status;
  2708. break;
  2709. }
  2710. }
  2711. MSpellsBook.unlock();
  2712. }
  2713. vector<SpellBookEntry*>* Player::GetSpellsSaveNeeded(){
  2714. vector<SpellBookEntry*>* ret = 0;
  2715. vector<SpellBookEntry*>::iterator itr;
  2716. MSpellsBook.lock();
  2717. SpellBookEntry* spell = 0;
  2718. for(itr = spells.begin(); itr != spells.end(); itr++){
  2719. spell = *itr;
  2720. if(spell->save_needed){
  2721. if(!ret)
  2722. ret = new vector<SpellBookEntry*>;
  2723. ret->push_back(spell);
  2724. }
  2725. }
  2726. MSpellsBook.unlock();
  2727. return ret;
  2728. }
  2729. int16 Player::GetTierUp(int16 tier)
  2730. {
  2731. switch(tier)
  2732. {
  2733. case 0:
  2734. break;
  2735. case 7:
  2736. case 9:
  2737. tier -= 2;
  2738. break;
  2739. default:
  2740. tier -= 1;
  2741. break;
  2742. }
  2743. return tier;
  2744. }
  2745. bool Player::HasSpell(int32 spell_id, int8 tier, bool include_higher_tiers, bool include_possible_scribe){
  2746. bool ret = false;
  2747. vector<SpellBookEntry*>::iterator itr;
  2748. MSpellsBook.lock();
  2749. SpellBookEntry* spell = 0;
  2750. for(itr = spells.begin(); itr != spells.end(); itr++){
  2751. spell = *itr;
  2752. if(spell->spell_id == spell_id && (tier == 255 || spell->tier == tier || (include_higher_tiers && spell->tier > tier) || (include_possible_scribe && tier <= spell->tier))){
  2753. ret = true;
  2754. break;
  2755. }
  2756. }
  2757. MSpellsBook.unlock();
  2758. return ret;
  2759. }
  2760. sint32 Player::GetFreeSpellBookSlot(int32 type){
  2761. sint32 ret = 0;
  2762. MSpellsBook.lock();
  2763. vector<SpellBookEntry*>::iterator itr;
  2764. SpellBookEntry* spell = 0;
  2765. for(itr = spells.begin(); itr != spells.end(); itr++){
  2766. spell = *itr;
  2767. if(spell->type == type && spell->slot > ret) //get last slot (add 1 to it on return)
  2768. ret = spell->slot;
  2769. }
  2770. MSpellsBook.unlock();
  2771. return ret+1;
  2772. }
  2773. SpellBookEntry* Player::GetSpellBookSpell(int32 spell_id){
  2774. MSpellsBook.lock();
  2775. vector<SpellBookEntry*>::iterator itr;
  2776. SpellBookEntry* ret = 0;
  2777. SpellBookEntry* spell = 0;
  2778. for(itr = spells.begin(); itr != spells.end(); itr++){
  2779. spell = *itr;
  2780. if(spell->spell_id == spell_id){
  2781. ret = spell;
  2782. break;
  2783. }
  2784. }
  2785. MSpellsBook.unlock();
  2786. return ret;
  2787. }
  2788. vector<int32> Player::GetSpellBookSpellIDBySkill(int32 skill_id) {
  2789. vector<int32> ret;
  2790. MSpellsBook.readlock(__FUNCTION__, __LINE__);
  2791. vector<SpellBookEntry*>::iterator itr;
  2792. Spell* spell = 0;
  2793. for(itr = spells.begin(); itr != spells.end(); itr++){
  2794. spell = master_spell_list.GetSpell((*itr)->spell_id, (*itr)->tier);
  2795. if(spell && spell->GetSpellData()->mastery_skill == skill_id)
  2796. ret.push_back(spell->GetSpellData()->id);
  2797. }
  2798. MSpellsBook.releasereadlock(__FUNCTION__, __LINE__);
  2799. return ret;
  2800. }
  2801. EQ2Packet* Player::GetSpellSlotMappingPacket(int16 version){
  2802. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", version);
  2803. if(packet){
  2804. int16 count = GetSpellSlotMappingCount();
  2805. int16 ptr = 0;
  2806. if(count > 0){
  2807. packet->setArrayLengthByName("spell_count", count);
  2808. MSpellsBook.lock();
  2809. for(int32 i=0;i<spells.size();i++){
  2810. SpellBookEntry* spell = (SpellBookEntry*)spells[i];
  2811. if(spell->slot < 0 || spell->spell_id == 0)
  2812. continue;
  2813. packet->setArrayDataByName("spell_id", spell->spell_id, ptr);
  2814. packet->setArrayDataByName("slot_id", (int16)spell->slot, ptr);
  2815. ptr++;
  2816. }
  2817. MSpellsBook.unlock();
  2818. EQ2Packet* ret = packet->serialize();
  2819. safe_delete(packet);
  2820. return ret;
  2821. }
  2822. safe_delete(packet);
  2823. }
  2824. return 0;
  2825. }
  2826. EQ2Packet* Player::GetSpellBookUpdatePacket(int16 version) {
  2827. PacketStruct* packet = configReader.getStruct("WS_UpdateSpellBook", version);
  2828. EQ2Packet* ret = 0;
  2829. if (packet) {
  2830. Spell* spell = 0;
  2831. SpellBookEntry* spell_entry = 0;
  2832. int16 count = GetSpellPacketCount();
  2833. int16 ptr = 0;
  2834. // Get the packet size
  2835. PacketStruct* packet2 = configReader.getStruct("SubStruct_UpdateSpellBook", version);
  2836. int32 total_bytes = packet2->GetTotalPacketSize();
  2837. safe_delete(packet2);
  2838. packet->setArrayLengthByName("spell_count", count);
  2839. if (count > 0) {
  2840. if (count > spell_count) {
  2841. uchar* tmp = 0;
  2842. if (spell_orig_packet) {
  2843. tmp = new uchar[count * total_bytes];
  2844. memset(tmp, 0, total_bytes * count);
  2845. memcpy(tmp, spell_orig_packet, spell_count * total_bytes);
  2846. safe_delete_array(spell_orig_packet);
  2847. safe_delete_array(spell_xor_packet);
  2848. spell_orig_packet = tmp;
  2849. }
  2850. else {
  2851. spell_orig_packet = new uchar[count * total_bytes];
  2852. memset(spell_orig_packet, 0, total_bytes * count);
  2853. }
  2854. spell_xor_packet = new uchar[count * total_bytes];
  2855. memset(spell_xor_packet, 0, count * total_bytes);
  2856. spell_count = count;
  2857. }
  2858. MSpellsBook.lock();
  2859. for (int32 i = 0; i < spells.size(); i++) {
  2860. spell_entry = (SpellBookEntry*)spells[i];
  2861. if (spell_entry->spell_id == 0)
  2862. continue;
  2863. spell = master_spell_list.GetSpell(spell_entry->spell_id, spell_entry->tier);
  2864. if (spell) {
  2865. if (spell_entry->recast_available == 0 || Timer::GetCurrentTime2() > spell_entry->recast_available) {
  2866. packet->setSubstructArrayDataByName("spells", "available", 1, 0, ptr);
  2867. }
  2868. packet->setSubstructArrayDataByName("spells", "spell_id", spell_entry->spell_id, 0, ptr);
  2869. packet->setSubstructArrayDataByName("spells", "type", spell_entry->type, 0, ptr);
  2870. packet->setSubstructArrayDataByName("spells", "recast_available", spell_entry->recast_available, 0, ptr);
  2871. packet->setSubstructArrayDataByName("spells", "recast_time", spell_entry->recast, 0, ptr);
  2872. packet->setSubstructArrayDataByName("spells", "status", spell_entry->status, 0, ptr);
  2873. packet->setSubstructArrayDataByName("spells", "icon", (spell->GetSpellIcon() * -1) - 1, 0, ptr);
  2874. packet->setSubstructArrayDataByName("spells", "icon_type", spell->GetSpellIconBackdrop(), 0, ptr);
  2875. packet->setSubstructArrayDataByName("spells", "icon2", spell->GetSpellIconHeroicOp(), 0, ptr);
  2876. packet->setSubstructArrayDataByName("spells", "unique_id", (spell_entry->tier + 1) * -1, 0, ptr); //this is actually GetSpellNameCrc(spell->GetName()), but hijacking it for spell tier
  2877. packet->setSubstructArrayDataByName("spells", "charges", 255, 0, ptr);
  2878. // Beastlord and Channeler spell support
  2879. if (spell->GetSpellData()->savage_bar == 1)
  2880. packet->setSubstructArrayDataByName("spells", "unknown6", 32, 0, ptr); // advantages
  2881. else if (spell->GetSpellData()->savage_bar == 2)
  2882. packet->setSubstructArrayDataByName("spells", "unknown6", 64, 0, ptr); // primal
  2883. else if (spell->GetSpellData()->savage_bar == 3) {
  2884. packet->setSubstructArrayDataByName("spells", "unknown6", 6, 1, ptr); // 6 = channeler
  2885. // Slot req for channelers
  2886. // 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
  2887. packet->setSubstructArrayDataByName("spells", "savage_bar_slot", spell->GetSpellData()->savage_bar_slot, 0, ptr);
  2888. }
  2889. ptr++;
  2890. }
  2891. }
  2892. MSpellsBook.unlock();
  2893. }
  2894. ret = packet->serializeCountPacket(version, 0, spell_orig_packet, spell_xor_packet);
  2895. //packet->PrintPacket();
  2896. //DumpPacket(ret);
  2897. safe_delete(packet);
  2898. }
  2899. return ret;
  2900. }
  2901. PlayerInfo::~PlayerInfo(){
  2902. RemoveOldPackets();
  2903. }
  2904. PlayerInfo::PlayerInfo(Player* in_player){
  2905. orig_packet = 0;
  2906. changes = 0;
  2907. pet_orig_packet = 0;
  2908. pet_changes = 0;
  2909. player = in_player;
  2910. info_struct = player->GetInfoStruct();
  2911. info_struct->set_name(std::string(player->GetName()));
  2912. info_struct->set_deity(std::string("None"));
  2913. info_struct->set_class1(classes.GetBaseClass(player->GetAdventureClass()));
  2914. info_struct->set_class2(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  2915. info_struct->set_class3(player->GetAdventureClass());
  2916. info_struct->set_race(player->GetRace());
  2917. info_struct->set_gender(player->GetGender());
  2918. info_struct->set_level(player->GetLevel());
  2919. info_struct->set_tradeskill_level(player->GetTSLevel()); // JA: added 2011.07.22 to address TODO below
  2920. info_struct->set_tradeskill_class1(classes.GetTSBaseClass(player->GetTradeskillClass()));
  2921. info_struct->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(player->GetTradeskillClass()));
  2922. info_struct->set_tradeskill_class3(player->GetTradeskillClass());
  2923. LogWrite(MISC__TODO, 1, "TODO", "Fix info_struct.tradeskill_level = player->GetArtLevel();\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  2924. for(int i=0;i<45;i++){
  2925. if(i<30){
  2926. info_struct->maintained_effects[i].spell_id = 0xFFFFFFFF;
  2927. info_struct->maintained_effects[i].icon = 0xFFFF;
  2928. info_struct->maintained_effects[i].spell = nullptr;
  2929. }
  2930. info_struct->spell_effects[i].spell_id = 0xFFFFFFFF;
  2931. info_struct->spell_effects[i].spell = nullptr;
  2932. }
  2933. house_zone_id = 0;
  2934. bind_zone_id = 0;
  2935. bind_x = 0;
  2936. bind_y = 0;
  2937. bind_z = 0;
  2938. bind_heading = 0;
  2939. boat_x_offset = 0;
  2940. boat_y_offset = 0;
  2941. boat_z_offset = 0;
  2942. boat_spawn = 0;
  2943. }
  2944. MaintainedEffects* Player::GetFreeMaintainedSpellSlot(){
  2945. MaintainedEffects* ret = 0;
  2946. InfoStruct* info = GetInfoStruct();
  2947. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2948. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2949. if(info->maintained_effects[i].spell_id == 0xFFFFFFFF){
  2950. ret = &info->maintained_effects[i];
  2951. ret->spell_id = 0;
  2952. ret->slot_pos = i;
  2953. break;
  2954. }
  2955. }
  2956. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2957. return ret;
  2958. }
  2959. MaintainedEffects* Player::GetMaintainedSpell(int32 id){
  2960. MaintainedEffects* ret = 0;
  2961. InfoStruct* info = GetInfoStruct();
  2962. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2963. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2964. if(info->maintained_effects[i].spell_id == id){
  2965. ret = &info->maintained_effects[i];
  2966. break;
  2967. }
  2968. }
  2969. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2970. return ret;
  2971. }
  2972. MaintainedEffects* Player::GetMaintainedSpellBySlot(int8 slot){
  2973. MaintainedEffects* ret = 0;
  2974. InfoStruct* info = GetInfoStruct();
  2975. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  2976. for(int i=0;i<NUM_MAINTAINED_EFFECTS;i++){
  2977. if(info->maintained_effects[i].slot_pos == slot){
  2978. ret = &info->maintained_effects[i];
  2979. break;
  2980. }
  2981. }
  2982. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  2983. return ret;
  2984. }
  2985. MaintainedEffects* Player::GetMaintainedSpells() {
  2986. return GetInfoStruct()->maintained_effects;
  2987. }
  2988. SpellEffects* Player::GetFreeSpellEffectSlot(){
  2989. SpellEffects* ret = 0;
  2990. InfoStruct* info = GetInfoStruct();
  2991. GetSpellEffectMutex()->readlock(__FUNCTION__, __LINE__);
  2992. for(int i=0;i<45;i++){
  2993. if(info->spell_effects[i].spell_id == 0xFFFFFFFF){
  2994. ret = &info->spell_effects[i];
  2995. ret->spell_id = 0;
  2996. break;
  2997. }
  2998. }
  2999. GetSpellEffectMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3000. return ret;
  3001. }
  3002. SpellEffects* Player::GetSpellEffects() {
  3003. return GetInfoStruct()->spell_effects;
  3004. }
  3005. // call inside info_mutex
  3006. void Player::ClearRemovalTimers(){
  3007. map<int32, SpawnQueueState*>::iterator itr;
  3008. for(itr = spawn_state_list.begin(); itr != spawn_state_list.end();) {
  3009. SpawnQueueState* sr = itr->second;
  3010. itr = spawn_state_list.erase(itr);
  3011. safe_delete(sr);
  3012. }
  3013. }
  3014. void Player::ClearEverything(){
  3015. index_mutex.writelock(__FUNCTION__, __LINE__);
  3016. player_spawn_id_map.clear();
  3017. player_spawn_reverse_id_map.clear();
  3018. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3019. map<int32, vector<int32>*>::iterator itr;
  3020. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  3021. for (itr = player_spawn_quests_required.begin(); itr != player_spawn_quests_required.end(); itr++){
  3022. safe_delete(itr->second);
  3023. }
  3024. player_spawn_quests_required.clear();
  3025. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  3026. m_playerSpawnHistoryRequired.writelock(__FUNCTION__, __LINE__);
  3027. for (itr = player_spawn_history_required.begin(); itr != player_spawn_history_required.end(); itr++){
  3028. safe_delete(itr->second);
  3029. }
  3030. player_spawn_history_required.clear();
  3031. m_playerSpawnHistoryRequired.releasewritelock(__FUNCTION__, __LINE__);
  3032. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3033. ClearRemovalTimers();
  3034. spawn_packet_sent.clear();
  3035. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3036. info_mutex.writelock(__FUNCTION__, __LINE__);
  3037. spawn_info_packet_list.clear();
  3038. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3039. vis_mutex.writelock(__FUNCTION__, __LINE__);
  3040. spawn_vis_packet_list.clear();
  3041. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3042. pos_mutex.writelock(__FUNCTION__, __LINE__);
  3043. spawn_pos_packet_list.clear();
  3044. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3045. }
  3046. bool Player::IsFullyLoggedIn() {
  3047. return fully_logged_in;
  3048. }
  3049. void Player::SetFullyLoggedIn(bool val) {
  3050. fully_logged_in = val;
  3051. }
  3052. bool Player::IsResurrecting(){
  3053. return resurrecting;
  3054. }
  3055. void Player::SetResurrecting(bool val){
  3056. resurrecting = val;
  3057. }
  3058. void Player::AddMaintainedSpell(LuaSpell* luaspell){
  3059. if(!luaspell)
  3060. return;
  3061. Spell* spell = luaspell->spell;
  3062. MaintainedEffects* effect = GetFreeMaintainedSpellSlot();
  3063. int32 target_type = 0;
  3064. Spawn* spawn = 0;
  3065. if(effect){
  3066. GetMaintainedMutex()->writelock(__FUNCTION__, __LINE__);
  3067. strcpy(effect->name, spell->GetSpellData()->name.data.c_str());
  3068. effect->target = luaspell->initial_target;
  3069. spawn = luaspell->caster->GetZone()->GetSpawnByID(luaspell->initial_target);
  3070. if (spawn){
  3071. if (spawn == this)
  3072. target_type = 0;
  3073. else if (GetPet() == spawn || GetCharmedPet() == spawn)
  3074. target_type = 1;
  3075. else
  3076. target_type = 2;
  3077. }
  3078. effect->target_type = target_type;
  3079. effect->spell = luaspell;
  3080. if(!luaspell->slot_pos)
  3081. luaspell->slot_pos = effect->slot_pos;
  3082. effect->spell_id = spell->GetSpellData()->id;
  3083. LogWrite(PLAYER__DEBUG, 5, "Player", "AddMaintainedSpell Spell ID: %u, req concentration: %u", spell->GetSpellData()->id, spell->GetSpellData()->req_concentration);
  3084. effect->icon = spell->GetSpellData()->icon;
  3085. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  3086. effect->conc_used = spell->GetSpellData()->req_concentration;
  3087. effect->total_time = spell->GetSpellDuration()/10;
  3088. effect->tier = spell->GetSpellData()->tier;
  3089. if (spell->GetSpellData()->duration_until_cancel)
  3090. effect->expire_timestamp = 0xFFFFFFFF;
  3091. else
  3092. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  3093. GetMaintainedMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3094. charsheet_changed = true;
  3095. }
  3096. }
  3097. void Player::AddSpellEffect(LuaSpell* luaspell, int32 override_expire_time){
  3098. if(!luaspell || !luaspell->caster)
  3099. return;
  3100. Spell* spell = luaspell->spell;
  3101. SpellEffects* old_effect = GetSpellEffect(spell->GetSpellID(), luaspell->caster);
  3102. SpellEffects* effect = 0;
  3103. if (old_effect){
  3104. GetZone()->RemoveTargetFromSpell(old_effect->spell, this);
  3105. RemoveSpellEffect(old_effect->spell);
  3106. }
  3107. effect = GetFreeSpellEffectSlot();
  3108. if(effect){
  3109. GetSpellEffectMutex()->writelock(__FUNCTION__, __LINE__);
  3110. effect->spell = luaspell;
  3111. effect->spell_id = spell->GetSpellData()->id;
  3112. effect->caster = luaspell->caster;
  3113. effect->total_time = spell->GetSpellDuration()/10;
  3114. if (spell->GetSpellData()->duration_until_cancel)
  3115. effect->expire_timestamp = 0xFFFFFFFF;
  3116. else if(override_expire_time)
  3117. effect->expire_timestamp = Timer::GetCurrentTime2() + override_expire_time;
  3118. else
  3119. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  3120. effect->icon = spell->GetSpellData()->icon;
  3121. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  3122. effect->tier = spell->GetSpellTier();
  3123. GetSpellEffectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3124. charsheet_changed = true;
  3125. if(luaspell->caster && luaspell->caster->IsPlayer() && luaspell->caster != this)
  3126. {
  3127. GetClient()->TriggerSpellSave();
  3128. ((Player*)luaspell->caster)->GetClient()->TriggerSpellSave();
  3129. }
  3130. }
  3131. }
  3132. void Player::RemoveMaintainedSpell(LuaSpell* luaspell){
  3133. if(!luaspell)
  3134. return;
  3135. bool found = false;
  3136. Client* client = GetZone()->GetClientBySpawn(this);
  3137. LuaSpell* old_spell = 0;
  3138. LuaSpell* current_spell = 0;
  3139. GetMaintainedMutex()->writelock(__FUNCTION__, __LINE__);
  3140. for(int i=0;i<30;i++){
  3141. // If we already found the spell then we are bumping all other up one so there are no gaps in the ui
  3142. // This check needs to be first so found can never be true on the first iteration (i = 0)
  3143. if (found) {
  3144. old_spell = GetInfoStruct()->maintained_effects[i - 1].spell;
  3145. current_spell = GetInfoStruct()->maintained_effects[i].spell;
  3146. //Update the maintained window uses_remaining and damage_remaining values
  3147. if (current_spell && current_spell->num_triggers > 0)
  3148. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, current_spell->num_triggers, 0);
  3149. else if (current_spell && current_spell->damage_remaining > 0)
  3150. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, current_spell->damage_remaining, 1);
  3151. else if (old_spell && old_spell->had_triggers)
  3152. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, 0, 0);
  3153. else if (old_spell && old_spell->had_dmg_remaining)
  3154. ClientPacketFunctions::SendMaintainedExamineUpdate(client, i - 1, 0, 1);
  3155. GetInfoStruct()->maintained_effects[i].slot_pos = i - 1;
  3156. GetInfoStruct()->maintained_effects[i - 1] = GetInfoStruct()->maintained_effects[i];
  3157. if (current_spell)
  3158. current_spell->slot_pos = i - 1;
  3159. }
  3160. // Compare spells, if we found a match set the found flag
  3161. if(GetInfoStruct()->maintained_effects[i].spell == luaspell)
  3162. found = true;
  3163. }
  3164. // 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
  3165. if (found) {
  3166. memset(&GetInfoStruct()->maintained_effects[29], 0, sizeof(MaintainedEffects));
  3167. GetInfoStruct()->maintained_effects[29].spell_id = 0xFFFFFFFF;
  3168. GetInfoStruct()->maintained_effects[29].icon = 0xFFFF;
  3169. GetInfoStruct()->maintained_effects[29].spell = nullptr;
  3170. charsheet_changed = true;
  3171. }
  3172. GetMaintainedMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3173. }
  3174. void Player::RemoveSpellEffect(LuaSpell* spell){
  3175. bool found = false;
  3176. GetSpellEffectMutex()->writelock(__FUNCTION__, __LINE__);
  3177. for(int i=0;i<45;i++){
  3178. if (found) {
  3179. GetInfoStruct()->spell_effects[i-1] = GetInfoStruct()->spell_effects[i];
  3180. }
  3181. if(GetInfoStruct()->spell_effects[i].spell == spell)
  3182. found = true;
  3183. }
  3184. if (found) {
  3185. memset(&GetInfoStruct()->spell_effects[44], 0, sizeof(SpellEffects));
  3186. GetInfoStruct()->spell_effects[44].spell_id = 0xFFFFFFFF;
  3187. changed = true;
  3188. info_changed = true;
  3189. AddChangedZoneSpawn();
  3190. charsheet_changed = true;
  3191. }
  3192. GetSpellEffectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  3193. }
  3194. bool Player::HasActiveMaintainedSpell(Spell* spell, Spawn* target){
  3195. GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  3196. for(int i=0;i<30;i++){
  3197. if (GetInfoStruct()->maintained_effects[i].spell_id == spell->GetSpellData()->id){
  3198. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3199. return true;
  3200. }
  3201. }
  3202. GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  3203. return false;
  3204. }
  3205. bool Player::HasActiveSpellEffect(Spell* spell, Spawn* target){
  3206. return false;
  3207. }
  3208. void Player::PrepareIncomingMovementPacket(int32 len, uchar* data, int16 version)
  3209. {
  3210. if(GetClient() && GetClient()->IsReloadingZone())
  3211. return;
  3212. LogWrite(PLAYER__DEBUG, 7, "Player", "Enter: %s", __FUNCTION__); // trace
  3213. // XML structs may be to slow to use in this portion of the code as a single
  3214. // client sends a LOT of these packets when they are moving. I have commented
  3215. // out all the code for xml structs, to switch to it just uncomment
  3216. // the code and comment the 2 if/else if/else blocks, both have a comment
  3217. // above them to let you know wich ones they are.
  3218. //PacketStruct* update = configReader.getStruct("WS_PlayerPosUpdate", version);
  3219. int16 total_bytes; // = update->GetTotalPacketSize();
  3220. // Comment out this if/else if/else block if you switch to xml structs
  3221. if (version >= 1144)
  3222. total_bytes = sizeof(Player_Update1144);
  3223. else if (version >= 1096)
  3224. total_bytes = sizeof(Player_Update1096);
  3225. else if (version <= 283)
  3226. total_bytes = sizeof(Player_Update283);
  3227. else
  3228. total_bytes = sizeof(Player_Update);
  3229. if (!movement_packet)
  3230. movement_packet = new uchar[total_bytes];
  3231. else if (!old_movement_packet)
  3232. old_movement_packet = new uchar[total_bytes];
  3233. if (movement_packet && old_movement_packet)
  3234. memcpy(old_movement_packet, movement_packet, total_bytes);
  3235. bool reverse = version > 283;
  3236. Unpack(len, data, movement_packet, total_bytes, 0, reverse);
  3237. if (!movement_packet || !old_movement_packet)
  3238. return;
  3239. Decode(movement_packet, old_movement_packet, total_bytes);
  3240. //update->LoadPacketData(movement_packet, total_bytes);
  3241. int32 activity; // = update->getType_int32_ByName("activity");
  3242. int32 grid_id; // = update->getType_int32_ByName("grid_location");
  3243. float direction1; // = update->getType_float_ByName("direction1");
  3244. float direction2; // = update->getType_float_ByName("direction2");;
  3245. float speed; // = update->getType_float_ByName("speed");;
  3246. float side_speed;
  3247. float x; // = update->getType_float_ByName("x");;
  3248. float y; // = update->getType_float_ByName("y");;
  3249. float z; // = update->getType_float_ByName("z");;
  3250. float x_speed;
  3251. float y_speed;
  3252. float z_speed;
  3253. // comment out this if/else if/else block if you use xml structs
  3254. if (version >= 1144) {
  3255. Player_Update1144* update = (Player_Update1144*)movement_packet;
  3256. activity = update->activity;
  3257. grid_id = update->grid_location;
  3258. direction1 = update->direction1;
  3259. direction2 = update->direction2;
  3260. speed = update->speed;
  3261. side_speed = update->side_speed;
  3262. x = update->x;
  3263. y = update->y;
  3264. z = update->z;
  3265. x_speed = update->speed_x;
  3266. y_speed = update->speed_y;
  3267. z_speed = update->speed_z;
  3268. SetPitch(180 + update->pitch);
  3269. }
  3270. else if (version >= 1096) {
  3271. Player_Update1096* update = (Player_Update1096*)movement_packet;
  3272. activity = update->activity;
  3273. grid_id = update->grid_location;
  3274. direction1 = update->direction1;
  3275. direction2 = update->direction2;
  3276. speed = update->speed;
  3277. side_speed = update->side_speed;
  3278. x = update->x;
  3279. y = update->y;
  3280. z = update->z;
  3281. x_speed = update->speed_x;
  3282. y_speed = update->speed_y;
  3283. z_speed = update->speed_z;
  3284. SetPitch(180 + update->pitch);
  3285. }
  3286. else if (version <= 283) {
  3287. Player_Update283* update = (Player_Update283*)movement_packet;
  3288. activity = update->activity;
  3289. grid_id = update->grid_location;
  3290. direction1 = update->direction1;
  3291. direction2 = update->direction2;
  3292. speed = update->speed;
  3293. side_speed = update->side_speed;
  3294. x = update->x;
  3295. y = update->y;
  3296. z = update->z;
  3297. x_speed = update->speed_x;
  3298. y_speed = update->speed_y;
  3299. z_speed = update->speed_z;
  3300. if (update->pitch != 0)
  3301. SetPitch(180 + update->pitch);
  3302. }
  3303. else {
  3304. Player_Update* update = (Player_Update*)movement_packet;
  3305. activity = update->activity;
  3306. grid_id = update->grid_location;
  3307. direction1 = update->direction1;
  3308. direction2 = update->direction2;
  3309. speed = update->speed;
  3310. side_speed = update->side_speed;
  3311. x = update->x;
  3312. y = update->y;
  3313. z = update->z;
  3314. x_speed = update->speed_x;
  3315. y_speed = update->speed_y;
  3316. z_speed = update->speed_z;
  3317. appearance.pos.X2 = update->orig_x;
  3318. appearance.pos.Y2 = update->orig_y;
  3319. appearance.pos.Z2 = update->orig_z;
  3320. appearance.pos.X3 = update->orig_x2;
  3321. appearance.pos.Y3 = update->orig_y2;
  3322. appearance.pos.Z3 = update->orig_z2;
  3323. SetPitch(180 + update->pitch);
  3324. }
  3325. SetHeading((sint16)(direction1 * 64), (sint16)(direction2 * 64));
  3326. if (activity != last_movement_activity) {
  3327. switch(activity) {
  3328. case UPDATE_ACTIVITY_RUNNING:
  3329. case UPDATE_ACTIVITY_RUNNING_AOM:
  3330. case UPDATE_ACTIVITY_IN_WATER_ABOVE:
  3331. case UPDATE_ACTIVITY_IN_WATER_BELOW:
  3332. case UPDATE_ACTIVITY_MOVE_WATER_ABOVE_AOM:
  3333. case UPDATE_ACTIVITY_MOVE_WATER_BELOW_AOM: {
  3334. if(GetZone() && GetZone()->GetDrowningVictim(this))
  3335. GetZone()->RemoveDrowningVictim(this);
  3336. break;
  3337. }
  3338. case UPDATE_ACTIVITY_DROWNING:
  3339. case UPDATE_ACTIVITY_DROWNING2:
  3340. case UPDATE_ACTIVITY_DROWNING_AOM:
  3341. case UPDATE_ACTIVITY_DROWNING2_AOM: {
  3342. if(GetZone() && !GetInvulnerable()) {
  3343. GetZone()->AddDrowningVictim(this);
  3344. }
  3345. break;
  3346. }
  3347. case UPDATE_ACTIVITY_JUMPING:
  3348. case UPDATE_ACTIVITY_JUMPING_AOM:
  3349. case UPDATE_ACTIVITY_FALLING:
  3350. case UPDATE_ACTIVITY_FALLING_AOM: {
  3351. if(GetInitialState() != 1024) {
  3352. SetInitialState(1024);
  3353. }
  3354. else if(GetInitialState() == 1024) {
  3355. if(activity == UPDATE_ACTIVITY_JUMPING_AOM) {
  3356. SetInitialState(UPDATE_ACTIVITY_JUMPING_AOM);
  3357. }
  3358. else {
  3359. SetInitialState(16512);
  3360. }
  3361. }
  3362. break;
  3363. }
  3364. }
  3365. last_movement_activity = activity;
  3366. }
  3367. //Player is riding a lift, update lift XYZ offsets and the lift's spawn pointer
  3368. if (activity & UPDATE_ACTIVITY_RIDING_BOAT) {
  3369. Spawn* boat = 0;
  3370. float boat_x = x;
  3371. float boat_y = y;
  3372. float boat_z = z;
  3373. if (GetBoatSpawn() == 0 && GetZone()) {
  3374. boat = GetZone()->GetClosestTransportSpawn(GetX(), GetY(), GetZ());
  3375. SetBoatSpawn(boat);
  3376. if(boat)
  3377. {
  3378. LogWrite(PLAYER__DEBUG, 0, "Player", "Set Player %s (%u) on Boat: %s",
  3379. GetName(), GetCharacterID(), boat ? boat->GetName() : "notset");
  3380. boat->AddRailPassenger(GetCharacterID());
  3381. GetZone()->CallSpawnScript(boat, SPAWN_SCRIPT_BOARD, this);
  3382. }
  3383. }
  3384. if (boat || (GetBoatSpawn() && GetZone())) {
  3385. if (!boat)
  3386. boat = GetZone()->GetSpawnByID(GetBoatSpawn());
  3387. if (boat && boat->IsWidget() && ((Widget*)boat)->GetMultiFloorLift()) {
  3388. boat_x -= boat->GetX();
  3389. boat_y -= boat->GetY();
  3390. boat_z -= boat->GetZ();
  3391. //appearance.pos.grid_id = grid_id;
  3392. }
  3393. }
  3394. SetBoatX(boat_x);
  3395. SetBoatY(boat_y);
  3396. SetBoatZ(boat_z);
  3397. pos_packet_speed = speed;
  3398. grid_id = appearance.pos.grid_id;
  3399. }
  3400. else if (GetBoatSpawn() > 0 && !lift_cooldown.Enabled())
  3401. {
  3402. lift_cooldown.Start(100, true);
  3403. }
  3404. else if(lift_cooldown.Check())
  3405. {
  3406. if(GetBoatSpawn())
  3407. {
  3408. Spawn* boat = GetZone()->GetSpawnByID(GetBoatSpawn());
  3409. if(boat)
  3410. {
  3411. LogWrite(PLAYER__DEBUG, 0, "Player", "Remove Player %s (%u) from Boat: %s",
  3412. GetName(), GetCharacterID(), boat ? boat->GetName() : "notset");
  3413. boat->RemoveRailPassenger(GetCharacterID());
  3414. GetZone()->CallSpawnScript(boat, SPAWN_SCRIPT_DEBOARD, this);
  3415. }
  3416. }
  3417. SetBoatSpawn(0);
  3418. lift_cooldown.Disable();
  3419. }
  3420. if (!IsResurrecting() && !GetBoatSpawn())
  3421. {
  3422. if (!IsRooted() && !IsMezzedOrStunned()) {
  3423. SetX(x);
  3424. SetY(y);
  3425. SetZ(z);
  3426. SetSpeedX(x_speed);
  3427. SetSpeedY(y_speed);
  3428. SetSpeedZ(z_speed);
  3429. SetSideSpeed(side_speed);
  3430. pos_packet_speed = speed;
  3431. }
  3432. else {
  3433. SetSpeedX(0);
  3434. SetSpeedY(0);
  3435. SetSpeedZ(0);
  3436. SetSideSpeed(0);
  3437. pos_packet_speed = 0;
  3438. }
  3439. }
  3440. if (appearance.pos.grid_id != grid_id)
  3441. {
  3442. LogWrite(PLAYER__DEBUG, 0, "Player", "%s left grid %u and entered grid %u", appearance.name, appearance.pos.grid_id, grid_id);
  3443. const char* zone_script = world.GetZoneScript(GetZone()->GetZoneID());
  3444. if (zone_script && lua_interface)
  3445. {
  3446. lua_interface->RunZoneScript(zone_script, "enter_location", GetZone(), this, grid_id);
  3447. lua_interface->RunZoneScript(zone_script, "leave_location", GetZone(), this, appearance.pos.grid_id);
  3448. }
  3449. appearance.pos.grid_id = grid_id;
  3450. }
  3451. if (activity == UPDATE_ACTIVITY_IN_WATER_ABOVE || activity == UPDATE_ACTIVITY_IN_WATER_BELOW) {
  3452. if (MakeRandomFloat(0, 100) < 25 && InWater())
  3453. GetSkillByName("Swimming", true);
  3454. }
  3455. // don't have to uncomment the print packet but you MUST uncomment the safe_delete() for xml structs
  3456. //update->PrintPacket();
  3457. //safe_delete(update);
  3458. LogWrite(PLAYER__DEBUG, 7, "Player", "Exit: %s", __FUNCTION__); // trace
  3459. }
  3460. int16 Player::GetLastMovementActivity(){
  3461. return last_movement_activity;
  3462. }
  3463. void Player::AddSpawnInfoPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3464. spawn_info_packet_list[spawn_id] = string((char*)packet, packet_size);
  3465. }
  3466. void Player::AddSpawnPosPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3467. spawn_pos_packet_list[spawn_id] = string((char*)packet, packet_size);
  3468. }
  3469. uchar* Player::GetSpawnPosPacketForXOR(int32 spawn_id){
  3470. uchar* ret = 0;
  3471. if(spawn_pos_packet_list.count(spawn_id) == 1)
  3472. ret = (uchar*)spawn_pos_packet_list[spawn_id].c_str();
  3473. return ret;
  3474. }
  3475. uchar* Player::GetSpawnInfoPacketForXOR(int32 spawn_id){
  3476. uchar* ret = 0;
  3477. if(spawn_info_packet_list.count(spawn_id) == 1)
  3478. ret = (uchar*)spawn_info_packet_list[spawn_id].c_str();
  3479. return ret;
  3480. }
  3481. void Player::AddSpawnVisPacketForXOR(int32 spawn_id, uchar* packet, int16 packet_size){
  3482. spawn_vis_packet_list[spawn_id] = string((char*)packet, packet_size);
  3483. }
  3484. uchar* Player::GetSpawnVisPacketForXOR(int32 spawn_id){
  3485. uchar* ret = 0;
  3486. if(spawn_vis_packet_list.count(spawn_id) == 1)
  3487. ret = (uchar*)spawn_vis_packet_list[spawn_id].c_str();
  3488. return ret;
  3489. }
  3490. uchar* Player::GetTempInfoPacketForXOR(){
  3491. return spawn_tmp_info_xor_packet;
  3492. }
  3493. uchar* Player::GetTempVisPacketForXOR(){
  3494. return spawn_tmp_vis_xor_packet;
  3495. }
  3496. uchar* Player::GetTempPosPacketForXOR(){
  3497. return spawn_tmp_pos_xor_packet;
  3498. }
  3499. uchar* Player::SetTempInfoPacketForXOR(int16 size){
  3500. spawn_tmp_info_xor_packet = new uchar[size];
  3501. info_xor_size = size;
  3502. return spawn_tmp_info_xor_packet;
  3503. }
  3504. uchar* Player::SetTempVisPacketForXOR(int16 size){
  3505. spawn_tmp_vis_xor_packet = new uchar[size];
  3506. vis_xor_size = size;
  3507. return spawn_tmp_vis_xor_packet;
  3508. }
  3509. uchar* Player::SetTempPosPacketForXOR(int16 size){
  3510. spawn_tmp_pos_xor_packet = new uchar[size];
  3511. pos_xor_size = size;
  3512. return spawn_tmp_pos_xor_packet;
  3513. }
  3514. bool Player::CheckPlayerInfo(){
  3515. return info != 0;
  3516. }
  3517. bool Player::SetSpawnSentState(Spawn* spawn, SpawnState state) {
  3518. bool val = true;
  3519. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3520. int16 index = GetIndexForSpawn(spawn);
  3521. if(index > 0 && (state == SpawnState::SPAWN_STATE_SENDING)) {
  3522. LogWrite(PLAYER__WARNING, 0, "Player", "Spawn ALREADY INDEXED for Player %s (%u). Spawn %s (index %u) attempted to state %u.",
  3523. GetName(), GetCharacterID(), spawn->GetName(), index, state);
  3524. if(GetClient()->IsReloadingZone()) {
  3525. spawn_packet_sent.insert(make_pair(spawn->GetID(), state));
  3526. val = false;
  3527. }
  3528. // we don't do anything this spawn is already populated by the player
  3529. }
  3530. else {
  3531. LogWrite(PLAYER__DEBUG, 0, "Player", "Spawn for Player %s (%u). Spawn %s (index %u) in state %u.",
  3532. GetName(), GetCharacterID(), spawn->GetName(), index, state);
  3533. map<int32,int8>::iterator itr = spawn_packet_sent.find(spawn->GetID());
  3534. if(itr != spawn_packet_sent.end())
  3535. itr->second = state;
  3536. else
  3537. spawn_packet_sent.insert(make_pair(spawn->GetID(), state));
  3538. if(state == SPAWN_STATE_SENT_WAIT) {
  3539. map<int32,SpawnQueueState*>::iterator state_itr;
  3540. if((state_itr = spawn_state_list.find(spawn->GetID())) != spawn_state_list.end()) {
  3541. safe_delete(state_itr->second);
  3542. spawn_state_list.erase(state_itr);
  3543. }
  3544. SpawnQueueState* removal = new SpawnQueueState;
  3545. removal->index_id = index;
  3546. removal->spawn_state_timer = Timer(500, true);
  3547. removal->spawn_state_timer.Start();
  3548. spawn_state_list.insert(make_pair(spawn->GetID(),removal));
  3549. }
  3550. else if(state == SpawnState::SPAWN_STATE_REMOVING &&
  3551. spawn_state_list.count(spawn->GetID()) == 0) {
  3552. SpawnQueueState* removal = new SpawnQueueState;
  3553. removal->index_id = index;
  3554. removal->spawn_state_timer = Timer(1000, true);
  3555. removal->spawn_state_timer.Start();
  3556. spawn_state_list.insert(make_pair(spawn->GetID(),removal));
  3557. }
  3558. }
  3559. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3560. return val;
  3561. }
  3562. void Player::CheckSpawnStateQueue() {
  3563. if(!GetClient()->IsReadyForUpdates())
  3564. return;
  3565. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  3566. map<int32, SpawnQueueState*>::iterator itr;
  3567. for(itr = spawn_state_list.begin(); itr != spawn_state_list.end();) {
  3568. if(itr->second->spawn_state_timer.Check()) {
  3569. map<int32, int8>::iterator sent_itr = spawn_packet_sent.find(itr->first);
  3570. LogWrite(PLAYER__DEBUG, 0, "Player", "Spawn for Player %s (%u). Spawn index %u in state %u.",
  3571. GetName(), GetCharacterID(), itr->second->index_id, sent_itr->second);
  3572. switch(sent_itr->second) {
  3573. case SpawnState::SPAWN_STATE_SENT_WAIT: {
  3574. sent_itr->second = SpawnState::SPAWN_STATE_SENT;
  3575. SpawnQueueState* sr = itr->second;
  3576. itr = spawn_state_list.erase(itr);
  3577. safe_delete(sr);
  3578. break;
  3579. }
  3580. case SpawnState::SPAWN_STATE_REMOVING: {
  3581. if(itr->first == GetID() && GetClient()->IsReloadingZone()) {
  3582. itr->second->spawn_state_timer.Disable();
  3583. continue;
  3584. }
  3585. if(itr->second->index_id) {
  3586. PacketStruct* packet = packet = configReader.getStruct("WS_DestroyGhostCmd", GetClient()->GetVersion());
  3587. packet->setDataByName("spawn_index", itr->second->index_id);
  3588. packet->setDataByName("delete", 1);
  3589. GetClient()->QueuePacket(packet->serialize());
  3590. safe_delete(packet);
  3591. }
  3592. sent_itr->second = SpawnState::SPAWN_STATE_REMOVING_SLEEP;
  3593. itr++;
  3594. break;
  3595. }
  3596. case SpawnState::SPAWN_STATE_REMOVING_SLEEP: {
  3597. map<int32, int8>::iterator sent_itr = spawn_packet_sent.find(itr->first);
  3598. sent_itr->second = SpawnState::SPAWN_STATE_REMOVED;
  3599. SpawnQueueState* sr = itr->second;
  3600. itr = spawn_state_list.erase(itr);
  3601. safe_delete(sr);
  3602. break;
  3603. }
  3604. default: {
  3605. // reset
  3606. itr->second->spawn_state_timer.Disable();
  3607. break;
  3608. }
  3609. }
  3610. }
  3611. else
  3612. itr++;
  3613. }
  3614. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  3615. }
  3616. bool Player::WasSentSpawn(int32 spawn_id){
  3617. if(GetID() == spawn_id)
  3618. return true;
  3619. bool ret = false;
  3620. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3621. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3622. if(itr != spawn_packet_sent.end() && itr->second == SpawnState::SPAWN_STATE_SENT) {
  3623. ret = true;
  3624. }
  3625. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3626. return ret;
  3627. }
  3628. bool Player::IsSendingSpawn(int32 spawn_id){
  3629. bool ret = false;
  3630. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3631. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3632. if(itr != spawn_packet_sent.end() && (itr->second == SpawnState::SPAWN_STATE_SENDING || itr->second == SPAWN_STATE_SENT_WAIT)) {
  3633. ret = true;
  3634. }
  3635. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3636. return ret;
  3637. }
  3638. bool Player::IsRemovingSpawn(int32 spawn_id){
  3639. bool ret = false;
  3640. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  3641. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  3642. if(itr != spawn_packet_sent.end() &&
  3643. (itr->second == SpawnState::SPAWN_STATE_REMOVING || itr->second == SpawnState::SPAWN_STATE_REMOVING_SLEEP)) {
  3644. ret = true;
  3645. }
  3646. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  3647. return ret;
  3648. }
  3649. PlayerSkillList* Player::GetSkills(){
  3650. return &skill_list;
  3651. }
  3652. void Player::InCombat(bool val, bool range) {
  3653. if (val)
  3654. GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() | (1 << (range?CF_RANGED_AUTO_ATTACK:CF_AUTO_ATTACK)));
  3655. else
  3656. GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() & ~(1 << (range?CF_RANGED_AUTO_ATTACK:CF_AUTO_ATTACK)));
  3657. bool changeCombatState = false;
  3658. if((in_combat && !val) || (!in_combat && val))
  3659. changeCombatState = true;
  3660. in_combat = val;
  3661. if(in_combat)
  3662. AddIconValue(64);
  3663. else
  3664. RemoveIconValue(64);
  3665. if(changeCombatState)
  3666. SetRegenValues(GetInfoStruct()->get_effective_level());
  3667. charsheet_changed = true;
  3668. info_changed = true;
  3669. }
  3670. void Player::SetCharSheetChanged(bool val){
  3671. charsheet_changed = val;
  3672. }
  3673. bool Player::GetCharSheetChanged(){
  3674. return charsheet_changed;
  3675. }
  3676. bool Player::AdventureXPEnabled(){
  3677. return (GetInfoStruct()->get_flags() & (1 << CF_COMBAT_EXPERIENCE_ENABLED));
  3678. }
  3679. bool Player::TradeskillXPEnabled() {
  3680. // TODO: need to identify the flag to togle tradeskill xp
  3681. return true;
  3682. }
  3683. void Player::set_character_flag(int flag){
  3684. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3685. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3686. if (flag > CF_MAXIMUM_FLAG) return;
  3687. if (flag < 32) GetInfoStruct()->set_flags(GetInfoStruct()->get_flags() | (1 << flag));
  3688. else GetInfoStruct()->set_flags2(GetInfoStruct()->get_flags2() | (1 << (flag - 32)));
  3689. charsheet_changed = true;
  3690. info_changed = true;
  3691. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3692. }
  3693. void Player::reset_character_flag(int flag){
  3694. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3695. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3696. if (flag > CF_MAXIMUM_FLAG) return;
  3697. if (flag < 32)
  3698. {
  3699. int8 origflag = GetInfoStruct()->get_flags();
  3700. GetInfoStruct()->set_flags(origflag &= ~(1 << flag));
  3701. }
  3702. else
  3703. {
  3704. int8 flag2 = GetInfoStruct()->get_flags2();
  3705. GetInfoStruct()->set_flags2(flag2 &= ~(1 << (flag - 32)));
  3706. }
  3707. charsheet_changed = true;
  3708. info_changed = true;
  3709. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3710. }
  3711. void Player::toggle_character_flag(int flag){
  3712. LogWrite(PLAYER__DEBUG, 0, "Player", "Flag: %u", flag);
  3713. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags before: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3714. if (flag > CF_MAXIMUM_FLAG) return;
  3715. if (flag < 32)
  3716. {
  3717. int32 origflag = GetInfoStruct()->get_flags();
  3718. GetInfoStruct()->set_flags(origflag ^= (1 << flag));
  3719. }
  3720. else
  3721. {
  3722. int32 flag2 = GetInfoStruct()->get_flags2();
  3723. GetInfoStruct()->set_flags2(flag2 ^= (1 << (flag - 32)));
  3724. }
  3725. charsheet_changed = true;
  3726. info_changed = true;
  3727. LogWrite(PLAYER__DEBUG, 0, "Player", "Flags after: %u, Flags2: %u", GetInfoStruct()->get_flags(), GetInfoStruct()->get_flags2());
  3728. }
  3729. bool Player::get_character_flag(int flag){
  3730. bool ret = false;
  3731. if (flag > CF_MAXIMUM_FLAG){
  3732. LogWrite(PLAYER__DEBUG, 0, "Player", "Player::get_character_flag error: attempted to check flag %i", flag);
  3733. return ret;
  3734. }
  3735. if (flag < 32) ret = ((GetInfoStruct()->get_flags()) >> flag & 1);
  3736. else ret = ((GetInfoStruct()->get_flags2()) >> (flag - 32) & 1);
  3737. return ret;
  3738. }
  3739. float Player::GetXPVitality(){
  3740. return GetInfoStruct()->get_xp_vitality();
  3741. }
  3742. float Player::GetTSXPVitality() {
  3743. return GetInfoStruct()->get_tradeskill_xp_vitality();
  3744. }
  3745. bool Player::DoubleXPEnabled(){
  3746. return GetInfoStruct()->get_xp_vitality() > 0;
  3747. }
  3748. void Player::SetCharacterID(int32 new_id){
  3749. char_id = new_id;
  3750. }
  3751. int32 Player::GetCharacterID(){
  3752. return char_id;
  3753. }
  3754. float Player::CalculateXP(Spawn* victim){
  3755. if(AdventureXPEnabled() == false || !victim)
  3756. return 0;
  3757. float multiplier = 0;
  3758. float zone_xp_modifier = 1; // let's be safe!!
  3759. if( GetZone()->GetXPModifier() != 0 ) {
  3760. zone_xp_modifier = GetZone()->GetXPModifier();
  3761. LogWrite(PLAYER__DEBUG, 5, "XP", "Zone XP Modifier = %.2f", zone_xp_modifier);
  3762. }
  3763. switch(GetArrowColor(victim->GetLevel())){
  3764. case ARROW_COLOR_GRAY:
  3765. LogWrite(PLAYER__DEBUG, 5, "XP", "Gray Arrow = No XP");
  3766. return 0.0f;
  3767. break;
  3768. case ARROW_COLOR_GREEN:
  3769. multiplier = 3.25;
  3770. LogWrite(PLAYER__DEBUG, 5, "XP", "Green Arrow Multiplier = %.2f", multiplier);
  3771. break;
  3772. case ARROW_COLOR_BLUE:
  3773. multiplier = 3.5;
  3774. LogWrite(PLAYER__DEBUG, 5, "XP", "Blue Arrow Multiplier = %.2f", multiplier);
  3775. break;
  3776. case ARROW_COLOR_WHITE:
  3777. multiplier = 4;
  3778. LogWrite(PLAYER__DEBUG, 5, "XP", "White Arrow Multiplier = %.2f", multiplier);
  3779. break;
  3780. case ARROW_COLOR_YELLOW:
  3781. multiplier = 4.25;
  3782. LogWrite(PLAYER__DEBUG, 5, "XP", "Yellow Arrow Multiplier = %.2f", multiplier);
  3783. break;
  3784. case ARROW_COLOR_ORANGE:
  3785. multiplier = 4.5;
  3786. LogWrite(PLAYER__DEBUG, 5, "XP", "Orange Arrow Multiplier = %.2f", multiplier);
  3787. break;
  3788. case ARROW_COLOR_RED:
  3789. multiplier = 6;
  3790. LogWrite(PLAYER__DEBUG, 5, "XP", "Red Arrow Multiplier = %.2f", multiplier);
  3791. break;
  3792. }
  3793. float total = multiplier * 8;
  3794. LogWrite(PLAYER__DEBUG, 5, "XP", "Multiplier * 8 = %.2f", total);
  3795. if(victim->GetEncounterLevel() > 6) { // no need to multiply by 1 if this is a normal mob
  3796. total *= (victim->GetEncounterLevel() - 5);
  3797. LogWrite(PLAYER__DEBUG, 5, "XP", "Encounter > 6, total = %.2f", total);
  3798. }
  3799. else if(victim->GetEncounterLevel() <= 5) {
  3800. total /= (7 - victim->GetEncounterLevel()); //1 down mobs are worth half credit, 2 down worth .25, etc
  3801. LogWrite(PLAYER__DEBUG, 5, "XP", "Encounter <= 5, total = %.2f", total);
  3802. }
  3803. if(victim->GetHeroic() > 1) {
  3804. total *= victim->GetHeroic();
  3805. LogWrite(PLAYER__DEBUG, 5, "XP", "Heroic, total = %.2f", total);
  3806. }
  3807. if(DoubleXPEnabled()) {
  3808. LogWrite(PLAYER__DEBUG, 5, "XP", "Calculating Double XP!");
  3809. float percent = (((float)(total))/GetNeededXP()) *100;
  3810. LogWrite(PLAYER__DEBUG, 5, "XP", "Percent of total / XP Needed * 100, percent = %.2f", percent);
  3811. float xp_vitality = GetXPVitality();
  3812. if(xp_vitality >= percent) {
  3813. GetInfoStruct()->set_xp_vitality(xp_vitality - percent);
  3814. total *= 2;
  3815. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality >= Percent, total = %.2f", total);
  3816. }
  3817. else {
  3818. total += ((GetXPVitality() / percent) *2)*total;
  3819. GetInfoStruct()->set_xp_vitality(0);
  3820. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality < Percent, total = %.2f", total);
  3821. }
  3822. }
  3823. LogWrite(PLAYER__DEBUG, 5, "XP", "Final total = %.2f", (total * world.GetXPRate() * zone_xp_modifier));
  3824. return total * world.GetXPRate() * zone_xp_modifier;
  3825. }
  3826. float Player::CalculateTSXP(int8 level){
  3827. if(TradeskillXPEnabled() == false)
  3828. return 0;
  3829. float multiplier = 0;
  3830. float zone_xp_modifier = 1; // let's be safe!!
  3831. if( GetZone()->GetXPModifier() != 0 ) {
  3832. zone_xp_modifier = GetZone()->GetXPModifier();
  3833. LogWrite(PLAYER__DEBUG, 5, "XP", "Zone XP Modifier = %.2f", zone_xp_modifier);
  3834. }
  3835. sint16 diff = level - GetTSLevel();
  3836. if(GetTSLevel() < 10)
  3837. diff *= 3;
  3838. else if(GetTSLevel() <= 20)
  3839. diff *= 2;
  3840. if(diff >= 9)
  3841. multiplier = 6;
  3842. else if(diff >= 5)
  3843. multiplier = 4.5;
  3844. else if(diff >= 1)
  3845. multiplier = 4.25;
  3846. else if(diff == 0)
  3847. multiplier = 4;
  3848. else if(diff <= -11)
  3849. multiplier = 0;
  3850. else if(diff <= -6)
  3851. multiplier = 3.25;
  3852. else //if(diff < 0)
  3853. multiplier = 3.5;
  3854. float total = multiplier * 8;
  3855. LogWrite(PLAYER__DEBUG, 5, "XP", "Multiplier * 8 = %.2f", total);
  3856. if(DoubleXPEnabled()) {
  3857. LogWrite(PLAYER__DEBUG, 5, "XP", "Calculating Double XP!");
  3858. float percent = (((float)(total))/GetNeededTSXP()) *100;
  3859. LogWrite(PLAYER__DEBUG, 5, "XP", "Percent of total / XP Needed * 100, percent = %.2f", percent);
  3860. float ts_xp_vitality = GetTSXPVitality();
  3861. if(ts_xp_vitality >= percent) {
  3862. GetInfoStruct()->set_tradeskill_xp_vitality(ts_xp_vitality - percent);
  3863. total *= 2;
  3864. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality >= Percent, total = %.2f", total);
  3865. }
  3866. else {
  3867. total += ((GetTSXPVitality() / percent) *2)*total;
  3868. GetInfoStruct()->set_tradeskill_xp_vitality(0);
  3869. LogWrite(PLAYER__DEBUG, 5, "XP", "Vitality < Percent, total = %.2f", total);
  3870. }
  3871. }
  3872. LogWrite(PLAYER__DEBUG, 5, "XP", "Final total = %.2f", (total * world.GetXPRate() * zone_xp_modifier));
  3873. return total * world.GetXPRate() * zone_xp_modifier;
  3874. }
  3875. void Player::CalculateOfflineDebtRecovery(int32 unix_timestamp)
  3876. {
  3877. float xpDebt = GetXPDebt();
  3878. // not a real timestamp to work with
  3879. if(unix_timestamp < 1 || xpDebt == 0.0f)
  3880. return;
  3881. uint32 diff = (Timer::GetCurrentTime2() - unix_timestamp)/1000;
  3882. float recoveryDebtPercentage = rule_manager.GetGlobalRule(R_Combat, ExperienceDebtRecoveryPercent)->GetFloat()/100.0f;
  3883. int32 recoveryPeriodSeconds = rule_manager.GetGlobalRule(R_Combat, ExperienceDebtRecoveryPeriod)->GetInt32();
  3884. if(recoveryDebtPercentage == 0.0f || recoveryPeriodSeconds < 1)
  3885. return;
  3886. float periodsPassed = (float)diff/(float)recoveryPeriodSeconds;
  3887. // not enough time passed to calculate debt xp recovered
  3888. if(periodsPassed < 1.0f)
  3889. return;
  3890. float debtToSubtract = xpDebt * ((recoveryDebtPercentage*periodsPassed)/100.0f);
  3891. if(debtToSubtract >= xpDebt)
  3892. GetInfoStruct()->set_xp_debt(0.0f);
  3893. else
  3894. GetInfoStruct()->set_xp_debt(xpDebt - debtToSubtract);
  3895. }
  3896. void Player::SetNeededXP(int32 val){
  3897. GetInfoStruct()->set_xp_needed(val);
  3898. }
  3899. void Player::SetNeededXP(){
  3900. //GetInfoStruct()->xp_needed = GetLevel() * 100;
  3901. // Get xp needed to get to the next level
  3902. int16 level = GetLevel() + 1;
  3903. // 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
  3904. if (level > 95)
  3905. SetNeededXP(m_levelXPReq[95] * ((level - 95) + 1));
  3906. else
  3907. SetNeededXP(m_levelXPReq[level]);
  3908. }
  3909. void Player::SetXP(int32 val){
  3910. GetInfoStruct()->set_xp(val);
  3911. }
  3912. void Player::SetNeededTSXP(int32 val) {
  3913. GetInfoStruct()->set_ts_xp_needed(val);
  3914. }
  3915. void Player::SetNeededTSXP() {
  3916. GetInfoStruct()->set_ts_xp_needed(GetTSLevel() * 100);
  3917. }
  3918. void Player::SetTSXP(int32 val) {
  3919. GetInfoStruct()->set_ts_xp(val);
  3920. }
  3921. float Player::GetXPDebt(){
  3922. return GetInfoStruct()->get_xp_debt();
  3923. }
  3924. int32 Player::GetNeededXP(){
  3925. return GetInfoStruct()->get_xp_needed();
  3926. }
  3927. int32 Player::GetXP(){
  3928. return GetInfoStruct()->get_xp();
  3929. }
  3930. int32 Player::GetNeededTSXP() {
  3931. return GetInfoStruct()->get_ts_xp_needed();
  3932. }
  3933. int32 Player::GetTSXP() {
  3934. return GetInfoStruct()->get_ts_xp();
  3935. }
  3936. bool Player::AddXP(int32 xp_amount){
  3937. MStats.lock();
  3938. xp_amount += (int32)(((float)xp_amount) * stats[ITEM_STAT_COMBATEXPMOD]) / 100;
  3939. MStats.unlock();
  3940. if(GetInfoStruct()->get_xp_debt())
  3941. {
  3942. float expRatioToDebt = rule_manager.GetGlobalRule(R_Combat, ExperienceToDebt)->GetFloat()/100.0f;
  3943. int32 amountToTakeFromDebt = (int32)((float)expRatioToDebt * (float)xp_amount);
  3944. int32 amountRequiredClearDebt = (GetInfoStruct()->get_xp_debt()/100.0f) * xp_amount;
  3945. if(amountToTakeFromDebt > amountRequiredClearDebt)
  3946. {
  3947. GetInfoStruct()->set_xp_debt(0.0f);
  3948. if(amountRequiredClearDebt > xp_amount)
  3949. xp_amount = 0;
  3950. else
  3951. xp_amount -= amountRequiredClearDebt;
  3952. }
  3953. else
  3954. {
  3955. float amountRemovedPct = ((float)amountToTakeFromDebt/(float)amountRequiredClearDebt);
  3956. GetInfoStruct()->set_xp_debt(GetInfoStruct()->get_xp_debt()-amountRemovedPct);
  3957. if(amountToTakeFromDebt > xp_amount)
  3958. xp_amount = 0;
  3959. else
  3960. xp_amount -= amountToTakeFromDebt;
  3961. }
  3962. }
  3963. // used up in xp debt
  3964. if(!xp_amount)
  3965. return true;
  3966. float current_xp_percent = ((float)GetXP()/(float)GetNeededXP())*100;
  3967. float miniding_min_percent = ((int)(current_xp_percent/10)+1)*10;
  3968. while((xp_amount + GetXP()) >= GetNeededXP()){
  3969. if (!CheckLevelStatus(GetLevel() + 1)) {
  3970. GetZone()->GetClientBySpawn(this)->SimpleMessage(CHANNEL_COLOR_RED, "You do not have the required status to level up anymore!");
  3971. return false;
  3972. }
  3973. xp_amount -= GetNeededXP() - GetXP();
  3974. SetLevel(GetLevel() + 1);
  3975. }
  3976. SetXP(GetXP() + xp_amount);
  3977. GetPlayerInfo()->CalculateXPPercentages();
  3978. current_xp_percent = ((float)GetXP()/(float)GetNeededXP())*100;
  3979. if(current_xp_percent >= miniding_min_percent){
  3980. SetHP(GetTotalHP());
  3981. SetPower(GetTotalPower());
  3982. GetZone()->SendCastSpellPacket(332, this, this); //send mini level up spell effect
  3983. }
  3984. return true;
  3985. }
  3986. bool Player::AddTSXP(int32 xp_amount){
  3987. MStats.lock();
  3988. xp_amount += ((xp_amount)*stats[ITEM_STAT_TRADESKILLEXPMOD]) / 100;
  3989. MStats.unlock();
  3990. float current_xp_percent = ((float)GetTSXP()/(float)GetNeededTSXP())*100;
  3991. float miniding_min_percent = ((int)(current_xp_percent/10)+1)*10;
  3992. while((xp_amount + GetTSXP()) >= GetNeededTSXP()){
  3993. if (!CheckLevelStatus(GetTSLevel() + 1)) {
  3994. GetZone()->GetClientBySpawn(this)->SimpleMessage(CHANNEL_COLOR_RED, "You do not have the required status to level up anymore!");
  3995. return false;
  3996. }
  3997. xp_amount -= GetNeededTSXP() - GetTSXP();
  3998. SetTSLevel(GetTSLevel() + 1);
  3999. SetTSXP(0);
  4000. SetNeededTSXP();
  4001. }
  4002. SetTSXP(GetTSXP() + xp_amount);
  4003. GetPlayerInfo()->CalculateXPPercentages();
  4004. current_xp_percent = ((float)GetTSXP()/(float)GetNeededTSXP())*100;
  4005. if(current_xp_percent >= miniding_min_percent){
  4006. SetHP(GetTotalHP());
  4007. SetPower(GetTotalPower());
  4008. }
  4009. if (GetTradeskillClass() == 0){
  4010. SetTradeskillClass(1);
  4011. GetInfoStruct()->set_tradeskill_class1(1);
  4012. GetInfoStruct()->set_tradeskill_class2(1);
  4013. GetInfoStruct()->set_tradeskill_class3(1);
  4014. }
  4015. return true;
  4016. }
  4017. void Player::CalculateLocation(){
  4018. if(GetSpeed() > 0 ){
  4019. if(GetHeading() >= 270 && GetHeading() <= 360){
  4020. SetX(GetX() + (GetSpeed()*.5)*((360-GetHeading())/90));
  4021. SetZ(GetZ() - (GetSpeed()*.5)*((GetHeading()-270)/90));
  4022. }
  4023. else if(GetHeading() >= 180 && GetHeading() < 270){
  4024. SetX(GetX() + (GetSpeed()*.5)*((GetHeading()-180)/90));
  4025. SetZ(GetZ() + (GetSpeed()*.5)*((270-GetHeading())/90));
  4026. }
  4027. else if(GetHeading() >= 90 && GetHeading() < 180){
  4028. SetX(GetX() - (GetSpeed()*.5)*((180-GetHeading())/90));
  4029. SetZ(GetZ() + (GetSpeed()*.5)*((GetHeading()-90)/90));
  4030. }
  4031. else if(GetHeading() >= 0 && GetHeading() < 90){
  4032. SetX(GetX() - (GetSpeed()*.5)*(GetHeading()/90));
  4033. SetZ(GetZ() - (GetSpeed()*.5)*((90-GetHeading())/90));
  4034. }
  4035. }
  4036. }
  4037. Spawn* Player::GetSpawnByIndex(int16 index){
  4038. Spawn* spawn = 0;
  4039. index_mutex.readlock(__FUNCTION__, __LINE__);
  4040. if(player_spawn_id_map.count(index) > 0)
  4041. spawn = player_spawn_id_map[index];
  4042. index_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4043. return spawn;
  4044. }
  4045. int16 Player::GetIndexForSpawn(Spawn* spawn) {
  4046. int16 val = 0;
  4047. index_mutex.readlock(__FUNCTION__, __LINE__);
  4048. if(player_spawn_reverse_id_map.count(spawn) > 0)
  4049. val = player_spawn_reverse_id_map[spawn];
  4050. index_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4051. return val;
  4052. }
  4053. bool Player::WasSpawnRemoved(Spawn* spawn){
  4054. bool wasRemoved = false;
  4055. if(IsRemovingSpawn(spawn->GetID()))
  4056. return false;
  4057. spawn_mutex.readlock(__FUNCTION__, __LINE__);
  4058. map<int32, int8>::iterator itr = spawn_packet_sent.find(spawn_id);
  4059. if(itr != spawn_packet_sent.end() && itr->second == SpawnState::SPAWN_STATE_REMOVED) {
  4060. wasRemoved = true;
  4061. }
  4062. spawn_mutex.releasereadlock(__FUNCTION__, __LINE__);
  4063. return wasRemoved;
  4064. }
  4065. void Player::RemoveSpawn(Spawn* spawn)
  4066. {
  4067. LogWrite(PLAYER__DEBUG, 3, "Player", "Remove Spawn '%s' (%u)", spawn->GetName(), spawn->GetID());
  4068. SetSpawnSentState(spawn, SpawnState::SPAWN_STATE_REMOVING);
  4069. info_mutex.writelock(__FUNCTION__, __LINE__);
  4070. vis_mutex.writelock(__FUNCTION__, __LINE__);
  4071. pos_mutex.writelock(__FUNCTION__, __LINE__);
  4072. index_mutex.writelock(__FUNCTION__, __LINE__);
  4073. if (player_spawn_reverse_id_map[spawn] && player_spawn_id_map.count(player_spawn_reverse_id_map[spawn]) > 0)
  4074. player_spawn_id_map.erase(player_spawn_reverse_id_map[spawn]);
  4075. if (player_spawn_reverse_id_map.count(spawn) > 0)
  4076. player_spawn_reverse_id_map.erase(spawn);
  4077. if (player_spawn_id_map.count(spawn->GetID()) && player_spawn_id_map[spawn->GetID()] == spawn)
  4078. player_spawn_id_map.erase(spawn->GetID());
  4079. int32 id = spawn->GetID();
  4080. if (spawn_info_packet_list.count(id))
  4081. spawn_info_packet_list.erase(id);
  4082. if (spawn_pos_packet_list.count(id))
  4083. spawn_pos_packet_list.erase(id);
  4084. if (spawn_vis_packet_list.count(id))
  4085. spawn_vis_packet_list.erase(id);
  4086. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4087. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4088. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4089. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  4090. }
  4091. vector<int32> Player::GetQuestIDs(){
  4092. vector<int32> ret;
  4093. map<int32, Quest*>::iterator itr;
  4094. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4095. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4096. if(itr->second)
  4097. ret.push_back(itr->second->GetQuestID());
  4098. }
  4099. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4100. return ret;
  4101. }
  4102. vector<Quest*>* Player::CheckQuestsItemUpdate(Item* item){
  4103. vector<Quest*>* quest_updates = 0;
  4104. map<int32, Quest*>::iterator itr;
  4105. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4106. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4107. if(itr->second && itr->second->CheckQuestItemUpdate(item->details.item_id, item->details.count)){
  4108. if(!quest_updates)
  4109. quest_updates = new vector<Quest*>();
  4110. quest_updates->push_back(itr->second);
  4111. }
  4112. }
  4113. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4114. return quest_updates;
  4115. }
  4116. void Player::CheckQuestsCraftUpdate(Item* item, int32 qty){
  4117. map<int32, Quest*>::iterator itr;
  4118. vector<Quest*>* update_list = new vector<Quest*>;
  4119. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4120. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4121. if(itr->second){
  4122. if(item && qty > 0){
  4123. if(itr->second->CheckQuestRefIDUpdate(item->details.item_id, qty)){
  4124. update_list->push_back(itr->second);
  4125. }
  4126. }
  4127. }
  4128. }
  4129. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4130. if(update_list && update_list->size() > 0){
  4131. Client* client = GetZone()->GetClientBySpawn(this);
  4132. if(client){
  4133. for(int8 i=0;i<update_list->size(); i++){
  4134. client->SendQuestUpdate(update_list->at(i));
  4135. client->SendQuestFailure(update_list->at(i));
  4136. }
  4137. }
  4138. }
  4139. update_list->clear();
  4140. safe_delete(update_list);
  4141. }
  4142. void Player::CheckQuestsHarvestUpdate(Item* item, int32 qty){
  4143. map<int32, Quest*>::iterator itr;
  4144. vector<Quest*>* update_list = new vector<Quest*>;
  4145. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4146. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4147. if(itr->second){
  4148. if(item && qty > 0){
  4149. if(itr->second->CheckQuestRefIDUpdate(item->details.item_id, qty)){
  4150. update_list->push_back(itr->second);
  4151. }
  4152. }
  4153. }
  4154. }
  4155. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4156. if(update_list && update_list->size() > 0){
  4157. Client* client = GetZone()->GetClientBySpawn(this);
  4158. if(client){
  4159. for(int8 i=0;i<update_list->size(); i++){
  4160. client->SendQuestUpdate(update_list->at(i));
  4161. client->SendQuestFailure(update_list->at(i));
  4162. }
  4163. }
  4164. }
  4165. update_list->clear();
  4166. safe_delete(update_list);
  4167. }
  4168. vector<Quest*>* Player::CheckQuestsSpellUpdate(Spell* spell) {
  4169. vector<Quest*>* quest_updates = 0;
  4170. map<int32, Quest*>::iterator itr;
  4171. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4172. for (itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4173. if (itr->second && itr->second->CheckQuestSpellUpdate(spell)) {
  4174. if (!quest_updates)
  4175. quest_updates = new vector<Quest*>();
  4176. quest_updates->push_back(itr->second);
  4177. }
  4178. }
  4179. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4180. return quest_updates;
  4181. }
  4182. PacketStruct* Player::GetQuestJournalPacket(bool all_quests, int16 version, int32 crc, int32 current_quest_id, bool updated){
  4183. PacketStruct* packet = configReader.getStruct("WS_QuestJournalUpdate", version);
  4184. Quest* quest = 0;
  4185. if(packet){
  4186. int16 total_quests_num = 0;
  4187. int16 total_completed_quests = 0;
  4188. map<int32, Quest*> total_quests = player_quests;
  4189. if(all_quests && completed_quests.size() > 0)
  4190. total_quests.insert(completed_quests.begin(), completed_quests.end());
  4191. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4192. if(total_quests.size() > 0){
  4193. map<string, int16> quest_types;
  4194. map<int32, Quest*>::iterator itr;
  4195. int16 zone_id = 0;
  4196. for(itr = total_quests.begin(); itr != total_quests.end(); itr++){
  4197. if(itr->first && itr->second){
  4198. if(current_quest_id == 0 && itr->second->GetTurnedIn() == false)
  4199. current_quest_id = itr->first;
  4200. if(itr->second->GetTurnedIn())
  4201. total_completed_quests++;
  4202. if(itr->second->GetType()){
  4203. if(quest_types.count(itr->second->GetType()) == 0){
  4204. quest_types[itr->second->GetType()] = zone_id;
  4205. zone_id++;
  4206. }
  4207. }
  4208. if(itr->second->GetZone()){
  4209. if(quest_types.count(itr->second->GetType()) == 0){
  4210. quest_types[itr->second->GetType()] = zone_id;
  4211. zone_id++;
  4212. }
  4213. }
  4214. total_quests_num++;
  4215. }
  4216. else
  4217. continue;
  4218. }
  4219. packet->setArrayLengthByName("num_quests", total_quests_num);
  4220. int16 i = 0;
  4221. for(itr = total_quests.begin(); itr != total_quests.end(); itr++){
  4222. if(i == 0 && quest_types.size() > 0){
  4223. packet->setArrayLengthByName("num_quest_zones", quest_types.size());
  4224. map<string, int16>::iterator type_itr;
  4225. int16 x = 0;
  4226. for(type_itr = quest_types.begin(); type_itr != quest_types.end(); type_itr++){
  4227. packet->setArrayDataByName("quest_zones_zone", type_itr->first.c_str(), x);
  4228. packet->setArrayDataByName("quest_zones_zone_id", type_itr->second, x);
  4229. x++;
  4230. }
  4231. }
  4232. if(itr->first == 0 || !itr->second)
  4233. continue;
  4234. if(!all_quests && !itr->second->GetUpdateRequired())
  4235. continue;
  4236. quest = itr->second;
  4237. if(!quest->GetDeleted())
  4238. packet->setArrayDataByName("active", 1, i);
  4239. packet->setArrayDataByName("name", quest->GetName(), i);
  4240. packet->setArrayDataByName("quest_type", quest->GetType(), i);
  4241. packet->setArrayDataByName("quest_zone", quest->GetZone(), i);
  4242. int8 display_status = QUEST_DISPLAY_STATUS_NORMAL;
  4243. if(itr->second->GetCompleted())
  4244. packet->setArrayDataByName("completed", 1, i);
  4245. if(itr->second->GetTurnedIn()){
  4246. packet->setArrayDataByName("turned_in", 1, i);
  4247. packet->setArrayDataByName("completed", 1, i);
  4248. packet->setArrayDataByName("visible", 1, i);
  4249. packet->setArrayDataByName("unknown3", 1, i);
  4250. display_status += QUEST_DISPLAY_STATUS_COMPLETED;
  4251. }
  4252. if (updated) {
  4253. packet->setArrayDataByName("quest_updated", 1, i);
  4254. packet->setArrayDataByName("journal_updated", 1, i);
  4255. }
  4256. packet->setArrayDataByName("quest_id", quest->GetQuestID(), i);
  4257. packet->setArrayDataByName("day", quest->GetDay(), i);
  4258. packet->setArrayDataByName("month", quest->GetMonth(), i);
  4259. packet->setArrayDataByName("year", quest->GetYear(), i);
  4260. packet->setArrayDataByName("level", quest->GetQuestLevel(), i);
  4261. int8 difficulty = 0;
  4262. string category = quest->GetType();
  4263. if(category == "Tradeskill")
  4264. difficulty = GetTSArrowColor(quest->GetQuestLevel());
  4265. else
  4266. difficulty = GetArrowColor(quest->GetQuestLevel());
  4267. packet->setArrayDataByName("difficulty", difficulty, i);
  4268. if (itr->second->GetEncounterLevel() > 4)
  4269. packet->setArrayDataByName("encounter_level", quest->GetEncounterLevel(), i);
  4270. else
  4271. packet->setArrayDataByName("encounter_level", 4, i);
  4272. if(version >= 931 && quest_types.count(quest->GetType()) > 0)
  4273. packet->setArrayDataByName("zonetype_id", quest_types[quest->GetType()], i);
  4274. if(version >= 931 && quest_types.count(quest->GetZone()) > 0)
  4275. packet->setArrayDataByName("zone_id", quest_types[quest->GetZone()], i);
  4276. if(version >= 931 && quest->GetVisible()){
  4277. if (quest->GetCompletedFlag())
  4278. display_status += QUEST_DISPLAY_STATUS_COMPLETE_FLAG;
  4279. else if (quest->IsRepeatable())
  4280. display_status += QUEST_DISPLAY_STATUS_REPEATABLE;
  4281. if (quest->GetYellowName() || quest->CheckCategoryYellow())
  4282. display_status += QUEST_DISPLAY_STATUS_YELLOW;
  4283. if (quest->IsTracked())
  4284. display_status += QUEST_DISPLAY_STATUS_CHECK;
  4285. else
  4286. display_status += QUEST_DISPLAY_STATUS_NO_CHECK;
  4287. if (quest->IsHidden() && !quest->GetTurnedIn())
  4288. display_status = QUEST_DISPLAY_STATUS_HIDDEN;
  4289. }
  4290. else
  4291. packet->setArrayDataByName("visible", quest->GetVisible(), i);
  4292. if (itr->second->IsRepeatable())
  4293. packet->setArrayDataByName("repeatable", 1, i);
  4294. packet->setArrayDataByName("display_status", display_status, i);
  4295. i++;
  4296. }
  4297. //packet->setDataByName("unknown4", 0);
  4298. packet->setDataByName("visible_quest_id", current_quest_id);
  4299. }
  4300. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4301. packet->setDataByName("player_crc", crc);
  4302. packet->setDataByName("player_name", GetName());
  4303. packet->setDataByName("used_quests", total_quests_num - total_completed_quests);
  4304. packet->setDataByName("max_quests", 75);
  4305. LogWrite(PLAYER__PACKET, 0, "Player", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  4306. #if EQDEBUG >= 9
  4307. packet->PrintPacket();
  4308. #endif
  4309. }
  4310. return packet;
  4311. }
  4312. PacketStruct* Player::GetQuestJournalPacket(Quest* quest, int16 version, int32 crc, bool updated) {
  4313. if (!quest)
  4314. return 0;
  4315. PacketStruct* packet = configReader.getStruct("WS_QuestJournalUpdate", version);
  4316. if (packet) {
  4317. packet->setArrayLengthByName("num_quests", 1);
  4318. packet->setArrayLengthByName("num_quest_zones", 1);
  4319. packet->setArrayDataByName("quest_zones_zone", quest->GetType());
  4320. packet->setArrayDataByName("quest_zones_zone_id", 0);
  4321. if(!quest->GetDeleted() && !quest->GetCompleted())
  4322. packet->setArrayDataByName("active", 1);
  4323. packet->setArrayDataByName("name", quest->GetName());
  4324. // don't see these two in the struct
  4325. packet->setArrayDataByName("quest_type", quest->GetType());
  4326. packet->setArrayDataByName("quest_zone", quest->GetZone());
  4327. int8 display_status = QUEST_DISPLAY_STATUS_NORMAL;
  4328. if(quest->GetCompleted())
  4329. packet->setArrayDataByName("completed", 1);
  4330. if(quest->GetTurnedIn()) {
  4331. packet->setArrayDataByName("turned_in", 1);
  4332. packet->setArrayDataByName("completed", 1);
  4333. packet->setArrayDataByName("visible", 1);
  4334. display_status += QUEST_DISPLAY_STATUS_COMPLETED;
  4335. }
  4336. packet->setArrayDataByName("quest_id", quest->GetQuestID());
  4337. packet->setArrayDataByName("day", quest->GetDay());
  4338. packet->setArrayDataByName("month", quest->GetMonth());
  4339. packet->setArrayDataByName("year", quest->GetYear());
  4340. packet->setArrayDataByName("level", quest->GetQuestLevel());
  4341. int8 difficulty = 0;
  4342. string category = quest->GetType();
  4343. if(category == "Tradeskill")
  4344. difficulty = GetTSArrowColor(quest->GetQuestLevel());
  4345. else
  4346. difficulty = GetArrowColor(quest->GetQuestLevel());
  4347. packet->setArrayDataByName("difficulty", difficulty);
  4348. if (quest->GetEncounterLevel() > 4)
  4349. packet->setArrayDataByName("encounter_level", quest->GetEncounterLevel());
  4350. else
  4351. packet->setArrayDataByName("encounter_level", 4);
  4352. if (version >= 931) {
  4353. packet->setArrayDataByName("zonetype_id", 0);
  4354. packet->setArrayDataByName("zone_id", 0);
  4355. }
  4356. if(version >= 931 && quest->GetVisible()){
  4357. if (quest->GetCompletedFlag())
  4358. display_status += QUEST_DISPLAY_STATUS_COMPLETE_FLAG;
  4359. else if (quest->IsRepeatable())
  4360. display_status += QUEST_DISPLAY_STATUS_REPEATABLE;
  4361. if (quest->GetYellowName() || quest->CheckCategoryYellow())
  4362. display_status += QUEST_DISPLAY_STATUS_YELLOW;
  4363. if (quest->IsTracked())
  4364. display_status += QUEST_DISPLAY_STATUS_CHECK;
  4365. else
  4366. display_status += QUEST_DISPLAY_STATUS_NO_CHECK;
  4367. if (quest->IsHidden() && !quest->GetTurnedIn())
  4368. display_status = QUEST_DISPLAY_STATUS_HIDDEN;
  4369. }
  4370. else
  4371. packet->setArrayDataByName("visible", quest->GetVisible());
  4372. if (quest->IsRepeatable())
  4373. packet->setArrayDataByName("repeatable", 1);
  4374. packet->setArrayDataByName("display_status", display_status);
  4375. if (updated) {
  4376. packet->setArrayDataByName("quest_updated", 1);
  4377. packet->setArrayDataByName("journal_updated", 1);
  4378. }
  4379. if(version >= 546)
  4380. packet->setDataByName("unknown3", 1);
  4381. packet->setDataByName("visible_quest_id", quest->GetQuestID());
  4382. packet->setDataByName("player_crc", crc);
  4383. packet->setDataByName("player_name", GetName());
  4384. packet->setDataByName("used_quests", player_quests.size());
  4385. packet->setDataByName("unknown4a", 1);
  4386. packet->setDataByName("max_quests", 75);
  4387. }
  4388. return packet;
  4389. }
  4390. Quest* Player::SetStepComplete(int32 id, int32 step){
  4391. Quest* ret = 0;
  4392. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4393. if(player_quests.count(id) > 0){
  4394. if(player_quests[id]->SetStepComplete(step))
  4395. ret = player_quests[id];
  4396. }
  4397. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4398. return ret;
  4399. }
  4400. Quest* Player::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4401. Quest* ret = 0;
  4402. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4403. if (player_quests.count(quest_id) > 0) {
  4404. if (player_quests[quest_id]->AddStepProgress(step, progress))
  4405. ret = player_quests[quest_id];
  4406. }
  4407. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4408. return ret;
  4409. }
  4410. int32 Player::GetStepProgress(int32 quest_id, int32 step_id) {
  4411. int32 ret = 0;
  4412. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4413. if (player_quests.count(quest_id) > 0)
  4414. ret = player_quests[quest_id]->GetStepProgress(step_id);
  4415. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4416. return ret;
  4417. }
  4418. void Player::RemoveQuest(int32 id, bool delete_quest){
  4419. MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  4420. if(delete_quest){
  4421. safe_delete(player_quests[id]);
  4422. }
  4423. player_quests.erase(id);
  4424. MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  4425. SendQuestRequiredSpawns(id);
  4426. }
  4427. vector<Quest*>* Player::CheckQuestsLocationUpdate(){
  4428. vector<Quest*>* quest_updates = 0;
  4429. map<int32, Quest*>::iterator itr;
  4430. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4431. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4432. if(itr->second && itr->second->CheckQuestLocationUpdate(GetX(), GetY(), GetZ(), (GetZone() ? GetZone()->GetZoneID() : 0))){
  4433. if(!quest_updates)
  4434. quest_updates = new vector<Quest*>();
  4435. quest_updates->push_back(itr->second);
  4436. }
  4437. }
  4438. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4439. return quest_updates;
  4440. }
  4441. vector<Quest*>* Player::CheckQuestsFailures(){
  4442. vector<Quest*>* quest_failures = 0;
  4443. map<int32, Quest*>::iterator itr;
  4444. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4445. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4446. if(itr->second && itr->second->GetQuestFailures()->size() > 0){
  4447. if(!quest_failures)
  4448. quest_failures = new vector<Quest*>();
  4449. quest_failures->push_back(itr->second);
  4450. }
  4451. }
  4452. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4453. return quest_failures;
  4454. }
  4455. vector<Quest*>* Player::CheckQuestsKillUpdate(Spawn* spawn, bool update){
  4456. vector<Quest*>* quest_updates = 0;
  4457. map<int32, Quest*>::iterator itr;
  4458. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4459. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4460. if(itr->second && itr->second->CheckQuestKillUpdate(spawn, update)){
  4461. if(!quest_updates)
  4462. quest_updates = new vector<Quest*>();
  4463. quest_updates->push_back(itr->second);
  4464. }
  4465. }
  4466. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4467. return quest_updates;
  4468. }
  4469. bool Player::HasQuestUpdateRequirement(Spawn* spawn){
  4470. bool reqMet = false;
  4471. map<int32, Quest*>::iterator itr;
  4472. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4473. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4474. if(itr->second && itr->second->CheckQuestReferencedSpawns(spawn)){
  4475. reqMet = true;
  4476. break;
  4477. }
  4478. }
  4479. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4480. return reqMet;
  4481. }
  4482. vector<Quest*>* Player::CheckQuestsChatUpdate(Spawn* spawn){
  4483. vector<Quest*>* quest_updates = 0;
  4484. map<int32, Quest*>::iterator itr;
  4485. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4486. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4487. if(itr->second && itr->second->CheckQuestChatUpdate(spawn->GetDatabaseID())){
  4488. if(!quest_updates)
  4489. quest_updates = new vector<Quest*>();
  4490. quest_updates->push_back(itr->second);
  4491. }
  4492. }
  4493. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4494. return quest_updates;
  4495. }
  4496. int16 Player::GetTaskGroupStep(int32 quest_id){
  4497. Quest* quest = 0;
  4498. int16 step = 0;
  4499. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4500. if(player_quests.count(quest_id) > 0){
  4501. quest = player_quests[quest_id];
  4502. step = quest->GetTaskGroupStep();
  4503. }
  4504. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4505. return step;
  4506. }
  4507. bool Player::GetQuestStepComplete(int32 quest_id, int32 step_id){
  4508. bool ret = false;
  4509. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4510. if(player_quests.count(quest_id) > 0){
  4511. Quest* quest = player_quests[quest_id];
  4512. if ( quest != NULL )
  4513. ret = quest->GetQuestStepCompleted(step_id);
  4514. }
  4515. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4516. return ret;
  4517. }
  4518. int16 Player::GetQuestStep(int32 quest_id){
  4519. Quest* quest = 0;
  4520. int16 step = 0;
  4521. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4522. if(player_quests.count(quest_id) > 0){
  4523. quest = player_quests[quest_id];
  4524. step = quest->GetQuestStep();
  4525. }
  4526. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4527. return step;
  4528. }
  4529. map<int32, Quest*>* Player::GetPlayerQuests(){
  4530. return &player_quests;
  4531. }
  4532. map<int32, Quest*>* Player::GetCompletedPlayerQuests(){
  4533. return &completed_quests;
  4534. }
  4535. Quest* Player::GetAnyQuest(int32 quest_id) {
  4536. if(player_quests.count(quest_id) > 0)
  4537. return player_quests[quest_id];
  4538. if(completed_quests.count(quest_id) > 0)
  4539. return completed_quests[quest_id];
  4540. return 0;
  4541. }
  4542. Quest* Player::GetCompletedQuest(int32 quest_id){
  4543. if(completed_quests.count(quest_id) > 0)
  4544. return completed_quests[quest_id];
  4545. return 0;
  4546. }
  4547. Quest* Player::GetQuest(int32 quest_id){
  4548. if(player_quests.count(quest_id) > 0)
  4549. return player_quests[quest_id];
  4550. return 0;
  4551. }
  4552. void Player::AddCompletedQuest(Quest* quest){
  4553. completed_quests[quest->GetQuestID()] = quest;
  4554. quest->SetSaveNeeded(true);
  4555. quest->SetTurnedIn(true);
  4556. if(quest->GetCompletedDescription())
  4557. quest->SetDescription(string(quest->GetCompletedDescription()));
  4558. quest->SetUpdateRequired(true);
  4559. }
  4560. bool Player::CheckQuestRemoveFlag(Spawn* spawn){
  4561. if(current_quest_flagged.count(spawn) > 0){
  4562. current_quest_flagged.erase(spawn);
  4563. return true;
  4564. }
  4565. return false;
  4566. }
  4567. bool Player::CheckQuestRequired(Spawn* spawn){
  4568. if(spawn)
  4569. return spawn->MeetsSpawnAccessRequirements(this);
  4570. return false;
  4571. }
  4572. int8 Player::CheckQuestFlag(Spawn* spawn){
  4573. int8 ret = 0;
  4574. if (!spawn) {
  4575. LogWrite(PLAYER__ERROR, 0, "Player", "CheckQuestFlag() called with an invalid spawn");
  4576. return ret;
  4577. }
  4578. if(spawn->HasProvidedQuests()){
  4579. vector<int32>* quests = spawn->GetProvidedQuests();
  4580. Quest* quest = 0;
  4581. for(int32 i=0;i<quests->size();i++){
  4582. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4583. if(player_quests.count(quests->at(i)) > 0){
  4584. if(player_quests[quests->at(i)]->GetCompleted() && player_quests[quests->at(i)]->GetQuestReturnNPC() == spawn->GetDatabaseID()){
  4585. ret = 2;
  4586. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4587. break;
  4588. }
  4589. }
  4590. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4591. int8 flag = 0;
  4592. if (CanReceiveQuest(quests->at(i), &flag)){
  4593. if(flag) {
  4594. ret = flag;
  4595. break;
  4596. }
  4597. master_quest_list.LockQuests();
  4598. quest = master_quest_list.GetQuest(quests->at(i), false);
  4599. master_quest_list.UnlockQuests();
  4600. if(quest){
  4601. int8 color = quest->GetFeatherColor();
  4602. // purple
  4603. if (color == 1)
  4604. ret = 16;
  4605. // green
  4606. else if (color == 2)
  4607. ret = 32;
  4608. // blue
  4609. else if (color == 3)
  4610. ret = 64;
  4611. // normal
  4612. else
  4613. ret = 1;
  4614. break;
  4615. }
  4616. }
  4617. }
  4618. }
  4619. map<int32, Quest*>::iterator itr;
  4620. MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4621. for(itr = player_quests.begin(); itr != player_quests.end(); itr++){
  4622. if(itr->second->CheckQuestChatUpdate(spawn->GetDatabaseID(), false))
  4623. ret = 2;
  4624. }
  4625. MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4626. if(ret > 0)
  4627. current_quest_flagged[spawn] = true;
  4628. return ret;
  4629. }
  4630. bool Player::CanReceiveQuest(int32 quest_id, int8* ret){
  4631. bool passed = true;
  4632. int32 x;
  4633. master_quest_list.LockQuests();
  4634. Quest* quest = master_quest_list.GetQuest(quest_id, false);
  4635. master_quest_list.UnlockQuests();
  4636. if (!quest)
  4637. passed = false;
  4638. //check if quest is already completed, and not repeatable
  4639. else if (GetCompletedQuest(quest_id) && !quest->IsRepeatable())
  4640. passed = false;
  4641. //check if the player already has this quest
  4642. else if (player_quests.count(quest_id) > 0)
  4643. passed = false;
  4644. //Check Prereq Adv Levels
  4645. else if (quest->GetPrereqLevel() > GetLevel())
  4646. passed = false;
  4647. else if (quest->GetPrereqMaxLevel() > 0){
  4648. if (GetLevel() > quest->GetPrereqMaxLevel())
  4649. passed = false;
  4650. }
  4651. //Check Prereq TS Levels
  4652. else if (quest->GetPrereqTSLevel() > GetTSLevel())
  4653. passed = false;
  4654. else if (quest->GetPrereqMaxTSLevel() > 0){
  4655. if (GetTSLevel() > quest->GetPrereqMaxLevel())
  4656. passed = false;
  4657. }
  4658. // Check quest pre req
  4659. vector<int32>* prereq_quests = quest->GetPrereqQuests();
  4660. if(passed && prereq_quests && prereq_quests->size() > 0){
  4661. for(int32 x=0;x<prereq_quests->size();x++){
  4662. if(completed_quests.count(prereq_quests->at(x)) == 0){
  4663. passed = false;
  4664. break;
  4665. }
  4666. }
  4667. }
  4668. //Check Prereq Classes
  4669. vector<int8>* prereq_classes = quest->GetPrereqClasses();
  4670. if(passed && prereq_classes && prereq_classes->size() > 0){
  4671. for(int32 x=0;x<prereq_classes->size();x++){
  4672. if(prereq_classes->at(x) == GetAdventureClass()){
  4673. passed = true;
  4674. break;
  4675. }
  4676. else
  4677. passed = false;
  4678. }
  4679. }
  4680. //Check Prereq TS Classes
  4681. vector<int8>* prereq_tsclasses = quest->GetPrereqTradeskillClasses();
  4682. if(passed && prereq_tsclasses && prereq_tsclasses->size() > 0){
  4683. for( x=0;x<prereq_tsclasses->size();x++){
  4684. if(prereq_tsclasses->at(x) == GetTradeskillClass()){
  4685. passed = true;
  4686. break;
  4687. }
  4688. else
  4689. passed = false;
  4690. }
  4691. }
  4692. // Check model prereq
  4693. vector<int16>* prereq_model_types = quest->GetPrereqModelTypes();
  4694. if(passed && prereq_model_types && prereq_model_types->size() > 0){
  4695. for(x=0;x<prereq_model_types->size();x++){
  4696. if(prereq_model_types->at(x) == GetModelType()){
  4697. passed = true;
  4698. break;
  4699. }
  4700. else
  4701. passed = false;
  4702. }
  4703. }
  4704. // Check faction pre req
  4705. vector<QuestFactionPrereq>* prereq_factions = quest->GetPrereqFactions();
  4706. if(passed && prereq_factions && prereq_factions->size() > 0){
  4707. sint32 val = 0;
  4708. for(x=0;x<prereq_factions->size();x++){
  4709. val = GetFactions()->GetFactionValue(prereq_factions->at(x).faction_id);
  4710. if(val >= prereq_factions->at(x).min && (prereq_factions->at(x).max == 0 || val <= prereq_factions->at(x).max)){
  4711. passed = true;
  4712. break;
  4713. }
  4714. else
  4715. passed = false;
  4716. }
  4717. }
  4718. LogWrite(MISC__TODO, 1, "TODO", "Check prereq items\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  4719. // Check race pre req
  4720. vector<int8>* prereq_races = quest->GetPrereqRaces();
  4721. if(passed && prereq_races && prereq_races->size() > 0){
  4722. for(x=0;x<prereq_races->size();x++){
  4723. if(prereq_races->at(x) == GetRace()){
  4724. passed = true;
  4725. break;
  4726. }
  4727. else
  4728. passed = false;
  4729. }
  4730. }
  4731. int32 flag = 0;
  4732. if(lua_interface->CallQuestFunction(quest, "ReceiveQuestCriteria", this, 0xFFFFFFFF, &flag)) {
  4733. if(ret)
  4734. *ret = flag;
  4735. if(!flag) {
  4736. passed = false;
  4737. }
  4738. else {
  4739. passed = true;
  4740. }
  4741. }
  4742. return passed;
  4743. }
  4744. bool Player::ShouldSendSpawn(Spawn* spawn){
  4745. if(spawn->IsDeletedSpawn() || IsSendingSpawn(spawn->GetID()) || IsRemovingSpawn(spawn->GetID()))
  4746. return false;
  4747. else if((WasSentSpawn(spawn->GetID()) == false) && (!spawn->IsPrivateSpawn() || spawn->AllowedAccess(this)))
  4748. return true;
  4749. return false;
  4750. }
  4751. int8 Player::GetArrowColor(int8 spawn_level){
  4752. int8 color = 0;
  4753. sint16 diff = spawn_level - GetLevel();
  4754. if(GetLevel() < 10)
  4755. diff *= 3;
  4756. else if(GetLevel() <= 20)
  4757. diff *= 2;
  4758. if(diff >= 9)
  4759. color = ARROW_COLOR_RED;
  4760. else if(diff >= 5)
  4761. color = ARROW_COLOR_ORANGE;
  4762. else if(diff >= 1)
  4763. color = ARROW_COLOR_YELLOW;
  4764. else if(diff == 0)
  4765. color = ARROW_COLOR_WHITE;
  4766. else if(diff <= -11)
  4767. color = ARROW_COLOR_GRAY;
  4768. else if(diff <= -6)
  4769. color = ARROW_COLOR_GREEN;
  4770. else //if(diff < 0)
  4771. color = ARROW_COLOR_BLUE;
  4772. return color;
  4773. }
  4774. int8 Player::GetTSArrowColor(int8 level){
  4775. int8 color = 0;
  4776. sint16 diff = level - GetTSLevel();
  4777. if(GetLevel() < 10)
  4778. diff *= 3;
  4779. else if(GetLevel() <= 20)
  4780. diff *= 2;
  4781. if(diff >= 9)
  4782. color = ARROW_COLOR_RED;
  4783. else if(diff >= 5)
  4784. color = ARROW_COLOR_ORANGE;
  4785. else if(diff >= 1)
  4786. color = ARROW_COLOR_YELLOW;
  4787. else if(diff == 0)
  4788. color = ARROW_COLOR_WHITE;
  4789. else if(diff <= -11)
  4790. color = ARROW_COLOR_GRAY;
  4791. else if(diff <= -6)
  4792. color = ARROW_COLOR_GREEN;
  4793. else //if(diff < 0)
  4794. color = ARROW_COLOR_BLUE;
  4795. return color;
  4796. }
  4797. void Player::AddCoins(int64 val){
  4798. int32 tmp = 0;
  4799. UpdatePlayerStatistic(STAT_PLAYER_TOTAL_WEALTH, (GetCoinsCopper() + (GetCoinsSilver() * 100) + (GetCoinsGold() * 10000) + (GetCoinsPlat() * 1000000)) + val, true);
  4800. if(val >= 1000000){
  4801. tmp = val / 1000000;
  4802. val -= tmp*1000000;
  4803. GetInfoStruct()->add_coin_plat(tmp);
  4804. }
  4805. if(val >= 10000){
  4806. tmp = val / 10000;
  4807. val -= tmp*10000;
  4808. GetInfoStruct()->add_coin_gold(tmp);
  4809. }
  4810. if(val >= 100){
  4811. tmp = val / 100;
  4812. val -= tmp*100;
  4813. GetInfoStruct()->add_coin_silver(tmp);
  4814. }
  4815. GetInfoStruct()->add_coin_copper(val);
  4816. int32 new_copper_value = GetInfoStruct()->get_coin_copper();
  4817. if(new_copper_value >= 100){
  4818. tmp = new_copper_value/100;
  4819. GetInfoStruct()->set_coin_copper(new_copper_value - (100 * tmp));
  4820. GetInfoStruct()->add_coin_silver(tmp);
  4821. }
  4822. int32 new_silver_value = GetInfoStruct()->get_coin_silver();
  4823. if(new_silver_value >= 100){
  4824. tmp = new_silver_value/100;
  4825. GetInfoStruct()->set_coin_silver(new_silver_value - (100 * tmp));
  4826. GetInfoStruct()->add_coin_gold(tmp);
  4827. }
  4828. int32 new_gold_value = GetInfoStruct()->get_coin_gold();
  4829. if(new_gold_value >= 100){
  4830. tmp = new_gold_value/100;
  4831. GetInfoStruct()->set_coin_gold(new_gold_value - (100 * tmp));
  4832. GetInfoStruct()->add_coin_plat(tmp);
  4833. }
  4834. charsheet_changed = true;
  4835. }
  4836. bool Player::RemoveCoins(int64 val){
  4837. int64 total_coins = GetInfoStruct()->get_coin_plat()*1000000;
  4838. total_coins += GetInfoStruct()->get_coin_gold()*10000;
  4839. total_coins += GetInfoStruct()->get_coin_silver()*100;
  4840. total_coins += GetInfoStruct()->get_coin_copper();
  4841. if(total_coins >= val){
  4842. total_coins -= val;
  4843. GetInfoStruct()->set_coin_plat(0);
  4844. GetInfoStruct()->set_coin_gold(0);
  4845. GetInfoStruct()->set_coin_silver(0);
  4846. GetInfoStruct()->set_coin_copper(0);
  4847. AddCoins(total_coins);
  4848. return true;
  4849. }
  4850. return false;
  4851. }
  4852. bool Player::HasCoins(int64 val) {
  4853. int64 total_coins = GetInfoStruct()->get_coin_plat()*1000000;
  4854. total_coins += GetInfoStruct()->get_coin_gold()*10000;
  4855. total_coins += GetInfoStruct()->get_coin_silver()*100;
  4856. total_coins += GetInfoStruct()->get_coin_copper();
  4857. if(total_coins >= val)
  4858. return true;
  4859. return false;
  4860. }
  4861. bool Player::HasPendingLootItems(int32 id){
  4862. return (pending_loot_items.count(id) > 0 && pending_loot_items[id].size() > 0);
  4863. }
  4864. bool Player::HasPendingLootItem(int32 id, int32 item_id){
  4865. return (pending_loot_items.count(id) > 0 && pending_loot_items[id].count(item_id) > 0);
  4866. }
  4867. vector<Item*>* Player::GetPendingLootItems(int32 id){
  4868. vector<Item*>* ret = 0;
  4869. if(pending_loot_items.count(id) > 0){
  4870. ret = new vector<Item*>();
  4871. map<int32, bool>::iterator itr;
  4872. for(itr = pending_loot_items[id].begin(); itr != pending_loot_items[id].end(); itr++){
  4873. if(master_item_list.GetItem(itr->first))
  4874. ret->push_back(master_item_list.GetItem(itr->first));
  4875. }
  4876. }
  4877. return ret;
  4878. }
  4879. void Player::RemovePendingLootItem(int32 id, int32 item_id){
  4880. if(pending_loot_items.count(id) > 0){
  4881. pending_loot_items[id].erase(item_id);
  4882. if(pending_loot_items[id].size() == 0)
  4883. pending_loot_items.erase(id);
  4884. }
  4885. }
  4886. void Player::RemovePendingLootItems(int32 id){
  4887. if(pending_loot_items.count(id) > 0)
  4888. pending_loot_items.erase(id);
  4889. }
  4890. void Player::AddPendingLootItems(int32 id, vector<Item*>* items){
  4891. if(items){
  4892. Item* item = 0;
  4893. for(int32 i=0;i<items->size();i++){
  4894. item = items->at(i);
  4895. if(item)
  4896. pending_loot_items[id][item->details.item_id] = true;
  4897. }
  4898. }
  4899. }
  4900. void Player::AddPlayerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date) {
  4901. if (statistics.count(stat_id) == 0) {
  4902. Statistic* stat = new Statistic;
  4903. stat->stat_id = stat_id;
  4904. stat->stat_value = stat_value;
  4905. stat->stat_date = stat_date;
  4906. stat->save_needed = false;
  4907. statistics[stat_id] = stat;
  4908. }
  4909. }
  4910. void Player::UpdatePlayerStatistic(int32 stat_id, sint32 stat_value, bool overwrite) {
  4911. if (statistics.count(stat_id) == 0)
  4912. AddPlayerStatistic(stat_id, 0, 0);
  4913. Statistic* stat = statistics[stat_id];
  4914. overwrite == true ? stat->stat_value = stat_value : stat->stat_value += stat_value;
  4915. stat->stat_date = Timer::GetUnixTimeStamp();
  4916. stat->save_needed = true;
  4917. }
  4918. void Player::WritePlayerStatistics() {
  4919. map<int32, Statistic*>::iterator stat_itr;
  4920. for (stat_itr = statistics.begin(); stat_itr != statistics.end(); stat_itr++) {
  4921. Statistic* stat = stat_itr->second;
  4922. if (stat->save_needed) {
  4923. stat->save_needed = false;
  4924. database.WritePlayerStatistic(this, stat);
  4925. }
  4926. }
  4927. }
  4928. sint64 Player::GetPlayerStatisticValue(int32 stat_id) {
  4929. if (stat_id >= 0 && statistics.count(stat_id) > 0)
  4930. return statistics[stat_id]->stat_value;
  4931. return 0;
  4932. }
  4933. void Player::RemovePlayerStatistics() {
  4934. map<int32, Statistic*>::iterator stat_itr;
  4935. for (stat_itr = statistics.begin(); stat_itr != statistics.end(); stat_itr++)
  4936. safe_delete(stat_itr->second);
  4937. statistics.clear();
  4938. }
  4939. void Player::SetGroup(PlayerGroup* new_group){
  4940. group = new_group;
  4941. }
  4942. /*PlayerGroup* Player::GetGroup(){
  4943. return group;
  4944. }*/
  4945. bool Player::IsGroupMember(Entity* player) {
  4946. bool ret = false;
  4947. if (GetGroupMemberInfo() && player) {
  4948. //world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4949. ret = world.GetGroupManager()->IsInGroup(GetGroupMemberInfo()->group_id, player);
  4950. /*deque<GroupMemberInfo*>::iterator itr;
  4951. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(GetGroupMemberInfo()->group_id);
  4952. for (itr = members->begin(); itr != members->end(); itr++) {
  4953. GroupMemberInfo* gmi = *itr;
  4954. if (gmi->client && gmi->client->GetPlayer() == player) {
  4955. ret = true;
  4956. break;
  4957. }
  4958. }
  4959. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);*/
  4960. }
  4961. return ret;
  4962. }
  4963. void Player::SetGroupInformation(PacketStruct* packet){
  4964. int8 det_count = 0;
  4965. Entity* member = 0;
  4966. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4967. if (GetGroupMemberInfo()) {
  4968. PlayerGroup* group = world.GetGroupManager()->GetGroup(GetGroupMemberInfo()->group_id);
  4969. if (group)
  4970. {
  4971. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4972. deque<GroupMemberInfo*>* members = group->GetMembers();
  4973. deque<GroupMemberInfo*>::iterator itr;
  4974. GroupMemberInfo* info = 0;
  4975. int x = 0;
  4976. for (itr = members->begin(); itr != members->end(); itr++) {
  4977. info = *itr;
  4978. if (info == GetGroupMemberInfo()) {
  4979. if (info->leader)
  4980. packet->setDataByName("group_leader_id", 0xFFFFFFFF); // If this player is the group leader then fill this element with FF FF FF FF
  4981. continue;
  4982. }
  4983. else {
  4984. if (info->leader)
  4985. packet->setDataByName("group_leader_id", x); // If leader is some one else then fill with the slot number they are in
  4986. }
  4987. member = info->member;
  4988. if (member && member->GetZone() == GetZone()) {
  4989. packet->setSubstructDataByName("group_members", "unknown3", 1, x);
  4990. packet->setSubstructDataByName("group_members", "spawn_id", GetIDWithPlayerSpawn(member), x);
  4991. if (member->HasPet()) {
  4992. if (member->GetPet())
  4993. packet->setSubstructDataByName("group_members", "pet_id", GetIDWithPlayerSpawn(member->GetPet()), x);
  4994. else
  4995. packet->setSubstructDataByName("group_members", "pet_id", GetIDWithPlayerSpawn(member->GetCharmedPet()), x);
  4996. }
  4997. else
  4998. packet->setSubstructDataByName("group_members", "pet_id", 0xFFFFFFFF, x);
  4999. //Send detriment counts as 255 if all dets of that type are incurable
  5000. det_count = member->GetTraumaCount();
  5001. if (det_count > 0) {
  5002. if (!member->HasCurableDetrimentType(DET_TYPE_TRAUMA))
  5003. det_count = 255;
  5004. }
  5005. packet->setSubstructDataByName("group_members", "trauma_count", det_count, x);
  5006. det_count = member->GetArcaneCount();
  5007. if (det_count > 0) {
  5008. if (!member->HasCurableDetrimentType(DET_TYPE_ARCANE))
  5009. det_count = 255;
  5010. }
  5011. packet->setSubstructDataByName("group_members", "arcane_count", det_count, x);
  5012. det_count = member->GetNoxiousCount();
  5013. if (det_count > 0) {
  5014. if (!member->HasCurableDetrimentType(DET_TYPE_NOXIOUS))
  5015. det_count = 255;
  5016. }
  5017. packet->setSubstructDataByName("group_members", "noxious_count", det_count, x);
  5018. det_count = member->GetElementalCount();
  5019. if (det_count > 0) {
  5020. if (!member->HasCurableDetrimentType(DET_TYPE_ELEMENTAL))
  5021. det_count = 255;
  5022. }
  5023. packet->setSubstructDataByName("group_members", "elemental_count", det_count, x);
  5024. det_count = member->GetCurseCount();
  5025. if (det_count > 0) {
  5026. if (!member->HasCurableDetrimentType(DET_TYPE_CURSE))
  5027. det_count = 255;
  5028. }
  5029. packet->setSubstructDataByName("group_members", "curse_count", det_count, x);
  5030. }
  5031. else {
  5032. packet->setSubstructDataByName("group_members", "unknown3", 2, x);
  5033. packet->setSubstructDataByName("group_members", "pet_id", 0xFFFFFFFF, x);
  5034. //packet->setSubstructDataByName("group_members", "unknown5", 1, x, 1); // unknown5 > 1 = name is blue
  5035. }
  5036. packet->setSubstructDataByName("group_members", "name", info->name.c_str(), x);
  5037. packet->setSubstructDataByName("group_members", "hp_current", info->hp_current, x);
  5038. packet->setSubstructDataByName("group_members", "hp_max", info->hp_max, x);
  5039. packet->setSubstructDataByName("group_members", "power_current", info->power_current, x);
  5040. packet->setSubstructDataByName("group_members", "power_max", info->power_max, x);
  5041. packet->setSubstructDataByName("group_members", "level_current", info->level_current, x);
  5042. packet->setSubstructDataByName("group_members", "level_max", info->level_max, x);
  5043. packet->setSubstructDataByName("group_members", "zone", info->zone.c_str(), x);
  5044. packet->setSubstructDataByName("group_members", "race_id", info->race_id, x);
  5045. packet->setSubstructDataByName("group_members", "class_id", info->class_id, x);
  5046. x++;
  5047. }
  5048. }
  5049. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5050. }
  5051. //packet->PrintPacket();
  5052. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5053. }
  5054. PlayerItemList* Player::GetPlayerItemList(){
  5055. return &item_list;
  5056. }
  5057. void Player::ResetSavedSpawns(){
  5058. spawn_mutex.writelock(__FUNCTION__, __LINE__);
  5059. ClearRemovalTimers();
  5060. spawn_packet_sent.clear();
  5061. spawn_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5062. info_mutex.writelock(__FUNCTION__, __LINE__);
  5063. spawn_info_packet_list.clear();
  5064. info_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5065. vis_mutex.writelock(__FUNCTION__, __LINE__);
  5066. spawn_vis_packet_list.clear();
  5067. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5068. pos_mutex.writelock(__FUNCTION__, __LINE__);
  5069. spawn_pos_packet_list.clear();
  5070. pos_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5071. index_mutex.writelock(__FUNCTION__, __LINE__);
  5072. player_spawn_reverse_id_map.clear();
  5073. player_spawn_id_map.clear();
  5074. player_spawn_id_map[1] = this;
  5075. player_spawn_reverse_id_map[this] = 1;
  5076. spawn_index = 1;
  5077. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5078. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  5079. player_spawn_quests_required.clear();
  5080. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5081. if(info)
  5082. info->RemoveOldPackets();
  5083. safe_delete_array(movement_packet);
  5084. safe_delete_array(old_movement_packet);
  5085. }
  5086. void Player::SetReturningFromLD(bool val){
  5087. if(val && val != returning_from_ld)
  5088. {
  5089. if(GetPlayerItemList())
  5090. GetPlayerItemList()->ResetPackets();
  5091. GetEquipmentList()->ResetPackets();
  5092. GetAppearanceEquipmentList()->ResetPackets();
  5093. skill_list.ResetPackets();
  5094. safe_delete_array(spell_orig_packet);
  5095. safe_delete_array(spell_xor_packet);
  5096. spell_orig_packet=0;
  5097. spell_xor_packet=0;
  5098. spell_count = 0;
  5099. reset_character_flag(CF_IS_SITTING);
  5100. if (GetActivityStatus() & ACTIVITY_STATUS_CAMPING)
  5101. SetActivityStatus(GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  5102. if (GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD)
  5103. SetActivityStatus(GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  5104. SetTempVisualState(0);
  5105. safe_delete_array(spawn_tmp_info_xor_packet);
  5106. safe_delete_array(spawn_tmp_vis_xor_packet);
  5107. safe_delete_array(spawn_tmp_pos_xor_packet);
  5108. spawn_tmp_info_xor_packet = 0;
  5109. spawn_tmp_vis_xor_packet = 0;
  5110. spawn_tmp_pos_xor_packet = 0;
  5111. pos_xor_size = 0;
  5112. info_xor_size = 0;
  5113. vis_xor_size = 0;
  5114. index_mutex.writelock(__FUNCTION__, __LINE__);
  5115. player_spawn_id_map[1] = this;
  5116. player_spawn_reverse_id_map[this] = 1;
  5117. spawn_index = 1;
  5118. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  5119. }
  5120. returning_from_ld = val;
  5121. }
  5122. bool Player::IsReturningFromLD(){
  5123. return returning_from_ld;
  5124. }
  5125. void Player::AddFriend(const char* name, bool save){
  5126. if(name){
  5127. if(save)
  5128. friend_list[name] = 1;
  5129. else
  5130. friend_list[name] = 0;
  5131. }
  5132. }
  5133. bool Player::IsFriend(const char* name){
  5134. if(name && friend_list.count(name) > 0 && friend_list[name] < 2)
  5135. return true;
  5136. return false;
  5137. }
  5138. void Player::RemoveFriend(const char* name){
  5139. if(friend_list.count(name) > 0)
  5140. friend_list[name] = 2;
  5141. }
  5142. map<string, int8>* Player::GetFriends(){
  5143. return &friend_list;
  5144. }
  5145. void Player::AddIgnore(const char* name, bool save){
  5146. if(name){
  5147. if(save)
  5148. ignore_list[name] = 1;
  5149. else
  5150. ignore_list[name] = 0;
  5151. }
  5152. }
  5153. bool Player::IsIgnored(const char* name){
  5154. if(name && ignore_list.count(name) > 0 && ignore_list[name] < 2)
  5155. return true;
  5156. return false;
  5157. }
  5158. void Player::RemoveIgnore(const char* name){
  5159. if(name && ignore_list.count(name) > 0)
  5160. ignore_list[name] = 2;
  5161. }
  5162. map<string, int8>* Player::GetIgnoredPlayers(){
  5163. return &ignore_list;
  5164. }
  5165. bool Player::CheckLevelStatus(int16 new_level) {
  5166. int16 LevelCap = rule_manager.GetGlobalRule(R_Player, MaxLevel)->GetInt16();
  5167. int16 LevelCapOverrideStatus = rule_manager.GetGlobalRule(R_Player, MaxLevelOverrideStatus)->GetInt16();
  5168. if ( (LevelCap < new_level) && (LevelCapOverrideStatus > GetZone()->GetClientBySpawn(this)->GetAdminStatus()) )
  5169. return false;
  5170. return true;
  5171. }
  5172. Skill* Player::GetSkillByName(const char* name, bool check_update){
  5173. Skill* ret = skill_list.GetSkillByName(name);
  5174. if(check_update)
  5175. {
  5176. if(skill_list.CheckSkillIncrease(ret))
  5177. CalculateBonuses();
  5178. }
  5179. return ret;
  5180. }
  5181. Skill* Player::GetSkillByID(int32 id, bool check_update){
  5182. Skill* ret = skill_list.GetSkill(id);
  5183. if(check_update)
  5184. {
  5185. if(skill_list.CheckSkillIncrease(ret))
  5186. CalculateBonuses();
  5187. }
  5188. return ret;
  5189. }
  5190. void Player::SetRangeAttack(bool val){
  5191. range_attack = val;
  5192. }
  5193. bool Player::GetRangeAttack(){
  5194. return range_attack;
  5195. }
  5196. bool Player::AddMail(Mail* mail) {
  5197. bool ret = false;
  5198. if (mail) {
  5199. mail_list.Put(mail->mail_id, mail);
  5200. ret = true;
  5201. }
  5202. return ret;
  5203. }
  5204. MutexMap<int32, Mail*>* Player::GetMail() {
  5205. return &mail_list;
  5206. }
  5207. Mail* Player::GetMail(int32 mail_id) {
  5208. Mail* mail = 0;
  5209. if (mail_list.count(mail_id) > 0)
  5210. mail = mail_list.Get(mail_id);
  5211. return mail;
  5212. }
  5213. void Player::DeleteMail(bool from_database) {
  5214. MutexMap<int32, Mail*>::iterator itr = mail_list.begin();
  5215. while (itr.Next())
  5216. DeleteMail(itr->first, from_database);
  5217. mail_list.clear();
  5218. }
  5219. void Player::DeleteMail(int32 mail_id, bool from_database) {
  5220. if (mail_list.count(mail_id) > 0) {
  5221. if (from_database)
  5222. database.DeletePlayerMail(mail_list.Get(mail_id));
  5223. mail_list.erase(mail_id);
  5224. }
  5225. }
  5226. ZoneServer* Player::GetGroupMemberInZone(int32 zone_id) {
  5227. //if ( GetGroup() == NULL )
  5228. return NULL;
  5229. /*GroupMemberInfo* info = 0;
  5230. for(int32 i=0;i<GetGroup()->members.size(); i++){
  5231. info = GetGroup()->members[i];
  5232. if(info == group_member_info)
  5233. continue;
  5234. // if the client exists, they are attached to a player,
  5235. // the player is currently in an instance, which has the same zone id (for that instance type)
  5236. if ( info->client != NULL && info->client->GetPlayer() != NULL &&
  5237. info->client->GetPlayer()->GetZone()->GetInstanceID() > 0 &&
  5238. info->client->GetPlayer()->GetZone()->GetZoneID() == zone_id )
  5239. {
  5240. return info->client->GetPlayer()->GetZone();
  5241. }
  5242. }
  5243. // no member is in an instance with this zone id
  5244. return NULL;*/
  5245. }
  5246. /* CharacterInstances */
  5247. CharacterInstances::CharacterInstances() {
  5248. m_instanceList.SetName("Mutex::m_instanceList");
  5249. }
  5250. CharacterInstances::~CharacterInstances() {
  5251. RemoveInstances();
  5252. }
  5253. 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) {
  5254. InstanceData data;
  5255. data.db_id = db_id;
  5256. data.instance_id = instance_id;
  5257. data.zone_id = zone_id;
  5258. data.zone_instance_type = zone_instancetype;
  5259. data.zone_name = zone_name;
  5260. data.last_success_timestamp = last_success_timestamp;
  5261. data.last_failure_timestamp = last_failure_timestamp;
  5262. data.success_lockout_time = success_lockout_time;
  5263. data.failure_lockout_time = failure_lockout_time;
  5264. instanceList.push_back(data);
  5265. }
  5266. void CharacterInstances::RemoveInstances() {
  5267. instanceList.clear();
  5268. }
  5269. bool CharacterInstances::RemoveInstanceByZoneID(int32 zone_id) {
  5270. vector<InstanceData>::iterator itr;
  5271. m_instanceList.writelock(__FUNCTION__, __LINE__);
  5272. for(itr = instanceList.begin(); itr != instanceList.end(); itr++) {
  5273. InstanceData* data = &(*itr);
  5274. if (data->zone_id == zone_id) {
  5275. instanceList.erase(itr);
  5276. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5277. return true;
  5278. }
  5279. }
  5280. m_instanceList.releasewritelock(__FUNCTION__, __LINE__);
  5281. return false;
  5282. }
  5283. bool CharacterInstances::RemoveInstanceByInstanceID(int32 instance_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->instance_id == instance_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. InstanceData* CharacterInstances::FindInstanceByZoneID(int32 zone_id) {
  5298. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5299. for(int32 i = 0; i < instanceList.size(); i++) {
  5300. InstanceData* data = &instanceList.at(i);
  5301. if (data->zone_id == zone_id) {
  5302. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5303. return data;
  5304. }
  5305. }
  5306. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5307. return 0;
  5308. }
  5309. InstanceData* CharacterInstances::FindInstanceByDBID(int32 db_id) {
  5310. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5311. for(int32 i = 0; i < instanceList.size(); i++) {
  5312. InstanceData* data = &instanceList.at(i);
  5313. if (data->db_id == db_id) {
  5314. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5315. return data;
  5316. }
  5317. }
  5318. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5319. return 0;
  5320. }
  5321. InstanceData* CharacterInstances::FindInstanceByInstanceID(int32 instance_id) {
  5322. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5323. for(int32 i = 0; i < instanceList.size(); i++) {
  5324. InstanceData* data = &instanceList.at(i);
  5325. if (data->instance_id == instance_id) {
  5326. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5327. return data;
  5328. }
  5329. }
  5330. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5331. return 0;
  5332. }
  5333. vector<InstanceData> CharacterInstances::GetLockoutInstances() {
  5334. vector<InstanceData> ret;
  5335. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5336. for (int32 i = 0; i < instanceList.size(); i++) {
  5337. InstanceData* data = &instanceList.at(i);
  5338. if (data->zone_instance_type == SOLO_LOCKOUT_INSTANCE || data->zone_instance_type == GROUP_LOCKOUT_INSTANCE || data->zone_instance_type == RAID_LOCKOUT_INSTANCE)
  5339. ret.push_back(*data);
  5340. }
  5341. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5342. return ret;
  5343. }
  5344. vector<InstanceData> CharacterInstances::GetPersistentInstances() {
  5345. vector<InstanceData> ret;
  5346. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5347. for (int32 i = 0; i < instanceList.size(); i++) {
  5348. InstanceData* data = &instanceList.at(i);
  5349. if (data->zone_instance_type == SOLO_PERSIST_INSTANCE || data->zone_instance_type == GROUP_PERSIST_INSTANCE || data->zone_instance_type == RAID_PERSIST_INSTANCE)
  5350. ret.push_back(*data);
  5351. }
  5352. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5353. return ret;
  5354. }
  5355. void CharacterInstances::ProcessInstanceTimers(Player* player) {
  5356. // Only need to check persistent instances here, lockout should be handled by zone shutting down
  5357. // 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,
  5358. // delete instance from `instances` if no more characters assigned to it
  5359. m_instanceList.readlock(__FUNCTION__, __LINE__);
  5360. for (int32 i = 0; i < instanceList.size(); i++) {
  5361. InstanceData* data = &instanceList.at(i);
  5362. // Check to see if we have a valid instance and if it is persistant
  5363. if (data->instance_id > 0) {
  5364. if (data->zone_instance_type == SOLO_PERSIST_INSTANCE || data->zone_instance_type == GROUP_PERSIST_INSTANCE || data->zone_instance_type == RAID_PERSIST_INSTANCE) {
  5365. // Check max duration (last success + success time)
  5366. if (Timer::GetUnixTimeStamp() >= (data->last_success_timestamp + data->success_lockout_time)) {
  5367. // Max duration has passed, instance has expired lets remove the player from it,
  5368. // this will also delete the instace if all players have been removed from it
  5369. database.DeleteCharacterFromInstance(player->GetCharacterID(), data->instance_id);
  5370. data->instance_id = 0;
  5371. }
  5372. }
  5373. if (data->zone_instance_type == SOLO_LOCKOUT_INSTANCE || data->zone_instance_type == GROUP_LOCKOUT_INSTANCE || data->zone_instance_type == RAID_LOCKOUT_INSTANCE) {
  5374. // Need to check lockout instance ids to ensure they are still valid.
  5375. if (!database.VerifyInstanceID(player->GetCharacterID(), data->instance_id))
  5376. data->instance_id = 0;
  5377. }
  5378. }
  5379. }
  5380. m_instanceList.releasereadlock(__FUNCTION__, __LINE__);
  5381. /*for(int32 i=0;i<instanceList->size();i++)
  5382. {
  5383. bool valuesUpdated = false;
  5384. InstanceData data = instanceList->at(i);
  5385. if ( data.grant_reenter_time_left > 0 )
  5386. {
  5387. if ( ( data.grant_reenter_time_left - msDiff ) < 1 )
  5388. data.grant_reenter_time_left = 0;
  5389. else
  5390. data.grant_reenter_time_left -= msDiff;
  5391. valuesUpdated = true;
  5392. }
  5393. if ( data.grant_reset_time_left > 0 )
  5394. {
  5395. if ( ( data.grant_reset_time_left - msDiff ) < 1 )
  5396. data.grant_reset_time_left = 0;
  5397. else
  5398. data.grant_reset_time_left -= msDiff;
  5399. valuesUpdated = true;
  5400. }
  5401. if ( data.lockout_time > 0 )
  5402. {
  5403. if ( ( data.lockout_time - msDiff ) < 1 )
  5404. {
  5405. data.lockout_time = 0;
  5406. // this means that their timer ran out and we need to clear it from db and player
  5407. RemoveInstanceByInstanceID(data.instance_id);
  5408. database.DeleteCharacterFromInstance(player->GetCharacterID(),data.instance_id);
  5409. }
  5410. else
  5411. data.lockout_time -= msDiff;
  5412. valuesUpdated = true;
  5413. }
  5414. if ( valuesUpdated )
  5415. database.UpdateCharacterInstanceTimers(player->GetCharacterID(),data.instance_id,data.lockout_time,data.grant_reset_time_left,data.grant_reenter_time_left);
  5416. }*/
  5417. }
  5418. int32 CharacterInstances::GetInstanceCount() {
  5419. return instanceList.size();
  5420. }
  5421. void Player::SetPlayerAdventureClass(int8 new_class){
  5422. SetAdventureClass(new_class);
  5423. GetInfoStruct()->set_class1(classes.GetBaseClass(new_class));
  5424. GetInfoStruct()->set_class2(classes.GetSecondaryBaseClass(new_class));
  5425. GetInfoStruct()->set_class3(new_class);
  5426. charsheet_changed = true;
  5427. if(GetZone())
  5428. GetZone()->TriggerCharSheetTimer();
  5429. }
  5430. void Player::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  5431. GetSkills()->AddSkillBonus(spell_id, skill_id, value);
  5432. }
  5433. SkillBonus* Player::GetSkillBonus(int32 spell_id) {
  5434. return GetSkills()->GetSkillBonus(spell_id);
  5435. }
  5436. void Player::RemoveSkillBonus(int32 spell_id) {
  5437. GetSkills()->RemoveSkillBonus(spell_id);
  5438. }
  5439. bool Player::HasFreeBankSlot() {
  5440. return item_list.HasFreeBankSlot();
  5441. }
  5442. int8 Player::FindFreeBankSlot() {
  5443. return item_list.FindFreeBankSlot();
  5444. }
  5445. void Player::AddTitle(sint32 title_id, const char *name, int8 prefix, bool save_needed){
  5446. Title* new_title = new Title;
  5447. new_title->SetID(title_id);
  5448. new_title->SetName(name);
  5449. new_title->SetPrefix(prefix);
  5450. new_title->SetSaveNeeded(save_needed);
  5451. player_titles_list.Add(new_title);
  5452. }
  5453. void Player::AddAAEntry(int16 template_id, int8 tab_id, int32 aa_id, int16 order,int8 treeid) {
  5454. }
  5455. void Player::AddLanguage(int32 id, const char *name, bool save_needed){
  5456. Skill* skill = master_skill_list.GetSkillByName(name);
  5457. if(skill && !GetSkills()->HasSkill(skill->skill_id)) {
  5458. AddSkill(skill->skill_id, 1, skill->max_val, true);
  5459. }
  5460. // Check to see if the player already has the language
  5461. if (HasLanguage(id))
  5462. return;
  5463. // Doesn't already have the language so add it
  5464. Language* new_language = new Language;
  5465. new_language->SetID(id);
  5466. new_language->SetName(name);
  5467. player_languages_list.Add(new_language);
  5468. if (save_needed)
  5469. database.SaveCharacterLang(GetCharacterID(), id);
  5470. }
  5471. bool Player::HasLanguage(int32 id){
  5472. list<Language*>* languages = player_languages_list.GetAllLanguages();
  5473. list<Language*>::iterator itr;
  5474. Language* language = 0;
  5475. bool ret = false;
  5476. for(itr = languages->begin(); itr != languages->end(); itr++){
  5477. language = *itr;
  5478. if(language->GetID() == id){
  5479. ret = true;
  5480. break;
  5481. }
  5482. }
  5483. return ret;
  5484. }
  5485. bool Player::HasLanguage(const char* name){
  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(!strncmp(language->GetName(), name, strlen(name))){
  5493. ret = true;
  5494. break;
  5495. }
  5496. }
  5497. return ret;
  5498. }
  5499. void Player::AddPassiveSpell(int32 id, int8 tier)
  5500. {
  5501. // Add the spell to the list of passives this player currently has
  5502. // list is used for quickly going over only the passive spells the
  5503. // player has instead of going through all their spells.
  5504. passive_spells.push_back(id);
  5505. Client* client = GetZone()->GetClientBySpawn(this);
  5506. // Don not apply passives if the client is null, zoning, or reviving
  5507. if (client == NULL || client->IsZoning() || IsResurrecting())
  5508. return;
  5509. Spell* spell = 0;
  5510. spell = master_spell_list.GetSpell(id, tier);
  5511. if (spell) {
  5512. SpellProcess* spellProcess = 0;
  5513. // Get the current zones spell process
  5514. spellProcess = GetZone()->GetSpellProcess();
  5515. // Cast the spell, CastPassives() bypasses the spell queue
  5516. spellProcess->CastPassives(spell, this);
  5517. }
  5518. }
  5519. void Player::ApplyPassiveSpells()
  5520. {
  5521. Spell* spell = 0;
  5522. SpellBookEntry* spell2 = 0;
  5523. vector<int32>::iterator itr;
  5524. SpellProcess* spellProcess = 0;
  5525. spellProcess = GetZone()->GetSpellProcess();
  5526. for (itr = passive_spells.begin(); itr != passive_spells.end(); itr++)
  5527. {
  5528. spell2 = GetSpellBookSpell((*itr));
  5529. spell = master_spell_list.GetSpell(spell2->spell_id, spell2->tier);
  5530. if (spell) {
  5531. spellProcess->CastPassives(spell, this);
  5532. }
  5533. }
  5534. }
  5535. void Player::RemovePassive(int32 id, int8 tier, bool remove_from_list)
  5536. {
  5537. Spell* spell = 0;
  5538. spell = master_spell_list.GetSpell(id, tier);
  5539. if (spell) {
  5540. SpellProcess* spellProcess = 0;
  5541. spellProcess = GetZone()->GetSpellProcess();
  5542. spellProcess->CastPassives(spell, this, true);
  5543. if (remove_from_list) {
  5544. vector<int32>::iterator remove;
  5545. remove = find(passive_spells.begin(), passive_spells.end(), id);
  5546. if (remove != passive_spells.end())
  5547. passive_spells.erase(remove);
  5548. }
  5549. database.DeleteCharacterSpell(GetCharacterID(), spell->GetSpellID());
  5550. }
  5551. }
  5552. void Player::RemoveAllPassives()
  5553. {
  5554. vector<int32>::iterator itr;
  5555. for (itr = passive_spells.begin(); itr != passive_spells.end(); itr++)
  5556. RemoveSpellBookEntry((*itr), false);
  5557. passive_spells.clear();
  5558. }
  5559. void Player::ResetPetInfo() {
  5560. GetInfoStruct()->set_pet_id(0xFFFFFFFF);
  5561. GetInfoStruct()->set_pet_name(std::string("No Pet"));
  5562. GetInfoStruct()->set_pet_movement(0);
  5563. GetInfoStruct()->set_pet_behavior(0);
  5564. GetInfoStruct()->set_pet_health_pct(0.0f);
  5565. GetInfoStruct()->set_pet_power_pct(0.0f);
  5566. // Make sure the values get sent to the client
  5567. SetCharSheetChanged(true);
  5568. }
  5569. bool Player::HasRecipeBook(int32 recipe_id){
  5570. return recipebook_list.HasRecipeBook(recipe_id);
  5571. }
  5572. bool Player::DiscoveredLocation(int32 locationID) {
  5573. bool ret = false;
  5574. // No discovery type entry then return false
  5575. if (m_characterHistory.count(HISTORY_TYPE_DISCOVERY) == 0)
  5576. return false;
  5577. // Is a discovery type entry but not a location subtype return false
  5578. if (m_characterHistory[HISTORY_TYPE_DISCOVERY].count(HISTORY_SUBTYPE_LOCATION) == 0)
  5579. return false;
  5580. vector<HistoryData*>::iterator itr;
  5581. for (itr = m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].begin(); itr != m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].end(); itr++) {
  5582. if ((*itr)->Value == locationID) {
  5583. ret = true;
  5584. break;
  5585. }
  5586. }
  5587. return ret;
  5588. }
  5589. void Player::UpdatePlayerHistory(int8 type, int8 subtype, int32 value, int32 value2) {
  5590. switch (type) {
  5591. case HISTORY_TYPE_NONE:
  5592. HandleHistoryNone(subtype, value, value2);
  5593. break;
  5594. case HISTORY_TYPE_DEATH:
  5595. HandleHistoryDeath(subtype, value, value2);
  5596. break;
  5597. case HISTORY_TYPE_DISCOVERY:
  5598. HandleHistoryDiscovery(subtype, value, value2);
  5599. break;
  5600. case HISTORY_TYPE_XP:
  5601. HandleHistoryXP(subtype, value, value2);
  5602. break;
  5603. default:
  5604. // Not a valid history event so return out before trying to save into the db
  5605. return;
  5606. }
  5607. }
  5608. void Player::HandleHistoryNone(int8 subtype, int32 value, int32 value2) {
  5609. }
  5610. void Player::HandleHistoryDeath(int8 subtype, int32 value, int32 value2) {
  5611. }
  5612. void Player::HandleHistoryDiscovery(int8 subtype, int32 value, int32 value2) {
  5613. switch (subtype) {
  5614. case HISTORY_SUBTYPE_NONE:
  5615. break;
  5616. case HISTORY_SUBTYPE_ADVENTURE:
  5617. break;
  5618. case HISTORY_SUBTYPE_TRADESKILL:
  5619. break;
  5620. case HISTORY_SUBTYPE_QUEST:
  5621. break;
  5622. case HISTORY_SUBTYPE_AA:
  5623. break;
  5624. case HISTORY_SUBTYPE_ITEM:
  5625. break;
  5626. case HISTORY_SUBTYPE_LOCATION: {
  5627. HistoryData* hd = new HistoryData;
  5628. hd->Value = value;
  5629. hd->Value2 = value2;
  5630. hd->EventDate = Timer::GetUnixTimeStamp();
  5631. strcpy(hd->Location, GetZone()->GetZoneName());
  5632. m_characterHistory[HISTORY_TYPE_DISCOVERY][HISTORY_SUBTYPE_LOCATION].push_back(hd);
  5633. break;
  5634. }
  5635. default:
  5636. // Invalid subtype, default to NONE
  5637. break;
  5638. }
  5639. }
  5640. void Player::HandleHistoryXP(int8 subtype, int32 value, int32 value2) {
  5641. switch (subtype) {
  5642. case HISTORY_SUBTYPE_NONE:
  5643. break;
  5644. case HISTORY_SUBTYPE_ADVENTURE: {
  5645. HistoryData* hd = new HistoryData;
  5646. hd->Value = value;
  5647. hd->Value2 = value2;
  5648. hd->EventDate = Timer::GetUnixTimeStamp();
  5649. strcpy(hd->Location, GetZone()->GetZoneName());
  5650. m_characterHistory[HISTORY_TYPE_XP][HISTORY_SUBTYPE_ADVENTURE].push_back(hd);
  5651. }
  5652. break;
  5653. case HISTORY_SUBTYPE_TRADESKILL:
  5654. break;
  5655. case HISTORY_SUBTYPE_QUEST:
  5656. break;
  5657. case HISTORY_SUBTYPE_AA:
  5658. break;
  5659. case HISTORY_SUBTYPE_ITEM:
  5660. break;
  5661. case HISTORY_SUBTYPE_LOCATION:
  5662. break;
  5663. default:
  5664. // Invalid subtype, default to NONE
  5665. break;
  5666. }
  5667. }
  5668. void Player::LoadPlayerHistory(int8 type, int8 subtype, HistoryData* hd) {
  5669. m_characterHistory[type][subtype].push_back(hd);
  5670. }
  5671. void Player::SaveHistory() {
  5672. LogWrite(PLAYER__DEBUG, 0, "Player", "Saving History for Player: '%s'", GetName());
  5673. map<int8, map<int8, vector<HistoryData*> > >::iterator itr;
  5674. map<int8, vector<HistoryData*> >::iterator itr2;
  5675. vector<HistoryData*>::iterator itr3;
  5676. for (itr = m_characterHistory.begin(); itr != m_characterHistory.end(); itr++) {
  5677. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  5678. for (itr3 = itr2->second.begin(); itr3 != itr2->second.end(); itr3++) {
  5679. database.SaveCharacterHistory(this, itr->first, itr2->first, (*itr3)->Value, (*itr3)->Value2, (*itr3)->Location, (*itr3)->EventDate);
  5680. }
  5681. }
  5682. }
  5683. }
  5684. void Player::InitXPTable() {
  5685. m_levelXPReq[2] = 600;
  5686. m_levelXPReq[3] = 800;
  5687. m_levelXPReq[4] = 1000;
  5688. m_levelXPReq[5] = 1400;
  5689. m_levelXPReq[6] = 1800;
  5690. m_levelXPReq[7] = 2200;
  5691. m_levelXPReq[8] = 2600;
  5692. m_levelXPReq[9] = 3000;
  5693. m_levelXPReq[10] = 3400;
  5694. m_levelXPReq[11] = 3800;
  5695. m_levelXPReq[12] = 4200;
  5696. m_levelXPReq[13] = 4600;
  5697. m_levelXPReq[14] = 5000;
  5698. m_levelXPReq[15] = 5500;
  5699. m_levelXPReq[16] = 6000;
  5700. m_levelXPReq[17] = 6500;
  5701. m_levelXPReq[18] = 7000;
  5702. m_levelXPReq[19] = 7500;
  5703. m_levelXPReq[20] = 8000;
  5704. m_levelXPReq[21] = 8500;
  5705. m_levelXPReq[22] = 9000;
  5706. m_levelXPReq[23] = 9500;
  5707. m_levelXPReq[24] = 10000;
  5708. m_levelXPReq[25] = 10500;
  5709. m_levelXPReq[26] = 11000;
  5710. m_levelXPReq[27] = 11750;
  5711. m_levelXPReq[28] = 12500;
  5712. m_levelXPReq[29] = 13250;
  5713. m_levelXPReq[30] = 14000;
  5714. m_levelXPReq[31] = 14750;
  5715. m_levelXPReq[32] = 15500;
  5716. m_levelXPReq[33] = 16250;
  5717. m_levelXPReq[34] = 17000;
  5718. m_levelXPReq[35] = 17750;
  5719. m_levelXPReq[36] = 18500;
  5720. m_levelXPReq[37] = 19250;
  5721. m_levelXPReq[38] = 20000;
  5722. m_levelXPReq[39] = 20750;
  5723. m_levelXPReq[40] = 21500;
  5724. m_levelXPReq[41] = 22250;
  5725. m_levelXPReq[42] = 23000;
  5726. m_levelXPReq[43] = 24000;
  5727. m_levelXPReq[44] = 25000;
  5728. m_levelXPReq[45] = 26000;
  5729. m_levelXPReq[46] = 27000;
  5730. m_levelXPReq[47] = 28000;
  5731. m_levelXPReq[48] = 29250;
  5732. m_levelXPReq[49] = 30500;
  5733. m_levelXPReq[50] = 32000;
  5734. m_levelXPReq[51] = 33750;
  5735. m_levelXPReq[52] = 35750;
  5736. m_levelXPReq[53] = 38000;
  5737. m_levelXPReq[54] = 40500;
  5738. m_levelXPReq[55] = 42500;
  5739. m_levelXPReq[56] = 45500;
  5740. m_levelXPReq[57] = 48500;
  5741. m_levelXPReq[58] = 51500;
  5742. m_levelXPReq[59] = 54500;
  5743. m_levelXPReq[60] = 57500;
  5744. m_levelXPReq[61] = 60500;
  5745. m_levelXPReq[62] = 63500;
  5746. m_levelXPReq[63] = 66500;
  5747. m_levelXPReq[64] = 70000;
  5748. m_levelXPReq[65] = 73500;
  5749. m_levelXPReq[66] = 77000;
  5750. m_levelXPReq[67] = 80500;
  5751. m_levelXPReq[68] = 84000;
  5752. m_levelXPReq[69] = 87500;
  5753. m_levelXPReq[70] = 91000;
  5754. m_levelXPReq[71] = 94500;
  5755. m_levelXPReq[72] = 98000;
  5756. m_levelXPReq[73] = 101500;
  5757. m_levelXPReq[74] = 105000;
  5758. m_levelXPReq[75] = 108500;
  5759. m_levelXPReq[76] = 116500;
  5760. m_levelXPReq[77] = 132500;
  5761. m_levelXPReq[78] = 152500;
  5762. m_levelXPReq[79] = 172500;
  5763. m_levelXPReq[80] = 192500;
  5764. m_levelXPReq[81] = 212500;
  5765. m_levelXPReq[82] = 232500;
  5766. m_levelXPReq[83] = 252500;
  5767. m_levelXPReq[84] = 272500;
  5768. m_levelXPReq[85] = 292500;
  5769. m_levelXPReq[86] = 312500;
  5770. m_levelXPReq[87] = 332500;
  5771. m_levelXPReq[88] = 352500;
  5772. m_levelXPReq[89] = 372500;
  5773. m_levelXPReq[90] = 392500;
  5774. m_levelXPReq[91] = 863550;
  5775. m_levelXPReq[92] = 949905;
  5776. m_levelXPReq[93] = 1044895;
  5777. m_levelXPReq[94] = 1149385;
  5778. m_levelXPReq[95] = 1264323;
  5779. }
  5780. void Player::SendQuestRequiredSpawns(int32 quest_id){
  5781. bool locked = true;
  5782. m_playerSpawnQuestsRequired.readlock(__FUNCTION__, __LINE__);
  5783. if (player_spawn_quests_required.size() > 0 ) {
  5784. ZoneServer* zone = GetZone();
  5785. Client* client = zone->GetClientBySpawn(this);
  5786. if (!client){
  5787. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5788. return;
  5789. }
  5790. int xxx = player_spawn_quests_required.count(quest_id);
  5791. if (player_spawn_quests_required.count(quest_id) > 0){
  5792. vector<int32> spawns = *player_spawn_quests_required[quest_id];
  5793. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5794. Spawn* spawn = 0;
  5795. vector<int32>::iterator itr;
  5796. for (itr = spawns.begin(); itr != spawns.end();){
  5797. spawn = zone->GetSpawnByID(*itr);
  5798. if (spawn)
  5799. zone->SendSpawnChanges(spawn, client, false, true);
  5800. else {
  5801. itr = spawns.erase(itr);
  5802. continue;
  5803. }
  5804. itr++;
  5805. }
  5806. locked = false;
  5807. }
  5808. }
  5809. if (locked)
  5810. m_playerSpawnQuestsRequired.releasereadlock(__FUNCTION__, __LINE__);
  5811. }
  5812. void Player::SendHistoryRequiredSpawns(int32 event_id){
  5813. bool locked = true;
  5814. m_playerSpawnHistoryRequired.readlock(__FUNCTION__, __LINE__);
  5815. if (player_spawn_history_required.size() > 0) {
  5816. ZoneServer* zone = GetZone();
  5817. Client* client = zone->GetClientBySpawn(this);
  5818. if (!client){
  5819. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5820. return;
  5821. }
  5822. if (player_spawn_history_required.count(event_id) > 0){
  5823. vector<int32> spawns = *player_spawn_history_required[event_id];
  5824. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5825. Spawn* spawn = 0;
  5826. vector<int32>::iterator itr;
  5827. for (itr = spawns.begin(); itr != spawns.end();){
  5828. spawn = zone->GetSpawnByID(*itr);
  5829. if (spawn)
  5830. zone->SendSpawnChanges(spawn, client, false, true);
  5831. else {
  5832. itr = spawns.erase(itr);
  5833. continue;
  5834. }
  5835. itr++;
  5836. }
  5837. locked = false;
  5838. }
  5839. }
  5840. if (locked)
  5841. m_playerSpawnHistoryRequired.releasereadlock(__FUNCTION__, __LINE__);
  5842. }
  5843. void Player::AddQuestRequiredSpawn(Spawn* spawn, int32 quest_id){
  5844. if(!spawn || !quest_id)
  5845. return;
  5846. m_playerSpawnQuestsRequired.writelock(__FUNCTION__, __LINE__);
  5847. if(player_spawn_quests_required.count(quest_id) == 0)
  5848. player_spawn_quests_required[quest_id] = new vector<int32>;
  5849. vector<int32>* quest_spawns = player_spawn_quests_required[quest_id];
  5850. int32 current_spawn = 0;
  5851. for(int32 i=0;i<quest_spawns->size();i++){
  5852. current_spawn = quest_spawns->at(i);
  5853. if (current_spawn == spawn->GetID()){
  5854. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5855. return;
  5856. }
  5857. }
  5858. player_spawn_quests_required[quest_id]->push_back(spawn->GetID());
  5859. m_playerSpawnQuestsRequired.releasewritelock(__FUNCTION__, __LINE__);
  5860. }
  5861. void Player::AddHistoryRequiredSpawn(Spawn* spawn, int32 event_id){
  5862. if (!spawn || !event_id)
  5863. return;
  5864. m_playerSpawnHistoryRequired.writelock(__FUNCTION__, __LINE__);
  5865. if (player_spawn_history_required.count(event_id) == 0)
  5866. player_spawn_history_required[event_id] = new vector<int32>;
  5867. vector<int32>* history_spawns = player_spawn_history_required[event_id];
  5868. vector<int32>::iterator itr = find(history_spawns->begin(), history_spawns->end(), spawn->GetID());
  5869. if (itr == history_spawns->end())
  5870. history_spawns->push_back(spawn->GetID());
  5871. m_playerSpawnHistoryRequired.releasewritelock(__FUNCTION__, __LINE__);
  5872. }
  5873. int32 PlayerInfo::GetBoatSpawn(){
  5874. return boat_spawn;
  5875. }
  5876. void PlayerInfo::SetBoatSpawn(Spawn* spawn){
  5877. if(spawn)
  5878. boat_spawn = spawn->GetID();
  5879. else
  5880. boat_spawn = 0;
  5881. }
  5882. void PlayerInfo::RemoveOldPackets(){
  5883. safe_delete_array(changes);
  5884. safe_delete_array(orig_packet);
  5885. safe_delete_array(pet_changes);
  5886. safe_delete_array(pet_orig_packet);
  5887. changes = 0;
  5888. orig_packet = 0;
  5889. pet_changes = 0;
  5890. pet_orig_packet = 0;
  5891. }
  5892. PlayerControlFlags::PlayerControlFlags(){
  5893. MControlFlags.SetName("PlayerControlFlags::MControlFlags");
  5894. MFlagChanges.SetName("PlayerControlFlags::MFlagChanges");
  5895. flags_changed = false;
  5896. flag_changes.clear();
  5897. current_flags.clear();
  5898. }
  5899. PlayerControlFlags::~PlayerControlFlags(){
  5900. flag_changes.clear();
  5901. current_flags.clear();
  5902. }
  5903. bool PlayerControlFlags::ControlFlagsChanged(){
  5904. bool ret;
  5905. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5906. ret = flags_changed;
  5907. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5908. return ret;
  5909. }
  5910. void PlayerControlFlags::SetPlayerControlFlag(int8 param, int8 param_value, bool is_active){
  5911. if (!param || !param_value)
  5912. return;
  5913. bool active_changed = false;
  5914. MControlFlags.writelock(__FUNCTION__, __LINE__);
  5915. active_changed = (current_flags[param][param_value] != is_active);
  5916. if (active_changed){
  5917. current_flags[param][param_value] = is_active;
  5918. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5919. flag_changes[param][param_value] = is_active ? 1 : 0;
  5920. flags_changed = true;
  5921. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5922. }
  5923. MControlFlags.releasewritelock(__FUNCTION__, __LINE__);
  5924. }
  5925. void PlayerControlFlags::SendControlFlagUpdates(Client* client){
  5926. if (!client)
  5927. return;
  5928. map<int8, int8>* ptr = 0;
  5929. map<int8, map<int8, int8> >::iterator itr;
  5930. map<int8, int8>::iterator itr2;
  5931. MFlagChanges.writelock(__FUNCTION__, __LINE__);
  5932. for (itr = flag_changes.begin(); itr != flag_changes.end(); itr++){
  5933. ptr = &itr->second;
  5934. for (itr2 = ptr->begin(); itr2 != ptr->end(); itr2++){
  5935. ClientPacketFunctions::SendServerControlFlags(client, itr->first, itr2->first, itr2->second);
  5936. }
  5937. }
  5938. flag_changes.clear();
  5939. flags_changed = false;
  5940. MFlagChanges.releasewritelock(__FUNCTION__, __LINE__);
  5941. }
  5942. bool Player::ControlFlagsChanged(){
  5943. return control_flags.ControlFlagsChanged();
  5944. }
  5945. void Player::SetPlayerControlFlag(int8 param, int8 param_value, bool is_active){
  5946. control_flags.SetPlayerControlFlag(param, param_value, is_active);
  5947. }
  5948. void Player::SendControlFlagUpdates(Client* client){
  5949. control_flags.SendControlFlagUpdates(client);
  5950. }
  5951. void Player::LoadLUAHistory(int32 event_id, LUAHistory* history) {
  5952. mLUAHistory.writelock();
  5953. if (m_charLuaHistory.count(event_id) > 0) {
  5954. LogWrite(PLAYER__ERROR, 0, "Player", "Attempted to added a dupicate event (%u) to character LUA history", event_id);
  5955. safe_delete(history);
  5956. mLUAHistory.releasewritelock();
  5957. return;
  5958. }
  5959. m_charLuaHistory.insert(make_pair(event_id,history));
  5960. mLUAHistory.releasewritelock();
  5961. }
  5962. void Player::SaveLUAHistory() {
  5963. mLUAHistory.readlock();
  5964. LogWrite(PLAYER__DEBUG, 0, "Player", "Saving LUA History for Player: '%s'", GetName());
  5965. map<int32, LUAHistory*>::iterator itr;
  5966. for (itr = m_charLuaHistory.begin(); itr != m_charLuaHistory.end(); itr++) {
  5967. if (itr->second->SaveNeeded) {
  5968. database.SaveCharacterLUAHistory(this, itr->first, itr->second->Value, itr->second->Value2);
  5969. itr->second->SaveNeeded = false;
  5970. }
  5971. }
  5972. mLUAHistory.releasereadlock();
  5973. }
  5974. void Player::UpdateLUAHistory(int32 event_id, int32 value, int32 value2) {
  5975. mLUAHistory.writelock();
  5976. LUAHistory* hd = 0;
  5977. if (m_charLuaHistory.count(event_id) > 0)
  5978. hd = m_charLuaHistory[event_id];
  5979. else {
  5980. hd = new LUAHistory;
  5981. m_charLuaHistory.insert(make_pair(event_id,hd));
  5982. }
  5983. hd->Value = value;
  5984. hd->Value2 = value2;
  5985. hd->SaveNeeded = true;
  5986. mLUAHistory.releasewritelock();
  5987. // release the mLUAHistory lock, we will maintain a readlock to avoid any further writes until we complete SendHistoryRequiredSpawns
  5988. // through Spawn::SendSpawnChanges -> Spawn::InitializeVisPacketData -> Spawn::MeetsSpawnAccessRequirements-> Player::GetLUAHistory (this was causing a deadlock)
  5989. mLUAHistory.readlock();
  5990. SendHistoryRequiredSpawns(event_id);
  5991. mLUAHistory.releasereadlock();
  5992. }
  5993. LUAHistory* Player::GetLUAHistory(int32 event_id) {
  5994. LUAHistory* ret = 0;
  5995. mLUAHistory.readlock();
  5996. if (m_charLuaHistory.count(event_id) > 0)
  5997. ret = m_charLuaHistory[event_id];
  5998. mLUAHistory.releasereadlock();
  5999. return ret;
  6000. }
  6001. bool Player::CanSeeInvis(Entity* target)
  6002. {
  6003. if (!target->IsStealthed() && !target->IsInvis())
  6004. return true;
  6005. if (target->IsStealthed() && HasSeeHideSpell())
  6006. return true;
  6007. else if (target->IsInvis() && HasSeeInvisSpell())
  6008. return true;
  6009. sint32 radius = rule_manager.GetGlobalRule(R_PVP, InvisPlayerDiscoveryRange)->GetSInt32();
  6010. if (radius == 0) // radius of 0 is always seen
  6011. return true;
  6012. // 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
  6013. else if (radius > -1 && this->GetDistance((Spawn*)target) < (float)radius)
  6014. return true;
  6015. // TODO: Implement See Invis Spells! http://cutpon.com:3000/devn00b/EQ2EMu/issues/43
  6016. Item* item = 0;
  6017. vector<Item*>* equipped_list = GetEquippedItemList();
  6018. bool seeInvis = false;
  6019. bool seeStealth = false;
  6020. for (int32 i = 0; i < equipped_list->size(); i++)
  6021. {
  6022. item = equipped_list->at(i);
  6023. seeInvis = item->HasStat(ITEM_STAT_SEEINVIS);
  6024. seeStealth = item->HasStat(ITEM_STAT_SEESTEALTH);
  6025. if (target->IsStealthed() && seeStealth)
  6026. return true;
  6027. else if (target->IsInvis() && seeInvis)
  6028. return true;
  6029. }
  6030. return false;
  6031. }
  6032. // returns true if we need to update target info due to see invis status change
  6033. bool Player::CheckChangeInvisHistory(Entity* target)
  6034. {
  6035. std::map<int32, bool>::iterator it;
  6036. it = target_invis_history.find(target->GetID());
  6037. if (it != target_invis_history.end())
  6038. {
  6039. //canSeeStatus
  6040. if (it->second)
  6041. {
  6042. if (!this->CanSeeInvis(target))
  6043. {
  6044. UpdateTargetInvisHistory(target->GetID(), false);
  6045. return true;
  6046. }
  6047. else
  6048. return false;
  6049. }
  6050. else
  6051. {
  6052. if (this->CanSeeInvis(target))
  6053. {
  6054. UpdateTargetInvisHistory(target->GetID(), true);
  6055. return true;
  6056. }
  6057. else
  6058. return false;
  6059. }
  6060. }
  6061. if (!this->CanSeeInvis(target))
  6062. UpdateTargetInvisHistory(target->GetID(), false);
  6063. else
  6064. UpdateTargetInvisHistory(target->GetID(), true);
  6065. return true;
  6066. }
  6067. void Player::UpdateTargetInvisHistory(int32 targetID, bool canSeeStatus)
  6068. {
  6069. target_invis_history[targetID] = canSeeStatus;
  6070. }
  6071. void Player::RemoveTargetInvisHistory(int32 targetID)
  6072. {
  6073. target_invis_history.erase(targetID);
  6074. }
  6075. bool Player::SetSpawnMap(Spawn* spawn)
  6076. {
  6077. if(!client->GetPlayer()->SetSpawnSentState(spawn, SpawnState::SPAWN_STATE_SENDING)) {
  6078. /*index_mutex.writelock(__FUNCTION__, __LINE__);
  6079. spawn_id += 1;
  6080. if (spawn_index == 255)
  6081. spawn_index += 1; //just so we dont have to worry about overloading
  6082. map<int32, Spawn*>::iterator itr = player_spawn_id_map.find(player_spawn_reverse_id_map[this]);
  6083. if(itr != player_spawn_id_map.end()) {
  6084. player_spawn_id_map.erase(itr);
  6085. }
  6086. player_spawn_id_map[spawn_id] = spawn;
  6087. player_spawn_reverse_id_map[this] = spawn_id;
  6088. index_mutex.releasewritelock(__FUNCTION__, __LINE__);*/
  6089. return false;
  6090. }
  6091. index_mutex.writelock(__FUNCTION__, __LINE__);
  6092. spawn_id += 1;
  6093. if (spawn_index == 255)
  6094. spawn_index += 1; //just so we dont have to worry about overloading
  6095. int32 tmp_id = spawn_id;
  6096. player_spawn_id_map[tmp_id] = spawn;
  6097. if(player_spawn_reverse_id_map.count(spawn))
  6098. player_spawn_reverse_id_map.erase(spawn);
  6099. player_spawn_reverse_id_map.insert(make_pair(spawn,tmp_id));
  6100. index_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6101. return true;
  6102. }
  6103. NPC* Player::InstantiateSpiritShard(float origX, float origY, float origZ, float origHeading, int32 origGridID, ZoneServer* origZone)
  6104. {
  6105. NPC* npc = new NPC();
  6106. string newName(GetName());
  6107. newName.append("'s spirit shard");
  6108. strcpy(npc->appearance.name, newName.c_str());
  6109. /*vector<EntityCommand*>* primary_command_list = zone->GetEntityCommandList(result.GetInt32(9));
  6110. vector<EntityCommand*>* secondary_command_list = zone->GetEntityCommandList(result.GetInt32(10));
  6111. if(primary_command_list){
  6112. npc->SetPrimaryCommands(primary_command_list);
  6113. npc->primary_command_list_id = result.GetInt32(9);
  6114. }
  6115. if(secondary_command_list){
  6116. npc->SetSecondaryCommands(secondary_command_list);
  6117. npc->secondary_command_list_id = result.GetInt32(10);
  6118. }*/
  6119. npc->appearance.level = GetLevel();
  6120. npc->appearance.race = GetRace();
  6121. npc->appearance.gender = GetGender();
  6122. npc->appearance.adventure_class = GetAdventureClass();
  6123. npc->appearance.model_type = GetModelType();
  6124. npc->appearance.soga_model_type = GetSogaModelType();
  6125. npc->appearance.display_name = 1;
  6126. npc->features.hair_type = GetHairType();
  6127. npc->features.hair_face_type = GetFacialHairType();
  6128. npc->features.wing_type = GetWingType();
  6129. npc->features.chest_type = GetChestType();
  6130. npc->features.legs_type = GetLegsType();
  6131. npc->features.soga_hair_type = GetSogaHairType();
  6132. npc->features.soga_hair_face_type = GetSogaFacialHairType();
  6133. npc->appearance.attackable = 0;
  6134. npc->appearance.show_level = 1;
  6135. npc->appearance.targetable = 1;
  6136. npc->appearance.show_command_icon = 1;
  6137. npc->appearance.display_hand_icon = 0;
  6138. npc->appearance.hide_hood = GetHideHood();
  6139. npc->size = GetSize();
  6140. npc->appearance.pos.collision_radius = appearance.pos.collision_radius;
  6141. npc->appearance.action_state = appearance.action_state;
  6142. npc->appearance.visual_state = 6193; // ghostly look
  6143. npc->appearance.mood_state = appearance.mood_state;
  6144. npc->appearance.emote_state = appearance.emote_state;
  6145. npc->appearance.pos.state = appearance.pos.state;
  6146. npc->appearance.activity_status = appearance.activity_status;
  6147. strncpy(npc->appearance.sub_title, appearance.sub_title, sizeof(npc->appearance.sub_title));
  6148. npc->SetPrefixTitle(GetPrefixTitle());
  6149. npc->SetSuffixTitle(GetSuffixTitle());
  6150. npc->SetLastName(GetLastName());
  6151. npc->SetX(origX);
  6152. npc->SetY(origY);
  6153. npc->SetZ(origZ);
  6154. npc->SetHeading(origHeading);
  6155. npc->SetSpawnOrigX(origX);
  6156. npc->SetSpawnOrigY(origY);
  6157. npc->SetSpawnOrigZ(origZ);
  6158. npc->SetSpawnOrigHeading(origHeading);
  6159. npc->appearance.pos.grid_id = origGridID;
  6160. const char* script = rule_manager.GetGlobalRule(R_Combat, SpiritShardSpawnScript)->GetString();
  6161. int32 dbid = database.CreateSpiritShard(newName.c_str(), GetLevel(), GetRace(), GetGender(), GetAdventureClass(), GetModelType(), GetSogaModelType(),
  6162. GetHairType(), GetFacialHairType(), GetWingType(), GetChestType(), GetLegsType(), GetSogaHairType(), GetSogaFacialHairType(), GetHideHood(),
  6163. GetSize(), npc->appearance.pos.collision_radius, npc->appearance.action_state, npc->appearance.visual_state, npc->appearance.mood_state,
  6164. npc->appearance.emote_state, npc->appearance.pos.state, npc->appearance.activity_status, npc->appearance.sub_title, GetPrefixTitle(), GetSuffixTitle(),
  6165. GetLastName(), origX, origY, origZ, origHeading, origGridID, GetCharacterID(), origZone->GetZoneID(), origZone->GetInstanceID());
  6166. npc->SetShardID(dbid);
  6167. npc->SetShardCharID(GetCharacterID());
  6168. npc->SetShardCreatedTimestamp(Timer::GetCurrentTime2());
  6169. if(script)
  6170. npc->SetSpawnScript(script);
  6171. return npc;
  6172. }
  6173. void Player::SaveSpellEffects()
  6174. {
  6175. if(stop_save_spell_effects)
  6176. {
  6177. LogWrite(PLAYER__WARNING, 0, "Player", "SaveSpellEffects called while player constructing / deconstructing!");
  6178. return;
  6179. }
  6180. SpellProcess* spellProcess = 0;
  6181. // Get the current zones spell process
  6182. spellProcess = GetZone()->GetSpellProcess();
  6183. Query savedEffects;
  6184. savedEffects.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_spell_effects where charid=%u", GetCharacterID());
  6185. savedEffects.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_spell_effect_targets where caster_char_id=%u", GetCharacterID());
  6186. InfoStruct* info = GetInfoStruct();
  6187. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  6188. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  6189. for(int i = 0; i < 45; i++) {
  6190. if(info->spell_effects[i].spell_id != 0xFFFFFFFF)
  6191. {
  6192. Spawn* spawn = nullptr;
  6193. int32 target_char_id = 0;
  6194. if(info->spell_effects[i].spell->initial_target_char_id != 0)
  6195. target_char_id = info->spell_effects[i].spell->initial_target_char_id;
  6196. else if((spawn = GetZone()->GetSpawnByID(info->spell_effects[i].spell->initial_target)) != nullptr && spawn->IsPlayer())
  6197. target_char_id = ((Player*)spawn)->GetCharacterID();
  6198. int32 timestamp = 0xFFFFFFFF;
  6199. if(!info->spell_effects[i].spell->spell->GetSpellData()->duration_until_cancel)
  6200. timestamp = info->spell_effects[i].expire_timestamp - Timer::GetCurrentTime2();
  6201. int32 caster_char_id = info->spell_effects[i].spell->initial_caster_char_id;
  6202. if(caster_char_id == 0)
  6203. continue;
  6204. Query effectSave;
  6205. effectSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT,
  6206. "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')",
  6207. database.getSafeEscapeString(info->spell_effects[i].spell->spell->GetName()).c_str(), caster_char_id,
  6208. 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,
  6209. info->spell_effects[i].icon, info->spell_effects[i].icon_backdrop, 0 /* no conc_used for spell_effects */, info->spell_effects[i].tier,
  6210. 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(),
  6211. 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,
  6212. 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());
  6213. }
  6214. if (i < NUM_MAINTAINED_EFFECTS && info->maintained_effects[i].spell_id != 0xFFFFFFFF){
  6215. Spawn* spawn = GetZone()->GetSpawnByID(info->maintained_effects[i].spell->initial_target);
  6216. int32 target_char_id = 0;
  6217. if(info->maintained_effects[i].spell->initial_target_char_id != 0)
  6218. target_char_id = info->maintained_effects[i].spell->initial_target_char_id;
  6219. else if(!info->maintained_effects[i].spell->initial_target)
  6220. target_char_id = GetCharacterID();
  6221. else if(spawn && spawn->IsPlayer())
  6222. target_char_id = ((Player*)spawn)->GetCharacterID();
  6223. else if (spawn && spawn->IsPet() && ((Entity*)spawn)->GetOwner() == (Entity*)this)
  6224. target_char_id = 0xFFFFFFFF;
  6225. 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;
  6226. int32 timestamp = 0xFFFFFFFF;
  6227. if(!info->maintained_effects[i].spell->spell->GetSpellData()->duration_until_cancel)
  6228. timestamp = info->maintained_effects[i].expire_timestamp - Timer::GetCurrentTime2();
  6229. Query effectSave;
  6230. effectSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT,
  6231. "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')",
  6232. 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,
  6233. info->maintained_effects[i].icon, info->maintained_effects[i].icon_backdrop, info->maintained_effects[i].conc_used, info->maintained_effects[i].tier,
  6234. 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(),
  6235. 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,
  6236. 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());
  6237. info->maintained_effects[i].spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6238. 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 ");
  6239. bool firstTarget = true;
  6240. map<Spawn*, int8> targetsInserted;
  6241. for (int8 t = 0; t < info->maintained_effects[i].spell->targets.size(); t++) {
  6242. int32 spawn_id = info->maintained_effects[i].spell->targets.at(t);
  6243. Spawn* spawn = GetZone()->GetSpawnByID(spawn_id);
  6244. LogWrite(SPELL__DEBUG, 0, "Spell", "%s has target %u to identify for spell %s", GetName(), spawn_id, info->maintained_effects[i].spell->spell->GetName());
  6245. if(spawn && (spawn->IsPlayer() || spawn->IsPet()))
  6246. {
  6247. int32 tmpCharID = 0;
  6248. int8 type = 0;
  6249. if(targetsInserted.find(spawn) != targetsInserted.end())
  6250. continue;
  6251. if(spawn->IsPlayer())
  6252. tmpCharID = ((Player*)spawn)->GetCharacterID();
  6253. else if (spawn->IsPet() && ((Entity*)spawn)->GetOwner() == (Entity*)this)
  6254. {
  6255. tmpCharID = 0xFFFFFFFF;
  6256. }
  6257. else if(spawn->IsPet() && ((Entity*)spawn)->GetOwner() &&
  6258. ((Entity*)spawn)->GetOwner()->IsPlayer())
  6259. {
  6260. type = ((Entity*)spawn)->GetPetType();
  6261. Player* petOwner = (Player*)((Entity*)spawn)->GetOwner();
  6262. tmpCharID = petOwner->GetCharacterID();
  6263. }
  6264. if(!firstTarget)
  6265. insertTargets.append(", ");
  6266. targetsInserted.insert(make_pair(spawn, true));
  6267. 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());
  6268. insertTargets.append("(" + std::to_string(caster_char_id) + ", " + std::to_string(tmpCharID) + ", " + std::to_string(type) + ", " +
  6269. std::to_string(DB_TYPE_MAINTAINEDEFFECTS) + ", " + std::to_string(info->maintained_effects[i].spell_id) + ", " + std::to_string(i) +
  6270. ", " + std::to_string(info->maintained_effects[i].slot_pos) + ")");
  6271. firstTarget = false;
  6272. }
  6273. }
  6274. multimap<int32,int8>::iterator entries;
  6275. for(entries = info->maintained_effects[i].spell->char_id_targets.begin(); entries != info->maintained_effects[i].spell->char_id_targets.end(); entries++)
  6276. {
  6277. if(!firstTarget)
  6278. insertTargets.append(", ");
  6279. 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());
  6280. insertTargets.append("(" + std::to_string(caster_char_id) + ", " + std::to_string(entries->first) + ", " + std::to_string(entries->second) + ", " +
  6281. std::to_string(DB_TYPE_MAINTAINEDEFFECTS) + ", " + std::to_string(info->maintained_effects[i].spell_id) + ", " + std::to_string(i) +
  6282. ", " + std::to_string(info->maintained_effects[i].slot_pos) + ")");
  6283. firstTarget = false;
  6284. }
  6285. info->maintained_effects[i].spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6286. if(!firstTarget)
  6287. {
  6288. Query targetSave;
  6289. targetSave.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, insertTargets.c_str());
  6290. }
  6291. }
  6292. }
  6293. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  6294. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  6295. }
  6296. void Player::MentorTarget()
  6297. {
  6298. if(client->GetPlayer()->GetGroupMemberInfo() && client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id)
  6299. {
  6300. client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id = 0;
  6301. reset_mentorship = true;
  6302. client->Message(CHANNEL_COMMAND_TEXT, "You stop mentoring, and return to level %u.", client->GetPlayer()->GetLevel());
  6303. }
  6304. else if(!reset_mentorship && client->GetPlayer()->GetTarget())
  6305. {
  6306. if(client->GetPlayer()->GetTarget()->IsPlayer())
  6307. {
  6308. Player* tmpPlayer = (Player*)client->GetPlayer()->GetTarget();
  6309. if(tmpPlayer->GetGroupMemberInfo() && tmpPlayer->GetGroupMemberInfo()->mentor_target_char_id)
  6310. {
  6311. client->Message(CHANNEL_COMMAND_TEXT, "You cannot mentor %s at this time.",tmpPlayer->GetName());
  6312. return;
  6313. }
  6314. if(client->GetPlayer()->group_id > 0 && client->GetPlayer()->GetTarget()->group_id == client->GetPlayer()->group_id)
  6315. {
  6316. 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())
  6317. {
  6318. SetMentorStats(client->GetPlayer()->GetTarget()->GetLevel(), tmpPlayer->GetCharacterID());
  6319. client->Message(CHANNEL_COMMAND_TEXT, "You are now mentoring %s, reducing your effective level to %u.",client->GetPlayer()->GetTarget()->GetName(), client->GetPlayer()->GetTarget()->GetLevel());
  6320. }
  6321. if(client->GetPlayer()->GetTarget()->GetName() == client->GetPlayer()->GetName()) {
  6322. client->Message(CHANNEL_COMMAND_TEXT, "You cannot mentor yourself.");
  6323. }
  6324. }
  6325. }
  6326. }
  6327. }
  6328. void Player::SetMentorStats(int32 effective_level, int32 target_char_id)
  6329. {
  6330. RemoveSpells();
  6331. if(client->GetPlayer()->GetGroupMemberInfo())
  6332. client->GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id = target_char_id;
  6333. InfoStruct* info = GetInfoStruct();
  6334. info->set_effective_level(effective_level);
  6335. client->GetPlayer()->SetTotalHPBase(effective_level * effective_level * 2 + 40);
  6336. client->GetPlayer()->SetTotalPowerBase((sint32)(effective_level * effective_level * 2.1 + 45));
  6337. client->GetPlayer()->CalculateBonuses();
  6338. client->GetPlayer()->SetHP(GetTotalHP());
  6339. client->GetPlayer()->SetPower(GetTotalPower());
  6340. info->set_agi_base(effective_level * 2 + 15);
  6341. info->set_intel_base(effective_level * 2 + 15);
  6342. info->set_wis_base(effective_level * 2 + 15);
  6343. info->set_str_base(effective_level * 2 + 15);
  6344. info->set_sta_base(effective_level * 2 + 15);
  6345. info->set_cold_base((int16)(effective_level * 1.5 + 10));
  6346. info->set_heat_base((int16)(effective_level * 1.5 + 10));
  6347. info->set_disease_base((int16)(effective_level * 1.5 + 10));
  6348. info->set_mental_base((int16)(effective_level * 1.5 + 10));
  6349. info->set_magic_base((int16)(effective_level * 1.5 + 10));
  6350. info->set_divine_base((int16)(effective_level * 1.5 + 10));
  6351. info->set_poison_base((int16)(effective_level * 1.5 + 10));
  6352. GetClient()->ClearSentItemDetails();
  6353. if(GetClient())
  6354. {
  6355. EQ2Packet* app = GetEquipmentList()->serialize(GetClient()->GetVersion(), this);
  6356. if (app) {
  6357. GetClient()->QueuePacket(app);
  6358. }
  6359. }
  6360. GetEquipmentList()->SendEquippedItems(this);
  6361. }
  6362. void Player::SetLevel(int16 level, bool setUpdateFlags) {
  6363. if(!GetGroupMemberInfo() || GetGroupMemberInfo()->mentor_target_char_id == 0) {
  6364. GetInfoStruct()->set_effective_level(level);
  6365. }
  6366. SetInfo(&appearance.level, level, setUpdateFlags);
  6367. SetXP(0);
  6368. SetNeededXP();
  6369. }
  6370. bool Player::SerializeItemPackets(EquipmentItemList* equipList, vector<EQ2Packet*>* packets, Item* item, int16 version, Item* to_item) {
  6371. if(item_list.AddItem(item)) {
  6372. item->save_needed = true;
  6373. SetEquippedItemAppearances();
  6374. packets->push_back(equipList->serialize(version, this));
  6375. packets->push_back(item->serialize(version, false));
  6376. if(to_item)
  6377. packets->push_back(to_item->serialize(version, false, this));
  6378. packets->push_back(item_list.serialize(this, version));
  6379. return true;
  6380. }
  6381. else {
  6382. LogWrite(PLAYER__ERROR, 0, "Player", "failed to add item to item_list");
  6383. }
  6384. return false;
  6385. }
  6386. void Player::AddGMVisualFilter(int32 filter_type, int32 filter_value, char* filter_search_str, int16 visual_tag) {
  6387. if(MatchGMVisualFilter(filter_type, filter_value, filter_search_str) > 0)
  6388. return;
  6389. vis_mutex.writelock(__FUNCTION__, __LINE__);
  6390. GMTagFilter filter;
  6391. filter.filter_type = filter_type;
  6392. filter.filter_value = filter_value;
  6393. memset(filter.filter_search_criteria, 0, sizeof(filter.filter_search_criteria));
  6394. if(filter_search_str)
  6395. memcpy(&filter.filter_search_criteria, filter_search_str, strnlen(filter_search_str, sizeof(filter.filter_search_criteria)));
  6396. filter.visual_tag = visual_tag;
  6397. gm_visual_filters.push_back(filter);
  6398. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6399. }
  6400. int16 Player::MatchGMVisualFilter(int32 filter_type, int32 filter_value, char* filter_search_str, bool in_vismutex_lock) {
  6401. if(!in_vismutex_lock)
  6402. vis_mutex.readlock(__FUNCTION__, __LINE__);
  6403. int16 tag_id = 0;
  6404. vector<GMTagFilter>::iterator itr = gm_visual_filters.begin();
  6405. for(;itr != gm_visual_filters.end();itr++) {
  6406. if(itr->filter_type == filter_type && itr->filter_value == filter_value) {
  6407. if(filter_search_str && !strcasecmp(filter_search_str, itr->filter_search_criteria)) {
  6408. tag_id = itr->visual_tag;
  6409. break;
  6410. }
  6411. }
  6412. }
  6413. if(!in_vismutex_lock)
  6414. vis_mutex.releasereadlock(__FUNCTION__, __LINE__);
  6415. return tag_id;
  6416. }
  6417. void Player::ClearGMVisualFilters() {
  6418. vis_mutex.writelock(__FUNCTION__, __LINE__);
  6419. gm_visual_filters.clear();
  6420. vis_mutex.releasewritelock(__FUNCTION__, __LINE__);
  6421. }
  6422. int Player::GetPVPAlignment(){
  6423. int bind_zone = GetPlayerInfo()->GetBindZoneID();
  6424. int alignment = 0;
  6425. if(bind_zone && bind_zone != 0){
  6426. //0 is good.
  6427. //1 is evil.
  6428. //2 is neutral aka haven players.
  6429. switch(bind_zone){
  6430. //good zones
  6431. case 114: //Gfay
  6432. case 221: //Qeynos Harbor
  6433. case 222: //North Qeynos
  6434. case 231: //South Qeynos
  6435. case 233: //Nettleville
  6436. case 234: //Starcrest
  6437. case 235: //Graystone
  6438. case 236: //CastleView
  6439. case 237: //Willowood
  6440. case 238: //Baubbleshire
  6441. case 470: //Frostfang
  6442. case 589: //Qeynos Combined 1
  6443. case 660: //Qeynos Combined 2
  6444. alignment = 0; //good
  6445. break;
  6446. //evil zones
  6447. case 128: //East Freeport
  6448. case 134: //Big Bend
  6449. case 135: //Stonestair
  6450. case 136: //Temple St.
  6451. case 137: //Beggars Ct.
  6452. case 138: //Longshadow
  6453. case 139: //Scale Yard
  6454. case 144: //North Freeport
  6455. case 166: //South Freeport
  6456. case 168: //West Freeport
  6457. case 184: //Neriak
  6458. case 644: //BigBend2
  6459. case 645: //Stonestair2
  6460. case 646: //Temple St2
  6461. case 647: //Beggars Ct2
  6462. case 648: //LongShadow2
  6463. case 649: //Scale Yard2
  6464. alignment = 1; //evil
  6465. break;
  6466. //Neutral (MajDul?)
  6467. case 45: //haven
  6468. case 46: //MajDul
  6469. alignment = 2;
  6470. break;
  6471. default:
  6472. alignment = -1; //error
  6473. }
  6474. //return -1 (error), 0 (good), 1 (evil), or 2 (Neutral)
  6475. return alignment;
  6476. }
  6477. return -1; //error
  6478. }