Player.cpp 253 KB

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