Player.cpp 193 KB

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