Player.cpp 203 KB

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