Player.cpp 257 KB

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