Player.cpp 187 KB

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