Player.cpp 260 KB

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