Player.cpp 190 KB

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