Player.cpp 187 KB

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