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