Player.cpp 252 KB

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