Player.cpp 228 KB

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