Player.cpp 187 KB

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