Player.cpp 185 KB

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