Player.cpp 193 KB

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