1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "../common/debug.h"
- #include <iostream>
- using namespace std;
- #include <string.h>
- #include "../common/misc.h"
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <regex>
- #include "Commands/Commands.h"
- #include "Zone/pathfinder_interface.h"
- #ifdef WIN32
- #include <WinSock2.h>
- #include <windows.h>
- #include <dbghelp.h>
- #pragma comment(lib,"imagehlp.lib")
- #else
- #include <sys/socket.h>
- #include <sys/stat.h>
- #ifdef FREEBSD //Timothy Whitman - January 7, 2003
- #include <sys/types.h>
- #endif
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <errno.h>
- #include <pthread.h>
- #include <stdarg.h>
- #include "../common/unix.h"
- #define SOCKET_ERROR -1
- #define INVALID_SOCKET -1
- extern int errno;
- #endif
- #include "../common/servertalk.h"
- #include "../common/packet_dump.h"
- #include "WorldDatabase.h"
- #include "races.h"
- #include "classes.h"
- #include "../common/seperator.h"
- #include "../common/EQStream.h"
- #include "../common/EQStreamFactory.h"
- #include "../common/opcodemgr.h"
- #include "zoneserver.h"
- #include "client.h"
- #include "LoginServer.h"
- #include "World.h"
- #include <string>
- #include <assert.h>
- #include "LuaInterface.h"
- #include "Factions.h"
- #include "VisualStates.h"
- #include "ClientPacketFunctions.h"
- #include "SpellProcess.h"
- #include "../common/Log.h"
- #include "Rules/Rules.h"
- #include "Chat/Chat.h"
- #include "Tradeskills/Tradeskills.h"
- #include "RaceTypes/RaceTypes.h"
- #include <algorithm>
- #include <random>
- #include "Zone/SPGrid.h"
- #include "Bots/Bot.h"
- #ifdef WIN32
- #define strncasecmp _strnicmp
- #define strcasecmp _stricmp
- #endif
- // int32 numplayers = 0; // never used?
- // extern bool GetZoneLongName(char* short_name, char** long_name); // never used?
- // extern bool holdzones; // never used?
- // extern volatile bool RunLoops; // never used in the zone server?
- // extern Classes classes; // never used in the zone server?
- extern WorldDatabase database;
- extern sint32 numzones;
- extern ClientList client_list;
- extern LoginServer loginserver;
- extern ZoneList zone_list;
- extern World world;
- extern ConfigReader configReader;
- extern Commands commands;
- extern LuaInterface* lua_interface;
- extern MasterFactionList master_faction_list;
- extern VisualStates visual_states;
- extern RuleManager rule_manager;
- extern Chat chat;
- extern MasterRaceTypeList race_types_list;
- extern MasterSpellList master_spell_list; // temp - remove later
- extern MasterSkillList master_skill_list;
- int32 MinInstanceID = 1000;
- // JA: Moved most default values to Rules and risky initializers to ZoneServer::Init() - 2012.12.07
- ZoneServer::ZoneServer(const char* name) {
- depop_zone = false;
- repop_zone = false;
- respawns_allowed = true;
- instanceID = 0;
- strcpy(zone_name, name);
- zoneID = 0;
- rain = 0;
- cityzone = false;
- always_loaded = false;
- locked = false; // JA: implementing /zone lock|unlock commands
- pNumPlayers = 0;
- LoadingData = true;
- zoneShuttingDown = false;
- ++numzones;
- revive_points = 0;
- zone_motd = "";
- finished_depop = true;
- initial_spawn_threads_active = 0;
- minimumStatus = 0;
- minimumLevel = 0;
- maximumLevel = 0;
- minimumVersion = 0;
- weather_current_severity = 0;
- weather_signaled = false;
- xp_mod = 0;
- isDusk = false;
- dusk_hour = 0;
- dusk_minute = 0;
- dawn_hour = 0;
- dawn_minute = 0;
- reloading_spellprocess = false;
- expansion_flag = 0;
- holiday_flag = 0;
- MMasterZoneLock = new CriticalSection(MUTEX_ATTRIBUTE_RECURSIVE);
-
- pathing = nullptr;
- strcpy(zonesky_file,"");
-
- reloading = true;
- watchdogTimestamp = Timer::GetCurrentTime2();
- MPendingSpawnRemoval.SetName("ZoneServer::MPendingSpawnRemoval");
- }
- ZoneServer::~ZoneServer() {
- zoneShuttingDown = true; //ensure other threads shut down too
- //allow other threads to properly shut down
- while (spawnthread_active || initial_spawn_threads_active > 0){
- if (spawnthread_active)
- LogWrite(ZONE__DEBUG, 7, "Zone", "Zone shutdown waiting on spawn thread");
- if (initial_spawn_threads_active > 0)
- LogWrite(ZONE__DEBUG, 7, "Zone", "Zone shutdown waiting on initial spawn thread");
- Sleep(10);
- }
- LogWrite(ZONE__INFO, 0, "Zone", "Initiating zone shutdown of '%s'", zone_name);
- changed_spawns.clear();
- transport_spawns.clear();
- safe_delete(spellProcess);
- safe_delete(tradeskillMgr);
- MMasterZoneLock->lock();
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- DeleteData(true);
- RemoveLocationProximities();
- RemoveLocationGrids();
- DeleteSpawns(true);
-
- DeleteGlobalSpawns();
- DeleteFlightPaths();
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
- MMasterZoneLock->unlock();
- safe_delete(MMasterZoneLock);
- world.UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, -1);
- // If lockout, public, tradeskill, or quest instance delete from db when zone shuts down
- if (InstanceType == SOLO_LOCKOUT_INSTANCE || InstanceType == GROUP_LOCKOUT_INSTANCE || InstanceType == RAID_LOCKOUT_INSTANCE ||
- InstanceType == PUBLIC_INSTANCE || InstanceType == TRADESKILL_INSTANCE || InstanceType == QUEST_INSTANCE) {
- LogWrite(INSTANCE__DEBUG, 0, "Instance", "Non persistent instance shutting down, deleting instance");
- database.DeleteInstance(instanceID);
- }
- if (pathing != nullptr)
- delete pathing;
- if (movementMgr != nullptr)
- delete movementMgr;
- LogWrite(ZONE__INFO, 0, "Zone", "Completed zone shutdown of '%s'", zone_name);
- --numzones;
- UpdateWindowTitle(0);
- zone_list.Remove(this);
- }
- void ZoneServer::Init()
- {
- LogWrite(ZONE__INFO, 0, "Zone", "Loading new Zone '%s'", zone_name);
- zone_list.Add(this);
- spellProcess = new SpellProcess();
- tradeskillMgr = new TradeskillMgr();
- /* Dynamic Timers */
- regenTimer.Start(rule_manager.GetGlobalRule(R_Zone, RegenTimer)->GetInt32());
- client_save.Start(rule_manager.GetGlobalRule(R_Zone, ClientSaveTimer)->GetInt32());
- shutdownTimer.Disable();
- spawn_range.Start(rule_manager.GetGlobalRule(R_Zone, CheckAttackPlayer)->GetInt32());
- aggro_timer.Start(rule_manager.GetGlobalRule(R_Zone, CheckAttackNPC)->GetInt32());
- /* Weather stuff */
- InitWeather();
- /* Static Timers */
- // JA - haven't decided yet if these should remain hard-coded. Changing them could break EQ2Emu functionality
- spawn_check_add.Start(1000);
- spawn_check_remove.Start(30000);
- spawn_expire_timer.Start(10000);
- respawn_timer.Start(10000);
- // there was never a starter for these?
- widget_timer.Start(5000);
- tracking_timer.Start(5000);
- movement_timer.Start(100);
- location_prox_timer.Start(1000);
- location_grid_timer.Start(1000);
- charsheet_changes.Start(500);
- // Send game time packet every in game hour (180 sec)
- sync_game_time_timer.Start(180000);
- // Get the dusk and dawn time from the rule manager and store it in the correct variables
- sscanf (rule_manager.GetGlobalRule(R_World, DuskTime)->GetString(), "%d:%d", &dusk_hour, &dusk_minute);
- sscanf (rule_manager.GetGlobalRule(R_World, DawnTime)->GetString(), "%d:%d", &dawn_hour, &dawn_minute);
- spawn_update.Start(rule_manager.GetGlobalRule(R_Zone, SpawnUpdateTimer)->GetInt16());
- LogWrite(ZONE__DEBUG, 0, "Zone", "SpawnUpdateTimer: %ims", rule_manager.GetGlobalRule(R_Zone, SpawnUpdateTimer)->GetInt16());
- spawn_delete_timer = rule_manager.GetGlobalRule(R_Zone, SpawnDeleteTimer)->GetInt32();
- LogWrite(ZONE__DEBUG, 0, "Zone", "SpawnDeleteTimer: %ums", spawn_delete_timer);
- LogWrite(ZONE__DEBUG, 0, "Zone", "Loading zone flight paths");
- database.LoadZoneFlightPaths(this);
- world.UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, 1);
- UpdateWindowTitle(0);
- string zoneName(GetZoneFile());
-
- world.LoadRegionMaps(zoneName);
-
- world.LoadMaps(zoneName);
-
- pathing = IPathfinder::Load(zoneName);
- movementMgr = new MobMovementManager();
- MMasterSpawnLock.SetName("ZoneServer::MMasterSpawnLock");
- m_npc_faction_list.SetName("ZoneServer::npc_faction_list");
- m_enemy_faction_list.SetName("ZoneServer::enemy_faction_list");
- m_reverse_enemy_faction_list.SetName("ZoneServer::reverse_enemy_faction_list");
- MDeadSpawns.SetName("ZoneServer::dead_spawns");
- MTransportSpawns.SetName("ZoneServer::transport_spawns");
- MSpawnList.SetName("ZoneServer::spawn_list");
- MTransporters.SetName("ZoneServer::m_transportMaps");
- MSpawnGroupAssociation.SetName("ZoneServer::spawn_group_associations");
- MSpawnGroupLocations.SetName("ZoneServer::spawn_group_locations");
- MSpawnLocationGroups.SetName("ZoneServer::spawn_location_groups");
- MSpawnGroupChances.SetName("ZoneServer::spawn_group_chances");
- MTransportLocations.SetName("ZoneServer::transporter_locations");
- MSpawnLocationList.SetName("ZoneServer::spawn_location_list");
- MSpawnDeleteList.SetName("ZoneServer::spawn_delete_list");
- MSpawnScriptTimers.SetName("ZoneServer::spawn_script_timers");
- MRemoveSpawnScriptTimersList.SetName("ZoneServer::remove_spawn_script_timers_list");
- MClientList.SetName("ZoneServer::clients");
- MWidgetTimers.SetName("ZoneServer::widget_timers");
- #ifdef WIN32
- _beginthread(ZoneLoop, 0, this);
- _beginthread(SpawnLoop, 0, this);
- #else
- pthread_create(&ZoneThread, NULL, ZoneLoop, this);
- pthread_detach(ZoneThread);
- pthread_create(&SpawnThread, NULL, SpawnLoop, this);
- pthread_detach(SpawnThread);
- #endif
- }
- void ZoneServer::CancelThreads() {
- #ifdef WIN32
- LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung, however CancelThreads is unsupported for WIN32.", GetZoneName());
- #else
- pthread_cancel(ZoneThread);
- pthread_cancel(SpawnThread);
- #endif
- }
- void ZoneServer::InitWeather()
- {
- weather_enabled = rule_manager.GetGlobalRule(R_Zone, WeatherEnabled)->GetBool();
- if( weather_enabled && isWeatherAllowed())
- {
- string tmp;
- // set up weather system when zone starts up
- weather_type = rule_manager.GetGlobalRule(R_Zone, WeatherType)->GetInt8();
- switch(weather_type)
- {
- case 3: tmp = "Chaotic"; break;
- case 2: tmp = "Random"; break;
- case 1: tmp = "Dynamic"; break;
- default: tmp = "Normal"; break;
- }
- LogWrite(ZONE__DEBUG, 0, "Zone", "%s: Setting up '%s' weather", zone_name, tmp.c_str());
- weather_frequency = rule_manager.GetGlobalRule(R_Zone, WeatherChangeFrequency)->GetInt32();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Change weather every %u seconds", zone_name, weather_frequency);
- weather_change_chance = rule_manager.GetGlobalRule(R_Zone, WeatherChangeChance)->GetInt8();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Chance of weather change: %i%%", zone_name, weather_change_chance);
- weather_min_severity = rule_manager.GetGlobalRule(R_Zone, MinWeatherSeverity)->GetFloat();
- weather_max_severity = rule_manager.GetGlobalRule(R_Zone, MaxWeatherSeverity)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Severity min/max is %.2f - %.2f", zone_name, weather_min_severity, weather_max_severity);
- // Allow a random roll to determine if weather should start out severe or calm
- if( MakeRandomInt(1, 100) > 50)
- {
- weather_pattern = 1; // default weather to increase in severity initially
- weather_current_severity = weather_min_severity;
- }
- else
- {
- weather_pattern = 0; // default weather to decrease in severity initially
- weather_current_severity = weather_max_severity;
- }
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Severity set to %.2f, pattern: %i", zone_name, weather_current_severity, weather_pattern);
- weather_change_amount = rule_manager.GetGlobalRule(R_Zone, WeatherChangePerInterval)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather change by %.2f each interval", zone_name, weather_change_amount);
- if( weather_type > 0 )
- {
- weather_dynamic_offset = rule_manager.GetGlobalRule(R_Zone, WeatherDynamicMaxOffset)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Max Offset changes no more than %.2f each interval", zone_name, weather_dynamic_offset);
- }
- else
- weather_dynamic_offset = 0;
- SetRain(weather_current_severity);
- weather_last_changed_time = Timer::GetUnixTimeStamp();
- weatherTimer.Start(rule_manager.GetGlobalRule(R_Zone, WeatherTimer)->GetInt32());
- }
- }
- void ZoneServer::DeleteSpellProcess(){
- //Just get a lock to make sure we aren't already looping the spawnprocess or clientprocess if this is different than the calling thread
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- MMasterZoneLock->lock();
- reloading_spellprocess = true;
- // Remove spells from NPC's
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->IsNPC())
- ((NPC*)spawn)->SetSpells(0);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- MMasterZoneLock->unlock();
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
- DismissAllPets();
- safe_delete(spellProcess);
- }
- void ZoneServer::LoadSpellProcess(){
- spellProcess = new SpellProcess();
- reloading_spellprocess = false;
- // Reload NPC's spells
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->IsNPC())
- ((NPC*)spawn)->SetSpells(GetNPCSpells(((NPC*)spawn)->GetPrimarySpellList(), ((NPC*)spawn)->GetSecondarySpellList()));
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::LockAllSpells(Player* player) {
- if (player && spellProcess) {
- Client* client = GetClientBySpawn(player);
- if (client)
- spellProcess->LockAllSpells(client);
- }
- }
-
- void ZoneServer::UnlockAllSpells(Player* player) {
- if (player && spellProcess) {
- Client* client = GetClientBySpawn(player);
- if (client)
- spellProcess->UnlockAllSpells(client);
- }
- }
- void ZoneServer::DeleteFactionLists() {
- map<int32, vector<int32> *>::iterator faction_itr;
- map<int32, vector<int32> *>::iterator spawn_itr;
- m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- for (faction_itr = enemy_faction_list.begin(); faction_itr != enemy_faction_list.end(); faction_itr++)
- safe_delete(faction_itr->second);
- enemy_faction_list.clear();
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- for (faction_itr = reverse_enemy_faction_list.begin(); faction_itr != reverse_enemy_faction_list.end(); faction_itr++)
- safe_delete(faction_itr->second);
- reverse_enemy_faction_list.clear();
- m_reverse_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- for (spawn_itr = npc_faction_list.begin(); spawn_itr != npc_faction_list.end(); spawn_itr++)
- safe_delete(spawn_itr->second);
- npc_faction_list.clear();
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteData(bool boot_clients){
- Spawn* spawn = 0;
- vector<Spawn*> tmp_player_list; // changed to a vector from a MutexList as this is a local variable and don't need mutex stuff for the list
- // Clear spawn groups
- spawn_group_map.clear();
- // Loop through the spawn list and set the spawn for deletion
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(!boot_clients && spawn->IsPlayer())
- tmp_player_list.push_back(spawn);
- else if(spawn->IsPlayer()){
- Client* client = GetClientBySpawn(spawn);
- if(client)
- client->Disconnect();
- }
- else{
- RemoveHeadingTimer(spawn); // called in RemoveSpawnSupportFunctions()
- RemoveSpawnSupportFunctions(spawn);
- AddPendingDelete(spawn);
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- // Quick hack to prevent a deadlock, RemoveSpawnSupportFunctions() will cancel spells and result in zone->GetSpawnByID()
- // being called which read locks the spawn list and caused a dead lock as the above mutex's were write locked
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- // Clear the spawn list, this was in the mutex above, moved it down so the above mutex could be a read lock
- spawn_list.clear();
- // Moved this up so we only read lock the list once in this list
- vector<Spawn*>::iterator spawn_iter2;
- for (spawn_iter2 = tmp_player_list.begin(); spawn_iter2 != tmp_player_list.end(); spawn_iter2++) {
- spawn_list[(*spawn_iter2)->GetID()] = (*spawn_iter2);
- }
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- // Clear player proximities
- RemovePlayerProximity(0, true);
- spawn_range_map.clear(true);
- if(boot_clients) {
- // Refactor
- vector<Client*>::iterator itr;
- MClientList.writelock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++)
- safe_delete(*itr);
- clients.clear();
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- }
- // Clear and delete spawn locations
- MSpawnLocationList.writelock(__FUNCTION__, __LINE__);
- map<int32, SpawnLocation*>::iterator spawn_location_iter;
- for (spawn_location_iter = spawn_location_list.begin(); spawn_location_iter != spawn_location_list.end(); spawn_location_iter++)
- safe_delete(spawn_location_iter->second);
- spawn_location_list.clear();
- MSpawnLocationList.releasewritelock(__FUNCTION__, __LINE__);
- // If we allow clients to stay in the zone we need to preserve the revive_points, otherwise if the player dies they will crash
- if(revive_points && boot_clients){
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++){
- safe_delete(*revive_iter);
- }
- safe_delete(revive_points);
- }
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- map<int32, set<int32>*>::iterator assoc_itr;
- for (assoc_itr = spawn_group_associations.begin(); assoc_itr != spawn_group_associations.end(); assoc_itr++)
- safe_delete(assoc_itr->second);
- spawn_group_associations.clear();
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- map<int32, map<int32, int32>*>::iterator loc_itr;
- for (loc_itr = spawn_group_locations.begin(); loc_itr != spawn_group_locations.end(); loc_itr++)
- safe_delete(loc_itr->second);
- spawn_group_locations.clear();
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- map<int32, list<int32>*>::iterator group_itr;
- for (group_itr = spawn_location_groups.begin(); group_itr != spawn_location_groups.end(); group_itr++)
- safe_delete(group_itr->second);
- spawn_location_groups.clear();
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
-
- // Clear lists that need more then just a Clear()
- DeleteFactionLists();
- DeleteSpawnScriptTimers(0, true);
- DeleteSpawnScriptTimers();
- ClearDeadSpawns();
- // Clear lists
- heading_timers.clear();
- movement_spawns.clear();
- respawn_timers.clear();
- transport_spawns.clear();
- quick_database_id_lookup.clear();
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- widget_timers.clear();
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- map<int16, PacketStruct*>::iterator struct_itr;
- for (struct_itr = versioned_info_structs.begin(); struct_itr != versioned_info_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_info_structs.clear();
- for (struct_itr = versioned_pos_structs.begin(); struct_itr != versioned_pos_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_pos_structs.clear();
- for (struct_itr = versioned_vis_structs.begin(); struct_itr != versioned_vis_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_vis_structs.clear();
- }
- void ZoneServer::RemoveLocationProximities() {
- MutexList<LocationProximity*>::iterator itr = location_proximities.begin();
- while(itr.Next()){
- safe_delete(itr->value);
- }
- location_proximities.clear();
- }
- RevivePoint* ZoneServer::GetRevivePoint(int32 id){
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++){
- if((*revive_iter)->id == id)
- return *revive_iter;
- }
- return 0;
- }
- vector<RevivePoint*>* ZoneServer::GetRevivePoints(Client* client)
- {
- vector<RevivePoint*>* points = new vector<RevivePoint*>;
- RevivePoint* closest_point = 0;
- // we should not check for revive points if this is null
- if ( revive_points != NULL )
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Got revive point in %s!", __FUNCTION__);
- float closest = 100000;
- float test_closest = 0;
- RevivePoint* test_point = 0;
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++)
- {
- test_point = *revive_iter;
- if(test_point)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Test Point Found!");
- test_closest = client->GetPlayer()->GetDistance(test_point->x, test_point->y, test_point->z);
- // should this be changed to list all revive points within max distance or just the closest
- if(test_closest < closest)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "test_closest: %.2f, closest: %.2f", test_closest, closest);
- closest = test_closest;
- closest_point = test_point;
- if(closest <= MAX_REVIVEPOINT_DISTANCE)
- points->push_back(closest_point);
- }
- }
- }
- }
- if(closest_point && points->size() == 0 && closest_point->zone_id == GetZoneID())
- {
- LogWrite(ZONE__WARNING, 0, "Zone", "Nearest Revive Point too far away. Add another!");
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "The closest revive point is quite far away, you might want to ask the server admin for a closer one.");
- points->push_back(closest_point);
- }
- else if(points->size() == 0)
- {
- LogWrite(ZONE__WARNING, 0, "Zone", "No Revive Points set for zoneID %u. Add some!", GetZoneID());
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "There are no revive points for this zone, you might want to ask the server admin for one.");
- closest_point = new RevivePoint;
- closest_point->heading = GetSafeHeading();
- closest_point->id = 0xFFFFFFFF;
- closest_point->location_name = "Zone Safe Point";
- closest_point->zone_id = GetZoneID();
- closest_point->x = GetSafeX();
- closest_point->y = GetSafeY();
- closest_point->z = GetSafeZ();
- points->push_back(closest_point);
- }
- return points;
- }
- void ZoneServer::TriggerCharSheetTimer(){
- charsheet_changes.Trigger();
- }
- void ZoneServer::RegenUpdate(){
- if(damaged_spawns.size(true) == 0)
- return;
- Spawn* spawn = 0;
- MutexList<int32>::iterator spawn_iter = damaged_spawns.begin();
- while(spawn_iter.Next()){
- spawn = GetSpawnByID(spawn_iter->value);
- if(spawn && (((spawn->GetHP() < spawn->GetTotalHP()) && spawn->GetHP()>0) || (spawn->GetPower() < spawn->GetTotalPower()))){
- if(spawn->IsEntity())
- ((Entity*)spawn)->DoRegenUpdate();
- if(spawn->IsPlayer()){
- Client* client = GetClientBySpawn(spawn);
- if(client && client->IsConnected())
- client->QueuePacket(client->GetPlayer()->GetPlayerInfo()->serialize(client->GetVersion()));
- }
- }
- else
- RemoveDamagedSpawn(spawn);
- //Spawn no longer valid, remove it from the list
- if (!spawn)
- damaged_spawns.Remove(spawn_iter->value);
- }
- }
- void ZoneServer::ClearDeadSpawns(){
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- dead_spawns.clear();
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessDepop(bool respawns_allowed, bool repop) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- Spawn* spawn = 0;
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- spawn_expire_timers.clear();
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client)
- continue;
- client->GetPlayer()->SetTarget(0);
- if(repop)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Zone Repop in progress...");
- else{
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Zone Depop in progress...");
- if(respawns_allowed)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawns will respawn according to their respawn timers.");
- }
- if(!packet || packet_version != client->GetVersion()){
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && !spawn->IsPlayer()){
- SendRemoveSpawn(client, spawn, packet);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- DeleteTransporters();
- safe_delete(packet);
- if(!repop && respawns_allowed){
- spawn_range_map.clear(true);
- MutexList<Spawn*> tmp_player_list; // Local variable, never be on another thread so probably don't need the extra mutex code that comes with a MutexList
- ClearDeadSpawns();
- map<int32, Spawn*>::iterator itr;
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn) {
- if(spawn->GetRespawnTime() > 0 && spawn->GetSpawnLocationID() > 0)
- respawn_timers.Put(spawn->GetSpawnLocationID(), Timer::GetCurrentTime2() + spawn->GetRespawnTime()*1000);
- if(spawn->IsPlayer())
- tmp_player_list.Add(spawn);
- else {
- RemoveSpawnSupportFunctions(spawn);
- AddPendingDelete(spawn);
- }
- }
- }
- spawn_list.clear();
- //add back just the clients
- MutexList<Spawn*>::iterator spawn_iter2 = tmp_player_list.begin();
- while(spawn_iter2.Next()) {
- spawn_list[spawn_iter2->value->GetID()] = spawn_iter2->value;
- }
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- else
- DeleteData(false);
- if(repop)
- LoadingData = true;
- }
- void ZoneServer::Depop(bool respawns, bool repop) {
- respawns_allowed = respawns;
- repop_zone = repop;
- finished_depop = false;
- depop_zone = true;
- }
- bool ZoneServer::AddCloseSpawnsToSpawnGroup(Spawn* spawn, float radius){
- if(!spawn)
- return false;
- Spawn* close_spawn = 0;
- bool ret = true;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- close_spawn = itr->second;
- if(close_spawn && close_spawn != spawn && !close_spawn->IsPlayer() && close_spawn->GetDistance(spawn) <= radius){
- if((spawn->IsNPC() && close_spawn->IsNPC()) || (spawn->IsGroundSpawn() && close_spawn->IsGroundSpawn()) || (spawn->IsObject() && close_spawn->IsObject()) || (spawn->IsWidget() && close_spawn->IsWidget()) || (spawn->IsSign() && close_spawn->IsSign())){
- if(close_spawn->GetSpawnGroupID() == 0){
- spawn->AddSpawnToGroup(close_spawn);
- close_spawn->AddSpawnToGroup(spawn);
- }
- else
- ret = false;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::RepopSpawns(Client* client, Spawn* in_spawn){
- vector<Spawn*>* spawns = in_spawn->GetSpawnGroup();
- PacketStruct* packet = configReader.getStruct("WS_DestroyGhostCmd", client->GetVersion());
- if(spawns){
- if(!packet)
- return;
- Spawn* spawn = 0;
- vector<Spawn*>::iterator itr;
- for(itr = spawns->begin(); itr != spawns->end(); itr++){
- spawn = *itr;
- SendRemoveSpawn(client, spawn, packet);
- }
- }
- safe_delete(spawns);
- SendRemoveSpawn(client, in_spawn, packet);
- spawn_check_add.Trigger();
- safe_delete(packet);
- }
- bool ZoneServer::AggroVictim(NPC* npc, Spawn* victim, Client* client)
- {
- bool isEntity = victim->IsEntity();
- if (npc->HasSpawnGroup()) {
- vector<Spawn*>* groupVec = npc->GetSpawnGroup();
- for (int32 i = 0; i < groupVec->size(); i++) {
- Spawn* group_member = groupVec->at(i);
- if (group_member && !group_member->EngagedInCombat() && group_member->Alive()) {
- CallSpawnScript(group_member, SPAWN_SCRIPT_AGGRO, victim);
- if (isEntity)
- ((NPC*)group_member)->AddHate((Entity*)victim, 50);
- else
- ((NPC*)group_member)->InCombat(true);
- }
- }
- safe_delete(groupVec);
- }
- else
- {
- if (isEntity)
- {
- CallSpawnScript(victim, SPAWN_SCRIPT_AGGRO, victim);
- npc->AddHate((Entity*)victim, 50);
- }
- else
- npc->InCombat(true);
- }
- return true;
- }
- bool ZoneServer::CheckNPCAttacks(NPC* npc, Spawn* victim, Client* client){
- if(!npc || !victim)
- return true;
- if (client) {
- if (client->IsConnected() && npc->CanSeeInvis(client->GetPlayer()) && client->GetPlayer()->GetFactions()->ShouldAttack(npc->GetFactionID()) && npc->AttackAllowed((Entity*)victim, false)) {
- if (!npc->EngagedInCombat() && client->GetPlayer()->GetArrowColor(npc->GetLevel()) != ARROW_COLOR_GRAY) {
- AggroVictim(npc, victim, client);
- }
- }
- }
- else{
- AggroVictim(npc, victim, client);
- }
- return true;
- }
- bool ZoneServer::CheckEnemyList(NPC* npc) {
- vector<int32> *factions;
- vector<int32>::iterator faction_itr;
- vector<int32> *spawns;
- vector<int32>::iterator spawn_itr;
- map<float, Spawn*> attack_spawns;
- map<float, Spawn*> reverse_attack_spawns;
- map<float, Spawn*>::iterator itr;
- int32 faction_id = npc->GetFactionID();
- float distance;
- if (faction_id == 0)
- return true;
- m_enemy_faction_list.readlock(__FUNCTION__, __LINE__);
- if (enemy_faction_list.count(faction_id) > 0) {
- factions = enemy_faction_list[faction_id];
- for (faction_itr = factions->begin(); faction_itr != factions->end(); faction_itr++) {
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(*faction_itr) > 0) {
- spawns = npc_faction_list[*faction_itr];
- spawn_itr = spawns->begin();
- for (spawn_itr = spawns->begin(); spawn_itr != spawns->end(); spawn_itr++) {
- Spawn* spawn = GetSpawnByID(*spawn_itr);
- if (spawn) {
- if ((distance = spawn->GetDistance(npc)) <= npc->GetAggroRadius())
- attack_spawns[distance] = spawn;
- }
- }
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- m_enemy_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.readlock(__FUNCTION__, __LINE__);
- if (reverse_enemy_faction_list.count(faction_id) > 0) {
- factions = reverse_enemy_faction_list[faction_id];
- for (faction_itr = factions->begin(); faction_itr != factions->end(); faction_itr++) {
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(*faction_itr) > 0) {
- spawns = npc_faction_list[*faction_itr];
- spawn_itr = spawns->begin();
- for (spawn_itr = spawns->begin(); spawn_itr != spawns->end(); spawn_itr++) {
- Spawn* spawn = GetSpawnByID(*spawn_itr);
- if (spawn) {
- if ((distance = spawn->GetDistance(npc)) <= npc->GetAggroRadius())
- reverse_attack_spawns[distance] = spawn;
- }
- }
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- m_reverse_enemy_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- if (attack_spawns.size() > 0) {
- for (itr = attack_spawns.begin(); itr != attack_spawns.end(); itr++)
- CheckNPCAttacks(npc, itr->second);
- }
- if (reverse_attack_spawns.size() > 0) {
- for (itr = reverse_attack_spawns.begin(); itr != reverse_attack_spawns.end(); itr++)
- CheckNPCAttacks((NPC*)itr->second, npc);
- }
- return attack_spawns.size() == 0;
- }
- void ZoneServer::RemoveDeadEnemyList(Spawn *spawn)
- {
- int32 faction_id = spawn->GetFactionID();
- vector<int32> *spawns;
- vector<int32>::iterator itr;
- LogWrite(ZONE__DEBUG, 7, "Zone", "Processing RemoveDeadEnemyList...");
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(faction_id) > 0) {
- spawns = npc_faction_list[faction_id];
- for (itr = spawns->begin(); itr != spawns->end(); itr++) {
- if (*itr == spawn->GetID()) {
- spawns->erase(itr);
- break;
- }
- }
- }
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddEnemyList(NPC* npc){
- int32 faction_id = npc->GetFactionID();
- vector<int32> *hostile_factions;
- vector<int32>::iterator itr;
- if(faction_id <= 9)
- return;
- if(!rule_manager.GetGlobalRule(R_Faction, AllowFactionBasedCombat)->GetBool()) {
- LogWrite(FACTION__WARNING, 0, "Faction", "Faction Combat is DISABLED via R_Faction::AllowFactionBasedCombat rule!");
- return;
- }
-
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(faction_id) == 0) {
- if(faction_id > 10) {
- if ((hostile_factions = master_faction_list.GetHostileFactions(faction_id)) != NULL) {
- itr = hostile_factions->begin();
- for (itr = hostile_factions->begin(); itr != hostile_factions->end(); itr++) {
- m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if (enemy_faction_list.count(faction_id) == 0)
- enemy_faction_list[faction_id] = new vector<int32>;
- enemy_faction_list[faction_id]->push_back(*itr);
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if(reverse_enemy_faction_list.count(*itr) == 0)
- reverse_enemy_faction_list[*itr] = new vector<int32>;
- reverse_enemy_faction_list[*itr]->push_back(faction_id);
- m_reverse_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- }
- /*m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if(enemy_faction_list.count(1) == 0)
- enemy_faction_list[1] = new vector<int32>;
- enemy_faction_list[1]->push_back(faction_id);
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);*/
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- if(npc_faction_list.count(faction_id) == 0)
- npc_faction_list[faction_id] = new vector<int32>;
- npc_faction_list[faction_id]->push_back(npc->GetID());
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckSpawnRange(Client* client, Spawn* spawn, bool initial_login){
- if(client && spawn && (initial_login || client->IsConnected())) {
- if(spawn != client->GetPlayer()) {
- if(spawn_range_map.count(client) == 0)
- spawn_range_map.Put(client, new MutexMap<int32, float >());
- float curDist = spawn->GetDistance(client->GetPlayer());
- if (!client->GetPlayer()->WasSentSpawn(spawn->GetID()) && curDist > SEND_SPAWN_DISTANCE)
- {
- return;
- }
- spawn_range_map.Get(client)->Put(spawn->GetID(), curDist);
- if(!initial_login && client && spawn->IsNPC() && curDist <= ((NPC*)spawn)->GetAggroRadius() && !client->GetPlayer()->GetInvulnerable())
- CheckNPCAttacks((NPC*)spawn, client->GetPlayer(), client);
- }
- if(!initial_login)
- CheckPlayerProximity(spawn, client);
- }
- }
- void ZoneServer::CheckSpawnRange(Spawn* spawn){
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsReadyForSpawns())
- CheckSpawnRange(client, spawn);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PrepareSpawnID(Player* player, Spawn* spawn){
- player->SetSpawnMap(spawn);
- }
- void ZoneServer::CheckSendSpawnToClient(Client* client, bool initial_login) {
- if (!client) {
- LogWrite(ZONE__ERROR, 0, "Zone", "CheckSendSpawnToClient called with an invalid client");
- return;
- }
- if (!initial_login && !client->GetInitialSpawnsSent() || (!initial_login && !client->IsReadyForUpdates()))
- return;
- Spawn* spawn = 0;
- map<float, vector<Spawn*>* > closest_spawns;
- if (spawn_range_map.count(client) > 0) {
- if (initial_login || client->IsConnected()) {
- MutexMap<int32, float >::iterator spawn_iter = spawn_range_map.Get(client)->begin();
- while (spawn_iter.Next()) {
- spawn = GetSpawnByID(spawn_iter->first, true);
- if (spawn && spawn->GetPrivateQuestSpawn()) {
- if (!spawn->IsPrivateSpawn())
- spawn->AddAllowAccessSpawn(spawn);
- if (spawn->MeetsSpawnAccessRequirements(client->GetPlayer())) {
- if (spawn->IsPrivateSpawn() && !spawn->AllowedAccess(client->GetPlayer()))
- spawn->AddAllowAccessSpawn(client->GetPlayer());
- }
- else if (spawn->AllowedAccess(client->GetPlayer()))
- spawn->RemoveSpawnAccess(client->GetPlayer());
- }
- if (spawn && spawn != client->GetPlayer() && client->GetPlayer()->ShouldSendSpawn(spawn)) {
- if ((!initial_login && spawn_iter->second <= SEND_SPAWN_DISTANCE) || (initial_login && (spawn_iter->second <= (SEND_SPAWN_DISTANCE / 2) || spawn->IsWidget()))) {
- if (closest_spawns.count(spawn_iter->second) == 0)
- closest_spawns[spawn_iter->second] = new vector<Spawn*>();
- closest_spawns[spawn_iter->second]->push_back(spawn);
- PrepareSpawnID(client->GetPlayer(), spawn);
- }
- }
- }
- }
- vector<Spawn*>::iterator spawn_iter2;
- map<float, vector<Spawn*>* >::iterator itr;
- for (itr = closest_spawns.begin(); itr != closest_spawns.end(); ) {
- for (spawn_iter2 = itr->second->begin(); spawn_iter2 != itr->second->end(); spawn_iter2++) {
- spawn = *spawn_iter2;
- client->GetPlayer()->ClearRemovedSpawn(spawn);
- SendSpawn(spawn, client);
- if (client->ShouldTarget() && client->GetCombineSpawn() == spawn)
- client->TargetSpawn(spawn);
- }
- vector<Spawn*>* vect = itr->second;
- map<float, vector<Spawn*>* >::iterator tmpitr = itr;
- itr++;
- closest_spawns.erase(tmpitr);
- safe_delete(vect);
- }
- }
- if (initial_login)
- client->SetInitialSpawnsSent(true);
- }
- void ZoneServer::CheckSendSpawnToClient(){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client->IsReadyForSpawns())
- CheckSendSpawnToClient(client);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckRemoveSpawnFromClient(Spawn* spawn) {
- vector<Client*>::iterator itr;
- Client* client = 0;
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client){
- if(!packet || packet_version != client->GetVersion()){
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- if(spawn && spawn != client->GetPlayer() &&
- client->GetPlayer()->WasSentSpawn(spawn->GetID()) &&
- client->GetPlayer()->WasSpawnRemoved(spawn) == false &&
- (spawn_range_map.Get(client)->Get(spawn->GetID()) > REMOVE_SPAWN_DISTANCE &&
- !spawn->IsSign() && !spawn->IsObject() && !spawn->IsWidget())){
- SendRemoveSpawn(client, spawn, packet);
- spawn_range_map.Get(client)->erase(spawn->GetID());
- }
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- bool ZoneServer::CombatProcess(Spawn* spawn) {
- bool ret = true;
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->ProcessCombat();
- return ret;
- }
- void ZoneServer::AddPendingDelete(Spawn* spawn) {
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if (spawn_delete_list.count(spawn) == 0)
- spawn_delete_list.insert(make_pair(spawn, Timer::GetCurrentTime2() + spawn_delete_timer)); //give other threads up to 30 seconds to stop using this spawn reference
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::RemovePendingDelete(Spawn* spawn) {
- if (!spawn)
- return;
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if (spawn_delete_list.count(spawn) > 0)
- {
- spawn_delete_list.erase(spawn);
- }
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteSpawns(bool delete_all) {
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if(spawn_delete_list.size() > 0){
- map<Spawn*, int32>::iterator itr;
- map<Spawn*, int32>::iterator erase_itr;
- int32 current_time = Timer::GetCurrentTime2();
- Spawn* spawn = 0;
- for (itr = spawn_delete_list.begin(); itr != spawn_delete_list.end(); ) {
- if (delete_all || current_time >= itr->second){
- spawn = itr->first;
- if (spawn && movementMgr != nullptr) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- erase_itr = itr++;
- spawn_delete_list.erase(erase_itr);
- safe_delete(spawn);
- }
- else
- itr++;
- }
- }
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddDamagedSpawn(Spawn* spawn){
- if (spawn)
- damaged_spawns.Add(spawn->GetID());
- }
- void ZoneServer::RemoveDamagedSpawn(Spawn* spawn){
- if (spawn)
- damaged_spawns.Remove(spawn->GetID());
- }
- bool ZoneServer::Process()
- {
- MMasterZoneLock->lock(); //Changing this back to a recursive lock to fix a possible /reload spells crash with multiple zones running - Foof
- SetWatchdogTime(Timer::GetCurrentTime2());
- #ifndef NO_CATCH
- try
- {
- #endif
- while (zoneID == 0) { //this is loaded by world
- SetWatchdogTime(Timer::GetCurrentTime2());
- Sleep(10);
- }
- if (LoadingData) {
- if (lua_interface) {
- string tmpScript("ZoneScripts/");
- tmpScript.append(GetZoneName());
- tmpScript.append(".lua");
- struct stat buffer;
- bool fileExists = (stat(tmpScript.c_str(), &buffer) == 0);
- if (fileExists)
- lua_interface->RunZoneScript(tmpScript.c_str(), "preinit_zone_script", this);
- }
- if (reloading) {
- LogWrite(COMMAND__DEBUG, 0, "Command", "-Loading Entity Commands...");
- database.LoadEntityCommands(this);
- LogWrite(NPC__INFO, 0, "NPC", "-Loading NPC data...");
- database.LoadNPCs(this);
- LogWrite(NPC__INFO, 0, "NPC", "-Load NPC data complete!");
- LogWrite(OBJECT__INFO, 0, "Object", "-Loading Object data...");
- database.LoadObjects(this);
- LogWrite(OBJECT__INFO, 0, "Object", "-Load Object data complete!");
- LogWrite(SIGN__INFO, 0, "Sign", "-Loading Sign data...");
- database.LoadSigns(this);
- LogWrite(SIGN__INFO, 0, "Sign", "-Load Sign data complete!");
- LogWrite(WIDGET__INFO, 0, "Widget", "-Loading Widget data...");
- database.LoadWidgets(this);
- LogWrite(WIDGET__INFO, 0, "Widget", "-Load Widget data complete!");
- LogWrite(GROUNDSPAWN__INFO, 0, "GSpawn", "-Loading Groundspawn data...");
- database.LoadGroundSpawns(this);
- database.LoadGroundSpawnEntries(this);
- LogWrite(GROUNDSPAWN__INFO, 0, "GSpawn", "-Load Groundspawn data complete!");
- LogWrite(PET__INFO, 0, "Pet", "-Loading Pet data...");
- database.GetPetNames(this);
- LogWrite(PET__INFO, 0, "Pet", "-Load Pet data complete!");
- LogWrite(LOOT__INFO, 0, "Loot", "-Loading Spawn loot data...");
- database.LoadLoot(this);
- LogWrite(LOOT__INFO, 0, "Loot", "-Loading Spawn loot data complete!");
- LogWrite(TRANSPORT__INFO, 0, "Transport", "-Loading Transporters...");
- database.LoadTransporters(this);
- LogWrite(TRANSPORT__INFO, 0, "Transport", "-Loading Transporters complete!");
- reloading = false;
- world.RemoveReloadingSubSystem("Spawns");
- }
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- spawn_group_associations.clear();
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- spawn_group_locations.clear();
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- spawn_location_groups.clear();
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupChances.writelock(__FUNCTION__, __LINE__);
- spawn_group_chances.clear();
- MSpawnGroupChances.releasewritelock(__FUNCTION__, __LINE__);
- Map* zonemap = world.GetMap(std::string(GetZoneName()),0);
- while (zonemap != nullptr && zonemap->IsMapLoading())
- {
- SetWatchdogTime(Timer::GetCurrentTime2());
- // Client loop
- ClientProcess();
- Sleep(10);
- }
- DeleteTransporters();
- ReloadTransporters();
- database.LoadSpawns(this);
- ProcessSpawnLocations();
- if (!revive_points)
- revive_points = new vector<RevivePoint*>;
- else {
- while (!revive_points->empty()) {
- safe_delete(revive_points->back());
- revive_points->pop_back();
- }
- }
- database.LoadRevivePoints(revive_points, GetZoneID());
- RemoveLocationGrids();
- database.LoadLocationGrids(this);
- LoadingData = false;
- spawn_range.Trigger();
- spawn_check_add.Trigger();
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (lua_interface && zone_script) {
- RemoveLocationProximities();
- lua_interface->RunZoneScript(zone_script, "init_zone_script", this);
- }
- }
- if(shutdownTimer.Enabled() && shutdownTimer.Check())
- zoneShuttingDown = true;
- if (reloading_spellprocess){
- MMasterZoneLock->unlock();
- return !zoneShuttingDown;
- }
- // client loop
- if(charsheet_changes.Check())
- SendCharSheetChanges();
- // Client loop
- ClientProcess();
- if(spellProcess)
- spellProcess->Process();
- if (tradeskillMgr)
- tradeskillMgr->Process();
-
- // Client loop
- if(client_save.Check())
- SaveClients();
- // Possibility to do a client loop
- if(weather_enabled && weatherTimer.Check())
- ProcessWeather();
- // client related loop, move to main thread?
- if(!zoneShuttingDown)
- ProcessDrowning();
- // client than location_proximities loop, move to main thread
- if (location_prox_timer.Check() && !zoneShuttingDown)
- CheckLocationProximity();
- // client than location_grid loop, move to main thread
- if (location_grid_timer.Check() && !zoneShuttingDown)
- CheckLocationGrids();
- if (sync_game_time_timer.Check() && !zoneShuttingDown)
- SendTimeUpdateToAllClients();
- if(lua_interface)
- lua_interface->Process();
- int hour = world.GetWorldTimeStruct()->hour;
- int minute = world.GetWorldTimeStruct()->minute;
- if (!isDusk && (hour >= 19 || hour < 8)) {//((hour > dusk_hour || hour < dawn_hour) || ((dusk_hour == hour && minute >= dusk_minute) || (hour == dawn_hour && minute < dawn_minute)))) {
- isDusk = true;
- const char* zone_script = world.GetZoneScript(GetZoneID());
- if (lua_interface && zone_script)
- lua_interface->RunZoneScript(zone_script, "dusk", this);
- ProcessSpawnConditional(SPAWN_CONDITIONAL_NIGHT);
- }
- else if (isDusk && hour >= 8 && hour < 19) {//((hour > dawn_hour && hour < dusk_hour) || ((hour == dawn_hour && minute >= dawn_minute) || (hour == dusk_hour && minute < dusk_minute)))) {
- isDusk = false;
- const char* zone_script = world.GetZoneScript(GetZoneID());
- if (lua_interface && zone_script)
- lua_interface->RunZoneScript(zone_script, "dawn", this);
- ProcessSpawnConditional(SPAWN_CONDITIONAL_DAY);
- }
- // damaged spawns loop, spawn related, move to spawn thread?
- if(regenTimer.Check())
- RegenUpdate();
- // heading_timers loop
- if(!zoneShuttingDown)
- CheckHeadingTimers();
- // respawn_timers loop
- if(respawn_timer.Check() && !zoneShuttingDown)
- CheckRespawns();
- // spawn_expire_timers loop
- if (spawn_expire_timer.Check() && !zoneShuttingDown)
- CheckSpawnExpireTimers();
- // widget_timers loop
- if(widget_timer.Check() && !zoneShuttingDown)
- CheckWidgetTimers();
- // spawn_script_timers loop
- if(!zoneShuttingDown)
- CheckSpawnScriptTimers();
- // Check to see if a dead spawn needs to be removed
- CheckDeadSpawnRemoval();
- #ifndef NO_CATCH
- }
- catch(...)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception while running '%s'", GetZoneName());
- zoneShuttingDown = true;
- MMasterZoneLock->unlock();
- return false;
- }
- #endif
- MMasterZoneLock->unlock();
- return (zoneShuttingDown == false);
- }
- bool ZoneServer::SpawnProcess(){
- if(depop_zone) {
- depop_zone = false;
- ProcessDepop(respawns_allowed, repop_zone);
- finished_depop = true;
- }
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- // If the zone is loading data or shutting down don't do anything
- if(!LoadingData && !zoneShuttingDown && !reloading_spellprocess) {
- // Set some bool's for timers
- bool movement = movement_timer.Check();
- bool spawnRange = spawn_range.Check();
- bool checkRemove = spawn_check_remove.Check();
- bool aggroCheck = aggro_timer.Check();
- vector<int32> pending_spawn_list_remove;
- // Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them all
- ProcessSpawnRemovals();
-
- map<int32, Spawn*>::iterator itr;
- if (spawnRange || checkRemove)
- {
- // Loop through the spawn list
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- // Loop throught the list to set up spawns to be sent to clients
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- // if zone is shutting down kill the loop
- if (zoneShuttingDown)
- break;
- Spawn* spawn = itr->second;
- if (spawn) {
- // Checks the range to all clients in the zone
- if (spawnRange)
- CheckSpawnRange(spawn);
- // Checks to see if the spawn needs to be removed from a client
- if (checkRemove)
- CheckRemoveSpawnFromClient(spawn);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- // Broke the spawn loop into 2 so spawns are sent to the client faster, send the spawns to clients now then resume the spawn loop
- // client loop, move to main thread?
- // moved this back to the spawn thread as on the main thread during a depop, done on the spawn thread, spawns would start to pop again
- // might be an issue with other functions moved from the spawn thread to the main thread?
- if(spawn_check_add.Check() && !zoneShuttingDown)
- CheckSendSpawnToClient();
- // send spawn changes, changed_spawns loop
- if (spawn_update.Check() && !zoneShuttingDown) { //check for changed spawns every {Rule:SpawnUpdateTimer} milliseconds (default: 200ms)
- SendSpawnChanges();
- }
- if (movement || aggroCheck)
- {
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- // Break the loop if the zone is shutting down
- if (zoneShuttingDown)
- break;
- Spawn* spawn = itr->second;
- if (spawn) {
- // Process spawn movement
- if (movement) {
- spawn->ProcessMovement(true);
- // update last_movement_update for all spawns (used for time_step)
- spawn->last_movement_update = Timer::GetCurrentTime2();
- if (!aggroCheck)
- CombatProcess(spawn);
- }
- // Makes NPC's KOS to other NPC's or players
- if (aggroCheck)
- {
- ProcessAggroChecks(spawn);
- CombatProcess(spawn);
- }
- }
- else {
- // unable to get a valid spawn, lets add the id to another list to remove from the spawn list after this loop is finished
- pending_spawn_list_remove.push_back(itr->first);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- // Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them all
- if (pending_spawn_list_remove.size() > 0) {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr2;
- for (itr2 = pending_spawn_list_remove.begin(); itr2 != pending_spawn_list_remove.end(); itr2++)
- spawn_list.erase(*itr2);
- pending_spawn_list_remove.clear();
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
-
- // Double Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them before we replace with pending spawns
- // and also potentially further down when we delete the Spawn* in DeleteSpawns(false)
- ProcessSpawnRemovals();
- // Check to see if there are spawns waiting to be added to the spawn list, if so add them all
- if (pending_spawn_list_add.size() > 0) {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- MPendingSpawnListAdd.writelock(__FUNCTION__, __LINE__);
- list<Spawn*>::iterator itr2;
- for (itr2 = pending_spawn_list_add.begin(); itr2 != pending_spawn_list_add.end(); itr2++) {
- Spawn* spawn = *itr2;
- if (spawn)
- spawn_list[spawn->GetID()] = spawn;
- }
- pending_spawn_list_add.clear();
- MPendingSpawnListAdd.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- if (movementMgr != nullptr)
- movementMgr->Process();
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- // Do other loops for spawns
- // tracking, client loop with spawn loop for each client that is tracking, change to a spawn_range_map loop instead of using the main spawn list?
- //if (tracking_timer.Check())
- //ProcessTracking(); // probably doesn't work as spawn loop iterator is never set
- // Delete unused spawns, do this last
- if(!zoneShuttingDown)
- DeleteSpawns(false);
- // Nothing should come after this
- //LogWrite(PLAYER__ERROR, 0, "Debug", "Spawn loop time %u", Timer::GetCurrentTime2() - time);
- }
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
-
- return (zoneShuttingDown == false);
- }
- void ZoneServer::CheckDeadSpawnRemoval() {
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if(dead_spawns.size() > 0){
- vector<Spawn*> tmp_dead_list;
- int32 current_time = Timer::GetCurrentTime2();
- Spawn* spawn = 0;
- map<int32, int32>::iterator itr = dead_spawns.begin();
- map<int32, int32>::iterator itr_delete;
- while (itr != dead_spawns.end()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn) {
- if(current_time >= itr->second)
- tmp_dead_list.push_back(spawn);
- itr++;
- }
- else {
- itr_delete = itr++;
- dead_spawns.erase(itr_delete);
- }
- }
- for(int i=tmp_dead_list.size()-1;i>=0;i--){
- spawn = tmp_dead_list[i];
- if (!spawn->IsPlayer())
- {
- dead_spawns.erase(spawn->GetID());
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- RemoveSpawn(spawn, true, true, true);
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- }
- }
- }
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckRespawns(){
- vector<int32> tmp_respawn_list;
- MutexMap<int32, int32>::iterator itr = respawn_timers.begin();
- while(itr.Next()){
- if(Timer::GetCurrentTime2() >= itr->second)
- tmp_respawn_list.push_back(itr->first);
- }
- for(int i=tmp_respawn_list.size()-1;i>=0;i--){
- if ( IsInstanceZone() )
- {
- if ( database.DeleteInstanceSpawnRemoved(GetInstanceID(),tmp_respawn_list[i]) )
- {
- }
- else
- {
- }
- }
- ProcessSpawnLocation(tmp_respawn_list[i], true);
- respawn_timers.erase(tmp_respawn_list[i]);
- }
- }
- void ZoneServer::CheckSpawnExpireTimers() {
- MutexMap<int32, int32>::iterator itr = spawn_expire_timers.begin();
- while (itr.Next()) {
- Spawn* spawn = GetSpawnByID(itr->first);
- if (spawn) {
- if (Timer::GetCurrentTime2() >= itr.second) {
- spawn_expire_timers.erase(itr.first);
- Despawn(spawn, spawn->GetRespawnTime());
- }
- }
- else
- spawn_expire_timers.erase(itr->first);
- }
- }
- void ZoneServer::AddSpawnExpireTimer(Spawn* spawn, int32 expire_time, int32 expire_offset) {
- if (spawn) {
- int32 actual_expire_time = expire_time;
- if (expire_offset > 0) {
- int32 low = expire_time;
- int32 high = expire_time + expire_offset;
- if (expire_offset < expire_time)
- low = expire_time - expire_offset;
- int32 range = (high - low) + 1;
- actual_expire_time = (low + (int32)((range * rand()) / (RAND_MAX + 1.0)));
- }
- actual_expire_time *= 1000;
- spawn_expire_timers.Put(spawn->GetID(), Timer::GetCurrentTime2() + actual_expire_time);
- }
- }
- void ZoneServer::SaveClient(Client* client){
- client->Save();
- }
- void ZoneServer::SaveClients(){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client->IsConnected()){
- SaveClient(client);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawnVisualState(Spawn* spawn, int16 type){
- if(!spawn)
- return;
- vector<Client*>::iterator itr;
- spawn->SetTempVisualState(type);
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client && client->GetPlayer() != spawn)
- AddChangedSpawn(spawn);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawnChangesByDBID(int32 db_id, Client* client, bool override_changes, bool override_vis_changes){
- Spawn* spawn = GetSpawnByDatabaseID(db_id);
- if(spawn && (spawn->changed || override_changes || override_vis_changes))
- SendSpawnChanges(spawn, client, override_changes, override_vis_changes);
- }
- void ZoneServer::SendSpawnChanges(Spawn* spawn, Client* client, bool override_changes, bool override_vis_changes){
- if(client && client->IsReadyForUpdates() && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn) && client->GetPlayer()->GetDistance(spawn) < SEND_SPAWN_DISTANCE){
- EQ2Packet* outapp = spawn->spawn_update_packet(client->GetPlayer(), client->GetVersion(), override_changes, override_vis_changes);
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- void ZoneServer::SendSpawnChanges(Spawn* spawn){
- MSpawnList.readlock();
- if(spawn && spawn->changed){
- if(!spawn->IsPlayer() || (spawn->IsPlayer() && (spawn->info_changed || spawn->vis_changed))){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- SendSpawnChanges(spawn, client);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- spawn->changed = false;
- spawn->info_changed = false;
- if(spawn->IsPlayer() == false)
- spawn->position_changed = false;
- spawn->vis_changed = false;
- }
- MSpawnList.releasereadlock();
- }
- Spawn* ZoneServer::FindSpawn(Player* searcher, const char* name){
- if(!searcher || !name)
- return 0;
- Spawn* spawn = 0;
- vector<Spawn*> find_spawn_list;
- vector<Spawn*>::iterator fspawn_iter;
- int8 name_size = strlen(name);
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && !strncasecmp(spawn->GetName(), name, name_size))
- find_spawn_list.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- Spawn* closest = 0;
- float distance = 0;
- float test_distance = 0;
- for(fspawn_iter=find_spawn_list.begin(); fspawn_iter!=find_spawn_list.end(); fspawn_iter++){
- spawn = *fspawn_iter;
- if(spawn && ((((test_distance = searcher->GetDistance(spawn)) < distance)) || !closest)){
- distance = test_distance;
- closest = spawn;
- }
- }
- return closest;
- }
- void ZoneServer::AddChangedSpawn(Spawn* spawn) {
- if (!spawn || (spawn->IsPlayer() && !spawn->info_changed && !spawn->vis_changed) || (spawn->IsPlayer() && ((Player*)spawn)->IsFullyLoggedIn() == false))
- return;
- if (changed_spawns.count(spawn->GetID()) == 0)
- changed_spawns.Add(spawn->GetID());
- }
- void ZoneServer::RemoveChangedSpawn(Spawn* spawn){
- if (spawn)
- changed_spawns.Remove(spawn->GetID());
- }
- void ZoneServer::AddDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client && drowning_victims.count(client) == 0)
- drowning_victims.Put(client, Timer::GetCurrentTime2());
- }
- void ZoneServer::RemoveDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client)
- drowning_victims.erase(client);
- }
- Client* ZoneServer::GetDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client && drowning_victims.count(client) > 0)
- return(client);
- return 0;
- }
- void ZoneServer::ProcessDrowning(){
- vector<Client*> dead_list;
- if(drowning_victims.size(true) > 0){
- sint32 damage = 0;
- int32 current_time = Timer::GetCurrentTime2();
- MutexMap<Client*, int32>::iterator itr = drowning_victims.begin();
- while(itr.Next()){
- if(current_time >= itr->second) {
- Client* client = itr->first;
- Player* player = client->GetPlayer();
- drowning_victims.Get(client) = Timer::GetCurrentTime2() + 2000;
- damage = player->GetTotalHP()/20 + player->GetHPRegen();
- player->TakeDamage(damage);
- if(player->GetHP() == 0)
- dead_list.push_back(client);
- player->SetCharSheetChanged(true);
- SendCharSheetChanges(client);
- SendDamagePacket(0, player, DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_DROWN, damage, 0);
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are drowning!");
- }
- }
- }
- if(dead_list.size() > 0){
- vector<Client*>::iterator itr;
- for(itr = dead_list.begin(); itr != dead_list.end(); itr++){
- RemoveDrowningVictim((*itr)->GetPlayer());
- KillSpawn(false, (*itr)->GetPlayer(), 0);
- (*itr)->SimpleMessage(CHANNEL_NARRATIVE, "You are sleeping with the fishes! Glug, glug...");
- }
- }
- }
- void ZoneServer::SendSpawnChanges(){
- if (changed_spawns.size() < 1)
- return;
- set<Spawn*> spawns_to_send;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- MutexList<int32>::iterator spawn_iter = changed_spawns.begin();
- int count = 0;
- while(spawn_iter.Next()){
- spawn = GetSpawnByID(spawn_iter->value);
- if(spawn){
- spawns_to_send.insert(spawn);
- }
- if (!spawn)
- changed_spawns.Remove(spawn_iter->value);
- }
- changed_spawns.clear();
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- client->SendSpawnChanges(spawns_to_send);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- for (const auto& spawn : spawns_to_send) {
- spawn->changed = false;
- spawn->position_changed = false;
- spawn->vis_changed = false;
- spawn->info_changed = false;
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendPlayerPositionChanges(Player* player){
- if(player){
- player->position_changed = false;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(player != client->GetPlayer() && client->GetPlayer()->WasSentSpawn(player->GetID()) && client->GetPlayer()->WasSpawnRemoved(player) == false){
- EQ2Packet* outapp = player->player_position_update_packet(client->GetPlayer(), client->GetVersion());
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendCharSheetChanges(){
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++)
- SendCharSheetChanges(*client_itr);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendCharSheetChanges(Client* client){
- if(client && client->IsConnected() && client->GetPlayer()->GetCharSheetChanged()){
- client->GetPlayer()->SetCharSheetChanged(false);
- ClientPacketFunctions::SendCharacterSheet(client);
- }
- }
- int32 ZoneServer::CalculateSpawnGroup(SpawnLocation* spawnlocation, bool respawn)
- {
- int32 group = 0;
- list<int32>* groups_at_location = GetSpawnGroupsByLocation(spawnlocation->placement_id);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(groups_at_location){
- list<int32>::iterator group_location_itr;
- float chance = 0;
- float total_chance = 0;
- map<int32, float> tmp_chances;
- set<int32>* associated_groups = 0;
- for (group_location_itr = groups_at_location->begin(); group_location_itr != groups_at_location->end(); group_location_itr++) {
- if(tmp_chances.count(*group_location_itr) > 0)
- continue;
- associated_groups = GetAssociatedGroups(*group_location_itr);
- if(associated_groups){
- set<int32>::iterator group_itr;
- for (group_itr = associated_groups->begin(); group_itr != associated_groups->end(); group_itr++) {
- chance = GetSpawnGroupChance(*group_itr);
- if(chance > 0){
- total_chance += chance;
- tmp_chances[*group_itr] = chance;
- }
- else
- tmp_chances[*group_itr] = 0;
- }
- }
- else{ //single group, no associations
- chance = GetSpawnGroupChance(*group_location_itr);
- total_chance += chance;
- tmp_chances[*group_location_itr] = chance;
- }
- }
- if(tmp_chances.size() > 1){
- //set the default for any chances not set
- map<int32, float>::iterator itr2;
- for(itr2 = tmp_chances.begin(); itr2 != tmp_chances.end(); itr2++){
- if(itr2->second == 0){
- total_chance += 100/tmp_chances.size();
- tmp_chances[itr2->first] = (float)(100 / tmp_chances.size());
- }
- }
- }
- if(tmp_chances.size() > 1){
- float roll = (float)(rand()%((int32)total_chance));
- map<int32, float>::iterator itr3;
- for (itr3 = tmp_chances.begin(); itr3 != tmp_chances.end(); itr3++){
- if(itr3->second >= roll){
- group = itr3->first;
- break;
- }
- else
- roll -= itr3->second;
- }
- }
- else if(tmp_chances.size() == 1)
- group = tmp_chances.begin()->first;
- }
- if(group > 0){
- map<int32, int32>* locations = GetSpawnLocationsByGroup(group);
- if(locations){
- map<int32, int32>::iterator itr;
- Spawn* spawn = 0;
- Spawn* leader = 0;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- for (itr = locations->begin(); itr != locations->end(); itr++) {
- if(spawn_location_list.count(itr->second) > 0){
- spawn = ProcessSpawnLocation(spawn_location_list[itr->second], respawn);
- if(!leader && spawn)
- leader = spawn;
- if(leader)
- leader->AddSpawnToGroup(spawn);
- if(spawn){
- //if(spawn_group_map.count(group) == 0)
- // spawn_group_map.Put(group, new MutexList<Spawn*>());
- MutexList<int32>* groupList = &spawn_group_map.Get(group);
- groupList->Add(spawn->GetID());
- spawn->SetSpawnGroupID(group);
- }
- }
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return group;
- }
- void ZoneServer::ProcessSpawnLocation(int32 location_id, bool respawn)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- if(spawn_location_list.count(location_id) > 0)
- {
- if(respawn) //see if there are any spawns still in game associated with this spawn's group, if so, dont spawn this
- {
- list<int32>* groups = GetSpawnGroupsByLocation(spawn_location_list[location_id]->placement_id);
- if(groups)
- {
- set<int32>* associated_groups = 0;
- bool should_spawn = true;
- list<int32>::iterator itr;
- for (itr = groups->begin(); itr != groups->end(); itr++) {
- associated_groups = GetAssociatedGroups(*itr);
- if(associated_groups)
- {
- set<int32>::iterator assoc_itr;
- for (assoc_itr = associated_groups->begin(); assoc_itr != associated_groups->end(); assoc_itr++) {
- if(spawn_group_map.count(*assoc_itr) > 0 && spawn_group_map.Get(*assoc_itr).size() > 0)
- should_spawn = false;
- }
- }
- }
- if(should_spawn)
- CalculateSpawnGroup(spawn_location_list[location_id]);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- // need to unlock the list before we exit the function
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- ProcessSpawnLocation(spawn_location_list[location_id], respawn);
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- Spawn* ZoneServer::ProcessSpawnLocation(SpawnLocation* spawnlocation, bool respawn)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(!spawnlocation)
- return 0;
- Spawn* spawn = 0;
- float rand_number = MakeRandomFloat(0, spawnlocation->total_percentage);
- for(int32 i=0;i<spawnlocation->entities.size();i++)
- {
- if(spawnlocation->entities[i]->spawn_percentage == 0)
- continue;
- if (spawnlocation->conditional > 0) {
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_DAY && isDusk)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_NIGHT) == SPAWN_CONDITIONAL_NIGHT && !isDusk)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_NOT_RAINING && rain >= 0.75f)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_RAINING && rain < 0.75f)
- continue;
- }
- if (spawnlocation->entities[i]->spawn_percentage >= rand_number) {
- if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = AddNPCSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = AddGroundSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = AddObjectSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = AddWidgetSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = AddSignSpawn(spawnlocation, spawnlocation->entities[i]);
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
- database.GetHouseSpawnInstanceData(this, spawn);
- if (!spawn)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
- continue;
- }
- if (spawn)
- {
- if(respawn)
- CallSpawnScript(spawn, SPAWN_SCRIPT_RESPAWN);
- else
- CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- break;
- }
- else
- rand_number -= spawnlocation->entities[i]->spawn_percentage;
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- Spawn* ZoneServer::ProcessInstanceSpawnLocation(SpawnLocation* spawnlocation, map<int32,int32>* instNPCs, map<int32,int32>* instGroundSpawns, map<int32,int32>* instObjSpawns, map<int32,int32>* instWidgetSpawns, map<int32,int32>* instSignSpawns, bool respawn)
- {
- if(!spawnlocation)
- return 0;
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Spawn* spawn = 0;
- float rand_number = MakeRandomFloat(0, spawnlocation->total_percentage);
- for(int32 i=0;i<spawnlocation->entities.size();i++)
- {
- if(spawnlocation->entities[i]->spawn_percentage == 0)
- continue;
- int32 spawnTime = 0;
- if(spawnlocation->entities[i]->spawn_percentage >= rand_number)
- {
- if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_NPC &&
- (spawnTime = database.CheckSpawnRemoveInfo(instNPCs,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddNPCSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN &&
- (spawnTime = database.CheckSpawnRemoveInfo(instGroundSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddGroundSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT &&
- (spawnTime = database.CheckSpawnRemoveInfo(instObjSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddObjectSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET &&
- (spawnTime = database.CheckSpawnRemoveInfo(instWidgetSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddWidgetSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_SIGN &&
- (spawnTime = database.CheckSpawnRemoveInfo(instSignSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddSignSpawn(spawnlocation, spawnlocation->entities[i]);
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
- database.GetHouseSpawnInstanceData(this, spawn);
- const char* script = 0;
- for(int x=0;x<3;x++)
- {
- switch(x)
- {
- case 0:
- script = world.GetSpawnEntryScript(spawnlocation->entities[i]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(spawnlocation->entities[i]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(spawnlocation->entities[i]->spawn_id);
- break;
- }
- if(spawn && script && lua_interface->GetSpawnScript(script) != 0)
- {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- if(spawn)
- {
- if (respawn)
- CallSpawnScript(spawn, SPAWN_SCRIPT_RESPAWN);
- else
- CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- if ( spawnTime > 1 )
- {
- spawn->SetRespawnTime(spawnTime);
- }
- }
- break;
- }
- else
- rand_number -= spawnlocation->entities[i]->spawn_percentage;
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- void ZoneServer::ProcessSpawnLocations()
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- map<int32,int32>* instNPCs = NULL;
- map<int32,int32>* instGroundSpawns = NULL;
- map<int32,int32>* instObjSpawns = NULL;
- map<int32,int32>* instWidgetSpawns = NULL;
- map<int32,int32>* instSignSpawns = NULL;
- if ( this->IsInstanceZone() )
- {
- LogWrite(SPAWN__DEBUG, 0, "Spawn", "Processing Instance Removed Spawns...");
- instNPCs = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_NPC );
- instGroundSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_GROUNDSPAWN );
- instObjSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_OBJECT );
- instWidgetSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_WIDGET );
- instSignSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_SIGN );
- }
- map<int32, bool> processed_spawn_locations;
- map<int32, SpawnLocation*>::iterator itr;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_location_list.begin(); itr != spawn_location_list.end(); itr++) {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "while spawn_location_list itr (#%u)", spawn_location_list.size());
- if(itr->second && processed_spawn_locations.count(itr->second->placement_id) > 0) //if we processed one spawn in a spawn group, we processed them all for that group
- continue;
- if(itr->second && spawn_location_groups.count(itr->second->placement_id) > 0)
- {
- int32 group_id = CalculateSpawnGroup(itr->second);
- if(group_id)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is group_id");
- set<int32>* associated_groups = GetAssociatedGroups(group_id);
- if(associated_groups)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is associated_groups");
- vector<int32>* associated_locations = GetAssociatedLocations(associated_groups);
- if(associated_locations)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is associated_locations");
- for(int32 i=0;i<associated_locations->size();i++)
- {
- LogWrite(SPAWN__DEBUG, 5, "Spawn", "Loading processed_spawn_locations...");
- processed_spawn_locations[associated_locations->at(i)] = true;
- }
- safe_delete(associated_locations);
- }
- }
- }
- }
- else
- {
- if ( this->IsInstanceZone() )
- {
- //LogWrite(SPAWN__DEBUG, 5, "Spawn", "ProcessInstanceSpawnLocation (%u)...", itr->second->placement_id);
- ProcessInstanceSpawnLocation(itr->second,instNPCs,instGroundSpawns,instObjSpawns,instWidgetSpawns,instSignSpawns);
- }
- else
- {
- //LogWrite(SPAWN__DEBUG, 5, "Spawn", "ProcessSpawnLocation (%u)...", itr->second->placement_id);
- ProcessSpawnLocation(itr->second);
- }
- }
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(instNPCs);
- safe_delete(instGroundSpawns);
- safe_delete(instObjSpawns);
- safe_delete(instWidgetSpawns);
- safe_delete(instSignSpawns);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- }
- void ZoneServer::AddLoot(NPC* npc){
- vector<int32> loot_tables = GetSpawnLootList(npc->GetDatabaseID(), GetZoneID(), npc->GetLevel(), race_types_list.GetRaceType(npc->GetModelType()));
- if(loot_tables.size() > 0){
- vector<LootDrop*>* loot_drops = 0;
- vector<LootDrop*>::iterator loot_drop_itr;
- LootTable* table = 0;
- vector<int32>::iterator loot_list_itr;
- float chancecoin = 0;
- float chancetable = 0;
- float chancedrop = 0;
- float chancetally = 0;
- float droptally = 0;
- // the following loop,loops through each table
- for(loot_list_itr = loot_tables.begin(); loot_list_itr != loot_tables.end(); loot_list_itr++){
- table = GetLootTable(*loot_list_itr);
- if(table && table->maxcoin > 0){
- chancecoin = rand()%100;
- if(table->coin_probability >= chancecoin){
- if(table->maxcoin > table->mincoin)
- npc->AddLootCoins(table->mincoin + rand()%(table->maxcoin - table->mincoin));
- }
- }
- int numberchances = 1;
- //if (table->lootdrop_probability == 100){ }
- //else
- //chancetally += table->lootdrop_probability;
- int maxchance = 0;
- if (table) {
- maxchance = table->maxlootitems;
- for (numberchances; numberchances <= maxchance; numberchances++) {
- chancetable = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Table Chance: '%f'", chancetable);
- float droppercenttotal = 0;
- //--------------------------------------------------------------------------------------------------------------------------------------------------------------
- if (table->lootdrop_probability == 100 || table->lootdrop_probability >= chancetable) {
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Probability:%f Table Chance: '%f'", table->lootdrop_probability, chancetable);
- loot_drops = GetLootDrops(*loot_list_itr);
- if (loot_drops && loot_drops->size() > 0) {
- LootDrop* drop = 0;
- int16 count = 0;
- std::shuffle(loot_drops->begin(), loot_drops->end(), std::default_random_engine(Timer::GetCurrentTime2()));
- int16 IC = 0;
- for (loot_drop_itr = loot_drops->begin(); loot_drop_itr != loot_drops->end(); loot_drop_itr++) {
- drop = *loot_drop_itr;
- droppercenttotal += drop->probability;
- }
-
- int droplistsize = loot_drops->size();
- float chancedroptally = 0;
- chancedrop = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- for (loot_drop_itr = loot_drops->begin(); loot_drop_itr != loot_drops->end(); loot_drop_itr++) {
- drop = *loot_drop_itr;
- if (npc->HasLootItemID(drop->item_id))
- continue;
- if (droppercenttotal >= 100)
- droppercenttotal = 100;
- chancedroptally += 100 / droppercenttotal * drop->probability;
- //chancedrop = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Loot drop: '%i' Chance: %f Prob tally: %f min: %f", drop, chancedrop, chancedroptally, chancedroptally - drop->probability);
- if ((chancedroptally == 100) || ((chancedroptally >= chancedrop) && (chancedroptally - (100 / droppercenttotal * drop->probability)) <= chancedrop)) {
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Loot drop: '%i' Chance: %f Prob: %f We have a loot drop winner", drop, chancedrop, chancedroptally);
- count++;
- npc->AddLootItem(drop->item_id, drop->item_charges);
- //LogWrite(PLAYER__DEBUG, 0, "Player", "loot Count: '%i'",count);
- //LogWrite(MISC__TODO, 1, "TODO", "Auto-Equip new looted items\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- //if(drop->equip_item)
- }
- if (table->maxlootitems > 0 && count >= table->maxlootitems)
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- void ZoneServer::DeterminePosition(SpawnLocation* spawnlocation, Spawn* spawn){
- if(!spawn || !spawnlocation)
- return;
- int offset = 0;
- if(spawnlocation->x_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->x_offset*1000)+1);
- spawn->SetX(spawnlocation->x + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetX(spawnlocation->x);
- if(spawnlocation->y_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->y_offset*1000)+1);
- spawn->SetY(spawnlocation->y + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetY(spawnlocation->y, true, true);
- if(spawnlocation->z_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->z_offset*1000)+1);
- spawn->SetZ(spawnlocation->z + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetZ(spawnlocation->z);
- spawn->SetHeading(spawnlocation->heading);
- spawn->SetPitch(spawnlocation->pitch);
- spawn->SetRoll(spawnlocation->roll);
- spawn->SetSpawnOrigX(spawn->GetX());
- spawn->SetSpawnOrigY(spawn->GetY());
- spawn->SetSpawnOrigZ(spawn->GetZ());
- spawn->SetSpawnOrigHeading(spawn->GetHeading());
- spawn->SetSpawnOrigPitch(spawnlocation->pitch);
- spawn->SetSpawnOrigRoll(spawnlocation->roll);
- spawn->appearance.pos.grid_id = spawnlocation->grid_id;
- spawn->SetSpawnLocationPlacementID(spawnlocation->placement_id);
- }
- NPC* ZoneServer::AddNPCSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- NPC* npc = GetNewNPC(spawnentry->spawn_id);
- if(npc){
- DeterminePosition(spawnlocation, npc);
- npc->SetDatabaseID(spawnentry->spawn_id);
- npc->SetSpawnLocationID(spawnentry->spawn_location_id);
- npc->SetSpawnEntryID(spawnentry->spawn_entry_id);
- npc->SetRespawnTime(spawnentry->respawn);
- npc->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(npc, spawnentry->expire_time, spawnentry->expire_offset);
- AddLoot(npc);
- SetSpawnScript(spawnentry, npc);
- CallSpawnScript(npc, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(npc);
- }
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- return npc;
- }
- vector<int32>* ZoneServer::GetAssociatedLocations(set<int32>* groups){
- vector<int32>* ret = 0;
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- if(groups){
- int32 group_id = 0;
- set<int32>::iterator group_itr;
- for (group_itr = groups->begin(); group_itr != groups->end(); group_itr++) {
- if(!ret)
- ret = new vector<int32>();
- group_id = *group_itr;
- MSpawnGroupLocations.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) > 0){
- map<int32, int32>::iterator itr;
- for (itr = spawn_group_locations[group_id]->begin(); itr != spawn_group_locations[group_id]->end(); itr++) {
- ret->push_back(itr->first);
- }
- }
- MSpawnGroupLocations.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- return ret;
- }
- set<int32>* ZoneServer::GetAssociatedGroups(int32 group_id) {
- set<int32>* ret = 0;
- MSpawnGroupAssociation.readlock(__FUNCTION__, __LINE__);
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- if(spawn_group_associations.count(group_id) > 0)
- ret = spawn_group_associations[group_id];
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- MSpawnGroupAssociation.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- map<int32, int32>* ZoneServer::GetSpawnLocationsByGroup(int32 group_id) {
- map<int32, int32>* ret = 0;
- MSpawnGroupLocations.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) > 0)
- ret = spawn_group_locations[group_id];
- MSpawnGroupLocations.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- list<int32>* ZoneServer::GetSpawnGroupsByLocation(int32 location_id){
- list<int32>* ret = 0;
- MSpawnLocationGroups.readlock(__FUNCTION__, __LINE__);
- if(spawn_location_groups.count(location_id) > 0)
- ret = spawn_location_groups[location_id];
- MSpawnLocationGroups.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- float ZoneServer::GetSpawnGroupChance(int32 group_id){
- float ret = -1;
- MSpawnGroupChances.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_chances.count(group_id) > 0)
- ret = spawn_group_chances[group_id];
- MSpawnGroupChances.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::AddSpawnGroupChance(int32 group_id, float percent){
- MSpawnGroupChances.writelock(__FUNCTION__, __LINE__);
- spawn_group_chances[group_id] = percent;
- MSpawnGroupChances.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnGroupAssociation(int32 group_id1, int32 group_id2) {
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- //Check if we already have containers for these group ids, if not create them
- if (spawn_group_associations.count(group_id1) == 0)
- spawn_group_associations[group_id1] = new set<int32>;
- if (spawn_group_associations.count(group_id2) == 0)
- spawn_group_associations[group_id2] = new set<int32>;
- //Associate groups 1 and 2 now
- set<int32>* group_1 = spawn_group_associations.find(group_id1)->second;
- set<int32>* group_2 = spawn_group_associations.find(group_id2)->second;
- group_1->insert(group_id2);
- group_2->insert(group_id1);
-
- //Associate the remaining groups together
- set<int32>::iterator itr;
- for (itr = group_1->begin(); itr != group_1->end(); itr++){
- group_2->insert(*itr);
- map<int32, set<int32>*>::iterator assoc_itr = spawn_group_associations.find(*itr);
- if (assoc_itr != spawn_group_associations.end())
- assoc_itr->second->insert(group_id2);
- else {
- set<int32>* new_set = new set<int32>;
- spawn_group_associations[*itr] = new_set;
- new_set->insert(group_id2);
- }
- }
- for (itr = group_2->begin(); itr != group_2->end(); itr++){
- group_1->insert(*itr);
- map<int32, set<int32>*>::iterator assoc_itr = spawn_group_associations.find(*itr);
- if (assoc_itr != spawn_group_associations.end())
- assoc_itr->second->insert(group_id1);
- else {
- set<int32>* new_set = new set<int32>;
- spawn_group_associations[*itr] = new_set;
- new_set->insert(group_id1);
- }
- }
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnGroupLocation(int32 group_id, int32 location_id, int32 spawn_location_id) {
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) == 0)
- spawn_group_locations[group_id] = new map<int32, int32>();
- (*spawn_group_locations[group_id])[location_id] = spawn_location_id;
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- if(spawn_location_groups.count(location_id) == 0)
- spawn_location_groups[location_id] = new list<int32>();
- spawn_location_groups[location_id]->push_back(group_id);
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- if(spawn_group_associations.count(group_id) == 0)
- spawn_group_associations[group_id] = new set<int32>();
- spawn_group_associations[group_id]->insert(group_id);
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- }
- bool ZoneServer::CallSpawnScript(Spawn* npc, int8 type, Spawn* spawn, const char* message){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(!npc)
- return false;
- const char* script = npc->GetSpawnScript();
- if ( script == nullptr || strlen(script) < 1 )
- {
- if (npc->GetZone() != nullptr)
- {
- string tmpScript;
- tmpScript.append("SpawnScripts/");
- tmpScript.append(npc->GetZone()->GetZoneName());
- tmpScript.append("/");
- int count = 0;
- for (int s = 0; s < strlen(npc->GetName()); s++)
- {
- if (isalnum(npc->GetName()[s]))
- {
- tmpScript += npc->GetName()[s];
- count++;
- }
- }
- tmpScript.append(".lua");
- if (count < 1)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Could not form script name %s..", __FUNCTION__);
- }
- else
- {
- struct stat buffer;
- bool fileExists = (stat(tmpScript.c_str(), &buffer) == 0);
- if (fileExists)
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "No script file described in the database, overriding with SpawnScript at %s", (char*)tmpScript.c_str());
- npc->SetSpawnScript(tmpScript);
- script = npc->GetSpawnScript();
- }
- }
- }
- }
- bool result = false;
- if(lua_interface && script){
- result = true; // default to true, if we don't match a switch case, return false in default case
- switch(type){
- case SPAWN_SCRIPT_SPAWN:{
- lua_interface->RunSpawnScript(script, "spawn", npc);
- break;
- }
- case SPAWN_SCRIPT_RESPAWN:{
- lua_interface->RunSpawnScript(script, "respawn", npc);
- break;
- }
- case SPAWN_SCRIPT_ATTACKED:{
- lua_interface->RunSpawnScript(script, "attacked", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_TARGETED:{
- lua_interface->RunSpawnScript(script, "targeted", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HAILED:{
- lua_interface->RunSpawnScript(script, "hailed", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HAILED_BUSY:{
- lua_interface->RunSpawnScript(script, "hailed_busy", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_DEATH:{
- lua_interface->RunSpawnScript(script, "death", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_KILLED:{
- lua_interface->RunSpawnScript(script, "killed", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_AGGRO:{
- lua_interface->RunSpawnScript(script, "aggro", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HEALTHCHANGED:{
- lua_interface->RunSpawnScript(script, "healthchanged", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_RANDOMCHAT:{
- lua_interface->RunSpawnScript(script, "randomchat", npc, 0, message);
- break;
- }
- case SPAWN_SCRIPT_CUSTOM:
- case SPAWN_SCRIPT_TIMER:
- case SPAWN_SCRIPT_CONVERSATION:{
- lua_interface->RunSpawnScript(script, message, npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_CASTED_ON: {
- lua_interface->RunSpawnScript(script, "casted_on", npc, spawn, message);
- break;
- }
- case SPAWN_SCRIPT_AUTO_ATTACK_TICK: {
- lua_interface->RunSpawnScript(script, "auto_attack_tick", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_COMBAT_RESET: {
- lua_interface->RunSpawnScript(script, "CombatReset", npc);
- break;
- }
- case SPAWN_SCRIPT_GROUP_DEAD: {
- lua_interface->RunSpawnScript(script, "group_dead", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HEAR_SAY: {
- lua_interface->RunSpawnScript(script, "hear_say", npc, spawn, message);
- break;
- }
- case SPAWN_SCRIPT_PRESPAWN: {
- lua_interface->RunSpawnScript(script, "prespawn", npc);
- break;
- }
- default:
- {
- result = false;
- break;
- }
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return result;
- }
- void ZoneServer::DeleteTransporters() {
- MTransportLocations.writelock(__FUNCTION__, __LINE__);
- transporter_locations.clear(); //world takes care of actually deleting the data
- MTransportLocations.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ReloadTransporters(){
- MutexList<LocationTransportDestination*>* locations = GetLocationTransporters(GetZoneID());
- if(locations){
- MutexList<LocationTransportDestination*>::iterator itr = locations->begin();
- while(itr.Next())
- AddTransporter(itr->value);
- }
- }
- void ZoneServer::CheckTransporters(Client* client) {
- MTransportLocations.readlock(__FUNCTION__, __LINE__);
- if(transporter_locations.size() > 0){
- LocationTransportDestination* loc = 0;
- list<LocationTransportDestination*>::iterator itr;
- for (itr = transporter_locations.begin(); itr != transporter_locations.end(); itr++) {
- loc = *itr;
- if(client->GetPlayer()->GetDistance(loc->trigger_x, loc->trigger_y, loc->trigger_z) <= loc->trigger_radius){
- if(loc->destination_zone_id == 0 || loc->destination_zone_id == GetZoneID()){
- EQ2Packet* packet = client->GetPlayer()->Move(loc->destination_x, loc->destination_y, loc->destination_z, client->GetVersion());
- if(packet)
- client->QueuePacket(packet);
- }
- else{
- ZoneServer* new_zone = zone_list.Get(loc->destination_zone_id);
- if(new_zone){
- client->GetPlayer()->SetX(loc->destination_x);
- client->GetPlayer()->SetY(loc->destination_y);
- client->GetPlayer()->SetZ(loc->destination_z);
- client->GetPlayer()->SetHeading(loc->destination_heading);
- client->Zone(new_zone, false);
- }
- }
- break;
- }
- }
- }
- MTransportLocations.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddTransporter(LocationTransportDestination* loc) {
- MTransportLocations.writelock(__FUNCTION__, __LINE__);
- transporter_locations.push_back(loc);
- MTransportLocations.releasewritelock(__FUNCTION__, __LINE__);
- }
- Sign* ZoneServer::AddSignSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Sign* sign = GetNewSign(spawnentry->spawn_id);
- if(sign){
- DeterminePosition(spawnlocation, sign);
- sign->SetDatabaseID(spawnentry->spawn_id);
- sign->SetSpawnLocationID(spawnentry->spawn_location_id);
- sign->SetSpawnEntryID(spawnentry->spawn_entry_id);
- sign->SetRespawnTime(spawnentry->respawn);
- sign->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(sign, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, sign);
- CallSpawnScript(sign, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(sign);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return sign;
- }
- Widget* ZoneServer::AddWidgetSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Widget* widget = GetNewWidget(spawnentry->spawn_id);
- if(widget){
- DeterminePosition(spawnlocation, widget);
- widget->SetDatabaseID(spawnentry->spawn_id);
- widget->SetSpawnLocationID(spawnentry->spawn_location_id);
- widget->SetSpawnEntryID(spawnentry->spawn_entry_id);
- if(!widget->GetIncludeLocation()){
- widget->SetX(widget->GetWidgetX());
- if(widget->GetCloseY() != 0)
- widget->SetY(widget->GetCloseY());
- widget->SetZ(widget->GetWidgetZ());
- }
- widget->SetRespawnTime(spawnentry->respawn);
- widget->SetExpireTime(spawnentry->expire_time);
- widget->SetSpawnOrigHeading(widget->GetHeading());
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(widget, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, widget);
- CallSpawnScript(widget, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(widget);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return widget;
- }
- Object* ZoneServer::AddObjectSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Object* object = GetNewObject(spawnentry->spawn_id);
- if(object){
- DeterminePosition(spawnlocation, object);
- object->SetDatabaseID(spawnentry->spawn_id);
- object->SetSpawnLocationID(spawnentry->spawn_location_id);
- object->SetSpawnEntryID(spawnentry->spawn_entry_id);
- object->SetRespawnTime(spawnentry->respawn);
- object->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(object, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, object);
- CallSpawnScript(object, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(object);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return object;
- }
- GroundSpawn* ZoneServer::AddGroundSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- GroundSpawn* spawn = GetNewGroundSpawn(spawnentry->spawn_id);
- if(spawn){
- DeterminePosition(spawnlocation, spawn);
- spawn->SetDatabaseID(spawnentry->spawn_id);
- spawn->SetSpawnLocationID(spawnentry->spawn_location_id);
- spawn->SetSpawnEntryID(spawnentry->spawn_entry_id);
- spawn->SetRespawnTime(spawnentry->respawn);
- spawn->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(spawn, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, spawn);
- CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(spawn);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- void ZoneServer::AddSpawn(Spawn* spawn) {
- if(!spawn->IsPlayer()) // we already set it on loadCharacter
- spawn->SetZone(this);
- spawn->position_changed = false;
- spawn->info_changed = false;
- spawn->vis_changed = false;
- spawn->changed = false;
- if(!spawn->IsPlayer() || (spawn->IsPlayer() && !((Player*)spawn)->IsReturningFromLD())) {
- // Write locking the spawn list here will cause deadlocks, so instead add it to a temp list that the
- // main spawn thread will put into the spawn_list when ever it has a chance.
- MPendingSpawnListAdd.writelock(__FUNCTION__, __LINE__);
- pending_spawn_list_add.push_back(spawn);
- MPendingSpawnListAdd.releasewritelock(__FUNCTION__, __LINE__);
- }
- else
- ((Player*)spawn)->SetReturningFromLD(false);
- spawn_range.Trigger();
- spawn_check_add.Trigger();
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE && spawn->IsObject())
- {
- spawn->AddSecondaryEntityCommand("Examine", 20, "house_spawn_examine", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Move", 20, "move_item", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Pack in Moving Crate", 20, "house_spawn_pack_in_moving_crate", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Pick Up", 20, "pickup", "", 0, 0);
- spawn->SetShowCommandIcon(1);
- }
- if(spawn->IsNPC())
- AddEnemyList((NPC*)spawn);
- if(spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo())
- world.GetGroupManager()->SendGroupUpdate(((Player*)spawn)->GetGroupMemberInfo()->group_id, GetClientBySpawn(spawn));
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->GetInfoStruct()->set_rain(rain);
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
-
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->AddMob((Entity*)spawn);
- }
- AddSpawnProximities(spawn);
- spawn->SetAddedToWorldTimestamp(Timer::GetCurrentTime2());
- }
- void ZoneServer::AddClient(Client* client){
- MClientList.writelock(__FUNCTION__, __LINE__);
- clients.push_back(client);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- connected_clients.Add(client);
- }
- void ZoneServer::RemoveClient(Client* client)
- {
- Guild *guild;
- if(client)
- {
- if (client->GetPlayer())
- client_list.RemovePlayerFromInvisHistory(client->GetPlayer()->GetID());
- LogWrite(ZONE__DEBUG, 0, "Zone", "Sending login equipment appearance updates...");
- loginserver.SendImmediateEquipmentUpdatesForChar(client->GetPlayer()->GetCharacterID());
- if (!client->IsZoning())
- {
- if ((guild = client->GetPlayer()->GetGuild()) != NULL)
- guild->GuildMemberLogoff(client->GetPlayer());
- chat.LeaveAllChannels(client);
- }
-
- int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
- int32 DisconnectClientTimer = rule_manager.GetGlobalRule(R_World, RemoveDisconnectedClientsTimer)->GetInt32();
- if(!zoneShuttingDown && !client->IsZoning())
- {
- GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
- if (gmi) {
- int32 size = world.GetGroupManager()->GetGroupSize(gmi->group_id);
- if (size > 1) {
- bool send_left_message = size > 2;
- world.GetGroupManager()->RemoveGroupMember(gmi->group_id, client->GetPlayer());
- if (send_left_message)
- world.GetGroupManager()->GroupMessage(gmi->group_id, "%s has left the group.", client->GetPlayer()->GetName());
- }
- }
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to LD/Exit...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- //connected_clients.Remove(client, true, LD_Timer + DisconnectClientTimer);
- }
- else
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to Camp/Quit...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- }
-
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetCharmedPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetDeityPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetCosmeticPet());
- //}
- }
- else
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to some client zoning...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- }
- map<int32, int32>::iterator itr;
- for (itr = client->GetPlayer()->SpawnedBots.begin(); itr != client->GetPlayer()->SpawnedBots.end(); itr++) {
- Spawn* spawn = GetSpawnByID(itr->second);
- if (spawn && spawn->IsBot())
- ((Bot*)spawn)->Camp();
- }
- LogWrite(ZONE__DEBUG, 0, "Zone", "Calling clients.Remove(client)...");
- MClientList.writelock(__FUNCTION__, __LINE__);
- clients.erase(find(clients.begin(), clients.end(), client));
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- LogWrite(ZONE__INFO, 0, "Zone", "Scheduling client '%s' for removal.", client->GetPlayer()->GetName());
- LogWrite(MISC__TODO, 1, "TODO", "Put Player Online Status updates in a timer eventually\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- database.ToggleCharacterOnline(client, 0);
-
- RemoveSpawn(client->GetPlayer(), false);
- connected_clients.Remove(client, true, DisconnectClientTimer); // changed from a hardcoded 30000 (30 sec) to the DisconnectClientTimer rule
- }
- }
- void ZoneServer::RemoveClientImmediately(Client* client) {
- Guild *guild;
- if(client)
- {
- loginserver.SendImmediateEquipmentUpdatesForChar(client->GetPlayer()->GetCharacterID());
- if(connected_clients.count(client) > 0)
- {
- if (!client->IsZoning() && (guild = client->GetPlayer()->GetGuild()))
- guild->GuildMemberLogoff(client->GetPlayer());
- MClientList.writelock(__FUNCTION__, __LINE__);
- std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
- if (itr != clients.end())
- clients.erase(itr);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- //clients.Remove(client);
- LogWrite(ZONE__INFO, 0, "Zone", "Removing connection for client '%s'.", client->GetPlayer()->GetName());
- connected_clients.Remove(client, true);
- }
- else
- {
- MClientList.writelock(__FUNCTION__, __LINE__);
- std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
- if (itr != clients.end())
- clients.erase(itr);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- //clients.Remove(client, true);
- }
- LogWrite(MISC__TODO, 1, "TODO", "Put Player Online Status updates in a timer eventually\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- database.ToggleCharacterOnline(client, 0);
- }
- }
- void ZoneServer::ClientProcess()
- {
- if(connected_clients.size(true) == 0)
- {
- if(!IsCityZone() && !AlwaysLoaded() && !shutdownTimer.Enabled())
- {
- LogWrite(ZONE__INFO, 0, "Zone", "Starting zone shutdown timers...");
- shutdownTimer.Start();
- }
- return;
- }
- shutdownTimer.Disable();
- Client* client = 0;
- MutexList<Client*>::iterator iterator = connected_clients.begin();
- while(iterator.Next())
- {
- client = iterator->value;
- #ifndef NO_CATCH
- try
- {
- #endif
- if(zoneShuttingDown || !client->Process(true))
- {
- if(!zoneShuttingDown && !client->IsZoning())
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Client is disconnecting in %s (camping = %s)", __FUNCTION__, (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 ? "false" : "true");
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 )
- {
- //only set LD flag if we're disconnecting but not camping/quitting
- client->GetPlayer()->SetActivityStatus(client->GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_LINKDEAD);
- if(client->GetPlayer()->GetGroupMemberInfo())
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Telling client's group they are disconnecting");
- world.GetGroupManager()->GroupMessage(client->GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", client->GetPlayer()->GetName());
- }
- }
- }
- client_spawn_map.Put(client->GetPlayer(), 0);
- client->Disconnect();
- RemoveClient(client);
- }
- #ifndef NO_CATCH
- }
- catch(...)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception caught when in ZoneServer::ClientProcess() for zone '%s'!\n%s, %i", GetZoneName(), __FUNCTION__, __LINE__);
- try{
- if(!client->IsZoning())
- {
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 )
- {
- client->GetPlayer()->SetActivityStatus(client->GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_LINKDEAD);
- if(client->GetPlayer()->GetGroupMemberInfo())
- world.GetGroupManager()->GroupMessage(client->GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", client->GetPlayer()->GetName());
- }
- }
- client_spawn_map.Put(client->GetPlayer(), 0);
- client->Disconnect();
- RemoveClient(client);
- }
- catch(...){
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception caught when in ZoneServer::ClientProcess(), second try\n%s, %i", __FUNCTION__, __LINE__);
- }
- }
- #endif
- }
- }
- void ZoneServer::SimpleMessage(int8 type, const char* message, Spawn* from, float distance, bool send_to_sender){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(from && client && client->IsConnected() && (send_to_sender || from != client->GetPlayer()) && from->GetDistance(client->GetPlayer()) <= distance){
- client->SimpleMessage(type, message);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleChatMessage(Client* client, Spawn* from, const char* to, int16 channel, const char* message, float distance, const char* channel_name, bool show_bubble, int32 language) {
- if ((!distance || from->GetDistance(client->GetPlayer()) <= distance) && (!from || !client->GetPlayer()->IsIgnored(from->GetName()))) {
- PacketStruct* packet = configReader.getStruct("WS_HearChat", client->GetVersion());
- if (packet) {
- if (from)
- packet->setMediumStringByName("from", from->GetName());
- if (client->GetPlayer() != from)
- packet->setMediumStringByName("to", client->GetPlayer()->GetName());
- packet->setDataByName("channel", client->GetMessageChannelColor(channel));
- if (from && ((from == client->GetPlayer()) || (client->GetPlayer()->WasSentSpawn(from->GetID()) && !client->GetPlayer()->WasSpawnRemoved(from))))
- packet->setDataByName("from_spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(from));
- else
- packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
- packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
- packet->setMediumStringByName("message", message);
- packet->setDataByName("language", language);
- if (language > 0 && !client->GetPlayer()->HasLanguage(language))
- packet->setDataByName("understood", 0);
- else
- packet->setDataByName("understood", 1);
- show_bubble == true ? packet->setDataByName("show_bubble", 1) : packet->setDataByName("show_bubble", 0);
- if (channel_name)
- packet->setMediumStringByName("channel_name", channel_name);
- EQ2Packet* outapp = packet->serialize();
- DumpPacket(outapp);
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- }
- void ZoneServer::HandleChatMessage(Spawn* from, const char* to, int16 channel, const char* message, float distance, const char* channel_name, bool show_bubble, int32 language){
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- HandleChatMessage(client, from, to, channel, message, distance, channel_name, show_bubble, language);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleBroadcast(const char* message) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- client->SimpleMessage(CHANNEL_BROADCAST, message);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleAnnouncement(const char* message) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- int32 words = ::CountWordsInString(message);
- if (words < 5)
- words = 5;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected()) {
- client->SimpleMessage(CHANNEL_BROADCAST, message);
- client->SendPopupMessage(10, message, "ui_harvest_normal", words, 0xFF, 0xFF, 0x00);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendTimeUpdate(Client* client){
- if(client){
- PacketStruct* packet = world.GetWorldTime(client->GetVersion());
- if(packet){
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void ZoneServer::SendTimeUpdateToAllClients(){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- SendTimeUpdate(client);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::UpdateVitality(float amount){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->GetPlayer()->GetInfoStruct()->get_xp_vitality() < 100){
- if((client->GetPlayer()->GetInfoStruct()->get_xp_vitality() + amount) > 100)
- client->GetPlayer()->GetInfoStruct()->set_xp_vitality(100);
- else
- client->GetPlayer()->GetInfoStruct()->add_xp_vitality(amount);
- client->GetPlayer()->SetCharSheetChanged(true);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawn(Spawn* spawn, Client* client){
- EQ2Packet* outapp = spawn->serialize(client->GetPlayer(), client->GetVersion());
- LogWrite(ZONE__DEBUG, 7, "Zone", "%s: Processing SendSpawn for spawn index %u (%s)...", client->GetPlayer()->GetName(), client->GetPlayer()->GetIndexForSpawn(spawn), spawn->GetName());
- if(outapp)
- client->QueuePacket(outapp);
- /*
- vis flags:
- 2 = show icon
- 4 = targetable
- 16 = show name
- 32 = show level/border
- activity_status:
- 4 - linkdead
- 8 - camping
- 16 - LFG
- 32 - LFW
- 2048 - mentoring
- 4096 - displays shield
- 8192 - immunity gained
- 16384 - immunity remaining
- attackable_status
- 1 - no_hp_bar
- 4 - not attackable
- npc_con
- -4 = scowls
- -3 = threatening
- -2 = dubiously
- -1 = apprehensively
- 0 = indifferent
- 1 = amiably
- 2 = kindly
- 3 = warmly
- 4 = ally
- quest_flag
- 1 = new quest
- 2 = update and new quest
- 3 = update
- */
- }
- Client* ZoneServer::GetClientBySpawn(Spawn* spawn){
- return client_spawn_map.Get(spawn);
- }
- Client* ZoneServer::GetClientByName(char* name) {
- Client* ret = 0;
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- if ((*itr)->GetPlayer()) {
- if (strncmp((*itr)->GetPlayer()->GetName(), name, strlen(name)) == 0) {
- ret = *itr;
- break;
- }
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::AddMovementNPC(Spawn* spawn){
- if (spawn)
- movement_spawns.Put(spawn->GetID(), 1);
- }
- void ZoneServer::RemoveMovementNPC(Spawn* spawn){
- if (spawn)
- remove_movement_spawns.Add(spawn->GetID());
- }
- void ZoneServer::PlayFlavor(Client* client, Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language){
- if(!client || !spawn)
- return;
- PacketStruct* packet = configReader.getStruct("WS_PlayFlavor", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("unknown1", 0xFFFFFFFF);
- packet->setDataByName("unknown5", 1, 1);
- packet->setDataByName("unknown5", 1, 6);
- if(mp3){
- packet->setMediumStringByName("mp3", mp3);
- packet->setDataByName("key", key1);
- packet->setDataByName("key", key2, 1);
- }
- packet->setMediumStringByName("name", spawn->GetName());
- if(text)
- packet->setMediumStringByName("text", text);
- if(emote)
- packet->setMediumStringByName("emote", emote);
- if (language != 0)
- packet->setDataByName("language", language);
- //We should probably add Common = language id 0 or 0xFF so admins can customize more..
- if (language == 0 || client->GetPlayer()->HasLanguage(language))
- packet->setDataByName("understood", 1);
- EQ2Packet* app = packet->serialize();
- //DumpPacket(app);
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- void ZoneServer::PlayVoice(Client* client, Spawn* spawn, const char* mp3, int32 key1, int32 key2){
- if(!client || !spawn)
- return;
- PacketStruct* packet = configReader.getStruct("WS_PlayVoice", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setMediumStringByName("mp3", mp3);
- packet->setDataByName("key", key1);
- packet->setDataByName("key", key2, 1);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void ZoneServer::PlayFlavor(Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language){
- if(!spawn)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->IsConnected() || !client->GetPlayer()->WasSentSpawn(spawn->GetID()) || client->GetPlayer()->WasSpawnRemoved(spawn) || client->GetPlayer()->GetDistance(spawn) > 30)
- continue;
- PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PlayVoice(Spawn* spawn, const char* mp3, int32 key1, int32 key2){
- if(!spawn || !mp3)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->IsConnected() || !client->GetPlayer()->WasSentSpawn(spawn->GetID()) || client->GetPlayer()->WasSpawnRemoved(spawn))
- continue;
- PlayVoice(client, spawn, mp3, key1, key2);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PlaySoundFile(Client* client, const char* name, float origin_x, float origin_y, float origin_z){
- if(!name)
- return;
- PacketStruct* packet = 0;
- if(client){
- packet = configReader.getStruct("WS_Play3DSound", client->GetVersion());
- if(packet){
- packet->setMediumStringByName("name", name);
- packet->setDataByName("x", origin_x);
- packet->setDataByName("y", origin_y);
- packet->setDataByName("z", origin_z);
- packet->setDataByName("unknown1", 1);
- packet->setDataByName("unknown2", 2.5);
- packet->setDataByName("unknown3", 15);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- else{
- EQ2Packet* outapp = 0;
- int16 packet_version = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && (!packet || packet_version != client->GetVersion())){
- safe_delete(packet);
- safe_delete(outapp);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_Play3DSound", packet_version);
- if(packet){
- packet->setMediumStringByName("name", name);
- packet->setDataByName("x", origin_x);
- packet->setDataByName("y", origin_y);
- packet->setDataByName("z", origin_z);
- packet->setDataByName("unknown1", 1);
- packet->setDataByName("unknown2", 2.5);
- packet->setDataByName("unknown3", 15);
- outapp = packet->serialize();
- }
- }
- if(outapp && client && client->IsConnected())
- client->QueuePacket(outapp->Copy());
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- safe_delete(outapp);
- }
- }
- void ZoneServer::AddHeadingTimer(Spawn* spawn){
- heading_timers.Put(spawn, Timer::GetCurrentTime2() + 30000);
- }
- void ZoneServer::RemoveHeadingTimer(Spawn* spawn){
- heading_timers.erase(spawn);
- }
- void ZoneServer::CheckHeadingTimers(){
- if(heading_timers.size() > 0){
- MutexMap<Spawn*, int32>::iterator itr = heading_timers.begin();
- Spawn* spawn = 0;
- int32 current_time = Timer::GetCurrentTime2();
- while(itr.Next()){
- if(current_time >= itr->second){
- spawn = itr->first;
- spawn->SetHeading(spawn->GetSpawnOrigHeading());
- spawn->SetTempActionState(-1);
- heading_timers.erase(itr->first);
- }
- }
- }
- }
- bool ZoneServer::HasWidgetTimer(Spawn* widget){
- bool ret = false;
- if (widget) {
- int32 id = widget->GetID();
- map<int32, int32>::iterator itr;
- MWidgetTimers.readlock(__FUNCTION__, __LINE__);
- for (itr = widget_timers.begin(); itr != widget_timers.end(); itr++) {
- if(itr->first == id){
- ret = true;
- break;
- }
- }
- MWidgetTimers.releasereadlock(__FUNCTION__, __LINE__);
- }
- return ret;
- }
- void ZoneServer::CheckWidgetTimers(){
- vector<int32> remove_list;
- map<int32, int32>::iterator itr;
- MWidgetTimers.readlock(__FUNCTION__, __LINE__);
- for (itr = widget_timers.begin(); itr != widget_timers.end(); itr++) {
- if(Timer::GetCurrentTime2() >= itr->second){
- /*Spawn* widget = GetSpawnByID(itr->first);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleTimerUpdate();*/
- remove_list.push_back(itr->first);
- }
- }
- MWidgetTimers.releasereadlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < remove_list.size(); i++) {
- Spawn* widget = GetSpawnByID(remove_list[i]);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleTimerUpdate();
- }
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- for(int32 i=0;i<remove_list.size(); i++)
- widget_timers.erase(remove_list[i]);
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddWidgetTimer(Spawn* widget, float time) {
- if (widget && widget->IsWidget()) {
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- widget_timers[widget->GetID()] = ((int32)(time * 1000)) + Timer::GetCurrentTime2();
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- Spawn* ZoneServer::GetSpawnGroup(int32 id){
- Spawn* ret = 0;
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(spawn->GetSpawnGroupID() == id){
- ret = spawn;
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByLocationID(int32 location_id) {
- Spawn* ret = 0;
- Spawn* current_spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- current_spawn = itr->second;
- if (current_spawn && current_spawn->GetSpawnLocationID() == location_id) {
- ret = current_spawn;
- break;
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByDatabaseID(int32 id){
- Spawn* ret = 0;
- if(quick_database_id_lookup.count(id) > 0)
- ret = GetSpawnByID(quick_database_id_lookup.Get(id));
- else{
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++){
- spawn = itr->second;
- if(spawn){
- if(spawn->GetDatabaseID() == id){
- quick_database_id_lookup.Put(id, spawn->GetID());
- ret = spawn;
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByID(int32 id, bool spawnListLocked) {
- Spawn* ret = 0;
- if (!spawnListLocked )
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- if (spawn_list.count(id) > 0)
- ret = spawn_list[id];
-
- if (!spawnListLocked)
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- bool ZoneServer::SendRemoveSpawn(Client* client, Spawn* spawn, PacketStruct* packet, bool delete_spawn)
- {
- if(!client || !spawn)
- return false;
- int16 index = client->GetPlayer()->GetIndexForSpawn(spawn);
- int32 cur_id = client->GetPlayer()->GetIDWithPlayerSpawn(spawn);
- bool wasRemoved = client->GetPlayer()->WasSpawnRemoved(spawn);
- LogWrite(ZONE__DEBUG, 7, "Zone", "%s: Processing SendRemoveSpawn for spawn index %u (%s)...cur_id: %i, wasremoved:: %i", client->GetPlayer()->GetName(), index, spawn->GetName(), cur_id, wasRemoved);
- if(packet && index > 0 && !wasRemoved)
- {
- packet->ResetData();
- packet->setDataByName("spawn_index", index);
- spawn->RemoveSpawnFromPlayer(client->GetPlayer());
- if(delete_spawn)
- packet->setDataByName("delete", 1);
-
- client->QueuePacket(packet->serialize());
- return true;
- }
- return false;
- }
- void ZoneServer::SetSpawnCommand(Spawn* spawn, int8 type, char* value, Client* client){
- //commands
- LogWrite(MISC__TODO, 1, "TODO", "%s does nothing!\n%s, %i", __FUNCTION__, __FILE__, __LINE__);
- }
- void ZoneServer::SetSpawnCommand(int32 spawn_id, int8 type, char* value, Client* client){
- LogWrite(MISC__TODO, 1, "TODO", "%s does nothing!\n%s, %i", __FUNCTION__, __FILE__, __LINE__);
- }
- void ZoneServer::ApplySetSpawnCommand(Client* client, Spawn* target, int8 type, const char* value){
- // This will apply the /spawn set command to all the spawns in the zone with the same DB ID, we do not want to set
- // location values (x, y, z, heading, grid) for all spawns in the zone with the same DB ID, only the targeted spawn
- if(type == SPAWN_SET_VALUE_SPAWNENTRY_SCRIPT || type == SPAWN_SET_VALUE_SPAWNLOCATION_SCRIPT || (type >= SPAWN_SET_VALUE_X && type <= SPAWN_SET_VALUE_LOCATION) ||
- type == SPAWN_SET_VALUE_PITCH || type == SPAWN_SET_VALUE_ROLL)
- return;
- Spawn* tmp = 0;
- if(target->IsNPC())
- tmp = GetNPC(target->GetDatabaseID());
- else if(target->IsObject())
- tmp = GetObject(target->GetDatabaseID());
- else if(target->IsGroundSpawn())
- tmp = GetGroundSpawn(target->GetDatabaseID());
- else if(target->IsSign())
- tmp = GetSign(target->GetDatabaseID());
- else if(target->IsWidget())
- tmp = GetWidget(target->GetDatabaseID());
- if(tmp && type == SPAWN_SET_VALUE_SPAWN_SCRIPT)
- tmp->SetSpawnScript(value);
- else if(tmp)
- commands.SetSpawnCommand(client, tmp, type, value); // set the master spawn
- Spawn* spawn = 0;
- // this check needs to be here otherwise every spawn with 0 will be set
- if ( target->GetDatabaseID ( ) > 0 )
- {
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->GetDatabaseID() == target->GetDatabaseID()){
- if(type == SPAWN_SET_VALUE_SPAWN_SCRIPT)
- spawn->SetSpawnScript(value);
- else
- commands.SetSpawnCommand(client, spawn, type, value);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::DeleteSpawnScriptTimers(Spawn* spawn, bool all){
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(spawn_script_timers.size() > 0){
- set<SpawnScriptTimer*>::iterator itr;
- SpawnScriptTimer* timer = 0;
- for (itr = spawn_script_timers.begin(); itr != spawn_script_timers.end(); itr++) {
- timer = *itr;
- if((all || timer->spawn == spawn->GetID()) && remove_spawn_script_timers_list.count(timer) == 0)
- remove_spawn_script_timers_list.insert(timer);
- }
- if(all)
- spawn_script_timers.clear();
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteSpawnScriptTimers() {
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(remove_spawn_script_timers_list.size() > 0){
- set<SpawnScriptTimer*>::iterator itr;
- SpawnScriptTimer* timer = 0;
-
- for (itr = remove_spawn_script_timers_list.begin(); itr != remove_spawn_script_timers_list.end(); itr++) {
- timer = *itr;
- spawn_script_timers.erase(timer);
- safe_delete(timer);
- }
- remove_spawn_script_timers_list.clear();
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckSpawnScriptTimers(){
- DeleteSpawnScriptTimers();
- SpawnScriptTimer* timer = 0;
- vector<SpawnScriptTimer*> call_timers;
- MSpawnScriptTimers.readlock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(spawn_script_timers.size() > 0){
- int32 current_time = Timer::GetCurrentTime2();
- set<SpawnScriptTimer*>::iterator itr;
- for (itr = spawn_script_timers.begin(); itr != spawn_script_timers.end(); itr++) {
- timer = *itr;
- if(timer->current_count < timer->max_count && current_time >= timer->timer){
- timer->current_count++;
- call_timers.push_back(timer);
- }
- if(timer->current_count >= timer->max_count && remove_spawn_script_timers_list.count(timer) == 0)
- remove_spawn_script_timers_list.insert(timer);
- }
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasereadlock(__FUNCTION__, __LINE__);
- if(call_timers.size() > 0){
- vector<SpawnScriptTimer*>::iterator itr;
- for(itr = call_timers.begin(); itr != call_timers.end(); itr++){
- timer = *itr;
- CallSpawnScript(GetSpawnByID(timer->spawn), SPAWN_SCRIPT_TIMER, timer->player > 0 ? GetSpawnByID(timer->player) : 0, timer->function.c_str());
- }
- }
- }
- void ZoneServer::KillSpawnByDistance(Spawn* spawn, float max_distance, bool include_players, bool send_packet){
- Spawn* test_spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn->IsEntity() && test_spawn != spawn && (!test_spawn->IsPlayer() || include_players)){
- if(test_spawn->GetDistance(spawn) < max_distance)
- KillSpawn(true, test_spawn, spawn, send_packet);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SpawnSetByDistance(Spawn* spawn, float max_distance, string field, string value){
- Spawn* test_spawn = 0;
- int32 type = commands.GetSpawnSetType(field);
- if(type == 0xFFFFFFFF)
- return;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn != spawn && !test_spawn->IsPlayer()){
- if(test_spawn->GetDistance(spawn) < max_distance){
- commands.SetSpawnCommand(0, test_spawn, type, value.c_str());
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnScriptTimer(SpawnScriptTimer* timer){
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- spawn_script_timers.insert(timer);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- /*
- void ZoneServer::RemoveFromRangeMap(Client* client){
- spawn_range_map.erase(client);
- }
- */
- void ZoneServer::RemoveSpawn(Spawn* spawn, bool delete_spawn, bool respawn, bool lock)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Processing RemoveSpawn function for %s (%i)...", spawn->GetName(),spawn->GetID());
- spawn->RemoveSpawnProximities();
- RemoveSpawnProximities(spawn);
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- RemoveSpawnSupportFunctions(spawn);
- if (reloading)
- RemoveDeadEnemyList(spawn);
- if (lock)
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if (dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns.erase(spawn->GetID());
- if (lock)
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- if (spawn_expire_timers.count(spawn->GetID()) > 0)
- spawn_expire_timers.erase(spawn->GetID());
-
- // we will remove the spawn ptr and entry in the spawn_list later.. it is not safe right now (lua? client process? spawn process? etc? too many factors)
- AddPendingSpawnRemove(spawn->GetID());
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if (client && (client->GetVersion() > 283 || !client->IsZoning() || client->GetPlayer() != spawn)) { //don't send destroy ghost of 283 client when zoning
- if (client->IsConnected() && (!packet || packet_version != client->GetVersion()))
- {
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- if (client->GetPlayer()->HasTarget() && client->GetPlayer()->GetTarget() == spawn)
- client->GetPlayer()->SetTarget(0);
- SendRemoveSpawn(client, spawn, packet, delete_spawn);
- if (spawn_range_map.count(client) > 0)
- spawn_range_map.Get(client)->erase(spawn->GetID());
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- if(respawn && !spawn->IsPlayer() && spawn->GetRespawnTime() > 0 && spawn->GetSpawnLocationID() > 0)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Handle NPC Respawn for '%s'.", spawn->GetName());
- // handle instance spawn db info
- // we don't care if a NPC or a client kills the spawn, we could have events that cause NPCs to kill NPCs.
- if(spawn->GetZone()->GetInstanceID() > 0 && spawn->GetSpawnLocationID() > 0)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Handle NPC Respawn in an Instance.");
- // use respawn time to either insert/update entry (likely insert in this situation)
- if ( spawn->IsNPC() )
- {
- database.CreateInstanceSpawnRemoved(spawn->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_NPC,
- spawn->GetRespawnTime(),spawn->GetZone()->GetInstanceID());
- }
- else if ( spawn->IsObject ( ) )
- {
- database.CreateInstanceSpawnRemoved(spawn->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_OBJECT,
- spawn->GetRespawnTime(),spawn->GetZone()->GetInstanceID());
- }
- }
- else
- {
- int32 spawnLocationID = spawn->GetSpawnLocationID();
- int32 spawnRespawnTime = spawn->GetRespawnTime();
- respawn_timers.Put(spawnLocationID, Timer::GetCurrentTime2() + spawnRespawnTime * 1000);
- }
- }
- // Do we really need the mutex locks and check to dead_spawns as we remove it from dead spawns at the start of this function
- if (lock && !respawn)
- MDeadSpawns.readlock(__FUNCTION__, __LINE__);
- if(delete_spawn && dead_spawns.count(spawn->GetID()) == 0)
- AddPendingDelete(spawn);
- if (lock && !respawn)
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- LogWrite(ZONE__DEBUG, 3, "Zone", "Done processing RemoveSpawn function...");
- }
- Spawn* ZoneServer::GetClosestSpawn(Spawn* spawn, int32 spawn_id){
- Spawn* closest_spawn = 0;
- Spawn* test_spawn = 0;
- float closest_distance = 1000000;
- float test_distance = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn != spawn && test_spawn->GetDatabaseID() == spawn_id){
- test_distance = test_spawn->GetDistance(spawn);
- if(test_distance < closest_distance){
- closest_distance = test_distance;
- closest_spawn = test_spawn;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return closest_spawn;
- }
- int32 ZoneServer::GetClosestLocation(Spawn* spawn){
- Spawn* closest_spawn = 0;
- Spawn* test_spawn = 0;
- float closest_distance = 1000000;
- float test_distance = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn){
- test_distance = test_spawn->GetDistance(spawn);
- if(test_distance < closest_distance){
- closest_distance = test_distance;
- closest_spawn = test_spawn;
- if(closest_distance < 10)
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- if(closest_spawn)
- return closest_spawn->GetLocation();
- return 0;
- }
- void ZoneServer::SendQuestUpdates(Client* client, Spawn* spawn){
- if(!client)
- return;
- if(spawn){
- if(client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn))
- SendSpawnChanges(spawn, client, false, true);
- }
- else{
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn) {
- spawn->m_requiredQuests.readlock(__FUNCTION__, __LINE__);
- if (spawn && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn) && (client->GetPlayer()->CheckQuestRemoveFlag(spawn) || client->GetPlayer()->CheckQuestFlag(spawn) != 0 || (spawn->HasQuestsRequired() && client->GetPlayer()->CheckQuestRequired(spawn))))
- SendSpawnChanges(spawn, client, false, true);
- spawn->m_requiredQuests.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendAllSpawnsForLevelChange(Client* client) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, false, true);
- // Attempt to slow down the packet spam sent to the client
- Sleep(5);
- }
- }
- }
- }
- void ZoneServer::SendAllSpawnsForSeeInvisChange(Client* client) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && spawn->IsEntity() && (((Entity*)spawn)->IsInvis() || ((Entity*)spawn)->IsStealthed()) && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, true, true);
- }
- }
- }
- }
- void ZoneServer::SendAllSpawnsForVisChange(Client* client, bool limitToEntities) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && (!limitToEntities || (limitToEntities && spawn->IsEntity())) && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, false, true);
- }
- }
- }
- }
- void ZoneServer::StartZoneSpawnsForLevelThread(Client* client){
- if(zoneShuttingDown)
- return;
- #ifdef WIN32
- _beginthread(SendLevelChangedSpawns, 0, client);
- #else
- pthread_t thread;
- pthread_create(&thread, NULL, SendLevelChangedSpawns, client);
- pthread_detach(thread);
- #endif
- }
- void ZoneServer::ReloadClientQuests(){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client)
- client->ReloadQuests();
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendCalculatedXP(Player* player, Spawn* victim){
- if (player && victim) {
- if (player->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- PlayerGroup* group = world.GetGroupManager()->GetGroup(player->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- deque<GroupMemberInfo*>::iterator itr;
- for (itr = members->begin(); itr != members->end(); itr++) {
- GroupMemberInfo* gmi = *itr;
- if (gmi->client) {
- Player* group_member = gmi->client->GetPlayer();
- float xp = group_member->CalculateXP(victim) / members->size();
- if (xp > 0) {
- int16 level = group_member->GetLevel();
- if (group_member->AddXP((int32)xp)) {
- gmi->client->Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience (GroupID %u)", group_member->GetName(), (int32)xp, player->GetGroupMemberInfo()->group_id);
- if (group_member->GetLevel() != level)
- gmi->client->ChangeLevel(level, group_member->GetLevel());
- group_member->SetCharSheetChanged(true);
- }
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else {
- float xp = player->CalculateXP(victim);
- if (xp > 0) {
- Client* client = GetClientBySpawn(player);
- if(!client)
- return;
- int16 level = player->GetLevel();
- if (player->AddXP((int32)xp)) {
- client->Message(CHANNEL_REWARD, "You gain %u XP!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience.", player->GetName(), (int32)xp);
- if(player->GetLevel() != level)
- client->ChangeLevel(level, player->GetLevel());
- player->SetCharSheetChanged(true);
- }
- }
- }
- }
- }
- void ZoneServer::ProcessFaction(Spawn* spawn, Client* client)
- {
- if(client && !spawn->IsPlayer() && spawn->GetFactionID() > 10)
- {
- bool update_result = false;
- Faction* faction = 0;
- vector<int32>* factions = 0;
- Player* player = client->GetPlayer();
- if(player->GetFactions()->ShouldDecrease(spawn->GetFactionID()))
- {
- update_result = player->GetFactions()->DecreaseFaction(spawn->GetFactionID());
- faction = master_faction_list.GetFaction(spawn->GetFactionID());
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
- factions = master_faction_list.GetHostileFactions(spawn->GetFactionID());
- if(factions)
- {
- vector<int32>::iterator itr;
- for(itr = factions->begin(); itr != factions->end(); itr++)
- {
- if(player->GetFactions()->ShouldIncrease(*itr))
- {
- update_result = player->GetFactions()->IncreaseFaction(*itr);
- faction = master_faction_list.GetFaction(*itr);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
- }
- }
- }
- }
- factions = master_faction_list.GetFriendlyFactions(spawn->GetFactionID());
- if(factions)
- {
- vector<int32>::iterator itr;
- for(itr = factions->begin(); itr != factions->end(); itr++)
- {
- if(player->GetFactions()->ShouldDecrease(*itr))
- {
- update_result = player->GetFactions()->DecreaseFaction(*itr);
- faction = master_faction_list.GetFaction(*itr);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
- }
- }
- }
- EQ2Packet* outapp = client->GetPlayer()->GetFactions()->FactionUpdate(client->GetVersion());
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- void ZoneServer::Despawn(Spawn* spawn, int32 timer){
- if (spawn && movementMgr != nullptr) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- if(!spawn || spawn->IsPlayer())
- return;
- RemoveSpawnSupportFunctions(spawn);
- if(spawn->IsEntity())
- ((Entity*)spawn)->InCombat(false);
- if(timer == 0)
- timer = 1;
- AddDeadSpawn(spawn, timer);
- }
- void ZoneServer::KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, bool send_packet, int8 damage_type, int16 kill_blow_type)
- {
- MDeadSpawns.readlock(__FUNCTION__, __LINE__);
- if(!dead || this->dead_spawns.count(dead->GetID()) > 0) {
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- PacketStruct* packet = 0;
- Client* client = 0;
- vector<int32>* encounter = 0;
- bool killer_in_encounter = false;
- if(dead->IsEntity())
- {
- ((Entity*)dead)->InCombat(false);
- dead->SetInitialState(16512, false); // This will make aerial npc's fall after death
- dead->SetHP(0);
- dead->SetSpawnType(3);
- dead->appearance.attackable = 0;
- // Remove hate towards dead from all npc's in the zone
- ClearHate((Entity*)dead);
- // Check kill and death procs
- if (killer && dead != killer){
- if (dead->IsEntity())
- ((Entity*)dead)->CheckProcs(PROC_TYPE_DEATH, killer);
- if (killer->IsEntity())
- ((Entity*)killer)->CheckProcs(PROC_TYPE_KILL, dead);
- }
- //Check if caster is alive after death proc called, incase of deathsave
- if (dead->Alive())
- return;
- RemoveSpellTimersFromSpawn(dead, true, !dead->IsPlayer());
- if(dead->IsPlayer())
- {
- ((Player*)dead)->UpdatePlayerStatistic(STAT_PLAYER_TOTAL_DEATHS, 1);
- client = GetClientBySpawn(dead);
- if(client) {
- if(client->GetPlayer()->DamageEquippedItems(10, client))
- client->QueuePacket(client->GetPlayer()->GetEquipmentList()->serialize(client->GetVersion()));
- client->DisplayDeadWindow();
- }
- }
- else if (dead->IsNPC()) {
- encounter = ((NPC*)dead)->Brain()->GetEncounter();
- }
- }
- dead->SetActionState(0);
- dead->SetTempActionState(0);
- // If dead is an npc get the encounter and loop through it giving out the rewards, no rewards for pets
- if (dead->IsNPC() && !dead->IsPet() && !dead->IsBot()) {
- Spawn* spawn = 0;
- int8 size = encounter->size();
- // Needs npc to have access to the encounter list for who is allowed to loot
- NPC* chest = 0;
- if (!((NPC*)dead)->Brain()->PlayerInEncounter()) {
- dead->SetLootCoins(0);
- dead->ClearLoot();
- }
- // If dead has loot attempt to drop a chest
- if (dead->HasLoot()) {
- chest = ((NPC*)dead)->DropChest();
- }
- for (int8 i = 0; i < encounter->size(); i++) {
- spawn = GetSpawnByID(encounter->at(i), spawnListLocked);
- // set a flag to let us know if the killer is in the encounter
- if (!killer_in_encounter && spawn == killer)
- killer_in_encounter = true;
- if (spawn && spawn->IsPlayer()) {
- // Update players total kill count
- ((Player*)spawn)->UpdatePlayerStatistic(STAT_PLAYER_TOTAL_NPC_KILLS, 1);
- // If this was an epic mob kill send the announcement for this player
- if (dead->GetEncounterLevel() >= 10)
- SendEpicMobDeathToGuild((Player*)spawn, dead);
- // Clear hostile spells from the players spell queue
- spellProcess->RemoveSpellFromQueue((Player*)spawn, true);
- // Get the client of the player
- client = GetClientBySpawn(spawn);
- // valid client?
- if (client) {
- // Check for quest kill updates
- client->CheckPlayerQuestsKillUpdate(dead);
- // If the dead mob is not a player and if it had a faction with an ID greater or equal to 10 the send faction changes
- if (!dead->IsPlayer() && dead->GetFactionID() > 10)
- ProcessFaction(dead, client);
- // Send xp...this is currently wrong fix it
- if (spawn != dead && ((Player*)spawn)->GetArrowColor(dead->GetLevel()) >= ARROW_COLOR_GREEN) {
- //SendCalculatedXP((Player*)spawn, dead);
- float xp = ((Player*)spawn)->CalculateXP(dead) / size;
- if (xp > 0) {
- int16 level = spawn->GetLevel();
- if (((Player*)spawn)->AddXP((int32)xp)) {
- client->Message(CHANNEL_REWARD, "You gain %u XP!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience.", spawn->GetName(), (int32)xp);
- if (spawn->GetLevel() != level)
- client->ChangeLevel(level, spawn->GetLevel());
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- }
- }
- }
- }
- // If a chest is being dropped add this spawn to the chest's encounter so they can loot it
- if (chest && spawn && spawn->IsEntity())
- chest->Brain()->AddToEncounter((Entity*)spawn);
- }
- // If a chest is being dropped add it to the world and set the timer to remove it.
- if (chest) {
- AddSpawn(chest);
- AddDeadSpawn(chest, 0xFFFFFFFF);
- LogWrite(LOOT__DEBUG, 0, "Loot", "Adding a chest to the world...");
- }
- }
- // Reset client pointer
- client = 0;
- // Killer was not in the encounter, give them the faction hit but no xp
- if (!killer_in_encounter) {
- // make sure the killer is a player and the dead spawn had a faction and wasn't a player
- if (killer && killer->IsPlayer()) {
- if (!dead->IsPlayer() && dead->GetFactionID() > 10) {
- client = GetClientBySpawn(killer);
- if (client)
- ProcessFaction(dead, client);
- }
- // Clear hostile spells from the killers spell queue
- spellProcess->RemoveSpellFromQueue((Player*)killer, true);
- }
- }
- // Reset client pointer
- client = 0;
- vector<Spawn*>* group = dead->GetSpawnGroup();
- if (group && group->size() == 1)
- CallSpawnScript(dead, SPAWN_SCRIPT_GROUP_DEAD, killer);
- safe_delete(group);
- // Remove the support functions for the dead spawn
- RemoveSpawnSupportFunctions(dead);
- // Erase the expire timer if it has one
- if (spawn_expire_timers.count(dead->GetID()) > 0)
- spawn_expire_timers.erase(dead->GetID());
- // If dead is an npc or object call the spawn scrip and handle instance stuff
- if(dead->IsNPC() || dead->IsObject())
- {
- // handle instance spawn db info
- // we don't care if a NPC or a client kills the spawn, we could have events that cause NPCs to kill NPCs.
- if(dead->GetZone()->GetInstanceID() > 0 && dead->GetSpawnLocationID() > 0)
- {
- // use respawn time to either insert/update entry (likely insert in this situation)
- if(dead->IsNPC())
- database.CreateInstanceSpawnRemoved(dead->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_NPC, dead->GetRespawnTime(),dead->GetZone()->GetInstanceID());
- else if ( dead->IsObject ( ) )
- database.CreateInstanceSpawnRemoved(dead->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_OBJECT, dead->GetRespawnTime(),dead->GetZone()->GetInstanceID());
- }
- // Call the spawn scripts death() function
- CallSpawnScript(dead, SPAWN_SCRIPT_DEATH, killer);
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (zone_script && lua_interface)
- lua_interface->RunZoneScript(zone_script, "spawn_killed", this, dead, 0, 0, killer);
- }
-
- int32 victim_id = dead->GetID();
- int32 attacker_id = 0xFFFFFFFF;
- if(killer)
- attacker_id = killer->GetID();
- if(send_packet)
- {
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client->GetPlayer()->WasSentSpawn(victim_id) || (attacker_id != 0xFFFFFFFF && !client->GetPlayer()->WasSentSpawn(attacker_id)) )
- continue;
- else if(client->GetPlayer()->WasSpawnRemoved(dead) || (attacker_id != 0xFFFFFFFF && client->GetPlayer()->WasSpawnRemoved(killer)))
- continue;
- else if(killer && killer->GetDistance(client->GetPlayer()) > HEAR_SPAWN_DISTANCE)
- continue;
- packet = configReader.getStruct("WS_HearDeath", client->GetVersion());
- if(packet)
- {
- if(killer)
- packet->setDataByName("attacker", client->GetPlayer()->GetIDWithPlayerSpawn(killer));
- else
- packet->setDataByName("attacker", 0xFFFFFFFF);
- packet->setDataByName("defender", client->GetPlayer()->GetIDWithPlayerSpawn(dead));
- packet->setDataByName("damage_type", damage_type);
- packet->setDataByName("blow_type", kill_blow_type);
- client->QueuePacket(packet->serialize());
- LogWrite(COMBAT__DEBUG, 0, "Combat", "Zone Killing '%s'", dead->GetName());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- int32 pop_timer = 0xFFFFFFFF;
- if(killer && killer->IsNPC())
- {
- // Call the spawn scripts killed() function
- CallSpawnScript(killer, SPAWN_SCRIPT_KILLED, dead);
- if(!dead->IsPlayer())
- {
- LogWrite(MISC__TODO, 1, "TODO", "Whenever pets are added, check for pet kills\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- // Set the time for the corpse to linger to 5 sec
- //pop_timer = 5000;
- // commented out the timer so in the event the killer is not a player (pet, guard, something else i haven't thought of)
- // the corpse doesn't vanish sooner then it should if it had loot for the players. AddDeadSpawn() will set timers based on if
- // the corpse has loot or not if the timer value (pop_timer) is 0xFFFFFFFF
- }
- }
-
- // If the dead spawns was not a player add it to the dead spawn list
- if (!dead->IsPlayer() && !dead->IsBot())
- AddDeadSpawn(dead, pop_timer);
- // if dead was a player clear hostile spells from its spell queue
- if (dead->IsPlayer())
- spellProcess->RemoveSpellFromQueue((Player*)dead, true);
- if (dead->IsNPC())
- ((NPC*)dead)->Brain()->ClearHate();
- // ResetPetInfo() is called in DismissPet(), might not need to be here
- // Players pet is killed, clear the pet info from char sheet
- /*if (dead->IsNPC() && ((NPC*)dead)->IsPet() && ((NPC*)dead)->GetOwner()->IsPlayer())
- ((Player*)((NPC*)dead)->GetOwner())->ResetPetInfo();*/
- safe_delete(encounter);
- }
- void ZoneServer::SendDamagePacket(Spawn* attacker, Spawn* victim, int8 type1, int8 type2, int8 damage_type, int16 damage, const char* spell_name) {
- //Scat: was set but never being used anywhere. i see references to 0xFFFFFFFF below so could be old code not used anymore
- //int32 attacker_id = 0xFFFFFFFF;
- //if(attacker)
- // attacker_id = attacker->GetID();
- PacketStruct* packet = 0;
- Client* client = 0;
- if (attacker && victim && victim->IsPlayer() && victim->GetTarget() == 0) {
- client = GetClientBySpawn(victim);
- if (client)
- client->TargetSpawn(attacker);
- }
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if (!client || (client->GetPlayer() != attacker && client->GetPlayer() != victim && ((attacker && client->GetPlayer()->WasSentSpawn(attacker->GetID()) == false) || (victim && client->GetPlayer()->WasSentSpawn(victim->GetID()) == false))))
- continue;
- if ((attacker && client->GetPlayer()->WasSpawnRemoved(attacker)) || (victim && client->GetPlayer()->WasSpawnRemoved(victim)))
- continue;
- if (attacker && attacker->GetDistance(client->GetPlayer()) > 50)
- continue;
- if (victim && victim->GetDistance(client->GetPlayer()) > 50)
- continue;
- switch (type1) {
- case DAMAGE_PACKET_TYPE_SIPHON_SPELL:
- case DAMAGE_PACKET_TYPE_SIPHON_SPELL2:
- packet = configReader.getStruct("WS_HearSiphonSpellDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_MULTIPLE_DAMAGE:
- if (client->GetVersion() > 546)
- packet = configReader.getStruct("WS_HearMultipleDamage", client->GetVersion());
- else
- packet = configReader.getStruct("WS_HearSimpleDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG:
- case DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE:
- packet = configReader.getStruct("WS_HearSimpleDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE2:
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE3:
- case DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG:
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE:
- if (client->GetVersion() > 546)
- packet = configReader.getStruct("WS_HearSpellDamage", client->GetVersion());
- else
- packet = configReader.getStruct("WS_HearSimpleDamage", client->GetVersion());
- if (packet)
- packet->setSubstructDataByName("header", "unknown", 5);
- break;
- case DAMAGE_PACKET_TYPE_RANGE_DAMAGE:
- packet = configReader.getStruct("WS_HearRangeDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG:
- case DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2:
- packet = configReader.getStruct("WS_HearRangeDamage", client->GetVersion());
- break;
- default:
- LogWrite(ZONE__ERROR, 0, "Zone", "Unknown Damage Packet type: %i in ZoneServer::SendDamagePacket.", type1);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- if (packet) {
- if (client->GetVersion() > 546) {
- packet->setSubstructDataByName("header", "packet_type", type1);
- packet->setSubstructDataByName("header", "result_type", type2);
- packet->setDataByName("damage_type", damage_type);
- packet->setDataByName("damage", damage);
- }
- else {
- switch (type2) {
- case DAMAGE_PACKET_RESULT_MISS:
- packet->setSubstructDataByName("header", "result_type", 1);
- break;
- case DAMAGE_PACKET_RESULT_DODGE:
- packet->setSubstructDataByName("header", "result_type", 2);
- break;
- case DAMAGE_PACKET_RESULT_PARRY:
- packet->setSubstructDataByName("header", "result_type", 3);
- break;
- case DAMAGE_PACKET_RESULT_RIPOSTE:
- packet->setSubstructDataByName("header", "result_type", 4);
- break;
- case DAMAGE_PACKET_RESULT_BLOCK:
- packet->setSubstructDataByName("header", "result_type", 5);
- break;
- case DAMAGE_PACKET_RESULT_INVULNERABLE:
- packet->setSubstructDataByName("header", "result_type", 7);
- break;
- case DAMAGE_PACKET_RESULT_RESIST:
- packet->setSubstructDataByName("header", "result_type", 9);
- break;
- case DAMAGE_PACKET_RESULT_REFLECT:
- packet->setSubstructDataByName("header", "result_type", 10);
- break;
- case DAMAGE_PACKET_RESULT_IMMUNE:
- packet->setSubstructDataByName("header", "result_type", 11);
- break;
- }
- packet->setArrayLengthByName("num_dmg", 1);
- packet->setSubstructDataByName("header", "defender_proxy", client->GetPlayer()->GetIDWithPlayerSpawn(victim));
- packet->setArrayDataByName("damage_type", damage_type);
- packet->setArrayDataByName("damage", damage);
- }
- if (!attacker)
- packet->setSubstructDataByName("header", "attacker", 0xFFFFFFFF);
- else
- packet->setSubstructDataByName("header", "attacker", client->GetPlayer()->GetIDWithPlayerSpawn(attacker));
- packet->setSubstructDataByName("header", "defender", client->GetPlayer()->GetIDWithPlayerSpawn(victim));
- if (spell_name) {
- packet->setDataByName("spell", 1);
- packet->setDataByName("spell_name", spell_name);
- }
- EQ2Packet* app = packet->serialize();
- //DumpPacket(app);
- client->QueuePacket(app);
- safe_delete(packet);
- packet = 0;
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendHealPacket(Spawn* caster, Spawn* target, int16 heal_type, int32 heal_amt, const char* spell_name){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client->GetPlayer() != caster && ((caster && client->GetPlayer()->WasSentSpawn(caster->GetID()) == false) || (target && client->GetPlayer()->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && client->GetPlayer()->WasSpawnRemoved(caster)) || (caster && client->GetPlayer()->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(target && target->GetDistance(client->GetPlayer()) > 50)
- continue;
-
- PacketStruct* packet = configReader.getStruct("WS_HearHeal", client->GetVersion());
- if (packet) {
- packet->setDataByName("caster", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("heal_amt", heal_amt);
- packet->setDataByName("spellname", spell_name);
- packet->setDataByName("type", heal_type);
- packet->setDataByName("unknown2", 1);
- EQ2Packet* app = packet->serialize();
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendThreatPacket(Spawn* caster, Spawn* target, int32 threat_amt, const char* spell_name) {
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client->GetPlayer() != caster && ((caster && client->GetPlayer()->WasSentSpawn(caster->GetID()) == false) || (target && client->GetPlayer()->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && client->GetPlayer()->WasSpawnRemoved(caster)) || (caster && client->GetPlayer()->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(target && target->GetDistance(client->GetPlayer()) > 50)
- continue;
-
- PacketStruct* packet = configReader.getStruct("WS_HearThreatCmd", client->GetVersion());
- if (packet) {
- packet->setDataByName("spell_name", spell_name);
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("threat_amount", threat_amt);
-
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpellFailedPacket(Client* client, int16 error){
- if(!client)
- return;
- PacketStruct* packet = configReader.getStruct("WS_DisplaySpellFailed", client->GetVersion());
- if(packet){
- /* Temp solution, need to modify the error code before this function and while we still have access to the spell/combat art */
- error = master_spell_list.GetSpellErrorValue(client->GetVersion(), error);
- packet->setDataByName("error_code", error);
- //packet->PrintPacket();
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void ZoneServer::SendInterruptPacket(Spawn* interrupted, LuaSpell* spell){
- if(!interrupted || !spell)
- return;
-
- EQ2Packet* outapp = 0;
- PacketStruct* packet = 0;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->GetPlayer()->WasSentSpawn(interrupted->GetID()) || client->GetPlayer()->WasSpawnRemoved(interrupted))
- continue;
- packet = configReader.getStruct("WS_Interrupt", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(interrupted));
- packet->setArrayLengthByName("num_targets", spell->targets.size());
- for (int32 i = 0; i < spell->targets.size(); i++)
- packet->setArrayDataByName("target_id", client->GetPlayer()->GetIDWithPlayerSpawn(client->GetPlayer()->GetZone()->GetSpawnByID(spell->targets[i])), i);
- packet->setDataByName("spell_id", spell->spell->GetSpellID());
- outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- void ZoneServer::SendCastSpellPacket(LuaSpell* spell, Entity* caster){
- EQ2Packet* outapp = 0;
- PacketStruct* packet = 0;
- Client* client = 0;
- if(!caster || !spell || !spell->spell || spell->interrupted)
- return;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client)
- continue;
- packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setArrayLengthByName("num_targets", spell->targets.size());
- for (int32 i = 0; i < spell->targets.size(); i++)
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(spell->caster->GetZone()->GetSpawnByID(spell->targets[i])), i);
- packet->setDataByName("spell_visual", spell->spell->GetSpellData()->spell_visual); //result
- packet->setDataByName("cast_time", spell->spell->GetSpellData()->cast_time*.01); //delay
- packet->setDataByName("spell_id", spell->spell->GetSpellID());
- packet->setDataByName("spell_level", 1);
- packet->setDataByName("spell_tier", spell->spell->GetSpellData()->tier);
- outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- void ZoneServer::SendCastSpellPacket(int32 spell_visual, Spawn* target, Spawn* caster) {
- if (target) {
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- Client* client = *client_itr;
- if (!client)
- continue;
- PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if (packet) {
- if (!caster) {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- packet->setDataByName("invoker_id", 0xFFFFFFFF);
- }
- else {
- int32 caster_id = client->GetPlayer()->GetIDWithPlayerSpawn(caster);
- packet->setDataByName("spawn_id", caster_id);
- packet->setDataByName("invoker_id", caster_id);
- }
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("spell_visual", spell_visual);
- packet->setDataByName("cast_time", 0);
- packet->setDataByName("spell_id", 0);
- packet->setDataByName("spell_level", 0);
- packet->setDataByName("spell_tier", 1);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendCastEntityCommandPacket(EntityCommand* entity_command, int32 spawn_id, int32 target_id) {
- if (entity_command) {
- Spawn* spawn = GetSpawnByID(spawn_id);
- Spawn* target = GetSpawnByID(target_id);
- if (!spawn || !target)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if (!client || !client->GetPlayer()->WasSentSpawn(spawn_id) || client->GetPlayer()->WasSpawnRemoved(spawn) || !client->GetPlayer()->WasSentSpawn(target_id) || client->GetPlayer()->WasSpawnRemoved(target))
- continue;
- PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("num_targets", 1);
- packet->setDataByName("spell_visual", entity_command->spell_visual); //result
- packet->setDataByName("cast_time", entity_command->cast_time * 0.01); //delay
- packet->setDataByName("spell_id", 1);
- packet->setDataByName("spell_level", 1);
- packet->setDataByName("spell_tier", 1);
- EQ2Packet* outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::StartZoneInitialSpawnThread(Client* client){
- if(zoneShuttingDown)
- return;
- #ifdef WIN32
- _beginthread(SendInitialSpawns, 0, client);
- #else
- pthread_t thread;
- pthread_create(&thread, NULL, SendInitialSpawns, client);
- pthread_detach(thread);
- #endif
- }
- void ZoneServer::SendZoneSpawns(Client* client){
- int8 count = 0;
- while (LoadingData && count <= 6000) { //sleep for max of 60 seconds (60000ms) while the maps are loading
- count++;
- Sleep(10);
- }
- count = 0;
- int16 size = 0;
- //give the spawn thread a tad bit of time to add the pending_spawns to spawn_list (up to 10 seconds)
- while (count < 1000) {
- MPendingSpawnListAdd.readlock(__FUNCTION__, __LINE__);
- size = pending_spawn_list_add.size();
- MPendingSpawnListAdd.releasereadlock(__FUNCTION__, __LINE__);
- if (size == 0)
- break;
- Sleep(10);
- count++;
- }
- initial_spawn_threads_active++;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- Spawn* spawn = itr->second;
- if (spawn) {
- CheckSpawnRange(client, spawn, true);
- }
- }
- CheckSendSpawnToClient(client, true);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- client->SetConnected(true);
- ClientPacketFunctions::SendFinishedEntitiesList(client);
- initial_spawn_threads_active--;
- }
- vector<Entity*> ZoneServer::GetPlayers(){
- vector<Entity*> ret;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- ret.push_back(client->GetPlayer());
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- int16 ZoneServer::SetSpawnTargetable(Spawn* spawn, float distance){
- Spawn* test_spawn = 0;
- int16 ret_val = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn){
- if(test_spawn->GetDistance(spawn) <= distance){
- test_spawn->SetTargetable(1);
- ret_val++;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret_val;
- }
- int16 ZoneServer::SetSpawnTargetable(int32 spawn_id){
- Spawn* spawn = 0;
- int16 ret_val = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(spawn->GetDatabaseID() == spawn_id){
- spawn->SetTargetable(1);
- ret_val++;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret_val;
- }
- ZoneInfoSlideStruct* ZoneServer::GenerateSlideStruct(float unknown1a, float unknown1b, int32 unknown2a, int32 unknown2b, int32 unknown3, int32 unknown4, const char* slide, const char* voiceover, int32 key1, int32 key2) {
- ZoneInfoSlideStructInfo* info = new ZoneInfoSlideStructInfo();
- memset(info, 0, sizeof(ZoneInfoSlideStructInfo));
- info->unknown1[0] = unknown1a;
- info->unknown1[1] = unknown1b;
- info->unknown2[0] = unknown2a;
- info->unknown2[1] = unknown2b;
- info->unknown3 = unknown3;
- info->unknown4 = unknown4;
- int8 length = strlen(slide);
- if (length >= 128)
- length = 127;
- strncpy(info->slide, slide, length);
- length = strlen(voiceover);
- if (length >= 128)
- length = 127;
- strncpy(info->voiceover, voiceover, length);
- info->key1 = key1;
- info->key2 = key2;
- ZoneInfoSlideStruct* ret = new ZoneInfoSlideStruct();
- ret->info = info;
- return ret;
- }
- void ZoneServer::AddZoneInfoSlideStructTransitionInfo(ZoneInfoSlideStruct* info, int32 x, int32 y, float zoom, float transition_time) {
- ZoneInfoSlideStructTransitionInfo* transition_info = new ZoneInfoSlideStructTransitionInfo();
- transition_info->transition_x = x;
- transition_info->transition_y = y;
- transition_info->transition_zoom = zoom;
- transition_info->transition_time = transition_time;
- info->slide_transition_info.push_back(transition_info);
- }
- vector<ZoneInfoSlideStruct*>* ZoneServer::GenerateTutorialSlides() {
- vector<ZoneInfoSlideStruct*>* slides = new vector<ZoneInfoSlideStruct*>();
- ZoneInfoSlideStruct* slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt01_final001.dds", "voiceover/english/antonia_intro/antonia_intro_001_64.mp3", 2519553957, 1010319376);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.5, 16);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt02_final001.dds", "voiceover/english/antonia_intro/antonia_intro_002_64.mp3", 567178266, 3055063399);
- AddZoneInfoSlideStructTransitionInfo(slide, 600, 365, 1.60000002384186, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 800, 370, 1.39999997615814, 9);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.20000004768372, 8);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt03_final001.dds", "voiceover/english/antonia_intro/antonia_intro_003_64.mp3", 3171561318, 593374281);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.20000004768372, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 750, 320, 1.60000002384186, 10);
- AddZoneInfoSlideStructTransitionInfo(slide, 575, 265, 2.29999995231628, 10);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt04_final001.dds", "voiceover/english/antonia_intro/antonia_intro_004_64.mp3", 1959944485, 4285605574);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 2.5, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.70000004768372, 8);
- AddZoneInfoSlideStructTransitionInfo(slide, 675, 390, 2.20000004768372, 11);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt05_final001.dds", "voiceover/english/antonia_intro/antonia_intro_005_64.mp3", 609693392, 260295215);
- AddZoneInfoSlideStructTransitionInfo(slide, 750, 500, 2.79999995231628, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 720, 300, 2.5, 9);
- AddZoneInfoSlideStructTransitionInfo(slide, 975, 270, 2.20000004768372, 9);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt06_final001.dds", "voiceover/english/antonia_intro/antonia_intro_006_64.mp3", 3056613203, 775201556);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.89999997615814, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 475, 1, 24);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt07_final001.dds", "voiceover/english/antonia_intro/antonia_intro_007_64.mp3", 3113327662, 1299367895);
- AddZoneInfoSlideStructTransitionInfo(slide, 1400, 420, 2.40000009536743, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 1200, 375, 1.70000004768372, 7);
- AddZoneInfoSlideStructTransitionInfo(slide, 800, 225, 2.29999995231628, 7);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt08_final001.dds", "voiceover/english/antonia_intro/antonia_intro_008_64.mp3", 2558791235, 2674773065);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.5, 27);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt09_final001.dds", "voiceover/english/antonia_intro/antonia_intro_009_64.mp3", 4029296401, 1369011033);
- AddZoneInfoSlideStructTransitionInfo(slide, 715, 305, 2.40000009536743, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 730, 325, 1.79999995231628, 6);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 395, 1.5, 5);
- AddZoneInfoSlideStructTransitionInfo(slide, 1360, 330, 1.79999995231628, 9);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt10_final001.dds", "voiceover/english/antonia_intro/antonia_intro_010_64.mp3", 3055524517, 3787058332);
- AddZoneInfoSlideStructTransitionInfo(slide, 670, 675, 2.20000004768372, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 710, 390, 1.79999995231628, 7);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 415, 1.60000002384186, 5.5);
- AddZoneInfoSlideStructTransitionInfo(slide, 1250, 675, 1.79999995231628, 8);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt11_final001.dds", "voiceover/english/antonia_intro/antonia_intro_011_64.mp3", 3525586740, 812068950);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 2, 19);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt12_final001.dds", "voiceover/english/antonia_intro/antonia_intro_012_64.mp3", 3493874350, 2037661816);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 2, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 43);
- slides->push_back(slide);
- return slides;
- }
- EQ2Packet* ZoneServer::GetZoneInfoPacket(Client* client){
- client_spawn_map.Put(client->GetPlayer(), client);
- PacketStruct* packet = configReader.getStruct("WS_ZoneInfo", client->GetVersion());
- packet->setSmallStringByName("server1",net.GetWorldName());
- packet->setSmallStringByName("server2",net.GetWorldName());
- packet->setDataByName("unknown1", 1, 1);//1, 1
- int32 expansions = EXPANSION_UNKNOWN + EXPANSION_DOF + EXPANSION_KOS + EXPANSION_EOF + EXPANSION_ROK + EXPANSION_TSO + EXPANSION_DOV;
- //packet->setDataByName("expansions_enabled", 82313211);//expansions 63181
- //packet->setDataByName("expansions_enabled", 552075103);//expansions 63182
- packet->setDataByName("expansions_enabled", 4294967295);//expansions 1096 //612499455 works
- if (client->GetVersion() >= 1193) {
- packet->setDataByName("unknown3", 4294967295, 0); // DOV and down
- packet->setDataByName("unknown3", 4294967295, 1); //COE and up
- packet->setDataByName("unknown3", 4294967295, 2);
- }
- else
- packet->setDataByName("unknown3", 4294967295, 0); // DOV and down
- packet->setSmallStringByName("auction_website", "eq2emulator.net");
- packet->setDataByName("auction_port", 80);
- packet->setSmallStringByName("upload_page", "test_upload.m");
- packet->setSmallStringByName("upload_key", "dsya987yda9");
- packet->setSmallStringByName("zone", GetZoneFile());
- //packet->setSmallStringByName("zone2", GetZoneName());
- //if ( strlen(GetZoneSkyFile()) > 0 )
- // packet->setSmallStringByName("zone_unknown2", GetZoneSkyFile()); // used for the sky map
- packet->setSmallStringByName("zone_desc", GetZoneDescription());
- packet->setSmallStringByName("char_name", client->GetPlayer()->GetName());
-
- packet->setDataByName("x", client->GetPlayer()->GetX());
- packet->setDataByName("y", client->GetPlayer()->GetY());
- packet->setDataByName("z", client->GetPlayer()->GetZ());
- if ((GetZoneFile() && strcmp("boat_06p_tutorial02", GetZoneFile()) == 0) && client->GetPlayer()->GetX() == this->GetSafeX() && client->GetPlayer()->GetY() == this->GetSafeY() && client->GetPlayer()->GetZ() == this->GetSafeZ()) { //basically the only time the player will see this is if their zone in coords are the exact same as the safe coords (they haven't moved)
- vector<ZoneInfoSlideStruct*>* slides = GenerateTutorialSlides();
- if (slides) {
- packet->setArrayLengthByName("num_slides", slides->size());
- ZoneInfoSlideStruct* slide = 0;
- for (int8 i = 0; i < slides->size(); i++) {
- slide = slides->at(i);
- packet->setArrayDataByName("unknown1", slide->info->unknown1[0], i, 0);
- packet->setArrayDataByName("unknown1", slide->info->unknown1[1], i, 1);
- packet->setArrayDataByName("unknown2", slide->info->unknown2[0], i, 0);
- packet->setArrayDataByName("unknown2", slide->info->unknown2[1], i, 1);
- packet->setArrayDataByName("unknown3", slide->info->unknown3, i);
- packet->setArrayDataByName("unknown4", slide->info->unknown4, i);
- packet->setArrayDataByName("slide", slide->info->slide, i);
- packet->setArrayDataByName("voiceover", slide->info->voiceover, i);
- packet->setArrayDataByName("key1", slide->info->key1, i);
- packet->setArrayDataByName("key2", slide->info->key2, i);
- packet->setSubArrayLengthByName("num_transitions", slide->slide_transition_info.size(), i);
- for (int8 x = 0; x < slide->slide_transition_info.size(); x++) {
- packet->setSubArrayDataByName("transition_x", slide->slide_transition_info[x]->transition_x, i, x);
- packet->setSubArrayDataByName("transition_y", slide->slide_transition_info[x]->transition_y, i, x);
- packet->setSubArrayDataByName("transition_zoom", slide->slide_transition_info[x]->transition_zoom, i, x);
- packet->setSubArrayDataByName("transition_time", slide->slide_transition_info[x]->transition_time, i, x);
- safe_delete(slide->slide_transition_info[x]);
- }
- safe_delete(slide->info);
- safe_delete(slide);
- }
- }
- safe_delete(slides);
- }
- packet->setDataByName("underworld", underworld);
-
- // unknown3 can prevent screen shots from being taken if
- //packet->setDataByName("unknown3", 2094661567, 1); // Screenshots allowed with this value
- //packet->setDataByName("unknown3", 3815767999, 1); // Screenshots disabled with this value
- //packet->setDataByName("unknown3", 1, 2);
- /*if (client->GetVersion() >= 63587) {
- packet->setArrayLengthByName("num_exp_feature_bytes", 9);
- packet->setArrayDataByName("exp_feature_bytes", 95, 0);//kos and dof
- packet->setArrayDataByName("exp_feature_bytes", 255, 1);//eof rok tso sf dov coe tov
- packet->setArrayDataByName("exp_feature_bytes", 247, 2);//aom tot ka exp14
- packet->setArrayDataByName("exp_feature_bytes", 32, 3);//rum cellar
- packet->setArrayDataByName("exp_feature_bytes", 140, 4);
- packet->setArrayDataByName("exp_feature_bytes", 62, 5);
- packet->setArrayDataByName("exp_feature_bytes", 0, 6);
- packet->setArrayDataByName("exp_feature_bytes", 45, 7);
- packet->setArrayDataByName("exp_feature_bytes", 128, 8);
- packet->setArrayLengthByName("num_unknown3b_bytes", 9);
- packet->setArrayDataByName("unknown3b_bytes", 95, 0);
- packet->setArrayDataByName("unknown3b_bytes", 255, 1);
- packet->setArrayDataByName("unknown3b_bytes", 247, 2);
- packet->setArrayDataByName("unknown3b_bytes", 237, 3);
- packet->setArrayDataByName("unknown3b_bytes", 143, 4);
- packet->setArrayDataByName("unknown3b_bytes", 255, 5);
- packet->setArrayDataByName("unknown3b_bytes", 255, 6);
- packet->setArrayDataByName("unknown3b_bytes", 255, 7);
- packet->setArrayDataByName("unknown3b_bytes", 128, 8);
- }
- else if (client->GetVersion() >= 63214) {
- packet->setArrayLengthByName("num_exp_feature_bytes", 9);
- packet->setArrayDataByName("exp_feature_bytes", 95, 0);//kos and dof
- packet->setArrayDataByName("exp_feature_bytes", 255, 1);//eof rok tso sf dov coe tov
- packet->setArrayDataByName("exp_feature_bytes", 247, 2);//aom tot ka exp14
- packet->setArrayDataByName("exp_feature_bytes", 32, 3);//rum cellar
- packet->setArrayDataByName("exp_feature_bytes", 140, 4);
- packet->setArrayDataByName("exp_feature_bytes", 62, 5);
- packet->setArrayDataByName("exp_feature_bytes", 0, 6);
- packet->setArrayDataByName("exp_feature_bytes", 45, 7);
- packet->setArrayDataByName("exp_feature_bytes", 128, 8);
- packet->setArrayLengthByName("num_unknown3b_bytes", 9);
- packet->setArrayDataByName("unknown3b_bytes", 95, 0);
- packet->setArrayDataByName("unknown3b_bytes", 255, 1);
- packet->setArrayDataByName("unknown3b_bytes", 247, 2);
- packet->setArrayDataByName("unknown3b_bytes", 237, 3);
- packet->setArrayDataByName("unknown3b_bytes", 143, 4);
- packet->setArrayDataByName("unknown3b_bytes", 255, 5);
- packet->setArrayDataByName("unknown3b_bytes", 255, 6);
- packet->setArrayDataByName("unknown3b_bytes", 255, 7);
- packet->setArrayDataByName("unknown3b_bytes", 128, 8);
- }*/
- if (client->GetVersion() >= 64644) {
- packet->setDataByName("unknown3a", 12598924);
- packet->setDataByName("unknown3b", 3992452959);
- packet->setDataByName("unknown3c", 4294967183);
- packet->setDataByName("unknown2a", 9);
- packet->setDataByName("unknown2b", 9);
- }
- else if (client->GetVersion() >= 63181) {
- packet->setDataByName("unknown3a", 750796556);//63182 73821356
- packet->setDataByName("unknown3b", 3991404383);// 63182 3991404383
- packet->setDataByName("unknown3c", 4278189967);// 63182 4278189967
- packet->setDataByName("unknown2a", 8);// 63182
- packet->setDataByName("unknown2b", 8);// 63182
-
- }
- else{
- //packet->setDataByName("unknown3", 872447025,0);//63181
- //packet->setDataByName("unknown3", 3085434875,1);// 63181
- //packet->setDataByName("unknown3", 2147483633,2);// 63181
- }
-
- packet->setDataByName("year", world.GetWorldTimeStruct()->year);
- packet->setDataByName("month", world.GetWorldTimeStruct()->month);
- packet->setDataByName("day", world.GetWorldTimeStruct()->day);
- packet->setDataByName("hour", world.GetWorldTimeStruct()->hour);
- packet->setDataByName("minute", world.GetWorldTimeStruct()->minute);
- packet->setDataByName("unknown", 0);
- packet->setDataByName("unknown7", 1);
- packet->setDataByName("unknown7", 1, 1);
-
- packet->setDataByName("unknown9", 13);
- //packet->setDataByName("unknown10", 25188959);4294967295
- //packet->setDataByName("unknown10", 25190239);
- packet->setDataByName("unknown10", 25191524);//25191524
- packet->setDataByName("unknown10b", 1);
- packet->setDataByName("permission_level",3);// added on 63182 for now till we figur it out 0=none,1=visitor,2=friend,3=trustee,4=owner
- packet->setDataByName("num_adv", 9);
- packet->setArrayDataByName("adv_name", "adv02_dun_drowned_caverns", 0);
- packet->setArrayDataByName("adv_id", 6, 0);
- packet->setArrayDataByName("adv_name", "adv02_dun_sundered_splitpaw_hub", 1);
- packet->setArrayDataByName("adv_id", 5, 1);
- packet->setArrayDataByName("adv_name", "exp03_rgn_butcherblock", 2);
- packet->setArrayDataByName("adv_id", 8, 2);
- packet->setArrayDataByName("adv_name", "exp03_rgn_greater_faydark", 3);
- packet->setArrayDataByName("adv_id", 7, 3);
- packet->setArrayDataByName("adv_name", "mod01_dun_crypt_of_thaen", 4);
- packet->setArrayDataByName("adv_id", 3, 4);
- packet->setArrayDataByName("adv_name", "mod01_dun_tombs_of_night", 5);
- packet->setArrayDataByName("adv_id", 4, 5);
- packet->setArrayDataByName("adv_name", "nektulos_mini01", 6);
- packet->setArrayDataByName("adv_id", 0, 6);
- packet->setArrayDataByName("adv_name", "nektulos_mini02", 7);
- packet->setArrayDataByName("adv_id", 1, 7);
- packet->setArrayDataByName("adv_name", "nektulos_mini03", 8);
- packet->setArrayDataByName("adv_id", 2, 8);
- LogWrite(MISC__TODO, 0, "TODO", "Put cl_ client commands back in variables (not Rules) so they can be dynamically maintained");
- vector<Variable*>* variables = world.GetClientVariables();
- packet->setArrayLengthByName("num_client_setup", variables->size());
- for(int i=variables->size()-1;i>=0;i--)
- packet->setArrayDataByName("client_cmds", variables->at(i)->GetNameValuePair().c_str(), i);
- // For AoM clients so item link work
- if (client->GetVersion() >= 60114)
- packet->setArrayDataByName("client_cmds", "chat_linkbrackets_item 1", variables->size());
- safe_delete(variables);
- //packet->setDataByName("unknown8", ); story?
- // AA Tabs for 1193+ clients
- if (client->GetVersion() >= 1193) {
- packet->setArrayLengthByName("tab_count", 48);
- int8 i = 0;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":es24a58bd8fcaac8c2:All", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c727bd47a6:Racial Innate", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c75a96e23c:Tradeskill Advancement", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c744f1fd99:Focus Effects", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71edd2a66:Heroic", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c76ee6239f:Shadows", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7e678b977:Prestige", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c77ee422d7:Animalist", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f165af77:Bard", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7421b9375:Brawler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7a03ae7d1:Cleric", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7c9605e9f:Crusader", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f9424168:Druid", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79cb9556c:Enchanter", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c8b6aa4:Predator", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73a43b6dd:Rogue", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c759fe7d15:Sorcerer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ad610aca:Summoner", i);
-
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71e056728:Warrior", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ba864c0b:Assassin", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7b8116aad:Beastlord", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f53feb7b:Berserker", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73d8a70e2:Brigand", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c770c766d6:Bruiser", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79226984b:Coercer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c58bb30:Conjurer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73dfe68d0:Defiler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c792919a6b:Dirge", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7062e5f55:Fury", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c762c1fdfc:Guardian", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78addfbf4:Illusionist", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ece054a7:Inquisitor", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7d550d2e7:Monk", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c743cfeaa2:Mystic", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f63c9c8c:Necromancer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c5de0ae:Paladin", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79bc97b3a:Ranger", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78fbd2256:Shadowknight", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7781cc625:Shaman", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c77eecdcdb:Swashbuckler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7648d181e:Templar", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78df47d77:Troubador", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7c78ce0b8:Warden", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c76290dcfa:Warlock", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7d1d52cf5:Wizard", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71c8f6f4d:Shaper", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c72f6e354d:Channeler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7df8bd37d:Dragon", i);
- }
- packet->setDataByName("unknown_mj", 1);//int8
- packet->setDataByName("unknown_mj1", 335544320);//int32
- packet->setDataByName("unknown_mj2", 4);//int32
- packet->setDataByName("unknown_mj3", 3962504088);//int32
- packet->setDataByName("unknown_mj4", 3985947216);//int32
- packet->setDataByName("unknown_mj5", 1);//int32
- packet->setDataByName("unknown_mj6", 386);//int32
- packet->setDataByName("unknown_mj7", 4294967295);//int32
- packet->setDataByName("unknown_mj8", 2716312211);//int32
- packet->setDataByName("unknown_mj9", 1774338333);//int32
- packet->setDataByName("unknown_mj10", 1);//int32
- packet->setDataByName("unknown_mj11", 391);//int32
- packet->setDataByName("unknown_mj12", 4294967295);//int32
- packet->setDataByName("unknown_mj13", 3168965163);//int32
- packet->setDataByName("unknown_mj14", 4117025286);//int32
- packet->setDataByName("unknown_mj15", 1);//int32
- packet->setDataByName("unknown_mj16", 394);//int32
- packet->setDataByName("unknown_mj17", 4294967295);//int32
- packet->setDataByName("unknown_mj18", 1790669110);//int32
- packet->setDataByName("unknown_mj19", 107158108);//int32
- packet->setDataByName("unknown_mj20", 1);//int32
- packet->setDataByName("unknown_mj21", 393);//int32
- packet->setDataByName("unknown_mj22", 4294967295);//int32
- EQ2Packet* outapp = packet->serialize();
- //packet->PrintPacket();
- //DumpPacket(outapp);
- safe_delete(packet);
- return outapp;
- }
- void ZoneServer::SendUpdateDefaultCommand(Spawn* spawn, const char* command, float distance, Spawn* toPlayer){
- if (spawn == nullptr || command == nullptr)
- return;
- if (toPlayer)
- {
- if (!toPlayer->IsPlayer())
- return;
- Client* client = GetClientBySpawn(toPlayer);
- if (client)
- {
- client->SendDefaultCommand(spawn, command, distance);
- }
- // we don't override the primary command cause that would change ALL clients
- return;
- }
- Client* client = 0;
- PacketStruct* packet = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- client->SendDefaultCommand(spawn, command, distance);
- }
-
- if (strlen(command)>0)
- spawn->SetPrimaryCommand(command, command, distance);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckPlayerProximity(Spawn* spawn, Client* client){
- if (player_proximities.size() < 1)
- return;
- if(player_proximities.count(spawn->GetID()) > 0){
- PlayerProximity* prox = player_proximities.Get(spawn->GetID());
- if(prox->clients_in_proximity.count(client) == 0 && spawn_range_map.count(client) > 0 && spawn_range_map.Get(client)->count(spawn->GetID()) > 0 && spawn_range_map.Get(client)->Get(spawn->GetID()) < prox->distance){
- prox->clients_in_proximity[client] = true;
- CallSpawnScript(spawn, SPAWN_SCRIPT_CUSTOM, client->GetPlayer(), prox->in_range_lua_function.c_str());
- }
- else if(prox->clients_in_proximity.count(client) > 0 && spawn_range_map.count(client) > 0 && spawn_range_map.Get(client)->count(spawn->GetID()) > 0 && spawn_range_map.Get(client)->Get(spawn->GetID()) > prox->distance){
- if(prox->leaving_range_lua_function.length() > 0)
- CallSpawnScript(spawn, SPAWN_SCRIPT_CUSTOM, client->GetPlayer(), prox->leaving_range_lua_function.c_str());
- prox->clients_in_proximity.erase(client);
- }
- }
- }
- void ZoneServer::AddPlayerProximity(Spawn* spawn, float distance, string in_range_function, string leaving_range_function){
- RemovePlayerProximity(spawn);
- PlayerProximity* prox = new PlayerProximity;
- prox->distance = distance;
- prox->in_range_lua_function = in_range_function;
- prox->leaving_range_lua_function = leaving_range_function;
- player_proximities.Put(spawn->GetID(), prox);
- }
- void ZoneServer::RemovePlayerProximity(Client* client){
- PlayerProximity* prox = 0;
- MutexMap<int32, PlayerProximity*>::iterator itr = player_proximities.begin();
- while(itr.Next()){
- prox = itr->second;
- if(prox->clients_in_proximity.count(client) > 0)
- prox->clients_in_proximity.erase(client);
- }
- }
- void ZoneServer::RemovePlayerProximity(Spawn* spawn, bool all){
- if(all){
- MutexMap<int32, PlayerProximity*>::iterator itr = player_proximities.begin();
- while(itr.Next()){
- player_proximities.erase(itr->first, false, true, 10000);
- }
- }
- else if(player_proximities.count(spawn->GetID()) > 0){
- player_proximities.erase(spawn->GetID(), false, true, 10000);
- }
- }
- void ZoneServer::AddLocationProximity(float x, float y, float z, float max_variation, string in_range_function, string leaving_range_function) {
- LocationProximity* prox = new LocationProximity;
- prox->x = x;
- prox->y = y;
- prox->z = z;
- prox->max_variation = max_variation;
- prox->in_range_lua_function = in_range_function;
- prox->leaving_range_lua_function = leaving_range_function;
- location_proximities.Add(prox);
- }
- void ZoneServer::CheckLocationProximity() {
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (!zone_script)
- return;
- if (location_proximities.size() > 0 && connected_clients.size() > 0) {
- Client* client = 0;
- MutexList<Client*>::iterator iterator = connected_clients.begin();
- while(iterator.Next()){
- client = iterator->value;
- if (client->IsConnected() && client->IsReadyForSpawns() && !client->IsZoning()) {
- try {
- MutexList<LocationProximity*>::iterator itr = location_proximities.begin();
- LocationProximity* prox = 0;
- while(itr.Next()){
- prox = itr->value;
- bool in_range = false;
- float char_x = client->GetPlayer()->GetX();
- float char_y = client->GetPlayer()->GetY();
- float char_z = client->GetPlayer()->GetZ();
- float x = prox->x;
- float y = prox->y;
- float z = prox->z;
- float max_variation = prox->max_variation;
- float total_diff = 0;
- float diff = x - char_x; //Check X
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- diff = z - char_z; //Check Z (we check Z first because it is far more likely to be a much greater variation than y)
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- if(total_diff <= max_variation) { //Check Total
- diff = y - char_y; //Check Y
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- if(total_diff <= max_variation) {
- in_range = true;
- if(lua_interface && prox->in_range_lua_function.length() > 0 && prox->clients_in_proximity.count(client) == 0) { //Check Total
- prox->clients_in_proximity[client] = true;
- lua_interface->RunZoneScript(zone_script, prox->in_range_lua_function.c_str(), this, client->GetPlayer());
- }
- }
- }
- }
- }
- }
- if (!in_range) {
- if(lua_interface && prox->leaving_range_lua_function.length() > 0 && prox->clients_in_proximity.count(client) > 0) {
- lua_interface->RunZoneScript(zone_script, prox->leaving_range_lua_function.c_str(), this, client->GetPlayer());
- prox->clients_in_proximity.erase(client);
- }
- }
- }
- }
- catch (...) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Except caught in ZoneServer::CheckLocationProximity");
- return;
- }
- }
- }
- }
- }
- void ZoneServer::CheckLocationGrids() {
- if (connected_clients.size() > 0 && location_grids.size() > 0) {
- MutexList<Client*>::iterator client_itr = connected_clients.begin();
- while (client_itr.Next()) {
- Client* client = client_itr.value;
- if (!client)
- continue;
- Player* player = client->GetPlayer();
- float x = player->GetX();
- float y = player->GetY();
- float z = player->GetZ();
- int32 grid_id = player->appearance.pos.grid_id;
- MutexList<LocationGrid*>::iterator location_grid_itr = location_grids.begin();
- while (location_grid_itr.Next()) {
- LocationGrid* grid = location_grid_itr.value;
- if (grid->locations.size() > 0 || /*(grid->grid_id == grid_id ||*/ grid->players.count(player) > 0) {
- float x_small = 0;
- float x_large = 0;
- float y_small = 0;
- float y_large = 0;
- float z_small = 0;
- float z_large = 0;
- bool first = true;
- bool in_grid = false;
- MutexList<Location*>::iterator location_itr = grid->locations.begin();
- while (location_itr.Next()) {
- Location* location = location_itr.value;
- if (first) {
- x_small = location->x;
- x_large = location->x;
- if (grid->include_y) {
- y_small = location->y;
- y_large = location->y;
- }
- z_small = location->z;
- z_large = location->z;
- first = false;
- }
- else {
- if (location->x < x_small)
- x_small = location->x;
- else if (location->x > x_large)
- x_large = location->x;
- if (grid->include_y) {
- if (location->y < y_small)
- y_small = location->y;
- else if (location->y > y_large)
- y_large = location->y;
- }
- if (location->z < z_small)
- z_small = location->z;
- else if (location->z > z_large)
- z_large = location->z;
- }
- }
- if (grid->include_y && (x >= x_small && x <= x_large && y >= y_small && y <= y_large && z >= z_small && z <= z_large))
- in_grid = true;
- else if (x >= x_small && x <= x_large && z >= z_small && z <= z_large)
- in_grid = true;
- if (in_grid && grid->players.count(player) == 0) {
- grid->players.Put(player, true);
- bool show_enter_location_popup = true;
- bool discovery_enabled = rule_manager.GetGlobalRule(R_World, EnablePOIDiscovery)->GetBool();
- if( grid->discovery && discovery_enabled && !player->DiscoveredLocation(grid->id) )
- {
- // check if player has already discovered this location
- // if not, process new discovery
- char tmp[200] = {0};
- sprintf(tmp, "\\#FFE400You have discovered\12\\#FFF283%s", grid->name.c_str());
- client->SendPopupMessage(11, tmp, "ui_discovery", 2.25, 0xFF, 0xFF, 0xFF);
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' discovered location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- player->UpdatePlayerHistory(HISTORY_TYPE_DISCOVERY, HISTORY_SUBTYPE_LOCATION, grid->id);
- show_enter_location_popup = false;
- // else, print standard location entry
- }
- if( show_enter_location_popup )
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' entering location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- client->SendPopupMessage(10, grid->name.c_str(), 0, 2.5, 255, 255, 0);
- }
- }
- else if (!in_grid && grid->players.count(player) > 0) {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' leaving location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- grid->players.erase(player);
- }
- }
- }
- }
- }
- }
- // Called from a command (client, main zone thread) and the main zone thread
- // so no need for a mutex container
- void ZoneServer::AddLocationGrid(LocationGrid* grid) {
- if (grid)
- location_grids.Add(grid);
- }
- void ZoneServer::RemoveLocationGrids() {
- MutexList<LocationGrid*>::iterator itr = location_grids.begin();
- while (itr.Next())
- itr.value->locations.clear(true);
- location_grids.clear(true);
- }
- void ZoneServer::RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, bool delete_recast){
- if(spellProcess)
- spellProcess->RemoveSpellTimersFromSpawn(spawn, remove_all, delete_recast);
- }
- void ZoneServer::Interrupted(Entity* caster, Spawn* interruptor, int16 error_code, bool cancel, bool from_movement){
- if(spellProcess)
- spellProcess->Interrupted(caster, interruptor, error_code, cancel, from_movement);
- }
- Spell* ZoneServer::GetSpell(Entity* caster){
- Spell* spell = 0;
- if(spellProcess)
- spell = spellProcess->GetSpell(caster);
- return spell;
- }
- void ZoneServer::ProcessSpell(Spell* spell, Entity* caster, Spawn* target, bool lock, bool harvest_spell, LuaSpell* customSpell, int16 custom_cast_time, bool in_heroic_opp){
- if(spellProcess)
- spellProcess->ProcessSpell(this, spell, caster, target, lock, harvest_spell, customSpell, custom_cast_time, in_heroic_opp);
- }
- void ZoneServer::ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock) {
- if (target && target->GetSpawnScript()) {
- Player* player = 0;
- if (caster && caster->IsPlayer())
- player = (Player*)caster;
- CallSpawnScript(target, SPAWN_SCRIPT_CUSTOM, player, entity_command->command.c_str());
- }
- if (spellProcess)
- spellProcess->ProcessEntityCommand(this, entity_command, caster, target, lock);
- }
- void ZoneServer::RemoveSpawnSupportFunctions(Spawn* spawn) {
- if(!spawn)
- return;
- LogWrite(ZONE__DEBUG, 7, "Zone", "Processing RemoveSpawnSupportFunctions...");
- if(spawn->IsEntity())
- RemoveSpellTimersFromSpawn((Entity*)spawn, true);
- RemoveDamagedSpawn(spawn);
- spawn->SendSpawnChanges(false);
- RemoveChangedSpawn(spawn);
-
- // Everything inside this if will be nuked during a reload in other spots, no need to do it twice
- if (!reloading) {
- RemoveDeadEnemyList(spawn);
- spawn->changed = true;
- spawn->info_changed = true;
- spawn->vis_changed = true;
- spawn->position_changed = true;
- SendSpawnChanges(spawn);
- if (spawn->GetSpawnGroupID() > 0) {
- int32 group_id = spawn->GetSpawnGroupID();
- spawn->RemoveSpawnFromGroup();
- if (spawn_group_map.count(group_id) > 0)
- spawn_group_map.Get(group_id).Remove(spawn->GetID());
- }
- if (!spawn->IsPlayer()) {
- if(quick_database_id_lookup.count(spawn->GetDatabaseID()) > 0)
- quick_database_id_lookup.erase(spawn->GetDatabaseID());
- }
- RemoveHeadingTimer(spawn);
- DeleteSpawnScriptTimers(spawn);
- RemovePlayerProximity(spawn);
- }
- // We don't use RemoveMovementNPC() here as it caused a hell of a delay during reloads
- // instead we remove it from the list directly
- if (spawn->IsNPC())
- movement_spawns.erase(spawn->GetID());
- }
- void ZoneServer::HandleEmote(Client* originator, string name) {
- if (!originator) {
- LogWrite(ZONE__ERROR, 0, "Zone", "HandleEmote called with an invalid client");
- return;
- }
- Client* client = 0;
- Emote* origEmote = visual_states.FindEmote(name, originator->GetVersion());
- if(!origEmote){
- originator->Message(CHANNEL_COLOR_YELLOW, "Unable to find emote '%s'. If this should be a valid emote be sure to submit a /bug report.", name.c_str());
- return;
- }
- Emote* emote = origEmote;
- PacketStruct* packet = 0;
- char* emoteResponse = 0;
- vector<Client*>::iterator client_itr;
-
- int32 cur_client_version = originator->GetVersion();
- map<int32, Emote*> emote_version_range;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client && client->GetPlayer()->IsIgnored(originator->GetPlayer()->GetName())))
- continue;
- // establish appropriate emote for the version used by the client
- if (client->GetVersion() != originator->GetVersion())
- {
- map<int32, Emote*>::iterator rangeitr = emote_version_range.find(client->GetVersion());
- if (rangeitr == emote_version_range.end())
- {
- Emote* tmp_new_emote = visual_states.FindEmote(name, client->GetVersion());
- if (tmp_new_emote)
- {
- emote_version_range.insert(make_pair(client->GetVersion(), tmp_new_emote));
- emote = tmp_new_emote;
- } // else its missing just use the current clients default
- }
- else // we have an existing emote already cached
- emote = rangeitr->second;
- }
- else // since the client and originator client match use the original emote
- emote = origEmote;
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id" , client->GetPlayer()->GetIDWithPlayerSpawn(originator->GetPlayer()));
- if(!emoteResponse){
- string message;
- if(originator->GetPlayer()->GetTarget() && originator->GetPlayer()->GetTarget()->GetID() != originator->GetPlayer()->GetID()){
- message = emote->GetTargetedMessageString();
- if(message.find("%t") < 0xFFFFFFFF)
- message.replace(message.find("%t"), 2, originator->GetPlayer()->GetTarget()->GetName());
- }
- if(message.length() == 0)
- message = emote->GetMessageString();
- if(message.find("%g1") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g1"), 3, "his");
- else
- message.replace(message.find("%g1"), 3, "her");
- }
- if(message.find("%g2") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g2"), 3, "him");
- else
- message.replace(message.find("%g2"), 3, "her");
- }
- if(message.find("%g3") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g3"), 3, "he");
- else
- message.replace(message.find("%g3"), 3, "she");
- }
- if(message.length() > 0){
- emoteResponse = new char[message.length() + strlen(originator->GetPlayer()->GetName()) + 10];
- sprintf(emoteResponse,"%s %s", originator->GetPlayer()->GetName(), message.c_str());
- }
- else{
- originator->Message(CHANNEL_COLOR_YELLOW, "%s is not properly configured, be sure to submit a /bug report.", name.c_str());
- safe_delete(packet);
- break;
- }
- }
- packet->setMediumStringByName("emote_msg", emoteResponse);
- packet->setDataByName("anim_type", emote->GetVisualState());
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- safe_delete_array(emoteResponse);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SetupInstance(int32 createdInstanceID) {
- if ( createdInstanceID == 0 ) // if this happens that isn't good!
- instanceID = ++MinInstanceID;
- else // db should pass the good ID
- instanceID = createdInstanceID;
- }
- void ZoneServer::RemoveDeadSpawn(Spawn* spawn){
- AddDeadSpawn(spawn, 0);
- }
- void ZoneServer::AddDeadSpawn(Spawn* spawn, int32 timer){
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if (dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns[spawn->GetID()] = Timer::GetCurrentTime2() + timer;
- else if(timer != 0xFFFFFFFF)
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + timer));
- else{
- if(spawn->IsEntity() && spawn->HasLoot()){
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + (15000 * spawn->GetLevel() + 240000)));
- SendUpdateDefaultCommand(spawn, "loot", 10);
- }
- else
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + 10000));
- }
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::WritePlayerStatistics() {
- MutexList<Client*>::iterator client_itr = connected_clients.begin();
- while(client_itr.Next())
- client_itr->value->GetPlayer()->WritePlayerStatistics();
- }
- bool ZoneServer::SendRadiusSpawnInfo(Client* client, float radius) {
- if (!client)
- return false;
- Spawn* spawn = 0;
- bool ret = false;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != client->GetPlayer() && !spawn->IsPlayer() && spawn->GetDistance(client->GetPlayer()) <= radius) {
- const char* type = "NPC";
- const char* specialTypeID = "N/A";
- int32 specialID = 0, spawnEntryID = spawn->GetSpawnEntryID();
- if (spawn->IsObject())
- {
- Object* obj = (Object*)spawn;
- specialID = obj->GetID();
- specialTypeID = "GetID";
- type = "Object";
- }
- else if (spawn->IsSign())
- {
- Sign* sign = (Sign*)spawn;
- specialID = sign->GetWidgetID();
- specialTypeID = "WidgetID";
- type = "Sign";
- }
- else if (spawn->IsWidget())
- {
- Widget* widget = (Widget*)spawn;
- specialID = widget->GetWidgetID();
- specialTypeID = "WidgetID";
- if ( specialID == 0xFFFFFFFF )
- specialTypeID = "WidgetID(spawn_widgets entry missing)";
- type = "Widget";
- }
- else if (spawn->IsGroundSpawn())
- {
- GroundSpawn* gs = (GroundSpawn*)spawn;
- specialID = gs->GetGroundSpawnEntryID();
- specialTypeID = "GroundSpawnEntryID";
- type = "GroundSpawn";
- }
- client->Message(CHANNEL_COLOR_RED, "Name: %s (%s), Spawn Table ID: %u, %s: %u", spawn->GetName(), type, spawn->GetDatabaseID(), specialTypeID, specialID);
- client->Message(CHANNEL_COLOR_RED, "Spawn Location ID: %u, Spawn Group ID: %u, SpawnEntryID: %u, Grid ID: %u", spawn->GetSpawnLocationID(), spawn->GetSpawnGroupID(), spawnEntryID, spawn->GetLocation());
- client->Message(CHANNEL_COLOR_RED, "Respawn Time: %u (sec), X: %f, Y: %f, Z: %f Heading: %f", spawn->GetRespawnTime(), spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetHeading());
- client->Message(CHANNEL_COLOR_YELLOW, "=============================");
- ret = true;
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::FindSpawn(Client* client, char* regSearchStr)
- {
- if (!regSearchStr || strlen(regSearchStr) < 1)
- {
- client->SimpleMessage(CHANNEL_COLOR_RED, "Bad ZoneServer::FindSpawn(Client*, char* regSearchStr) attempt, regSearchStr is NULL or empty.");
- return;
- }
- string resString = string(regSearchStr);
- try
- {
- std::regex pre_re_check("^[a-zA-Z0-9_ ]+$");
- bool output = std::regex_match(resString, pre_re_check);
- if (output)
- {
- string newStr(".*");
- newStr.append(regSearchStr);
- newStr.append(".*");
- resString = newStr;
- }
- }
- catch (...)
- {
- client->SimpleMessage(CHANNEL_COLOR_RED, "Try/Catch ZoneServer::FindSpawn(Client*, char* regSearchStr) failure.");
- return;
- }
- client->Message(CHANNEL_NARRATIVE, "RegEx Search Spawn List: %s", regSearchStr);
- client->Message(CHANNEL_NARRATIVE, "Database ID | Spawn Name | X , Y , Z");
- client->Message(CHANNEL_NARRATIVE, "========================");
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- int32 spawnsFound = 0;
- std::regex re(resString, std::regex_constants::icase);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- Spawn* spawn = itr->second;
- if (!spawn || !spawn->GetName())
- continue;
- bool output = false;
- try {
- output = std::regex_match(string(spawn->GetName()), re);
- }
- catch (...)
- {
- continue;
- }
- if (output)
- {
- client->Message(CHANNEL_NARRATIVE, "%i | %s | %f , %f , %f", spawn->GetDatabaseID(), spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
- spawnsFound++;
- }
- }
- client->Message(CHANNEL_NARRATIVE, "========================", spawnsFound);
- client->Message(CHANNEL_NARRATIVE, "%u Results Found.", spawnsFound);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddPlayerTracking(Player* player) {
- if (player && !player->GetIsTracking() && players_tracking.count(player->GetDatabaseID()) == 0) {
- Client* client = GetClientBySpawn(player);
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- player->SetIsTracking(true);
- players_tracking.Put(client->GetCharacterID(), player);
- packet->setDataByName("mode", TRACKING_START);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- }
- void ZoneServer::RemovePlayerTracking(Player* player, int8 mode) {
- if (player && player->GetIsTracking()) {
- Client* client = GetClientBySpawn(player);
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- player->SetIsTracking(false);
- players_tracking.erase(client->GetCharacterID());
- packet->setDataByName("mode", mode);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- }
- void ZoneServer::ProcessTracking() {
- MutexMap<int32, Player*>::iterator itr = players_tracking.begin();
- while (itr.Next())
- ProcessTracking(GetClientBySpawn(itr->second));
- }
- void ZoneServer::ProcessTracking(Client* client) {
- if (!client)
- return;
- Player* player = client->GetPlayer();
- if (player && player->GetIsTracking()) {
- MutexMap<int32, Spawn*>::iterator spawn_itr;
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- packet->setDataByName("mode", TRACKING_UPDATE);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- vector<TrackedSpawn*> spawns_tracked;
- while (spawn_itr.Next()) {
- Spawn* spawn = spawn_itr->second;
- float distance = player->GetDistance(spawn);
- if (spawn->IsEntity() && distance <= 80 && spawn != player) {
- TrackedSpawn* ts = new TrackedSpawn;
- ts->spawn = spawn;
- ts->distance = distance;
- /* Add spawns in ascending order from closest to furthest */
- if (spawns_tracked.empty())
- spawns_tracked.push_back(ts);
- else {
- vector<TrackedSpawn*>::iterator tracked_itr;
- bool added = false;
- for (tracked_itr = spawns_tracked.begin(); tracked_itr != spawns_tracked.end(); tracked_itr++) {
- TrackedSpawn* cur_ts = *tracked_itr;
- if (ts->distance <= cur_ts->distance) {
- spawns_tracked.insert(tracked_itr, ts);
- added = true;
- break;
- }
- }
- if (!added)
- spawns_tracked.push_back(ts);
- }
- }
- }
- packet->setArrayLengthByName("num_spawns", spawns_tracked.size());
- for (int32 i = 0; i < spawns_tracked.size(); i++) {
- TrackedSpawn* ts = spawns_tracked[i];
- LogWrite(ZONE__DEBUG, 0, "Zone", "%s (%f)", ts->spawn->GetName(), ts->distance);
- packet->setArrayDataByName("spawn_id", player->GetIDWithPlayerSpawn(ts->spawn), i);
- packet->setArrayDataByName("spawn_name", ts->spawn->GetName(), i);
- if (ts->spawn->IsPlayer())
- packet->setArrayDataByName("spawn_type", TRACKING_SPAWN_TYPE_PC, i);
- else
- packet->setArrayDataByName("spawn_type", TRACKING_SPAWN_TYPE_NPC, i);
- packet->setArrayDataByName("spawn_con_color", player->GetArrowColor(ts->spawn->GetLevel()), i);
- }
- packet->setArrayLengthByName("num_array1", 0);
- //for (int32 i = 0; i < spawns_tracked.size(); i++) {
- //}
- packet->setArrayLengthByName("num_spawns2", spawns_tracked.size());
- for (int32 i = 0; i < spawns_tracked.size(); i++) {
- TrackedSpawn* ts = spawns_tracked[i];
- packet->setArrayDataByName("list_spawn_id", player->GetIDWithPlayerSpawn(ts->spawn), i);
- packet->setArrayDataByName("list_number", i, i);
- }
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- for (int32 i = 0; i < spawns_tracked.size(); i++)
- safe_delete(spawns_tracked[i]);
- }
- }
- }
- void ZoneServer::SendEpicMobDeathToGuild(Player* killer, Spawn* victim) {
- if (killer && victim) {
- LogWrite(MISC__TODO, 1, "TODO" , "Check if player is in raid\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- if (killer->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(killer->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- for (itr = members->begin(); itr != members->end(); itr++) {
- GroupMemberInfo* gmi = *itr;
- if (gmi->client) {
- Player* group_member = gmi->client->GetPlayer();
- if (group_member->GetGuild()) {
- Guild* guild = group_member->GetGuild();
- string message = Guild::GetEpicMobDeathMessage(group_member->GetName(), victim->GetName());
- guild->AddNewGuildEvent(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str(), Timer::GetUnixTimeStamp());
- guild->SendMessageToGuild(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str());
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else if (killer->GetGuild()) {
- Guild* guild = killer->GetGuild();
- string message = Guild::GetEpicMobDeathMessage(killer->GetName(), victim->GetName());
- guild->AddNewGuildEvent(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str(), Timer::GetUnixTimeStamp());
- guild->SendMessageToGuild(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str());
- }
- }
- }
- void ZoneServer::ProcessAggroChecks(Spawn* spawn) {
- if (spawn->GetFactionID() < 1 || spawn->EngagedInCombat())
- return;
- // If faction based combat is not allowed then no need to run the loops so just return out
- if(!rule_manager.GetGlobalRule(R_Faction, AllowFactionBasedCombat)->GetBool())
- return;
- if (spawn && spawn->IsNPC() && spawn->Alive())
- CheckEnemyList((NPC*)spawn);
- }
- void ZoneServer::SendUpdateTitles(Client* client, Title* suffix, Title* prefix) {
- assert(client);
- if (client->GetVersion() > 546)
- SendUpdateTitles(client->GetPlayer(), suffix, prefix);
- }
- void ZoneServer::SendUpdateTitles(Spawn *spawn, Title *suffix, Title *prefix) {
- if (!spawn)
- return;
- vector<Client*>::iterator itr;
- PacketStruct *packet;
- Client* current_client;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- current_client = *itr;
- if (current_client->GetVersion() <= 546)
- continue;
- if (!(packet = configReader.getStruct("WS_UpdateTitle", current_client->GetVersion())))
- continue;
- packet->setDataByName("player_id", current_client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("player_name", spawn->GetName());
- packet->setDataByName("unknown1", 1, 1);
- if(suffix)
- packet->setDataByName("suffix_title", suffix->GetName());
- else
- packet->setDataByName("suffix_title", spawn->GetSuffixTitle());
- if(prefix)
- packet->setDataByName("prefix_title", prefix->GetName());
- else
- packet->setDataByName("prefix_title", spawn->GetPrefixTitle());
- packet->setDataByName("last_name", spawn->GetLastName());
- packet->setDataByName("sub_title", spawn->GetSubTitle());
- current_client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddTransportSpawn(Spawn* spawn){
- if(!spawn)
- return;
- MTransportSpawns.writelock(__FUNCTION__, __LINE__);
- transport_spawns.push_back(spawn->GetID());
- MTransportSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- Spawn* ZoneServer::GetClosestTransportSpawn(float x, float y, float z){
- Spawn* spawn = 0;
- Spawn* closest_spawn = 0;
- float closest_distance = 0.0;
- MTransportSpawns.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr = transport_spawns.begin();
- while(itr != transport_spawns.end()){
- spawn = GetSpawnByID(*itr);
- if(spawn){
- if(closest_distance == 0.0){
- closest_spawn = spawn;
- closest_distance = spawn->GetDistance(x, y, z);
- }
- else if(spawn->GetDistance(x, y, z) < closest_distance){
- closest_spawn = spawn;
- closest_distance = spawn->GetDistance(x, y, z);
- }
- itr++;
- }
- else
- itr = transport_spawns.erase(itr);
- }
- MTransportSpawns.releasewritelock(__FUNCTION__, __LINE__);
- return closest_spawn;
- }
- void ZoneServer::SetRain(float val) {
- rain = val;
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- client->GetPlayer()->GetInfoStruct()->set_rain(val);
- client->GetPlayer()->SetCharSheetChanged(true);
- if( val >= 0.75 && !weather_signaled )
- {
- client->SimpleMessage(CHANNEL_NARRATIVE, "It starts to rain.");
- }
- else if( val < 0.75 && weather_signaled )
- {
- client->SimpleMessage(CHANNEL_NARRATIVE, "It stops raining.");
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- if (val >= 0.75 && !weather_signaled) {
- weather_signaled = true;
- ProcessSpawnConditional(SPAWN_CONDITIONAL_RAINING);
- }
- else if (val < 0.75 && weather_signaled) {
- weather_signaled = false;
- ProcessSpawnConditional(SPAWN_CONDITIONAL_NOT_RAINING);
- }
- }
- void ZoneServer::SetWind(float val) {
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- client->GetPlayer()->GetInfoStruct()->set_wind(val);
- client->GetPlayer()->SetCharSheetChanged(true);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessWeather()
- {
- // if the global rule to disable weather is set, or if the `weather_allowed` field in the zone record == 0, do not process weather
- if( !weather_enabled || !isWeatherAllowed() )
- return;
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Processing weather changes", zone_name);
- float new_weather = 0;
- float weather_offset = 0;
- bool change_weather = false;
- // check to see if it is time to change the weather according to weather_frequency (time between changes)
- if( weather_last_changed_time <= (Timer::GetUnixTimeStamp() - weather_frequency) )
- {
- LogWrite(ZONE__DEBUG, 2, "Zone", "%s: Checking for weather changes", zone_name);
- // reset last changed time (frequency check)
- weather_last_changed_time = Timer::GetUnixTimeStamp();
- // this is the chance a weather change occurs at all at the expired interval
- int8 weather_random = MakeRandomInt(1, 100);
- LogWrite(ZONE__DEBUG, 2, "Zone", "%s: Chance to change weather: %i%%, rolled: %i%% - Change weather: %s", zone_name, weather_change_chance, weather_random, weather_random <= weather_change_chance ? "True" : "False");
- if( weather_random <= weather_change_chance )
- {
- change_weather = true;
- weather_offset = weather_change_amount;
- if( weather_type == 3 ) // chaotic weather patterns, random weather between min/max
- {
- new_weather = MakeRandomFloat(weather_min_severity, weather_max_severity);
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Chaotic weather severity changed to %.2f", zone_name, new_weather);
- weather_pattern = 2;
- }
- else if( weather_type == 2 ) // random weather patterns, combination of normal + dynamic + max_offset
- {
- weather_offset = MakeRandomFloat(weather_change_amount, weather_dynamic_offset);
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Random weather severity changed by %.2f", zone_name, weather_offset);
- int8 weather_alter = weather_change_chance / 10; // the divide is to prevent too many direction changes in a cycle
- weather_random = MakeRandomInt(1, 100); // chance that the weather changes direction (weather_pattern)
- if( weather_random <= weather_alter )
- weather_pattern = ( weather_pattern == 0 ) ? 1 : 0;
- }
- else if( weather_type == 1 ) // dynamic weather patterns, weather may not reach min/max
- {
- int8 weather_alter = weather_change_chance / 10; // the divide is to prevent too many direction changes in a cycle
- weather_random = MakeRandomInt(1, 100); // chance that the weather changes direction (weather_pattern)
- if( weather_random <= weather_alter )
- {
- weather_pattern = ( weather_pattern == 0 ) ? 1 : 0;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Dynamic weather pattern changed to %i", zone_name, weather_pattern);
- }
- }
- else // normal weather patterns, weather starts at min, goes to max, then back down again
- {
- // do nothing (processed below)
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Normal weather severity changed by %.2f", zone_name, weather_offset);
- }
- // when all done, change the weather
- if( change_weather )
- {
- if( weather_pattern == 1 )
- {
- // weather is getting worse, til it reaches weather_max_severity
- new_weather = ( weather_current_severity <= weather_max_severity ) ? weather_current_severity + weather_offset : weather_max_severity;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Increased weather severity by %.2f", zone_name, weather_offset);
- if(new_weather > weather_max_severity)
- {
- new_weather = weather_max_severity - weather_offset;
- weather_pattern = 0;
- }
- }
- else if( weather_pattern == 0 )
- {
- // weather is clearing up, til it reaches weather_min_severity
- new_weather = ( weather_current_severity >= weather_min_severity ) ? weather_current_severity - weather_offset : weather_min_severity;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Decreased weather severity by %.2f", zone_name, weather_offset);
- if(new_weather < weather_min_severity)
- {
- new_weather = weather_min_severity + weather_offset;
- weather_pattern = 1;
- }
- }
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather change triggered from %.2f to %.2f", zone_name, weather_current_severity, new_weather);
- this->SetRain(new_weather);
- weather_current_severity = new_weather;
- }
- }
- }
- else
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Not time to change weather yet", zone_name);
- }
- void ZoneServer::HidePrivateSpawn(Spawn* spawn) {
- if (!spawn->IsPrivateSpawn())
- return;
- Client* client = 0;
- Player* player = 0;
- PacketStruct* packet = 0;
- int32 packet_version = 0;
- MutexList<Client*>::iterator itr = connected_clients.begin();
- while (itr->Next()) {
- client = itr->value;
- player = client->GetPlayer();
- if (player->WasSentSpawn(spawn->GetID()) && !player->WasSpawnRemoved(spawn)) {
- if (!packet || packet_version != client->GetVersion()) {
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- SendRemoveSpawn(client, spawn, packet);
- if(spawn_range_map.count(client) > 0)
- spawn_range_map.Get(client)->erase(spawn->GetID());
- if(player->GetTarget() == spawn)
- player->SetTarget(0);
- }
- }
- safe_delete(packet);
- }
- SpawnLocation* ZoneServer::GetSpawnLocation(int32 id) {
- SpawnLocation* ret = 0;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- if (spawn_location_list.count(id) > 0)
- ret = spawn_location_list[id];
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::PlayAnimation(Spawn* spawn, int32 visual_state, Spawn* spawn2, int8 hide_type){
- Client* client = 0;
- PacketStruct* packet = 0;
- Spawn* exclude_spawn = 0;
- if (!spawn)
- return;
- if (spawn2){
- if(hide_type == 1){
- client = GetClientBySpawn(spawn2);
- if(client){
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("anim_type", visual_state);
- client->QueuePacket(packet->serialize());
- }
- return;
- }
- if(hide_type == 2)
- exclude_spawn = spawn2;
- }
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(spawn->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(exclude_spawn == client->GetPlayer())
- continue;
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("anim_type", visual_state);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- vector<Spawn*> ZoneServer::GetSpawnsByID(int32 id) {
- vector<Spawn*> tmp_list;
- Spawn* spawn;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && (spawn->GetDatabaseID() == id))
- tmp_list.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return tmp_list;
- }
- vector<Spawn*> ZoneServer::GetAttackableSpawnsByDistance(Spawn* caster, float distance) {
- vector<Spawn*> ret;
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsNPC() && spawn->appearance.attackable > 0 && spawn != caster && spawn->Alive() && spawn->GetDistance(caster, true) <= distance)
- ret.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::ResurrectSpawn(Spawn* spawn, Client* client) {
- if(!client || !spawn)
- return;
- PendingResurrection* rez = client->GetCurrentRez();
- if(!rez || !rez->caster)
- return;
- PacketStruct* packet = 0;
- float power_perc = rez->mp_perc;
- float health_perc = rez->hp_perc;
- Spawn* caster_spawn = rez->caster;
- sint32 heal_amt = 0;
- sint32 power_amt = 0;
- bool no_calcs = rez->no_calcs;
- int8 crit_mod = rez->crit_mod;
- Entity* caster = 0;
- InfoStruct* info = 0;
- bool crit = false;
- string heal_spell = rez->heal_name;
- int16 heal_packet_type = 0;
- int16 power_packet_type = 0;
- //Calculations for how much to heal the spawn
- if(health_perc > 0)
- heal_amt = (spawn->GetTotalHP() * (health_perc / 100));
- if(power_perc > 0)
- power_amt = (spawn->GetTotalPower() * (power_perc / 100));
- if(caster_spawn->IsEntity()){
- caster = ((Entity*)caster_spawn);
- info = caster->GetInfoStruct();
- }
- if(!no_calcs && caster){
- //Potency Mod
- heal_amt *= ((caster->stats[ITEM_STAT_POTENCY] / 100) + 1);
- power_amt *= ((caster->stats[ITEM_STAT_POTENCY] / 100) + 1);
- //Ability Mod
- heal_amt += (int32)min((int32)info->get_ability_modifier(), (int32)(heal_amt / 2));
- power_amt += (int32)min((int32)info->get_ability_modifier(), (int32)(power_amt / 2));
- if(!crit_mod || crit_mod == 1){
- if(crit_mod == 1)
- crit = true;
- else {
- // Crit Roll
- float chance = (float)max((float)0, (float)info->get_crit_chance());
- crit = (MakeRandomFloat(0, 100) <= chance);
- }
- if(crit){
- //Apply total crit multiplier with crit bonus
- heal_amt *= ((info->get_crit_bonus() / 100) + 1.3);
- power_amt *= ((info->get_crit_bonus() / 100) + 1.3);
- }
- }
- }
- //Set this rez as a crit to be passed to subspell (not yet used)
- rez->crit = true;
- //Set Heal amt to 1 if 0 now so the player has health
- if(heal_amt == 0)
- heal_amt = 1;
- if(heal_amt > spawn->GetTotalHP())
- heal_amt = spawn->GetTotalHP();
- if(power_amt > spawn->GetTotalPower())
- power_amt = spawn->GetTotalPower();
- spawn->SetHP(heal_amt);
- if(power_amt > 0)
- spawn->SetPower(power_amt);
- if(client && caster){
- EQ2Packet* move = ((Player*)spawn)->Move(caster->GetX(), caster->GetY(), caster->GetZ(), client->GetVersion());
- if(move)
- client->QueuePacket(move);
- }
- if(crit){
- power_packet_type = HEAL_PACKET_TYPE_CRIT_MANA;
- heal_packet_type = HEAL_PACKET_TYPE_CRIT_HEAL;
- }
- else {
- power_packet_type = HEAL_PACKET_TYPE_SIMPLE_MANA;
- heal_packet_type = HEAL_PACKET_TYPE_SIMPLE_HEAL;
- }
- SendHealPacket(caster, spawn, heal_packet_type, heal_amt, heal_spell.c_str());
- if(power_amt > 0)
- SendHealPacket(caster, spawn, power_packet_type, power_amt, heal_spell.c_str());
- //The following code sets the spawn as alive
- if(dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns.erase(spawn->GetID());
- if(spawn->IsPlayer()){
- spawn->SetSpawnType(4);
- client = GetClientBySpawn(spawn);
- if(client){
- packet = configReader.getStruct("WS_Resurrected", client->GetVersion());
- if(packet){
- client->QueuePacket(packet->serialize());
- }
- packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
- if(packet)
- {
- packet->setDataByName("parameter1", 8);
- client->QueuePacket(packet->serialize());
- packet->setDataByName("parameter1", 16);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- client->SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
- }
- }
- spawn->SendSpawnChanges(true);
- spawn->SetTempActionState(-1);
- spawn->appearance.attackable = 1;
- }
- void ZoneServer::SendDispellPacket(Entity* caster, Spawn* target, string dispell_name, string spell_name, int8 dispell_type){
- if(!caster || !target)
- return;
- Client* client = 0;
- Player* player = 0;
- PacketStruct* packet = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++){
- client = *client_itr;
- if(!client || !(player = client->GetPlayer()) || (player != caster && ((caster && player->WasSentSpawn(caster->GetID()) == false) || (target && player->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && player->WasSpawnRemoved(caster)) || (caster && player->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(player) > 50)
- continue;
- if(target && target->GetDistance(player) > 50)
- continue;
- packet = configReader.getStruct("WS_HearDispell", client->GetVersion());
- if(packet){
- packet->setDataByName("spell_name", spell_name.c_str());
- packet->setDataByName("dispell_name", dispell_name.c_str());
- packet->setDataByName("caster", player->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", player->GetIDWithPlayerSpawn(target));
- packet->setDataByName("type", dispell_type);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DismissAllPets() {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsPet() && ((NPC*)spawn)->GetOwner())
- ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::RemoveTargetFromSpell(LuaSpell* spell, Spawn* target){
- if (spellProcess)
- spellProcess->RemoveTargetFromSpell(spell, target);
- }
- void ZoneServer::ClearHate(Entity* entity) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain())
- ((NPC*)spawn)->Brain()->ClearHate(entity);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- ThreadReturnType ZoneLoop(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("ZoneLoop(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- ZoneServer* zs = (ZoneServer*) tmp;
- while (zs->Process()) {
- if(zs->GetClientCount() == 0)
- Sleep(1000);
- else
- Sleep(10);
- }
- zs->Process(); //run loop once more to clean up some functions
- safe_delete(zs);
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SpawnLoop(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SpawnLoop(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- ZoneServer* zs = (ZoneServer*) tmp;
- #ifndef NO_CATCH
- try {
- #endif
- zs->spawnthread_active = true;
- while (zs->SpawnProcess()) {
- if(zs->GetClientCount() == 0)
- Sleep(1000);
- else
- Sleep(20);
- }
- zs->spawnthread_active = false;
- #ifndef NO_CATCH
- }
- catch(...) {
- zs->spawnthread_active = false;
- zs->initial_spawn_threads_active = 0;
- LogWrite(ZONE__ERROR, 0, "Zone", "Error Processing SpawnLoop, shutting down zone '%s'...", zs->GetZoneName());
- try{
- zs->Shutdown();
- }
- catch(...){
- LogWrite(ZONE__ERROR, 0, "Zone", "Error Processing SpawnLoop while shutting down zone '%s'...", zs->GetZoneName());
- throw;
- }
- throw;
- }
- #endif
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SendInitialSpawns(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SendInitialSpawns(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- Client* client = (Client*) tmp;
- client->GetCurrentZone()->SendZoneSpawns(client);
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SendLevelChangedSpawns(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SendLevelChangedSpawns(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- Client* client = (Client*)tmp;
- client->GetCurrentZone()->SendAllSpawnsForLevelChange(client);
- THREAD_RETURN(NULL);
- }
- void ZoneServer::SetSpawnStructs(Client* client) {
- int16 client_ver = client->GetVersion();
- Player* player = client->GetPlayer();
- //Save a copy of the correct spawn substructs for the client's player, save here a copy if we don't have one
- PacketStruct* pos = configReader.getStruct("Substruct_SpawnPositionStruct", client_ver);
- player->SetSpawnPosStruct(pos);
- if (versioned_pos_structs.count(pos->GetVersion()) == 0)
- versioned_pos_structs[pos->GetVersion()] = new PacketStruct(pos, true);
- PacketStruct* vis = configReader.getStruct("Substruct_SpawnVisualizationInfoStruct", client_ver);
- player->SetSpawnVisStruct(vis);
- if (versioned_vis_structs.count(vis->GetVersion()) == 0)
- versioned_vis_structs[vis->GetVersion()] = new PacketStruct(vis, true);
- PacketStruct* info = configReader.getStruct("Substruct_SpawnInfoStruct", client_ver);
- player->SetSpawnInfoStruct(info);
- if (versioned_info_structs.count(info->GetVersion()) == 0)
- versioned_info_structs[info->GetVersion()] = new PacketStruct(info, true);
- PacketStruct* header = configReader.getStruct("WS_SpawnStruct_Header", client_ver);
- player->SetSpawnHeaderStruct(header);
- PacketStruct* footer = configReader.getStruct("WS_SpawnStruct_Footer", client_ver);
- player->SetSpawnFooterStruct(footer);
- PacketStruct* sfooter = configReader.getStruct("WS_SignWidgetSpawnStruct_Footer", client_ver);
- player->SetSignFooterStruct(sfooter);
- PacketStruct* wfooter = configReader.getStruct("WS_WidgetSpawnStruct_Footer", client_ver);
- player->SetWidgetFooterStruct(wfooter);
- }
- Spawn* ZoneServer::GetSpawn(int32 id){
- Spawn* ret = 0;
- if(GetNPC(id))
- ret = GetNewNPC(id);
- else if(this->GetObject(id))
- ret = GetNewObject(id);
- else if(GetWidget(id))
- ret = GetNewWidget(id);
- else if(GetSign(id))
- ret = GetNewSign(id);
- else if(GetGroundSpawn(id))
- ret = GetNewGroundSpawn(id);
- // Unable to find the spawn in the list lets attempt to add it if we are not currently reloading
- else if (!reloading && database.LoadNPC(this, id)) {
- if (GetNPC(id))
- ret = GetNewNPC(id);
- else
- LogWrite(NPC__ERROR, 0, "NPC", "Database inserted npc (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadObject(this, id)) {
- if (this->GetObject(id))
- ret = GetNewObject(id);
- else
- LogWrite(OBJECT__ERROR, 0, "Object", "Database inserted object (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadWidget(this, id)) {
- if (GetWidget(id))
- ret = GetNewWidget(id);
- else
- LogWrite(WIDGET__ERROR, 0, "Widget", "Database inserted widget (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadSign(this, id)) {
- if (GetSign(id))
- ret = GetNewSign(id);
- else
- LogWrite(SIGN__ERROR, 0, "Sign", "Database inserted sign (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadGroundSpawn(this, id)) {
- if (GetGroundSpawn(id))
- ret = GetNewGroundSpawn(id);
- else
- LogWrite(GROUNDSPAWN__ERROR, 0, "GSpawn", "Database inserted ground spawn (%u) but was still unable to retrieve it!", id);
- }
- if(ret)
- ret->SetID(Spawn::NextID());
- return ret;
- }
- vector<EntityCommand*>* ZoneServer::GetEntityCommandList(int32 id){
- if(entity_command_list.count(id) > 0)
- return entity_command_list[id];
- else
- return 0;
- }
- void ZoneServer::SetEntityCommandList(int32 id, EntityCommand* command) {
- if (entity_command_list.count(id) == 0)
- entity_command_list[id] = new vector<EntityCommand*>;
- entity_command_list[id]->push_back(command);
- }
- EntityCommand* ZoneServer::GetEntityCommand(int32 id, string name) {
- EntityCommand* ret = 0;
- if (entity_command_list.count(id) == 0)
- return ret;
- vector<EntityCommand*>::iterator itr;
- for (itr = entity_command_list[id]->begin(); itr != entity_command_list[id]->end(); itr++) {
- if ((*itr)->name == name) {
- ret = (*itr);
- break;
- }
- }
- return ret;
- }
- void ZoneServer::ClearEntityCommands() {
- if (entity_command_list.size() > 0) {
- map<int32, vector<EntityCommand*>* >::iterator itr;
- for (itr = entity_command_list.begin(); itr != entity_command_list.end(); itr++) {
- vector<EntityCommand*>* entity_commands = itr->second;
- if (entity_commands && entity_commands->size() > 0) {
- vector<EntityCommand*>::iterator v_itr;
- for (v_itr = entity_commands->begin(); v_itr != entity_commands->end(); v_itr++)
- safe_delete(*v_itr);
- entity_commands->clear();
- }
- safe_delete(entity_commands);
- }
- entity_command_list.clear();
- }
- }
- void ZoneServer::AddNPCSpell(int32 list_id, int32 spell_id, int8 tier){
- npc_spell_list[list_id][spell_id] = tier;
- }
- vector<Spell*>* ZoneServer::GetNPCSpells(int32 primary_list, int32 secondary_list){
- vector<Spell*>* ret = 0;
- if(npc_spell_list.count(primary_list) > 0){
- ret = new vector<Spell*>();
- map<int32, int8>::iterator itr;
- Spell* tmpSpell = 0;
- for(itr = npc_spell_list[primary_list].begin(); itr != npc_spell_list[primary_list].end(); itr++){
- tmpSpell = master_spell_list.GetSpell(itr->first, itr->second);
- if(tmpSpell)
- ret->push_back(tmpSpell);
- }
- }
- if(npc_spell_list.count(secondary_list) > 0){
- if(!ret)
- ret = new vector<Spell*>();
- map<int32, int8>::iterator itr;
- Spell* tmpSpell = 0;
- for(itr = npc_spell_list[secondary_list].begin(); itr != npc_spell_list[secondary_list].end(); itr++){
- tmpSpell = master_spell_list.GetSpell(itr->first, itr->second);
- if(tmpSpell)
- ret->push_back(tmpSpell);
- }
- }
- if(ret && ret->size() == 0){
- safe_delete(ret);
- ret = 0;
- }
- return ret;
- }
- void ZoneServer::AddNPCSkill(int32 list_id, int32 skill_id, int16 value){
- npc_skill_list[list_id][skill_id] = value;
- }
- map<string, Skill*>* ZoneServer::GetNPCSkills(int32 primary_list, int32 secondary_list){
- map<string, Skill*>* ret = 0;
- if(npc_skill_list.count(primary_list) > 0){
- ret = new map<string, Skill*>();
- map<int32, int16>::iterator itr;
- Skill* tmpSkill = 0;
- for(itr = npc_skill_list[primary_list].begin(); itr != npc_skill_list[primary_list].end(); itr++){
- tmpSkill = master_skill_list.GetSkill(itr->first);
- if(tmpSkill){
- tmpSkill = new Skill(tmpSkill);
- tmpSkill->current_val = itr->second;
- tmpSkill->max_val = tmpSkill->current_val+5;
- (*ret)[tmpSkill->name.data] = tmpSkill;
- }
- }
- }
- if(npc_skill_list.count(secondary_list) > 0){
- if(!ret)
- ret = new map<string, Skill*>();
- map<int32, int16>::iterator itr;
- Skill* tmpSkill = 0;
- for(itr = npc_skill_list[secondary_list].begin(); itr != npc_skill_list[secondary_list].end(); itr++){
- tmpSkill = master_skill_list.GetSkill(itr->first);
- if(tmpSkill){
- tmpSkill = new Skill(tmpSkill);
- tmpSkill->current_val = itr->second;
- tmpSkill->max_val = tmpSkill->current_val+5;
- (*ret)[tmpSkill->name.data] = tmpSkill;
- }
- }
- }
- if(ret && ret->size() == 0){
- safe_delete(ret);
- ret = 0;
- }
- return ret;
- }
- void ZoneServer::AddNPCEquipment(int32 list_id, int32 item_id){
- npc_equipment_list[list_id].push_back(item_id);
- }
- void ZoneServer::SetNPCEquipment(NPC* npc) {
- if(npc_equipment_list.count(npc->GetEquipmentListID()) > 0){
- Item* tmpItem = 0;
- int8 slot = 0;
- vector<int32>::iterator itr;
- for(itr = npc_equipment_list[npc->GetEquipmentListID()].begin(); itr != npc_equipment_list[npc->GetEquipmentListID()].end(); itr++){
- tmpItem = master_item_list.GetItem(*itr);
- if(tmpItem){
- slot = npc->GetEquipmentList()->GetFreeSlot(tmpItem);
- if(slot < 255){
- tmpItem = new Item(tmpItem);
- npc->GetEquipmentList()->SetItem(slot, tmpItem);
- }
- }
- }
- }
- }
- void ZoneServer::AddNPC(int32 id, NPC* npc) {
- npc_list[id] = npc;
- }
- void ZoneServer::AddWidget(int32 id, Widget* widget) {
- widget_list[id] = widget;
- }
- Widget* ZoneServer::GetWidget(int32 id, bool override_loading) {
- if((!reloading || override_loading) && widget_list.count(id) > 0)
- return widget_list[id];
- else
- return 0;
- }
- Widget* ZoneServer::GetNewWidget(int32 id) {
- if(!reloading && widget_list.count(id) > 0)
- return widget_list[id]->Copy();
- else
- return 0;
- }
- void ZoneServer::LoadGroundSpawnEntries(){
- MGroundSpawnItems.lock();
- database.LoadGroundSpawnEntries(this);
- MGroundSpawnItems.unlock();
- }
- void ZoneServer::LoadGroundSpawnItems() {
- }
- void ZoneServer::AddGroundSpawnEntry(int32 groundspawn_id, int16 min_skill_level, int16 min_adventure_level, int8 bonus_table, float harvest1, float harvest3, float harvest5, float harvest_imbue, float harvest_rare, float harvest10, int32 harvest_coin) {
- GroundSpawnEntry* entry = new GroundSpawnEntry;
- entry->min_skill_level = min_skill_level;
- entry->min_adventure_level = min_adventure_level;
- entry->bonus_table = bonus_table;
- entry->harvest1 = harvest1;
- entry->harvest3 = harvest3;
- entry->harvest5 = harvest5;
- entry->harvest_imbue = harvest_imbue;
- entry->harvest_rare = harvest_rare;
- entry->harvest10 = harvest10;
- entry->harvest_coin = harvest_coin;
- groundspawn_entries[groundspawn_id].push_back(entry);
- }
- void ZoneServer::AddGroundSpawnItem(int32 groundspawn_id, int32 item_id, int8 is_rare, int32 grid_id) {
- GroundSpawnEntryItem* entry = new GroundSpawnEntryItem;
- entry->item_id = item_id;
- entry->is_rare = is_rare;
- entry->grid_id = grid_id;
- groundspawn_items[groundspawn_id].push_back(entry);
- }
- vector<GroundSpawnEntry*>* ZoneServer::GetGroundSpawnEntries(int32 id){
- vector<GroundSpawnEntry*>* ret = 0;
- MGroundSpawnItems.lock();
- if(groundspawn_entries.count(id) > 0)
- ret = &groundspawn_entries[id];
- MGroundSpawnItems.unlock();
- return ret;
- }
- vector<GroundSpawnEntryItem*>* ZoneServer::GetGroundSpawnEntryItems(int32 id){
- vector<GroundSpawnEntryItem*>* ret = 0;
- if(groundspawn_items.count(id) > 0)
- ret = &groundspawn_items[id];
- return ret;
- }
- // TODO - mis-named, should be DeleteGroundSpawnEntries() but this is ok for now :)
- void ZoneServer::DeleteGroundSpawnItems()
- {
- MGroundSpawnItems.lock();
- map<int32, vector<GroundSpawnEntry*> >::iterator groundspawnentry_map_itr;
- vector<GroundSpawnEntry*>::iterator groundspawnentry_itr;
- for(groundspawnentry_map_itr = groundspawn_entries.begin(); groundspawnentry_map_itr != groundspawn_entries.end(); groundspawnentry_map_itr++)
- {
- for(groundspawnentry_itr = groundspawnentry_map_itr->second.begin(); groundspawnentry_itr != groundspawnentry_map_itr->second.end(); groundspawnentry_itr++)
- {
- safe_delete(*groundspawnentry_itr);
- }
- }
- groundspawn_entries.clear();
- map<int32, vector<GroundSpawnEntryItem*> >::iterator groundspawnitem_map_itr;
- vector<GroundSpawnEntryItem*>::iterator groundspawnitem_itr;
- for(groundspawnitem_map_itr = groundspawn_items.begin(); groundspawnitem_map_itr != groundspawn_items.end(); groundspawnitem_map_itr++)
- {
- for(groundspawnitem_itr = groundspawnitem_map_itr->second.begin(); groundspawnitem_itr != groundspawnitem_map_itr->second.end(); groundspawnitem_itr++)
- {
- safe_delete(*groundspawnitem_itr);
- }
- }
- groundspawn_items.clear();
- MGroundSpawnItems.unlock();
- }
- void ZoneServer::AddGroundSpawn(int32 id, GroundSpawn* spawn) {
- groundspawn_list[id] = spawn;
- }
- GroundSpawn* ZoneServer::GetGroundSpawn(int32 id, bool override_loading) {
- if((!reloading || override_loading) && groundspawn_list.count(id) > 0)
- return groundspawn_list[id];
- else
- return 0;
- }
- GroundSpawn* ZoneServer::GetNewGroundSpawn(int32 id) {
- if(!reloading && groundspawn_list.count(id) > 0)
- return groundspawn_list[id]->Copy();
- else
- return 0;
- }
- void ZoneServer::AddLootTable(int32 id, LootTable* table){
- loot_tables[id] = table;
- }
- void ZoneServer::AddLootDrop(int32 id, LootDrop* drop){
- loot_drops[id].push_back(drop);
- }
- void ZoneServer::AddSpawnLootList(int32 spawn_id, int32 id) {
- spawn_loot_list[spawn_id].push_back(id);
- }
- void ZoneServer::ClearSpawnLootList(int32 spawn_id) {
- spawn_loot_list[spawn_id].clear();
- }
- void ZoneServer::AddLevelLootList(GlobalLoot* loot) {
- level_loot_list.push_back(loot);
- }
- void ZoneServer::AddRacialLootList(int16 racial_id, GlobalLoot* loot) {
- racial_loot_list[racial_id].push_back(loot);
- }
- void ZoneServer::AddZoneLootList(int32 zone, GlobalLoot* loot) {
- zone_loot_list[zone].push_back(loot);
- }
- void ZoneServer::ClearLootTables(){
- map<int32,LootTable*>::iterator table_itr;
- for(table_itr = loot_tables.begin(); table_itr != loot_tables.end(); table_itr++){
- safe_delete(table_itr->second);
- }
- map<int32, vector<LootDrop*> >::iterator drop_itr;
- vector<LootDrop*>::iterator drop_itr2;
- for(drop_itr = loot_drops.begin(); drop_itr != loot_drops.end(); drop_itr++){
- for(drop_itr2 = drop_itr->second.begin(); drop_itr2 != drop_itr->second.end(); drop_itr2++){
- safe_delete(*drop_itr2);
- }
- }
- vector<GlobalLoot*>::iterator level_itr;
- for (level_itr = level_loot_list.begin(); level_itr != level_loot_list.end(); level_itr++) {
- safe_delete(*level_itr);
- }
- map<int16, vector<GlobalLoot*> >::iterator race_itr;
- vector<GlobalLoot*>::iterator race_itr2;
- for (race_itr = racial_loot_list.begin(); race_itr != racial_loot_list.end(); race_itr++) {
- for (race_itr2 = race_itr->second.begin(); race_itr2 != race_itr->second.end(); race_itr2++) {
- safe_delete(*race_itr2);
- }
- }
- map<int32, vector<GlobalLoot*> >::iterator zone_itr;
- vector<GlobalLoot*>::iterator zone_itr2;
- for(zone_itr = zone_loot_list.begin(); zone_itr != zone_loot_list.end(); zone_itr++) {
- for (zone_itr2 = zone_itr->second.begin(); zone_itr2 != zone_itr->second.end(); zone_itr2++) {
- safe_delete(*zone_itr2);
- }
- }
- loot_tables.clear();
- loot_drops.clear();
- spawn_loot_list.clear();
- level_loot_list.clear();
- racial_loot_list.clear();
- zone_loot_list.clear();
- }
- vector<int32> ZoneServer::GetSpawnLootList(int32 spawn_id, int32 zone_id, int8 spawn_level, int16 racial_id) {
- vector<int32> ret;
- if(reloading)
- return ret;
- if (spawn_loot_list.count(spawn_id) > 0)
- ret.insert(ret.end(), spawn_loot_list[spawn_id].begin(), spawn_loot_list[spawn_id].end());
- if (level_loot_list.size() > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = level_loot_list.begin(); itr != level_loot_list.end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- if (racial_loot_list.count(racial_id) > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = racial_loot_list[racial_id].begin(); itr != racial_loot_list[racial_id].end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- if (zone_loot_list.count(zone_id) > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = zone_loot_list[zone_id].begin(); itr != zone_loot_list[zone_id].end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- return ret;
- }
- vector<LootDrop*>* ZoneServer::GetLootDrops(int32 table_id){
- if(!reloading && loot_drops.count(table_id) > 0)
- return &(loot_drops[table_id]);
- else
- return 0;
- }
- LootTable* ZoneServer::GetLootTable(int32 table_id){
- return loot_tables[table_id];
- }
- void ZoneServer::AddLocationTransporter(int32 zone_id, string message, float trigger_x, float trigger_y, float trigger_z, float trigger_radius, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading, int32 cost, int32 unique_id){
- LocationTransportDestination* loc = new LocationTransportDestination;
- loc->message = message;
- loc->trigger_x = trigger_x;
- loc->trigger_y = trigger_y;
- loc->trigger_z = trigger_z;
- loc->trigger_radius = trigger_radius;
- loc->destination_zone_id = destination_zone_id;
- loc->destination_x = destination_x;
- loc->destination_y = destination_y;
- loc->destination_z = destination_z;
- loc->destination_heading = destination_heading;
- loc->cost = cost;
- loc->unique_id = unique_id;
- MTransporters.lock();
- if(location_transporters.count(zone_id) == 0)
- location_transporters[zone_id] = new MutexList<LocationTransportDestination*>();
- location_transporters[zone_id]->Add(loc);
- MTransporters.unlock();
- }
- void ZoneServer::AddTransporter(int32 transport_id, int8 type, string name, string message, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading,
- int32 cost, int32 unique_id, int8 min_level, int8 max_level, int32 quest_req, int16 quest_step_req, int32 quest_complete, int32 map_x, int32 map_y, int32 expansion_flag, int32 holiday_flag, int32 min_client_version,
- int32 max_client_version, int32 flight_path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color){
- TransportDestination* transport = new TransportDestination;
- transport->type = type;
- transport->display_name = name;
- transport->message = message;
- transport->destination_zone_id = destination_zone_id;
- transport->destination_x = destination_x;
- transport->destination_y = destination_y;
- transport->destination_z = destination_z;
- transport->destination_heading = destination_heading;
- transport->cost = cost;
- transport->unique_id = unique_id;
- transport->min_level = min_level;
- transport->max_level = max_level;
- transport->req_quest = quest_req;
- transport->req_quest_step = quest_step_req;
- transport->req_quest_complete = quest_complete;
- transport->map_x = map_x;
- transport->map_y = map_y;
- transport->expansion_flag = expansion_flag;
- transport->holiday_flag = holiday_flag;
- transport->min_client_version = min_client_version;
- transport->max_client_version = max_client_version;
- transport->flight_path_id = flight_path_id;
- transport->mount_id = mount_id;
- transport->mount_red_color = mount_red_color;
- transport->mount_green_color = mount_green_color;
- transport->mount_blue_color = mount_blue_color;
- MTransporters.lock();
- transporters[transport_id].push_back(transport);
- MTransporters.unlock();
- }
- void ZoneServer::GetTransporters(vector<TransportDestination*>* returnList, Client* client, int32 transport_id){
- if (!returnList)
- return;
- MTransporters.lock();
- if (transporters.count(transport_id) > 0)
- {
- vector<TransportDestination*> list;
- for (int i = 0; i < transporters[transport_id].size(); i++)
- {
- if (transporters[transport_id][i]->min_client_version && client->GetVersion() < transporters[transport_id][i]->min_client_version)
- continue;
- else if (transporters[transport_id][i]->max_client_version && client->GetVersion() > transporters[transport_id][i]->max_client_version)
- continue;
- if (database.CheckExpansionFlags(this, transporters[transport_id][i]->expansion_flag) && database.CheckHolidayFlags(this, transporters[transport_id][i]->holiday_flag))
- {
- returnList->push_back(transporters[transport_id][i]);
- }
- }
- }
- MTransporters.unlock();
- }
- MutexList<LocationTransportDestination*>* ZoneServer::GetLocationTransporters(int32 zone_id){
- MutexList<LocationTransportDestination*>* ret = 0;
- MTransporters.lock();
- if(location_transporters.count(zone_id) > 0)
- ret = location_transporters[zone_id];
- MTransporters.unlock();
- return ret;
- }
- void ZoneServer::DeleteGlobalTransporters(){
- MTransporters.lock();
- map<int32, vector<TransportDestination*> >::iterator itr;
- vector<TransportDestination*>::iterator transport_vector_itr;
- for(itr = transporters.begin(); itr != transporters.end(); itr++){
- for(transport_vector_itr = itr->second.begin(); transport_vector_itr != itr->second.end(); transport_vector_itr++){
- safe_delete(*transport_vector_itr);
- }
- }
- map<int32, MutexList<LocationTransportDestination*>* >::iterator itr2;
- for(itr2 = location_transporters.begin(); itr2 != location_transporters.end(); itr2++){
- itr2->second->clear(true);
- delete itr2->second;
- }
- transporters.clear();
- location_transporters.clear();
- MTransporters.unlock();
- }
- void ZoneServer::DeleteGlobalSpawns() {
- ClearLootTables();
-
- map<int32, NPC*>::iterator npc_list_iter;
- for(npc_list_iter=npc_list.begin();npc_list_iter!=npc_list.end();npc_list_iter++) {
- safe_delete(npc_list_iter->second);
- }
- npc_list.clear();
- map<int32, Object*>::iterator object_list_iter;
- for(object_list_iter=object_list.begin();object_list_iter!=object_list.end();object_list_iter++) {
- safe_delete(object_list_iter->second);
- }
- object_list.clear();
- map<int32, GroundSpawn*>::iterator groundspawn_list_iter;
- for(groundspawn_list_iter=groundspawn_list.begin();groundspawn_list_iter!=groundspawn_list.end();groundspawn_list_iter++) {
- safe_delete(groundspawn_list_iter->second);
- }
- groundspawn_list.clear();
- map<int32, Widget*>::iterator widget_list_iter;
- for(widget_list_iter=widget_list.begin();widget_list_iter!=widget_list.end();widget_list_iter++) {
- safe_delete(widget_list_iter->second);
- }
- widget_list.clear();
- map<int32, Sign*>::iterator sign_list_iter;
- for(sign_list_iter=sign_list.begin();sign_list_iter!=sign_list.end();sign_list_iter++) {
- safe_delete(sign_list_iter->second);
- }
- sign_list.clear();
- /*map<int32, AppearanceData*>::iterator appearance_list_iter;
- for(appearance_list_iter=npc_appearance_list.begin();appearance_list_iter!=npc_appearance_list.end();appearance_list_iter++) {
- safe_delete(appearance_list_iter->second);
- }
- npc_appearance_list.clear();*/
-
- ClearEntityCommands();
- DeleteGroundSpawnItems();
- DeleteGlobalTransporters();
- DeleteTransporterMaps();
- }
- void ZoneServer::AddTransportMap(int32 id, string name) {
- MTransportMaps.writelock(__FUNCTION__, __LINE__);
- m_transportMaps[id] = name;
- MTransportMaps.releasewritelock(__FUNCTION__, __LINE__);
- }
- bool ZoneServer::TransportHasMap(int32 id) {
- bool ret = false;
- MTransportMaps.readlock(__FUNCTION__, __LINE__);
- ret = m_transportMaps.count(id) > 0;
- MTransportMaps.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- string ZoneServer::GetTransportMap(int32 id) {
- string ret;
- MTransportMaps.readlock(__FUNCTION__, __LINE__);
- if (m_transportMaps.count(id) > 0)
- ret = m_transportMaps[id];
- MTransportMaps.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::DeleteTransporterMaps() {
- MTransportMaps.writelock(__FUNCTION__, __LINE__);
- m_transportMaps.clear();
- MTransportMaps.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ReloadSpawns() {
- if (reloading)
- return;
- reloading = true;
- world.SetReloadingSubsystem("Spawns");
- // Let every one in the zone know what is happening
- HandleBroadcast("Reloading all spawns for this zone.");
- DeleteGlobalSpawns();
- Depop(false, true);
- }
- void ZoneServer::SendStateCommand(Spawn* spawn, int32 state) {
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- if (client && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn))
- ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), state);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddFlightPath(int32 id, FlightPathInfo* info) {
- if (m_flightPaths.count(id) > 0) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Duplicate flight path (%u)", id);
- safe_delete(info);
- return;
- }
- m_flightPaths[id] = info;
- }
- void ZoneServer::AddFlightPathLocation(int32 id, FlightPathLocation* location) {
- if (m_flightPaths.count(id) == 0) {
- LogWrite(ZONE__ERROR, 0, "Zone", "There is no flight info for this route (%u)", id);
- safe_delete(location);
- return;
- }
- m_flightPathRoutes[id].push_back(location);
- }
- void ZoneServer::DeleteFlightPaths() {
- map<int32, vector<FlightPathLocation*> >::iterator itr;
- vector<FlightPathLocation*>::iterator itr2;
- map<int32, FlightPathInfo*>::iterator itr3;
- for (itr = m_flightPathRoutes.begin(); itr != m_flightPathRoutes.end(); itr++) {
- for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
- safe_delete(*itr2);
- }
- itr->second.clear();
- }
- m_flightPathRoutes.clear();
- for (itr3 = m_flightPaths.begin(); itr3 != m_flightPaths.end(); itr3++) {
- safe_delete(itr3->second);
- }
- m_flightPaths.clear();
- }
- void ZoneServer::SendFlightPathsPackets(Client* client) {
- // Only send a packet if there are flight paths
- if (m_flightPathRoutes.size() > 0) {
- PacketStruct* packet = configReader.getStruct("WS_FlightPathsMsg", client->GetVersion());
- if (packet) {
- int32 num_routes = m_flightPaths.size();
- packet->setArrayLengthByName("number_of_routes", num_routes);
- packet->setArrayLengthByName("number_of_routes2", num_routes);
- packet->setArrayLengthByName("number_of_routes3", num_routes);
- packet->setArrayLengthByName("number_of_routes4", num_routes);
- map<int32, FlightPathInfo*>::iterator itr;
- int32 i = 0;
- for (itr = m_flightPaths.begin(); itr != m_flightPaths.end(); itr++, i++) {
- packet->setArrayDataByName("route_length", m_flightPathRoutes[itr->first].size(), i);
- packet->setArrayDataByName("ground_mount", itr->second->flying ? 0 : 1, i);
- packet->setArrayDataByName("allow_dismount", itr->second->dismount ? 1 : 0, i);
- packet->setSubArrayLengthByName("route_length2", m_flightPathRoutes[itr->first].size(), i);
- vector<FlightPathLocation*>::iterator itr2;
- int32 j = 0;
- for (itr2 = m_flightPathRoutes[itr->first].begin(); itr2 != m_flightPathRoutes[itr->first].end(); itr2++, j++) {
- packet->setSubArrayDataByName("x", (*itr2)->X, i, j);
- packet->setSubArrayDataByName("y", (*itr2)->Y, i, j);
- packet->setSubArrayDataByName("z", (*itr2)->Z, i, j);
- }
- }
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- int32 ZoneServer::GetFlightPathIndex(int32 id) {
- int32 index = 0;
- map<int32, FlightPathInfo*>::iterator itr;
- for (itr = m_flightPaths.begin(); itr != m_flightPaths.end(); itr++, index++) {
- if (itr->first == id)
- return index;
- }
- return -1;
- }
- float ZoneServer::GetFlightPathSpeed(int32 id) {
- float speed = 1;
- if (m_flightPaths.count(id) > 0)
- speed = m_flightPaths[id]->speed;
- return speed;
- }
- void ZoneServer::ProcessSpawnConditional(int8 condition) {
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- map<int32, Spawn*>::iterator itr;
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- if (itr->second != NULL) // null itr->second still coming into ProcessSpawnConditional
- {
- SpawnLocation* loc = spawn_location_list[itr->second->GetSpawnLocationID()];
- if (loc && loc->conditional > 0) {
- if ((loc->conditional & condition) != condition) {
- Despawn(itr->second, 0);
- }
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- map<int32, SpawnLocation*>::iterator itr2;
- for (itr2 = spawn_location_list.begin(); itr2 != spawn_location_list.end(); itr2++) {
- SpawnLocation* loc = itr2->second;
- if (loc && loc->conditional > 0 && ((loc->conditional & condition) == condition))
- if (GetSpawnByLocationID(loc->placement_id) == NULL)
- ProcessSpawnLocation(loc);
- }
-
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnProximities(Spawn* newSpawn) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- MPendingSpawnListAdd.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != newSpawn) {
- if (newSpawn->GetDatabaseID())
- spawn->AddSpawnToProximity(newSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (newSpawn->GetSpawnLocationID())
- spawn->AddSpawnToProximity(newSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- if (spawn->GetDatabaseID())
- newSpawn->AddSpawnToProximity(spawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (spawn->GetSpawnLocationID())
- newSpawn->AddSpawnToProximity(spawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- }
- }
- list<Spawn*>::iterator itr2;
- for (itr2 = pending_spawn_list_add.begin(); itr2 != pending_spawn_list_add.end(); itr2++) {
- spawn = *itr2;
- if (spawn && spawn != newSpawn) {
- if (newSpawn->GetDatabaseID())
- spawn->AddSpawnToProximity(newSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (newSpawn->GetSpawnLocationID())
- spawn->AddSpawnToProximity(newSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- if (spawn->GetDatabaseID())
- newSpawn->AddSpawnToProximity(spawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (spawn->GetSpawnLocationID())
- newSpawn->AddSpawnToProximity(spawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- }
- }
- MPendingSpawnListAdd.releasereadlock(__FUNCTION__, __LINE__);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- // we only call this inside a write lock
- void ZoneServer::RemoveSpawnProximities(Spawn* oldSpawn) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != oldSpawn) {
- if (oldSpawn->GetDatabaseID())
- spawn->RemoveSpawnFromProximity(oldSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (oldSpawn->GetSpawnLocationID())
- spawn->RemoveSpawnFromProximity(oldSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- // don't need to remove oldSpawn proximities, we clear them all out
- }
- }
- }
- void ZoneServer::SetSpawnScript(SpawnEntry* entry, Spawn* spawn)
- {
- if (!entry || !spawn)
- return;
- const char* script = 0;
- for (int x = 0; x < 3; x++)
- {
- switch (x)
- {
- case 0:
- script = world.GetSpawnEntryScript(entry->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(entry->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(entry->spawn_id);
- break;
- }
- if (script && lua_interface && lua_interface->GetSpawnScript(script) != 0)
- {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- }
- vector<HouseItem> ZoneServer::GetHouseItems(Client* client)
- {
- if (!client->GetCurrentZone()->GetInstanceID() || !client->HasOwnerOrEditAccess())
- return std::vector<HouseItem>();
- PacketStruct* packet = configReader.getStruct("WS_HouseItemsList", client->GetVersion());
- std::vector<HouseItem> items;
- map<int32, Spawn*>::iterator itr;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsObject() && spawn->GetPickupItemID())
- {
- HouseItem tmpItem;
- tmpItem.item_id = spawn->GetPickupItemID();
- tmpItem.unique_id = spawn->GetPickupUniqueItemID();
- tmpItem.spawn_id = spawn->GetID();
- tmpItem.item = master_item_list.GetItem(spawn->GetPickupItemID());
- if (!tmpItem.item)
- continue;
- items.push_back(tmpItem);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return items;
- }
- void ZoneServer::SendHouseItems(Client* client)
- {
- if (!client->GetCurrentZone()->GetInstanceID() || !client->HasOwnerOrEditAccess())
- return;
- PacketStruct* packet = configReader.getStruct("WS_HouseItemsList", client->GetVersion());
- std::vector<HouseItem> items = GetHouseItems(client);
- // setting this to 1 puts it on the door widget
- packet->setDataByName("is_widget_door", 1);
- packet->setArrayLengthByName("num_items", items.size());
- for (int i = 0; i < items.size(); i++)
- {
- HouseItem tmpItem = items[i];
- packet->setArrayDataByName("unique_id", tmpItem.unique_id, i); // unique_id is in fact the item_id...
- packet->setArrayDataByName("item_name", tmpItem.item->name.c_str(), i);
- packet->setArrayDataByName("status_reduction", tmpItem.item->houseitem_info->status_rent_reduction, i);
- // location, 0 = floor, 1 = ceiling
- //packet->setArrayDataByName("location", 1, i, 0);
- // item_state int8
- // 0 = normal (cannot pick up item / move item / toggle visibility)
- // 1 = virtual (toggle visibility available, no move item)
- // 2 = hidden (cannot pick up item / move item / toggle visibility)
- // 3 = virtual/hidden/toggle visibility
- // 4 = none (cannot pick up item / move item / toggle visibility)
- // 5 = none, toggle visibility (cannot pick up item / move item)
- // 8 = none (cannot pick up item / move item / toggle visibility)
- //packet->setArrayDataByName("item_state", tmpvalue, i, 0);
- // makes it so we don't have access to move item/retrieve item
- // cannot use in conjunction with ui_tab_flag1/ui_tab_flag2
- //packet->setArrayDataByName("tradeable", 1, i);
- //packet->setArrayDataByName("item_description", "failboat", i);
- // access to move item/retrieve item, do not use in conjunction with tradeable
- packet->setArrayDataByName("ui_tab_flag1", 1, i, 0);
- packet->setArrayDataByName("ui_tab_flag2", 1, i, 0);
- // both of these can serve as description fields (only one should be used they populate the same area below the item name)
- //packet->setArrayDataByName("first_item_description", "test", i);
- //packet->setArrayDataByName("second_item_description", "Description here!", i);
- packet->setArrayDataByName("icon", tmpItem.item->details.icon, i);
- }
- EQ2Packet* pack = packet->serialize();
- client->QueuePacket(pack);
- safe_delete(packet);
- }
- Spawn* ZoneServer::GetSpawnFromUniqueItemID(int32 unique_id)
- {
- if (!GetInstanceID() || GetInstanceType() != Instance_Type::PERSONAL_HOUSE_INSTANCE)
- return nullptr;
- map<int32, Spawn*>::iterator itr;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsObject() && spawn->GetPickupUniqueItemID() == unique_id)
- {
- Spawn* tmpSpawn = spawn;
- MSpawnList.releasereadlock();
- return tmpSpawn;
- }
- }
- MSpawnList.releasereadlock();
- return nullptr;
- }
- void ZoneServer::AddPendingSpawnRemove(int32 id)
- {
- MPendingSpawnRemoval.writelock(__FUNCTION__, __LINE__);
- m_pendingSpawnRemove.push_back(id);
- MPendingSpawnRemoval.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessSpawnRemovals()
- {
- MPendingSpawnRemoval.writelock(__FUNCTION__, __LINE__);
- if (m_pendingSpawnRemove.size() > 0) {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr2;
- for (itr2 = m_pendingSpawnRemove.begin(); itr2 != m_pendingSpawnRemove.end(); itr2++)
- spawn_list.erase(*itr2);
- m_pendingSpawnRemove.clear();
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- MPendingSpawnRemoval.releasewritelock(__FUNCTION__, __LINE__);
- }
|