Player.cpp 205 KB

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