9
3

Player.cpp 207 KB

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