Player.cpp 205 KB

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