9
3

LuaFunctions.cpp 290 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. extern WorldDatabase database;
  36. extern LuaInterface* lua_interface;
  37. extern ConfigReader configReader;
  38. extern MasterQuestList master_quest_list;
  39. extern MasterItemList master_item_list;
  40. extern MasterSpellList master_spell_list;
  41. extern World world;
  42. extern Commands commands;
  43. extern ZoneList zone_list;
  44. extern Races races;
  45. extern Classes classes;
  46. extern Variables variables;
  47. extern MasterSkillList master_skill_list;
  48. extern MasterHeroicOPList master_ho_list;
  49. extern MasterRaceTypeList race_types_list;
  50. extern MasterLanguagesList master_languages_list;
  51. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  52. if (!lua_interface)
  53. return 0;
  54. Spawn* spawn = lua_interface->GetSpawn(state);
  55. string mp3_string = lua_interface->GetStringValue(state, 2);
  56. string text_string = lua_interface->GetStringValue(state, 3);
  57. string emote_string = lua_interface->GetStringValue(state, 4);
  58. int32 key1 = lua_interface->GetInt32Value(state, 5);
  59. int32 key2 = lua_interface->GetInt32Value(state, 6);
  60. Spawn* player = lua_interface->GetSpawn(state, 7);
  61. int8 language = lua_interface->GetInt8Value(state, 8);
  62. if (spawn) {
  63. const char* mp3 = 0;
  64. const char* text = 0;
  65. const char* emote = 0;
  66. if (mp3_string.length() > 0)
  67. mp3 = mp3_string.c_str();
  68. if (text_string.length() > 0)
  69. text = text_string.c_str();
  70. if (emote_string.length() > 0)
  71. emote = emote_string.c_str();
  72. Client* client = 0;
  73. if (player && player->IsPlayer())
  74. client = spawn->GetZone()->GetClientBySpawn(player);
  75. if (client) {
  76. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  77. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  78. }
  79. else
  80. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  81. }
  82. return 0;
  83. }
  84. int EQ2Emu_lua_PlaySound(lua_State* state) {
  85. if (!lua_interface)
  86. return 0;
  87. Spawn* spawn = lua_interface->GetSpawn(state);
  88. string sound_string = lua_interface->GetStringValue(state, 2);
  89. float x = lua_interface->GetFloatValue(state, 3);
  90. float y = lua_interface->GetFloatValue(state, 4);
  91. float z = lua_interface->GetFloatValue(state, 5);
  92. Spawn* player = lua_interface->GetSpawn(state, 6);
  93. if (spawn && sound_string.length() > 0) {
  94. Client* client = 0;
  95. if (player && player->IsPlayer())
  96. client = spawn->GetZone()->GetClientBySpawn(player);
  97. if (client)
  98. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  99. else
  100. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  101. }
  102. return 0;
  103. }
  104. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  105. if (!lua_interface)
  106. return 0;
  107. Spawn* spawn = lua_interface->GetSpawn(state);
  108. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  109. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  110. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  111. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  112. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  113. if (!spawn) {
  114. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  115. return 0;
  116. }
  117. if (quest_id > 0) {
  118. //Add this quest to the list of required quests for this spawn
  119. spawn->SetQuestsRequired(quest_id, quest_step);
  120. //If private spawn value set
  121. if (private_spawn) {
  122. //Set the spawn to be private when not granted access through this quest
  123. spawn->AddAllowAccessSpawn(spawn);
  124. spawn->SetPrivateQuestSpawn(true);
  125. }
  126. //This value allows access after a quest step, or the whole quest has been completed
  127. if (continued_access)
  128. spawn->SetQuestsRequiredContinuedAccess(true);
  129. //This value will override vis_flags in the vis packet
  130. if (flag_override > 0)
  131. spawn->SetQuestsRequiredOverride(flag_override);
  132. }
  133. return 0;
  134. }
  135. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  136. if (!lua_interface)
  137. return 0;
  138. Spawn* spawn = lua_interface->GetSpawn(state);
  139. float max_distance = lua_interface->GetFloatValue(state, 2);
  140. string variable = lua_interface->GetStringValue(state, 3);
  141. string value = lua_interface->GetStringValue(state, 4);
  142. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  143. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  144. return 0;
  145. }
  146. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  147. if (!lua_interface)
  148. return 0;
  149. Client* client = 0;
  150. Spawn* player = lua_interface->GetSpawn(state);
  151. if (!player) {
  152. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  153. return 0;
  154. }
  155. if (!player->IsPlayer()) {
  156. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  157. return 0;
  158. }
  159. if (player->GetZone())
  160. client = player->GetZone()->GetClientBySpawn(player);
  161. if (!client) {
  162. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  163. return 0;
  164. }
  165. int16 value1 = lua_interface->GetInt16Value(state, 2);
  166. int16 value2 = lua_interface->GetInt16Value(state, 3);
  167. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  168. if (packet) {
  169. packet->setDataByName("unknown1", value1);
  170. packet->setDataByName("unknown2", value2);
  171. client->QueuePacket(packet->serialize());
  172. safe_delete(packet);
  173. }
  174. return 0;
  175. }
  176. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  177. if (!lua_interface)
  178. return 0;
  179. Spawn* dead = lua_interface->GetSpawn(state);
  180. Spawn* killer = lua_interface->GetSpawn(state, 2);
  181. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  182. if (dead && dead->Alive() && dead->GetZone())
  183. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  184. return 0;
  185. }
  186. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  187. if (!lua_interface)
  188. return 0;
  189. Spawn* spawn = lua_interface->GetSpawn(state);
  190. float max_distance = lua_interface->GetFloatValue(state, 2);
  191. bool include_players = lua_interface->GetInt8Value(state, 3);
  192. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  193. if (max_distance > 0 && spawn && spawn->GetZone())
  194. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  195. return 0;
  196. }
  197. int EQ2Emu_lua_Despawn(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 delay = lua_interface->GetInt32Value(state, 2);
  202. if (spawn && spawn->GetZone())
  203. spawn->GetZone()->Despawn(spawn, delay);
  204. return 0;
  205. }
  206. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  207. if (!lua_interface)
  208. return 0;
  209. Spawn* spawn = lua_interface->GetSpawn(state);
  210. string variable = lua_interface->GetStringValue(state, 2);
  211. string value = lua_interface->GetStringValue(state, 3);
  212. int32 type = commands.GetSpawnSetType(variable);
  213. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  214. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  215. return 0;
  216. }
  217. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  218. if (!lua_interface)
  219. return 0;
  220. Spawn* spawn = lua_interface->GetSpawn(state);
  221. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  222. if (spawn && spawn_id > 0) {
  223. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  224. if (closest_spawn) {
  225. lua_interface->SetSpawnValue(state, closest_spawn);
  226. return 1;
  227. }
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. string variable_name = lua_interface->GetStringValue(state);
  235. Variable* var = variables.FindVariable(variable_name);
  236. if (var) {
  237. lua_interface->SetStringValue(state, var->GetValue());
  238. return 1;
  239. }
  240. return 0;
  241. }
  242. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  243. if (!lua_interface)
  244. return 0;
  245. int32 total_coins = lua_interface->GetInt32Value(state);
  246. if (total_coins == 0) {
  247. lua_interface->SetStringValue(state, "0 copper");
  248. return 1;
  249. }
  250. char tmp[64] = { 0 };
  251. string message = "";
  252. int32 val = 0;
  253. if (total_coins >= 1000000) {
  254. val = total_coins / 1000000;
  255. total_coins -= 1000000 * val;
  256. sprintf(tmp, " %u Platinum", val);
  257. message.append(tmp);
  258. memset(tmp, 0, 64);
  259. }
  260. if (total_coins >= 10000) {
  261. val = total_coins / 10000;
  262. total_coins -= 10000 * val;
  263. sprintf(tmp, " %u Gold", val);
  264. message.append(tmp);
  265. memset(tmp, 0, 64);
  266. }
  267. if (total_coins >= 100) {
  268. val = total_coins / 100;
  269. total_coins -= 100 * val;
  270. sprintf(tmp, " %u Silver", val);
  271. message.append(tmp);
  272. memset(tmp, 0, 64);
  273. }
  274. if (total_coins > 0) {
  275. sprintf(tmp, " %u Copper", (int32)total_coins);
  276. message.append(tmp);
  277. }
  278. lua_interface->SetStringValue(state, message.c_str());
  279. return 1;
  280. }
  281. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  282. ZoneServer* zone = lua_interface->GetZone(state);
  283. int32 group_id = lua_interface->GetInt32Value(state, 2);
  284. if (zone) {
  285. Spawn* spawn = zone->GetSpawnGroup(group_id);
  286. if (spawn) {
  287. lua_interface->SetSpawnValue(state, spawn);
  288. return 1;
  289. }
  290. }
  291. return 0;
  292. }
  293. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  294. ZoneServer* zone = lua_interface->GetZone(state);
  295. int32 location_id = lua_interface->GetInt32Value(state, 2);
  296. if (zone) {
  297. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  298. if (spawn) {
  299. lua_interface->SetSpawnValue(state, spawn);
  300. return 1;
  301. }
  302. }
  303. return 0;
  304. }
  305. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. if (spawn) {
  308. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  309. return 1;
  310. }
  311. return 0;
  312. }
  313. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  314. Spawn* spawn = lua_interface->GetSpawn(state);
  315. if (spawn) {
  316. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  317. return 1;
  318. }
  319. return 0;
  320. }
  321. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  322. Spawn* spawn = lua_interface->GetSpawn(state);
  323. if (spawn) {
  324. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  325. return 1;
  326. }
  327. return 0;
  328. }
  329. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  330. Spawn* spawn = lua_interface->GetSpawn(state);
  331. if (spawn) {
  332. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  333. return 1;
  334. }
  335. return 0;
  336. }
  337. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  338. Player* player = (Player*)lua_interface->GetSpawn(state);
  339. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  340. if (player && player->IsPlayer() && faction_id > 0) {
  341. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  342. return 1;
  343. }
  344. return 0;
  345. }
  346. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  347. if (!lua_interface)
  348. return 0;
  349. Spawn* spawn = lua_interface->GetSpawn(state);
  350. int32 value = lua_interface->GetInt32Value(state, 2);
  351. if (spawn) {
  352. spawn->SetFactionID(value);
  353. }
  354. return 0;
  355. }
  356. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. if (spawn) {
  359. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  360. return 1;
  361. }
  362. return 0;
  363. }
  364. int EQ2Emu_lua_GetGender(lua_State* state) {
  365. Spawn* spawn = lua_interface->GetSpawn(state);
  366. if (spawn) {
  367. lua_interface->SetInt32Value(state, spawn->GetGender());
  368. return 1;
  369. }
  370. return 0;
  371. }
  372. int EQ2Emu_lua_GetTarget(lua_State* state) {
  373. Spawn* spawn = lua_interface->GetSpawn(state);
  374. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  375. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  376. return 1;
  377. }
  378. return 0;
  379. }
  380. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  381. if (!lua_interface)
  382. return 0;
  383. Spawn* spawn = lua_interface->GetSpawn(state);
  384. string mp3_string = lua_interface->GetStringValue(state, 2);
  385. int32 key1 = lua_interface->GetInt32Value(state, 3);
  386. int32 key2 = lua_interface->GetInt32Value(state, 4);
  387. Spawn* player = lua_interface->GetSpawn(state, 5);
  388. if (spawn && mp3_string.length() > 0) {
  389. Client* client = 0;
  390. if (player && player->IsPlayer())
  391. client = spawn->GetZone()->GetClientBySpawn(player);
  392. if (client) {
  393. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  394. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  395. }
  396. else
  397. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  398. }
  399. return 0;
  400. }
  401. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  402. if (!lua_interface)
  403. return 0;
  404. Spawn* spawn = lua_interface->GetSpawn(state);
  405. if (spawn) {
  406. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  407. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  408. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  409. return 3;
  410. }
  411. return 0;
  412. }
  413. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. if (spawn && spawn->IsEntity()) {
  418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  419. int16 charges = lua_interface->GetInt16Value(state, 3);
  420. if (charges == 0)
  421. charges = 1;
  422. ((Entity*)spawn)->AddLootItem(item_id, charges);
  423. }
  424. return 0;
  425. }
  426. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  427. if (!lua_interface)
  428. return 0;
  429. Spawn* spawn = lua_interface->GetSpawn(state);
  430. if (spawn && spawn->IsEntity()) {
  431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  432. ((Entity*)spawn)->LootItem(item_id);
  433. }
  434. return 0;
  435. }
  436. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  437. if (!lua_interface)
  438. return 0;
  439. Spawn* spawn = lua_interface->GetSpawn(state);
  440. if (spawn && spawn->IsEntity()) {
  441. int32 val = lua_interface->GetInt32Value(state, 2);
  442. ((Entity*)spawn)->AddLootCoins(val);
  443. }
  444. return 0;
  445. }
  446. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  447. if (!lua_interface)
  448. return 0;
  449. Spawn* entity = lua_interface->GetSpawn(state);
  450. Spawn* player = lua_interface->GetSpawn(state, 2);
  451. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  452. int32 coins = lua_interface->GetInt32Value(state, 3);
  453. vector<Item*>* items = 0;
  454. int i = 0;
  455. int32 item_id = 0;
  456. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  457. if (items == 0)
  458. items = new vector<Item*>;
  459. if (master_item_list.GetItem(item_id))
  460. items->push_back(master_item_list.GetItem(item_id));
  461. i++;
  462. }
  463. Client* client = 0;
  464. client = entity->GetZone()->GetClientBySpawn(player);
  465. if (client) {
  466. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  467. client->Loot(coins, ((Player*)player)->GetPendingLootItems(entity->GetID()), (Entity*)entity);
  468. }
  469. safe_delete(items);
  470. }
  471. return 0;
  472. }
  473. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  474. if (!lua_interface)
  475. return 0;
  476. Spawn* entity = lua_interface->GetSpawn(state);
  477. Spawn* player = lua_interface->GetSpawn(state, 2);
  478. int32 item_id = lua_interface->GetInt32Value(state, 3);
  479. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  480. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  481. return 1;
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* entity = lua_interface->GetSpawn(state);
  489. Spawn* player = lua_interface->GetSpawn(state, 2);
  490. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  491. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  492. return 1;
  493. }
  494. return 0;
  495. }
  496. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  497. if (!lua_interface)
  498. return 0;
  499. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  500. safe_delete(conversation);
  501. conversation = new vector<ConversationOption>();
  502. lua_interface->SetConversationValue(state, conversation);
  503. return 1;
  504. }
  505. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  509. if (conversation) {
  510. ConversationOption conv_option;
  511. conv_option.option = lua_interface->GetStringValue(state, 2);
  512. conv_option.function = lua_interface->GetStringValue(state, 3);
  513. if (conv_option.option.length() > 0)
  514. conversation->push_back(conv_option);
  515. }
  516. return 0;
  517. }
  518. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  519. if (!lua_interface)
  520. return 0;
  521. Spawn* npc = lua_interface->GetSpawn(state);
  522. Spawn* player = lua_interface->GetSpawn(state, 2);
  523. if (npc && player && player->IsPlayer() && player->GetZone()) {
  524. Client* client = player->GetZone()->GetClientBySpawn(player);
  525. if (client) {
  526. int32 conversation_id = client->GetConversationID(npc, 0);
  527. client->CloseDialog(conversation_id);
  528. }
  529. }
  530. return 0;
  531. }
  532. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  533. if (!lua_interface)
  534. return 0;
  535. Item* item = lua_interface->GetItem(state);
  536. Spawn* player = lua_interface->GetSpawn(state, 2);
  537. if (item && player && player->IsPlayer() && player->GetZone()) {
  538. Client* client = player->GetZone()->GetClientBySpawn(player);
  539. if (client) {
  540. int32 conversation_id = client->GetConversationID(0, item);
  541. client->CloseDialog(conversation_id);
  542. }
  543. }
  544. return 0;
  545. }
  546. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  547. if (!lua_interface)
  548. return 0;
  549. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  550. Spawn* spawn = 0;
  551. Item* item = 0;
  552. int8 type = lua_interface->GetInt8Value(state, 2);
  553. if (type == 1 || type == 3)
  554. spawn = lua_interface->GetSpawn(state, 3);
  555. else if (type == 2 || type == 4)
  556. item = lua_interface->GetItem(state, 3);
  557. Spawn* player = lua_interface->GetSpawn(state, 4);
  558. string text = lua_interface->GetStringValue(state, 5);
  559. string mp3 = lua_interface->GetStringValue(state, 6);
  560. int32 key1 = lua_interface->GetInt32Value(state, 7);
  561. int32 key2 = lua_interface->GetInt32Value(state, 8);
  562. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  563. Client* client = player->GetZone()->GetClientBySpawn(player);
  564. if (client) {
  565. if (spawn) {
  566. // Need to do this so the function works the same as it did before
  567. if (type == 1)
  568. type++;
  569. if (mp3.length() > 0)
  570. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  571. else
  572. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  573. }
  574. else {
  575. if (mp3.length() > 0)
  576. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  577. else
  578. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  579. }
  580. }
  581. }
  582. safe_delete(conversation);
  583. lua_interface->SetConversationValue(state, NULL);
  584. return 0;
  585. }
  586. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  587. if(!lua_interface)
  588. return 0;
  589. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  590. Item* item = lua_interface->GetItem(state, 2);
  591. Spawn* player = lua_interface->GetSpawn(state, 3);
  592. string text = lua_interface->GetStringValue(state, 4);
  593. string mp3 = lua_interface->GetStringValue(state, 5);
  594. int32 key1 = lua_interface->GetInt32Value(state, 6);
  595. int32 key2 = lua_interface->GetInt32Value(state, 7);
  596. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  597. Client* client = player->GetZone()->GetClientBySpawn(player);
  598. if(client){
  599. if(mp3.length() > 0)
  600. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  601. else
  602. client->DisplayConversation(item, conversation, (char*)text.c_str());
  603. }
  604. safe_delete(conversation);
  605. }
  606. return 0;
  607. }*/
  608. int EQ2Emu_lua_StartConversation(lua_State* state) {
  609. if (!lua_interface)
  610. return 0;
  611. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  612. Spawn* npc = lua_interface->GetSpawn(state, 2);
  613. Spawn* player = lua_interface->GetSpawn(state, 3);
  614. string text = lua_interface->GetStringValue(state, 4);
  615. string mp3 = lua_interface->GetStringValue(state, 5);
  616. int32 key1 = lua_interface->GetInt32Value(state, 6);
  617. int32 key2 = lua_interface->GetInt32Value(state, 7);
  618. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  619. Client* client = npc->GetZone()->GetClientBySpawn(player);
  620. if (mp3.length() > 0)
  621. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  622. else
  623. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  624. safe_delete(conversation);
  625. lua_interface->SetConversationValue(state, NULL);
  626. }
  627. else
  628. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  629. return 0;
  630. }
  631. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  632. if (!lua_interface)
  633. return 0;
  634. Spawn* spawn = lua_interface->GetSpawn(state);
  635. float distance = lua_interface->GetFloatValue(state, 2);
  636. string in_range_function = lua_interface->GetStringValue(state, 3);
  637. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  638. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  639. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  640. return 0;
  641. }
  642. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  643. ZoneServer* zone = lua_interface->GetZone(state);
  644. float x = lua_interface->GetFloatValue(state, 2);
  645. float y = lua_interface->GetFloatValue(state, 3);
  646. float z = lua_interface->GetFloatValue(state, 4);
  647. float max_variation = lua_interface->GetFloatValue(state, 5);
  648. string in_range_function = lua_interface->GetStringValue(state, 6);
  649. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  650. if (zone && in_range_function.length() > 0)
  651. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  652. return 0;
  653. }
  654. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. if (spawn && spawn->IsEntity()) {
  659. int32 val = lua_interface->GetInt32Value(state, 2);
  660. ((Entity*)spawn)->SetLootCoins(val);
  661. }
  662. return 0;
  663. }
  664. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  665. if (!lua_interface)
  666. return 0;
  667. Spawn* spawn = lua_interface->GetSpawn(state);
  668. if (spawn && spawn->IsEntity()) {
  669. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  670. return 1;
  671. }
  672. return 0;
  673. }
  674. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  675. if (!lua_interface)
  676. return 0;
  677. Spawn* spawn = lua_interface->GetSpawn(state);
  678. float x = lua_interface->GetFloatValue(state, 2);
  679. float y = lua_interface->GetFloatValue(state, 3);
  680. float z = lua_interface->GetFloatValue(state, 4);
  681. float speed = lua_interface->GetFloatValue(state, 5);
  682. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  683. string function = lua_interface->GetStringValue(state, 7);
  684. if (spawn) {
  685. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  686. spawn->GetZone()->AddMovementNPC(spawn);
  687. }
  688. lua_interface->ResetFunctionStack(state);
  689. return 0;
  690. }
  691. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  692. if (!lua_interface)
  693. return 0;
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn) {
  696. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  697. return 1;
  698. }
  699. return 0;
  700. }
  701. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  702. if (!lua_interface)
  703. return 0;
  704. Spawn* spawn = lua_interface->GetSpawn(state);
  705. Spawn* target = lua_interface->GetSpawn(state, 2);
  706. if (spawn && target) {
  707. if (spawn->IsEntity())
  708. // ((Entity*)spawn)->FaceTarget(target);
  709. static_cast<Entity*>(spawn)->FaceTarget(target);
  710. }
  711. lua_interface->ResetFunctionStack(state);
  712. return 0;
  713. }
  714. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  715. if (!lua_interface)
  716. return 0;
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. float x = lua_interface->GetFloatValue(state, 2);
  719. float y = lua_interface->GetFloatValue(state, 3);
  720. float z = lua_interface->GetFloatValue(state, 4);
  721. float speed = lua_interface->GetFloatValue(state, 5);
  722. string lua_function = lua_interface->GetStringValue(state, 6);
  723. bool more_points = lua_interface->GetBooleanValue(state, 7);
  724. if (spawn) {
  725. if (speed == 0)
  726. speed = spawn->GetSpeed();
  727. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  728. }
  729. lua_interface->ResetFunctionStack(state);
  730. return 0;
  731. }
  732. int EQ2Emu_lua_Say(lua_State* state) {
  733. if (!lua_interface)
  734. return 0;
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. string message = lua_interface->GetStringValue(state, 2);
  737. Spawn* player = lua_interface->GetSpawn(state, 3);
  738. int32 language = lua_interface->GetInt32Value(state, 4);
  739. if (spawn && message.length() > 0) {
  740. Client* client = 0;
  741. if (player && player->IsPlayer())
  742. client = spawn->GetZone()->GetClientBySpawn(player);
  743. if (client)
  744. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  745. else
  746. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  747. }
  748. lua_interface->ResetFunctionStack(state);
  749. return 0;
  750. }
  751. int EQ2Emu_lua_Shout(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* spawn = lua_interface->GetSpawn(state);
  755. string message = lua_interface->GetStringValue(state, 2);
  756. Spawn* player = lua_interface->GetSpawn(state, 3);
  757. if (spawn && message.length() > 0) {
  758. Client* client = 0;
  759. if (player && player->IsPlayer())
  760. client = spawn->GetZone()->GetClientBySpawn(player);
  761. if (client)
  762. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  763. else
  764. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  765. }
  766. lua_interface->ResetFunctionStack(state);
  767. return 0;
  768. }
  769. int EQ2Emu_lua_SayOOC(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. string message = lua_interface->GetStringValue(state, 2);
  774. Spawn* player = lua_interface->GetSpawn(state, 3);
  775. if (spawn && message.length() > 0) {
  776. Client* client = 0;
  777. if (player && player->IsPlayer())
  778. client = spawn->GetZone()->GetClientBySpawn(player);
  779. if (client)
  780. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  781. else
  782. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  783. }
  784. lua_interface->ResetFunctionStack(state);
  785. return 0;
  786. }
  787. int EQ2Emu_lua_Emote(lua_State* state) {
  788. if (!lua_interface)
  789. return 0;
  790. Spawn* spawn = lua_interface->GetSpawn(state);
  791. string message = lua_interface->GetStringValue(state, 2);
  792. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  793. Spawn* player = lua_interface->GetSpawn(state, 4);
  794. char* to = 0;
  795. if (spawn2)
  796. to = spawn2->GetName();
  797. if (spawn && message.length() > 0) {
  798. Client* client = 0;
  799. if (player && player->IsPlayer())
  800. client = spawn->GetZone()->GetClientBySpawn(player);
  801. if (client)
  802. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  803. else
  804. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  813. if (!luaspell)
  814. return 0;
  815. Spawn* caster = luaspell->caster;
  816. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  817. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  818. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  819. Spawn* target = lua_interface->GetSpawn(state, 4);
  820. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  821. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  822. lua_interface->ResetFunctionStack(state);
  823. if (caster && caster->IsEntity()) {
  824. bool success = false;
  825. luaspell->resisted = false;
  826. if (target) {
  827. float distance = caster->GetDistance(target, true);
  828. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  829. success = true;
  830. }
  831. if (luaspell->targets.size() > 0) {
  832. Spawn* target = 0;
  833. ZoneServer* zone = luaspell->caster->GetZone();
  834. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  835. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  836. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  837. float distance = caster->GetDistance(target, true);
  838. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  839. }
  840. }
  841. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  842. success = true;
  843. }
  844. if (success) {
  845. if (caster->GetZone())
  846. caster->GetZone()->TriggerCharSheetTimer();
  847. }
  848. }
  849. return 0;
  850. }
  851. int EQ2Emu_lua_SummonItem(lua_State* state) {
  852. if (!lua_interface)
  853. return 0;
  854. Spawn* spawn = lua_interface->GetSpawn(state);
  855. int32 item_id = lua_interface->GetInt32Value(state, 2);
  856. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  857. string location = lua_interface->GetStringValue(state, 4);
  858. if (spawn && spawn->IsPlayer()) {
  859. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  860. if (client && item_id > 0) {
  861. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  862. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  863. else
  864. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  865. if (send_messages) {
  866. Item* item = master_item_list.GetItem(item_id);
  867. if (item) {
  868. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  869. string popup_text = "You receive " + item->name;
  870. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  871. }
  872. }
  873. return 1;
  874. }
  875. }
  876. lua_interface->SetBooleanValue(state, false);
  877. return 1;
  878. }
  879. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  880. Spawn* spawn = lua_interface->GetSpawn(state);
  881. int32 item_id = lua_interface->GetInt32Value(state, 2);
  882. Client* client;
  883. Item* item;
  884. if (spawn && spawn->IsPlayer() && item_id > 0) {
  885. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  886. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  887. if (client->RemoveItem(item, 1)) {
  888. lua_interface->SetBooleanValue(state, true);
  889. return 1;
  890. }
  891. }
  892. }
  893. }
  894. lua_interface->SetBooleanValue(state, false);
  895. return 1;
  896. }
  897. int EQ2Emu_lua_HasItem(lua_State* state) {
  898. Spawn* player = lua_interface->GetSpawn(state);
  899. int32 item_id = lua_interface->GetInt32Value(state, 2);
  900. bool include_bank = lua_interface->GetInt8Value(state, 3);
  901. if (player && player->IsPlayer()) {
  902. bool hasItem = false;
  903. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  904. if (!hasItem)
  905. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  906. lua_interface->SetBooleanValue(state, hasItem);
  907. return 1;
  908. }
  909. lua_interface->SetBooleanValue(state, false);
  910. return 1;
  911. }
  912. int EQ2Emu_lua_Spawn(lua_State* state) {
  913. if (!lua_interface)
  914. return 0;
  915. ZoneServer* zone = lua_interface->GetZone(state);
  916. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  917. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  918. float x = lua_interface->GetFloatValue(state, 4);
  919. float y = lua_interface->GetFloatValue(state, 5);
  920. float z = lua_interface->GetFloatValue(state, 6);
  921. float heading = lua_interface->GetFloatValue(state, 7);
  922. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  923. Spawn* spawn = zone->GetSpawn(spawn_id);
  924. if (!spawn)
  925. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  926. else {
  927. spawn->SetX(x);
  928. spawn->SetZ(z);
  929. spawn->SetY(y,true,true);
  930. spawn->SetLocation(zone->GetClosestLocation(spawn));
  931. spawn->SetHeading(heading);
  932. if (restricted_npc)
  933. spawn->AddAllowAccessSpawn(spawn);
  934. const char* spawn_script = world.GetSpawnScript(spawn_id);
  935. bool scriptActive = false;
  936. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  937. scriptActive = true;
  938. spawn->SetSpawnScript(string(spawn_script));
  939. }
  940. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  941. zone->AddSpawn(spawn);
  942. if (scriptActive) {
  943. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  944. }
  945. lua_interface->SetSpawnValue(state, spawn);
  946. return 1;
  947. }
  948. }
  949. else {
  950. string output = "Invalid paramaters to LUA Spawn command: \n";
  951. if (!zone)
  952. output = output.append("\t").append("Missing zone reference. \n");
  953. if (spawn_id == 0)
  954. output = output.append("\t").append("Missing spawn_id.");
  955. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone - %s", lua_interface->GetScriptName(state), output.c_str());
  956. }
  957. return 0;
  958. }
  959. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  960. if (!lua_interface)
  961. return 0;
  962. ZoneServer* zone = lua_interface->GetZone(state);
  963. if (zone) {
  964. lua_interface->SetStringValue(state, zone->GetZoneName());
  965. return 1;
  966. }
  967. return 0;
  968. }
  969. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  970. if (!lua_interface)
  971. return 0;
  972. ZoneServer* zone = lua_interface->GetZone(state);
  973. if (zone) {
  974. lua_interface->SetInt32Value(state, zone->GetZoneID());
  975. return 1;
  976. }
  977. return 0;
  978. }
  979. int EQ2Emu_lua_GetZone(lua_State* state) {
  980. if (!lua_interface)
  981. return 0;
  982. int32 zone_id = lua_interface->GetInt32Value(state);
  983. ZoneServer* zone = 0;
  984. if (zone_id > 0)
  985. zone = zone_list.Get(zone_id);
  986. else {
  987. string zone_name = lua_interface->GetStringValue(state);
  988. if (zone_name.length() > 0) {
  989. zone = zone_list.Get(zone_name.c_str());
  990. }
  991. else {
  992. Spawn* spawn = lua_interface->GetSpawn(state);
  993. if (spawn)
  994. zone = spawn->GetZone();
  995. }
  996. }
  997. if (zone) {
  998. lua_interface->SetZoneValue(state, zone);
  999. return 1;
  1000. }
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_AddHate(lua_State* state) {
  1004. Spawn* entity = lua_interface->GetSpawn(state);
  1005. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1006. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1007. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1008. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1009. if (entity && entity->IsEntity() && amount != 0) {
  1010. if (luaspell) {
  1011. ZoneServer* zone = luaspell->caster->GetZone();
  1012. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1013. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1014. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1015. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1016. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1017. if (send_packet)
  1018. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1019. }
  1020. }
  1021. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1022. }
  1023. else if (npc && npc->IsNPC() && npc->GetZone())
  1024. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1025. }
  1026. return 0;
  1027. }
  1028. int EQ2Emu_lua_Zone(lua_State* state) {
  1029. if (!lua_interface)
  1030. return 0;
  1031. ZoneServer* zone = lua_interface->GetZone(state);
  1032. Spawn* player = lua_interface->GetSpawn(state, 2);
  1033. Client* client = 0;
  1034. if (player && player->IsPlayer())
  1035. client = player->GetZone()->GetClientBySpawn(player);
  1036. float x = lua_interface->GetFloatValue(state, 3);
  1037. float y = lua_interface->GetFloatValue(state, 4);
  1038. float z = lua_interface->GetFloatValue(state, 5);
  1039. float heading = lua_interface->GetFloatValue(state, 6);
  1040. if (zone && client) {
  1041. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1042. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1043. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1044. {
  1045. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1046. return 0;
  1047. }
  1048. if (x != 0 || y != 0 || z != 0) {
  1049. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1050. player->SetX(x);
  1051. player->SetY(y);
  1052. player->SetZ(z);
  1053. player->SetHeading(heading);
  1054. client->Zone(zone->GetZoneName(), false);
  1055. }
  1056. else
  1057. client->Zone(zone->GetZoneName());
  1058. }
  1059. else
  1060. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1061. return 0;
  1062. }
  1063. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1064. if (!lua_interface)
  1065. return 0;
  1066. Spawn* spawn = lua_interface->GetSpawn(state);
  1067. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1068. if (spawn && spawn2)
  1069. spawn->AddAllowAccessSpawn(spawn2);
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* target = lua_interface->GetSpawn(state);
  1076. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1077. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1078. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1079. if (!target) {
  1080. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1081. return 0;
  1082. }
  1083. if (!target->IsEntity()) {
  1084. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1085. return 0;
  1086. }
  1087. if (spell_id <= 0) {
  1088. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1089. return 0;
  1090. }
  1091. if (caster && !caster->IsEntity()) {
  1092. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1093. return 0;
  1094. }
  1095. if (spell_tier == 0)
  1096. spell_tier = 1;
  1097. if (!caster)
  1098. caster = target;
  1099. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* target = lua_interface->GetSpawn(state);
  1106. int32 target_id = 0;
  1107. if (target)
  1108. target_id = target->GetID();
  1109. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1110. if (!luaspell)
  1111. return 0;
  1112. Spawn* caster = luaspell->caster;
  1113. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1114. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1115. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1116. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1117. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1118. //lua_interface->ResetFunctionStack(state);
  1119. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1120. vector<int16> faction_req;
  1121. vector<int16> race_req;
  1122. int32 class_req = 0;
  1123. int32 i = 0;
  1124. int8 f = 0;
  1125. int8 r = 0;
  1126. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1127. if (class_id < 100) {
  1128. class_req += pow(2.0, double(class_id - 1));
  1129. }
  1130. else if (class_id > 100 && class_id < 1000) {
  1131. race_req.push_back(class_id);
  1132. r++;
  1133. }
  1134. else {
  1135. faction_req.push_back(class_id);
  1136. f++;
  1137. }
  1138. i++;
  1139. }
  1140. if (caster && caster->IsEntity()) {
  1141. bool race_match = false;
  1142. bool success = false;
  1143. luaspell->resisted = false;
  1144. if (luaspell->initial_target == target_id) {
  1145. int xxx = 0;
  1146. }
  1147. if (luaspell->targets.size() > 0) {
  1148. ZoneServer* zone = luaspell->caster->GetZone();
  1149. Spawn* target = 0;
  1150. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1151. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1152. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1153. if (race_req.size() > 0) {
  1154. for (int8 i = 0; i < race_req.size(); i++) {
  1155. int32 xxx = target->GetLuaRaceId();
  1156. if (target->GetLuaRaceId() == race_req[i]) {
  1157. race_match = true;
  1158. }
  1159. }
  1160. }
  1161. else
  1162. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1163. if (race_match == true) {
  1164. float distance = caster->GetDistance(target, true);
  1165. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1166. }
  1167. }
  1168. }
  1169. success = true;
  1170. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1171. }
  1172. else if (target) {
  1173. //check class and race/faction here
  1174. if (race_req.size() > 0) {
  1175. for (int8 i = 0; i < race_req.size(); i++) {
  1176. if (target->GetLuaRaceId() == race_req[i]) {
  1177. race_match = true;
  1178. }
  1179. }
  1180. }
  1181. else
  1182. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1183. if (race_match == true) {
  1184. float distance = caster->GetDistance(target, true);
  1185. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1186. success = true;
  1187. }
  1188. }
  1189. if (success) {
  1190. Spell* spell = luaspell->spell;
  1191. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1192. ((Player*)caster)->InCombat(true);
  1193. if (caster->GetZone())
  1194. caster->GetZone()->TriggerCharSheetTimer();
  1195. }
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1201. if (!lua_interface)
  1202. return 0;
  1203. Spawn* spawn = lua_interface->GetSpawn(state);
  1204. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1205. lua_interface->ResetFunctionStack(state);
  1206. if (spawn && value != 0) {
  1207. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1208. spawn->SetPower(spawn->GetTotalPower());
  1209. else
  1210. spawn->SetPower(spawn->GetPower() + value);
  1211. }
  1212. return 0;
  1213. }
  1214. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1215. if (!lua_interface)
  1216. return 0;
  1217. Spawn* spawn = lua_interface->GetSpawn(state);
  1218. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1219. lua_interface->ResetFunctionStack(state);
  1220. if (spawn && value != 0) {
  1221. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1222. spawn->SetHP(spawn->GetTotalHP());
  1223. else
  1224. spawn->SetHP(spawn->GetHP() + value);
  1225. }
  1226. return 0;
  1227. }
  1228. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1229. if (!lua_interface)
  1230. return 0;
  1231. Spawn* spawn = lua_interface->GetSpawn(state);
  1232. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1233. lua_interface->ResetFunctionStack(state);
  1234. if (spawn && value != 0) {
  1235. spawn->SetPower(spawn->GetPower() + value);
  1236. if (value > spawn->GetTotalHPBase())
  1237. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1238. }
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. Spawn* spawn = lua_interface->GetSpawn(state);
  1245. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1246. lua_interface->ResetFunctionStack(state);
  1247. if (spawn && value != 0) {
  1248. spawn->SetHP(spawn->GetHP() + value);
  1249. if (value > spawn->GetTotalHPBase())
  1250. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1251. }
  1252. return 0;
  1253. }
  1254. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1255. if (!lua_interface)
  1256. return 0;
  1257. Spawn* spawn = lua_interface->GetSpawn(state);
  1258. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1259. lua_interface->ResetFunctionStack(state);
  1260. if (spawn && value > 0) {
  1261. spawn->SetHP(value);
  1262. if (value > spawn->GetTotalHPBase())
  1263. spawn->SetTotalHP(value);
  1264. }
  1265. return 0;
  1266. }
  1267. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1268. if (!lua_interface)
  1269. return 0;
  1270. Spawn* spawn = lua_interface->GetSpawn(state);
  1271. float value = lua_interface->GetFloatValue(state, 2);
  1272. lua_interface->ResetFunctionStack(state);
  1273. if (spawn && spawn->IsEntity() && value > 0)
  1274. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1275. if (spawn->IsPlayer())
  1276. ((Player*)spawn)->SetCharSheetChanged(true);
  1277. return 0;
  1278. }
  1279. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1280. if (!lua_interface)
  1281. return 0;
  1282. Spawn* spawn = lua_interface->GetSpawn(state);
  1283. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1284. lua_interface->ResetFunctionStack(state);
  1285. if (spawn && spawn->IsEntity() && value > 0)
  1286. ((Entity*)spawn)->SetTotalHPBase(value);
  1287. return 0;
  1288. }
  1289. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1290. if (!lua_interface)
  1291. return 0;
  1292. Spawn* spawn = lua_interface->GetSpawn(state);
  1293. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1294. lua_interface->ResetFunctionStack(state);
  1295. if (spawn && value > 0) {
  1296. spawn->SetPower(value);
  1297. if (value > spawn->GetTotalPowerBase())
  1298. spawn->SetTotalPower(value);
  1299. }
  1300. return 0;
  1301. }
  1302. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1303. if (!lua_interface)
  1304. return 0;
  1305. Spawn* spawn = lua_interface->GetSpawn(state);
  1306. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1307. lua_interface->ResetFunctionStack(state);
  1308. if (spawn && spawn->IsEntity() && value > 0)
  1309. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1310. return 0;
  1311. }
  1312. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1313. if (!lua_interface)
  1314. return 0;
  1315. Spawn* spawn = lua_interface->GetSpawn(state);
  1316. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1317. lua_interface->ResetFunctionStack(state);
  1318. if (spawn && spawn->IsEntity() && value > 0)
  1319. ((Entity*)spawn)->SetTotalPowerBase(value);
  1320. return 0;
  1321. }
  1322. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1323. if (!lua_interface)
  1324. return 0;
  1325. Spawn* spawn = lua_interface->GetSpawn(state);
  1326. float x = lua_interface->GetFloatValue(state, 2);
  1327. float y = lua_interface->GetFloatValue(state, 3);
  1328. float z = lua_interface->GetFloatValue(state, 4);
  1329. float heading = lua_interface->GetFloatValue(state, 5);
  1330. lua_interface->ResetFunctionStack(state);
  1331. if (spawn) {
  1332. spawn->SetX(x);
  1333. spawn->SetY(y);
  1334. spawn->SetZ(z);
  1335. if (heading != 0)
  1336. spawn->SetHeading(heading);
  1337. spawn->SetSpawnOrigX(spawn->GetX());
  1338. spawn->SetSpawnOrigY(spawn->GetY());
  1339. spawn->SetSpawnOrigZ(spawn->GetZ());
  1340. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1341. if (spawn->IsPlayer()) {
  1342. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1343. if (client) {
  1344. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1345. client->QueuePacket(packet);
  1346. }
  1347. }
  1348. }
  1349. return 0;
  1350. }
  1351. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1352. if (!lua_interface)
  1353. return 0;
  1354. Spawn* spawn = lua_interface->GetSpawn(state);
  1355. float value = lua_interface->GetFloatValue(state, 2);
  1356. lua_interface->ResetFunctionStack(state);
  1357. if (spawn) {
  1358. spawn->SetHeading(value);
  1359. if (spawn->IsPlayer()) {
  1360. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1361. if (client) {
  1362. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1363. client->QueuePacket(packet);
  1364. }
  1365. }
  1366. }
  1367. return 0;
  1368. }
  1369. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1370. if (!lua_interface)
  1371. return 0;
  1372. Spawn* spawn = lua_interface->GetSpawn(state);
  1373. int16 value = lua_interface->GetInt16Value(state, 2);
  1374. lua_interface->ResetFunctionStack(state);
  1375. if (spawn)
  1376. spawn->SetModelType(value);
  1377. return 0;
  1378. }
  1379. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1380. if (!lua_interface)
  1381. return 0;
  1382. Spawn* spawn = lua_interface->GetSpawn(state);
  1383. int8 value = lua_interface->GetInt8Value(state, 2);
  1384. lua_interface->ResetFunctionStack(state);
  1385. if (spawn) {
  1386. if (spawn->IsPlayer())
  1387. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1388. else
  1389. spawn->SetAdventureClass(value);
  1390. }
  1391. return 0;
  1392. }
  1393. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1394. if (!lua_interface)
  1395. return 0;
  1396. Spawn* spawn = lua_interface->GetSpawn(state);
  1397. int8 value = lua_interface->GetInt8Value(state, 2);
  1398. lua_interface->ResetFunctionStack(state);
  1399. if (spawn) {
  1400. spawn->SetTradeskillClass(value);
  1401. if (spawn->IsEntity()) {
  1402. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1403. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1404. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1405. }
  1406. if (spawn->IsPlayer())
  1407. ((Player*)spawn)->SetCharSheetChanged(true);
  1408. }
  1409. return 0;
  1410. }
  1411. int EQ2Emu_lua_SetMount(lua_State* state) {
  1412. if (!lua_interface)
  1413. return 0;
  1414. Spawn* spawn = lua_interface->GetSpawn(state);
  1415. int16 value = lua_interface->GetInt16Value(state, 2);
  1416. if (spawn && spawn->IsEntity()) {
  1417. ((Entity*)spawn)->SetMount(value);
  1418. EQ2_Color color;
  1419. color.red = 255;
  1420. color.green = 255;
  1421. color.blue = 255;
  1422. ((Entity*)spawn)->SetMountColor(&color);
  1423. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1424. }
  1425. return 0;
  1426. }
  1427. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1428. if (!lua_interface)
  1429. return 0;
  1430. Spawn* spawn = lua_interface->GetSpawn(state);
  1431. EQ2_Color mount_color;
  1432. EQ2_Color saddle_color;
  1433. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1434. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1435. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1436. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1437. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1438. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1439. if (spawn && spawn->IsEntity()) {
  1440. ((Entity*)spawn)->SetMountColor(&mount_color);
  1441. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1442. }
  1443. return 0;
  1444. }
  1445. int EQ2Emu_lua_GetMount(lua_State* state) {
  1446. if (!lua_interface)
  1447. return 0;
  1448. Spawn* spawn = lua_interface->GetSpawn(state);
  1449. if (spawn && spawn->IsEntity()) {
  1450. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1451. return 1;
  1452. }
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_GetRace(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* spawn = lua_interface->GetSpawn(state);
  1459. if (spawn)
  1460. {
  1461. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1462. lua_interface->SetInt32Value(state, spawn->GetRace());
  1463. return 1;
  1464. }
  1465. return 0;
  1466. }
  1467. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1468. if (!lua_interface)
  1469. return 0;
  1470. Spawn* spawn = lua_interface->GetSpawn(state);
  1471. if (spawn) {
  1472. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1473. return 1;
  1474. }
  1475. return 0;
  1476. }
  1477. int EQ2Emu_lua_GetClass(lua_State* state) {
  1478. Spawn* spawn = lua_interface->GetSpawn(state);
  1479. if (spawn) {
  1480. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1481. return 1;
  1482. }
  1483. return 0;
  1484. }
  1485. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1486. Spawn* spawn = lua_interface->GetSpawn(state);
  1487. if (spawn) {
  1488. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1489. return 1;
  1490. }
  1491. return 0;
  1492. }
  1493. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1494. if (!lua_interface)
  1495. return 0;
  1496. Spawn* spawn = lua_interface->GetSpawn(state);
  1497. float value = lua_interface->GetFloatValue(state, 2);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (spawn) {
  1500. spawn->SetSpeed(value);
  1501. ((Entity*)spawn)->SetSpeed(value);
  1502. if (spawn->IsPlayer()) {
  1503. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1504. if (client) {
  1505. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1506. if (packet) {
  1507. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1508. packet->setDataByName("speed", value);
  1509. packet->setDataByName("size", 0.51);
  1510. EQ2Packet* app = packet->serialize();
  1511. client->QueuePacket(app);
  1512. safe_delete(packet);
  1513. }
  1514. }
  1515. }
  1516. }
  1517. return 0;
  1518. }
  1519. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1520. if (!lua_interface)
  1521. return 0;
  1522. Spawn* spawn = lua_interface->GetSpawn(state);
  1523. const int16 type = lua_interface->GetInt16Value(state, 2);
  1524. const float value = lua_interface->GetFloatValue(state, 3);
  1525. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1526. int64 class_req = 0;
  1527. int32 class_id = 0;
  1528. vector<int16> faction_req;
  1529. vector<int16> race_req;
  1530. int32 i = 0;
  1531. int8 f = 0;
  1532. int8 r = 0;
  1533. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1534. if (class_id < 100) {
  1535. class_req += pow(2.0, double(class_id - 1));
  1536. }
  1537. else if (class_id > 100 && class_id < 1000) {
  1538. race_req.push_back(class_id);
  1539. r++;
  1540. }
  1541. else {
  1542. faction_req.push_back(class_id);
  1543. f++;
  1544. }
  1545. i++;
  1546. }
  1547. if (value != 0 && type >= 0) {
  1548. if (luaspell && luaspell->spell && luaspell->caster) {
  1549. ZoneServer* zone = luaspell->caster->GetZone();
  1550. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1551. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1552. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1553. if (target) {
  1554. if (target->IsPlayer()) {
  1555. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1556. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1557. if (((Player*)target)->GetGroupMemberInfo())
  1558. ((Player*)target)->UpdateGroupMemberInfo();
  1559. ((Player*)target)->SetCharSheetChanged(true);
  1560. }
  1561. else if (target->IsNPC())
  1562. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1563. else
  1564. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1565. }
  1566. }
  1567. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1569. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1570. }
  1571. else if (spawn && spawn->IsEntity()) {
  1572. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1573. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1574. if (spawn->IsPlayer())
  1575. ((Player*)spawn)->SetCharSheetChanged(true);
  1576. }
  1577. else
  1578. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1579. }
  1580. else
  1581. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1582. return 0;
  1583. }
  1584. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1585. if (!lua_interface)
  1586. return 0;
  1587. Spawn* spawn = lua_interface->GetSpawn(state);
  1588. int16 type = lua_interface->GetInt16Value(state, 2);
  1589. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1590. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1591. if (!spawn) {
  1592. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1593. return 0;
  1594. }
  1595. if (!spawn->IsEntity()) {
  1596. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1597. return 0;
  1598. }
  1599. if (value == 0) {
  1600. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1601. return 0;
  1602. }
  1603. if (!luaspell || !luaspell->spell) {
  1604. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1605. return 0;
  1606. }
  1607. int32 class_req = 0;
  1608. vector<int16> faction_req;
  1609. vector<int16> race_req;
  1610. int32 class_id = 0;
  1611. int32 i = 0;
  1612. int8 f = 0;
  1613. int8 r = 0;
  1614. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1615. if (class_id < 100) {
  1616. class_req += pow(2.0, double(class_id - 1));
  1617. }
  1618. else if (class_id > 100 && class_id < 1000) {
  1619. race_req.push_back(class_id);
  1620. r++;
  1621. }
  1622. else {
  1623. faction_req.push_back(class_id);
  1624. f++;
  1625. }
  1626. i++;
  1627. }
  1628. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1629. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1630. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1631. if (spawn->IsPlayer())
  1632. ((Player*)spawn)->SetCharSheetChanged(true);
  1633. return 0;
  1634. }
  1635. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1636. if (!lua_interface)
  1637. return 0;
  1638. Spawn* spawn = lua_interface->GetSpawn(state);
  1639. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1640. if (luaspell && luaspell->spell) {
  1641. ZoneServer* zone = luaspell->caster->GetZone();
  1642. Spawn* target = 0;
  1643. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1644. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1645. target = zone->GetSpawnByID(luaspell->targets[i]);
  1646. if (target && target->IsEntity()) {
  1647. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1648. if (target->IsPlayer())
  1649. ((Player*)target)->SetCharSheetChanged(true);
  1650. }
  1651. }
  1652. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1653. }
  1654. else if (spawn && spawn->IsEntity()) {
  1655. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1656. if (spawn->IsPlayer())
  1657. ((Player*)spawn)->SetCharSheetChanged(true);
  1658. }
  1659. return 0;
  1660. }
  1661. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1662. if (!lua_interface)
  1663. return 0;
  1664. Spawn* spawn = lua_interface->GetSpawn(state);
  1665. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1666. float value = lua_interface->GetFloatValue(state, 3);
  1667. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1668. if (value != 0) {
  1669. int32 spell_id = 0;
  1670. if (luaspell && luaspell->spell && luaspell->caster) {
  1671. spell_id = luaspell->spell->GetSpellID();
  1672. ZoneServer* zone = luaspell->caster->GetZone();
  1673. Spawn* target = 0;
  1674. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1675. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1676. target = zone->GetSpawnByID(luaspell->targets[i]);
  1677. if (target && target->Alive()) {
  1678. if (target->IsPlayer()) {
  1679. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1680. Client* client = target->GetZone()->GetClientBySpawn(target);
  1681. if (client) {
  1682. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1683. if (packet)
  1684. client->QueuePacket(packet);
  1685. }
  1686. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1687. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1688. }
  1689. else if (target->IsNPC()) {
  1690. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1691. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1692. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1693. }
  1694. else
  1695. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1696. }
  1697. }
  1698. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1699. }
  1700. else if (spawn) {
  1701. if (spawn->IsPlayer()) {
  1702. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1703. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1704. if (client) {
  1705. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1706. if (packet)
  1707. client->QueuePacket(packet);
  1708. }
  1709. }
  1710. else if (spawn->IsNPC())
  1711. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1712. else
  1713. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1714. }
  1715. }
  1716. else
  1717. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1718. return 0;
  1719. }
  1720. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1721. if (!lua_interface)
  1722. return 0;
  1723. Spawn* spawn = lua_interface->GetSpawn(state);
  1724. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1725. if (spawn && spawn->IsPlayer()) {
  1726. int32 spell_id = 0;
  1727. if (luaspell && luaspell->spell) {
  1728. spell_id = luaspell->spell->GetSpellID();
  1729. ZoneServer* zone = luaspell->caster->GetZone();
  1730. Spawn* target = 0;
  1731. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1732. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1733. target = zone->GetSpawnByID(luaspell->targets[i]);
  1734. if (target) {
  1735. if (target->IsPlayer()) {
  1736. ((Player*)target)->RemoveSkillBonus(spell_id);
  1737. Client* client = target->GetZone()->GetClientBySpawn(target);
  1738. if (client) {
  1739. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1740. if (packet)
  1741. client->QueuePacket(packet);
  1742. }
  1743. }
  1744. else if (target->IsNPC())
  1745. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1746. else
  1747. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1748. }
  1749. }
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (spawn) {
  1753. if (spawn->IsPlayer()) {
  1754. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1755. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1756. if (client) {
  1757. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1758. if (packet)
  1759. client->QueuePacket(packet);
  1760. }
  1761. }
  1762. else if (spawn->IsNPC())
  1763. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  1764. else
  1765. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1766. }
  1767. }
  1768. return 0;
  1769. }
  1770. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  1771. if (!lua_interface)
  1772. return 0;
  1773. Spawn* spawn = lua_interface->GetSpawn(state);
  1774. int8 type = lua_interface->GetInt32Value(state, 2);
  1775. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1776. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1777. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  1778. ZoneServer* zone = luaspell->caster->GetZone();
  1779. Spawn* target = 0;
  1780. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1781. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1782. target = zone->GetSpawnByID(luaspell->targets[i]);
  1783. if (target && target->IsEntity()) {
  1784. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1785. ((Entity*)target)->AddMezSpell(luaspell);
  1786. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1787. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1788. if (target->IsNPC())
  1789. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1790. }
  1791. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1792. ((Entity*)target)->AddStifleSpell(luaspell);
  1793. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1794. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1795. if (target->IsNPC())
  1796. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1797. }
  1798. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1799. ((Entity*)target)->AddDazeSpell(luaspell);
  1800. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1801. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1802. if (target->IsNPC())
  1803. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1804. }
  1805. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1806. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1807. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1808. ((Entity*)target)->AddStunSpell(luaspell);
  1809. if (target->IsNPC())
  1810. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1811. }
  1812. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1813. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1814. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1815. ((Entity*)target)->AddRootSpell(luaspell);
  1816. if (target->IsNPC())
  1817. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1818. }
  1819. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1820. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1821. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1822. ((Entity*)target)->AddFearSpell(luaspell);
  1823. if (target->IsNPC())
  1824. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1825. }
  1826. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1827. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  1828. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1829. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1830. }
  1831. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1832. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  1833. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1834. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1835. }
  1836. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1837. ((Entity*)target)->AddSnareSpell(luaspell);
  1838. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1839. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1840. if (target->IsNPC())
  1841. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1842. }
  1843. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1844. ((Entity*)target)->AddFlightSpell(luaspell);
  1845. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1846. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1847. }
  1848. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1849. ((Entity*)target)->AddGlideSpell(luaspell);
  1850. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1851. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1852. }
  1853. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1854. ((Entity*)target)->AddSafefallSpell(luaspell);
  1855. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1856. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1857. }
  1858. else
  1859. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1860. }
  1861. else
  1862. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  1863. }
  1864. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1865. }
  1866. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  1867. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1868. ((Entity*)spawn)->AddMezSpell(luaspell);
  1869. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1870. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1871. }
  1872. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1873. ((Entity*)spawn)->AddStifleSpell(luaspell);
  1874. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1875. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1876. }
  1877. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1878. ((Entity*)spawn)->AddDazeSpell(luaspell);
  1879. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1880. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1881. }
  1882. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1883. ((Entity*)spawn)->AddStunSpell(luaspell);
  1884. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1885. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1886. }
  1887. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1888. ((Entity*)spawn)->AddRootSpell(luaspell);
  1889. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1890. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1891. }
  1892. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1893. ((Entity*)spawn)->AddFearSpell(luaspell);
  1894. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1895. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1896. }
  1897. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1898. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  1899. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1900. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1901. }
  1902. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1903. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  1904. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1905. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1906. }
  1907. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1908. ((Entity*)spawn)->AddSnareSpell(luaspell);
  1909. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1910. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1911. }
  1912. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1913. ((Entity*)spawn)->AddFlightSpell(luaspell);
  1914. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1915. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1916. }
  1917. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1918. ((Entity*)spawn)->AddGlideSpell(luaspell);
  1919. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1920. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1921. }
  1922. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1923. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  1924. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1925. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1926. }
  1927. else
  1928. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1929. }
  1930. else
  1931. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  1932. return 0;
  1933. }
  1934. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  1935. if (!lua_interface)
  1936. return 0;
  1937. Spawn* spawn = lua_interface->GetSpawn(state);
  1938. int8 type = lua_interface->GetInt8Value(state, 2);
  1939. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1940. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1941. if (spawn && spawn->IsEntity()) {
  1942. if (!only_remove_spawn && luaspell && luaspell->spell) {
  1943. ZoneServer* zone = luaspell->caster->GetZone();
  1944. Spawn* target = 0;
  1945. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1946. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1947. target = zone->GetSpawnByID(luaspell->targets[i]);
  1948. if (target) {
  1949. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1950. ((Entity*)target)->RemoveMezSpell(luaspell);
  1951. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1952. ((Entity*)target)->RemoveStifleSpell(luaspell);
  1953. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1954. ((Entity*)target)->RemoveDazeSpell(luaspell);
  1955. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1956. ((Entity*)target)->RemoveStunSpell(luaspell);
  1957. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1958. ((Entity*)target)->RemoveRootSpell(luaspell);
  1959. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1960. ((Entity*)target)->RemoveFearSpell(luaspell);
  1961. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1962. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  1963. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1964. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  1965. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1966. ((Entity*)target)->RemoveSnareSpell(luaspell);
  1967. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1968. ((Entity*)target)->RemoveFlightSpell(luaspell);
  1969. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1970. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1971. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1972. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1973. else
  1974. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1975. }
  1976. }
  1977. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1978. }
  1979. else if (only_remove_spawn) {
  1980. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1981. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  1982. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1983. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  1984. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1985. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  1986. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1987. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  1988. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1989. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  1990. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1991. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  1992. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1993. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  1994. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1995. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  1996. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1997. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  1998. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1999. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2000. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2001. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2002. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2003. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2004. else
  2005. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2006. }
  2007. }
  2008. return 0;
  2009. }
  2010. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2011. if (!lua_interface)
  2012. return 0;
  2013. Spawn* spawn = lua_interface->GetSpawn(state);
  2014. int16 value = lua_interface->GetInt16Value(state, 2);
  2015. if (spawn && spawn->IsEntity()) {
  2016. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2017. if (spawn->IsPlayer())
  2018. ((Player*)spawn)->SetCharSheetChanged(true);
  2019. }
  2020. return 0;
  2021. }
  2022. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2023. if (!lua_interface)
  2024. return 0;
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. int16 value = lua_interface->GetInt16Value(state, 2);
  2027. if (spawn && spawn->IsEntity()) {
  2028. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2029. if (spawn->IsPlayer())
  2030. ((Player*)spawn)->SetCharSheetChanged(true);
  2031. }
  2032. return 0;
  2033. }
  2034. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2035. if (!lua_interface)
  2036. return 0;
  2037. Spawn* spawn = lua_interface->GetSpawn(state);
  2038. int16 value = lua_interface->GetInt16Value(state, 2);
  2039. if (spawn && spawn->IsEntity()) {
  2040. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2041. if (spawn->IsPlayer())
  2042. ((Player*)spawn)->SetCharSheetChanged(true);
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. int16 value = lua_interface->GetInt16Value(state, 2);
  2051. if (spawn && spawn->IsEntity()) {
  2052. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2053. if (spawn->IsPlayer())
  2054. ((Player*)spawn)->SetCharSheetChanged(true);
  2055. }
  2056. return 0;
  2057. }
  2058. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2059. if (!lua_interface)
  2060. return 0;
  2061. Spawn* spawn = lua_interface->GetSpawn(state);
  2062. int16 value = lua_interface->GetInt16Value(state, 2);
  2063. if (spawn && spawn->IsEntity()) {
  2064. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2065. if (spawn->IsPlayer())
  2066. ((Player*)spawn)->SetCharSheetChanged(true);
  2067. }
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetInt(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2075. if (spawn && spawn->IsEntity()) {
  2076. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2077. if (spawn->IsPlayer())
  2078. ((Player*)spawn)->SetCharSheetChanged(true);
  2079. }
  2080. return 0;
  2081. }
  2082. int EQ2Emu_lua_SetWis(lua_State* state) {
  2083. if (!lua_interface)
  2084. return 0;
  2085. Spawn* spawn = lua_interface->GetSpawn(state);
  2086. float value = lua_interface->GetFloatValue(state, 2);
  2087. if (spawn && spawn->IsEntity()) {
  2088. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2089. if (spawn->IsPlayer())
  2090. ((Player*)spawn)->SetCharSheetChanged(true);
  2091. }
  2092. return 0;
  2093. }
  2094. int EQ2Emu_lua_SetSta(lua_State* state) {
  2095. if (!lua_interface)
  2096. return 0;
  2097. Spawn* spawn = lua_interface->GetSpawn(state);
  2098. float value = lua_interface->GetFloatValue(state, 2);
  2099. if (spawn && spawn->IsEntity()) {
  2100. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetStr(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. float value = lua_interface->GetFloatValue(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2113. if (spawn->IsPlayer())
  2114. ((Player*)spawn)->SetCharSheetChanged(true);
  2115. }
  2116. return 0;
  2117. }
  2118. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2119. if (!lua_interface)
  2120. return 0;
  2121. Spawn* spawn = lua_interface->GetSpawn(state);
  2122. float value = lua_interface->GetFloatValue(state, 2);
  2123. if (spawn && spawn->IsEntity()) {
  2124. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2125. if (spawn->IsPlayer())
  2126. ((Player*)spawn)->SetCharSheetChanged(true);
  2127. }
  2128. return 0;
  2129. }
  2130. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2131. if (!lua_interface)
  2132. return 0;
  2133. Spawn* spawn = lua_interface->GetSpawn(state);
  2134. if (spawn) {
  2135. lua_interface->SetInt32Value(state, spawn->GetHP());
  2136. return 1;
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn) {
  2145. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn) {
  2155. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2156. return 1;
  2157. }
  2158. return 0;
  2159. }
  2160. int EQ2Emu_lua_GetName(lua_State* state) {
  2161. if (!lua_interface)
  2162. return 0;
  2163. Spawn* spawn = lua_interface->GetSpawn(state);
  2164. if (spawn) {
  2165. lua_interface->SetStringValue(state, spawn->GetName());
  2166. return 1;
  2167. }
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2171. Spawn* spawn = lua_interface->GetSpawn(state);
  2172. if (spawn) {
  2173. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2174. return 1;
  2175. }
  2176. return 0;
  2177. }
  2178. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2179. if (!lua_interface)
  2180. return 0;
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetInt32Value(state, spawn->GetPower());
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. if (spawn) {
  2193. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2194. return 1;
  2195. }
  2196. return 0;
  2197. }
  2198. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2199. if (!lua_interface)
  2200. return 0;
  2201. Spawn* spawn = lua_interface->GetSpawn(state);
  2202. if (spawn) {
  2203. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2204. return 1;
  2205. }
  2206. return 0;
  2207. }
  2208. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2209. if (!lua_interface)
  2210. return 0;
  2211. Spawn* spawn = lua_interface->GetSpawn(state);
  2212. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2213. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2214. if (spawn && spawn2) {
  2215. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2216. lua_interface->SetFloatValue(state, distance);
  2217. return 1;
  2218. }
  2219. return 0;
  2220. }
  2221. int EQ2Emu_lua_GetX(lua_State* state) {
  2222. if (!lua_interface)
  2223. return 0;
  2224. Spawn* spawn = lua_interface->GetSpawn(state);
  2225. if (spawn) {
  2226. lua_interface->SetFloatValue(state, spawn->GetX());
  2227. return 1;
  2228. }
  2229. return 0;
  2230. }
  2231. int EQ2Emu_lua_GetY(lua_State* state) {
  2232. if (!lua_interface)
  2233. return 0;
  2234. Spawn* spawn = lua_interface->GetSpawn(state);
  2235. if (spawn) {
  2236. lua_interface->SetFloatValue(state, spawn->GetY());
  2237. return 1;
  2238. }
  2239. return 0;
  2240. }
  2241. int EQ2Emu_lua_GetZ(lua_State* state) {
  2242. if (!lua_interface)
  2243. return 0;
  2244. Spawn* spawn = lua_interface->GetSpawn(state);
  2245. if (spawn) {
  2246. lua_interface->SetFloatValue(state, spawn->GetZ());
  2247. return 1;
  2248. }
  2249. return 0;
  2250. }
  2251. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2252. if (!lua_interface)
  2253. return 0;
  2254. Spawn* spawn = lua_interface->GetSpawn(state);
  2255. if (spawn) {
  2256. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2257. return 1;
  2258. }
  2259. return 0;
  2260. }
  2261. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2262. if (!lua_interface)
  2263. return 0;
  2264. Spawn* spawn = lua_interface->GetSpawn(state);
  2265. if (spawn) {
  2266. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2267. return 1;
  2268. }
  2269. return 0;
  2270. }
  2271. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2272. if (!lua_interface)
  2273. return 0;
  2274. Spawn* spawn = lua_interface->GetSpawn(state);
  2275. if (spawn) {
  2276. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2277. return 1;
  2278. }
  2279. return 0;
  2280. }
  2281. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2282. if (!lua_interface)
  2283. return 0;
  2284. Spawn* spawn = lua_interface->GetSpawn(state);
  2285. if (spawn && spawn->IsEntity()) {
  2286. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2287. return 1;
  2288. }
  2289. return 0;
  2290. }
  2291. int EQ2Emu_lua_GetInt(lua_State* state) {
  2292. if (!lua_interface)
  2293. return 0;
  2294. Spawn* spawn = lua_interface->GetSpawn(state);
  2295. if (spawn && spawn->IsEntity()) {
  2296. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2297. return 1;
  2298. }
  2299. return 0;
  2300. }
  2301. int EQ2Emu_lua_GetWis(lua_State* state) {
  2302. if (!lua_interface)
  2303. return 0;
  2304. Spawn* spawn = lua_interface->GetSpawn(state);
  2305. if (spawn && spawn->IsEntity()) {
  2306. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2307. return 1;
  2308. }
  2309. return 0;
  2310. }
  2311. int EQ2Emu_lua_GetSta(lua_State* state) {
  2312. if (!lua_interface)
  2313. return 0;
  2314. Spawn* spawn = lua_interface->GetSpawn(state);
  2315. if (spawn && spawn->IsEntity()) {
  2316. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2317. return 1;
  2318. }
  2319. return 0;
  2320. }
  2321. int EQ2Emu_lua_GetStr(lua_State* state) {
  2322. if (!lua_interface)
  2323. return 0;
  2324. Spawn* spawn = lua_interface->GetSpawn(state);
  2325. if (spawn && spawn->IsEntity()) {
  2326. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2327. return 1;
  2328. }
  2329. return 0;
  2330. }
  2331. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2332. if (!lua_interface)
  2333. return 0;
  2334. Spawn* spawn = lua_interface->GetSpawn(state);
  2335. if (spawn && spawn->IsEntity()) {
  2336. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2337. return 1;
  2338. }
  2339. return 0;
  2340. }
  2341. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2342. if (!lua_interface)
  2343. return 0;
  2344. Spawn* spawn = lua_interface->GetSpawn(state);
  2345. if (spawn && spawn->IsEntity()) {
  2346. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2347. return 1;
  2348. }
  2349. return 0;
  2350. }
  2351. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2352. if (!lua_interface)
  2353. return 0;
  2354. Spawn* spawn = lua_interface->GetSpawn(state);
  2355. if (spawn && spawn->IsEntity()) {
  2356. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2357. return 1;
  2358. }
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. if (spawn && spawn->IsEntity()) {
  2366. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2367. return 1;
  2368. }
  2369. return 0;
  2370. }
  2371. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2372. if (!lua_interface)
  2373. return 0;
  2374. Spawn* spawn = lua_interface->GetSpawn(state);
  2375. if (spawn && spawn->IsEntity()) {
  2376. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2377. return 1;
  2378. }
  2379. return 0;
  2380. }
  2381. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2382. if (!lua_interface)
  2383. return 0;
  2384. Spawn* spawn = lua_interface->GetSpawn(state);
  2385. if (spawn && spawn->IsEntity()) {
  2386. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2387. return 1;
  2388. }
  2389. return 0;
  2390. }
  2391. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2392. if (!lua_interface)
  2393. return 0;
  2394. Spawn* player = lua_interface->GetSpawn(state);
  2395. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2396. int32 step = lua_interface->GetInt32Value(state, 3);
  2397. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2398. Client* client = player->GetZone()->GetClientBySpawn(player);
  2399. if (client)
  2400. client->AddPendingQuestUpdate(quest_id, step);
  2401. }
  2402. return 0;
  2403. }
  2404. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2405. Spawn* player = lua_interface->GetSpawn(state);
  2406. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2407. int32 step = lua_interface->GetInt32Value(state, 3);
  2408. int32 progress = lua_interface->GetInt32Value(state, 4);
  2409. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2410. Client* client = player->GetZone()->GetClientBySpawn(player);
  2411. if (client)
  2412. client->AddPendingQuestUpdate(quest_id, step, progress);
  2413. }
  2414. return 0;
  2415. }
  2416. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2417. if (!lua_interface)
  2418. return 0;
  2419. Spawn* player = lua_interface->GetSpawn(state);
  2420. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2421. if (player && player->IsPlayer() && quest_id > 0) {
  2422. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2423. return 1;
  2424. }
  2425. return 0;
  2426. }
  2427. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2428. if (!lua_interface)
  2429. return 0;
  2430. Spawn* player = lua_interface->GetSpawn(state);
  2431. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2432. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2433. if (player && player->IsPlayer() && quest_id > 0) {
  2434. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2435. return 1;
  2436. }
  2437. return 0;
  2438. }
  2439. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2440. if (!lua_interface)
  2441. return 0;
  2442. Spawn* player = lua_interface->GetSpawn(state);
  2443. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2444. if (player && player->IsPlayer() && quest_id > 0) {
  2445. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2446. return 1;
  2447. }
  2448. return 0;
  2449. }
  2450. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2451. if (!lua_interface)
  2452. return 0;
  2453. Quest* quest = lua_interface->GetQuest(state);
  2454. string name = lua_interface->GetStringValue(state, 2);
  2455. string type = lua_interface->GetStringValue(state, 3);
  2456. string zone = lua_interface->GetStringValue(state, 4);
  2457. int16 level = lua_interface->GetInt16Value(state, 5);
  2458. string description = lua_interface->GetStringValue(state, 6);
  2459. bool load = true;
  2460. if (!quest) {
  2461. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2462. load = false;
  2463. }
  2464. if (load && name.length() == 0) {
  2465. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2466. load = false;
  2467. }
  2468. if (load && type.length() == 0) {
  2469. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2470. load = false;
  2471. }
  2472. if (load && zone.length() == 0) {
  2473. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2474. load = false;
  2475. }
  2476. if (load && description.length() == 0) {
  2477. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2478. load = false;
  2479. }
  2480. if (load && level == 0) {
  2481. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2482. load = false;
  2483. }
  2484. if (load)
  2485. quest->RegisterQuest(name, type, zone, level, description);
  2486. return 0;
  2487. }
  2488. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2489. if (!lua_interface)
  2490. return 0;
  2491. Quest* quest = lua_interface->GetQuest(state);
  2492. if (quest) {
  2493. int8 level = lua_interface->GetInt16Value(state, 2);
  2494. quest->SetPrereqLevel(level);
  2495. }
  2496. return 0;
  2497. }
  2498. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2499. if (!lua_interface)
  2500. return 0;
  2501. Quest* quest = lua_interface->GetQuest(state);
  2502. if (quest) {
  2503. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2504. quest->AddPrereqQuest(quest_id);
  2505. }
  2506. return 0;
  2507. }
  2508. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2509. if (!lua_interface)
  2510. return 0;
  2511. Quest* quest = lua_interface->GetQuest(state);
  2512. if (quest) {
  2513. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2514. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2515. if (quantity == 0)
  2516. quantity = 1;
  2517. Item* master_item = master_item_list.GetItem(item_id);
  2518. if (master_item) {
  2519. Item* item = new Item(master_item);
  2520. item->details.count = quantity;
  2521. quest->AddPrereqItem(item);
  2522. }
  2523. }
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2527. if (!lua_interface)
  2528. return 0;
  2529. Spawn* player = lua_interface->GetSpawn(state);
  2530. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2531. if (player && player->IsPlayer() && quest_id > 0) {
  2532. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2533. return 1;
  2534. }
  2535. return 0;
  2536. }
  2537. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2538. if (!lua_interface)
  2539. return 0;
  2540. Quest* quest = lua_interface->GetQuest(state);
  2541. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2542. if (quest && spawn_id > 0)
  2543. quest->SetQuestReturnNPC(spawn_id);
  2544. return 0;
  2545. }
  2546. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2547. if (!lua_interface)
  2548. return 0;
  2549. Spawn* spawn = lua_interface->GetSpawn(state);
  2550. if (!spawn) {
  2551. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2552. return 0;
  2553. }
  2554. int32 time = lua_interface->GetInt32Value(state, 2);
  2555. if (time <= 0) {
  2556. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2557. return 0;
  2558. }
  2559. string function = lua_interface->GetStringValue(state, 3);
  2560. if (function.length() == 0) {
  2561. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2562. return 0;
  2563. }
  2564. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2565. Spawn* player = lua_interface->GetSpawn(state, 5);
  2566. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2567. timer->timer = Timer::GetCurrentTime2() + time;
  2568. timer->function = function;
  2569. timer->spawn = spawn->GetID();
  2570. timer->player = player ? player->GetID() : 0;
  2571. if (max_count == 0)
  2572. max_count = 1;
  2573. timer->max_count = max_count;
  2574. timer->current_count = 0;
  2575. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2576. return 0;
  2577. }
  2578. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2579. if (!lua_interface)
  2580. return 0;
  2581. Spawn* player = lua_interface->GetSpawn(state);
  2582. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2583. if (player && player->IsPlayer() && quest_id > 0) {
  2584. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2585. return 1;
  2586. }
  2587. return 0;
  2588. }
  2589. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2590. if (!lua_interface)
  2591. return 0;
  2592. Spawn* player = lua_interface->GetSpawn(state);
  2593. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2594. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2595. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2596. if (quest)
  2597. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2598. return 1;
  2599. }
  2600. return 0;
  2601. }
  2602. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2603. if (!lua_interface)
  2604. return 0;
  2605. Spawn* player = lua_interface->GetSpawn(state);
  2606. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2607. if (player && player->IsPlayer() && quest_id > 0) {
  2608. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* npc = lua_interface->GetSpawn(state);
  2617. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2618. if (npc && !npc->IsPlayer() && quest_id > 0)
  2619. npc->AddProvidedQuest(quest_id);
  2620. return 0;
  2621. }
  2622. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2623. if (!lua_interface)
  2624. return 0;
  2625. Spawn* npc = lua_interface->GetSpawn(state);
  2626. Spawn* player = lua_interface->GetSpawn(state, 2);
  2627. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2628. /* NPC is allowed to be null */
  2629. if (player && player->IsPlayer() && quest_id > 0) {
  2630. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2631. if (master_quest) {
  2632. Client* client = player->GetZone()->GetClientBySpawn(player);
  2633. Quest* quest = new Quest(master_quest);
  2634. if (client && quest) {
  2635. client->AddPendingQuest(quest);
  2636. if (npc)
  2637. quest->SetQuestGiver(npc->GetDatabaseID());
  2638. else
  2639. quest->SetQuestGiver(0);
  2640. }
  2641. }
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Quest* quest = lua_interface->GetQuest(state);
  2649. if (quest) {
  2650. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2651. quest->AddPrereqClass(class_id);
  2652. }
  2653. return 0;
  2654. }
  2655. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Quest* quest = lua_interface->GetQuest(state);
  2659. if (quest) {
  2660. int8 race = lua_interface->GetInt8Value(state, 2);
  2661. quest->AddPrereqRace(race);
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Quest* quest = lua_interface->GetQuest(state);
  2669. if (quest) {
  2670. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2671. quest->AddPrereqModelType(model_type);
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Quest* quest = lua_interface->GetQuest(state);
  2679. if (!quest) {
  2680. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2681. return 0;
  2682. }
  2683. int8 level = lua_interface->GetInt8Value(state, 2);
  2684. quest->SetPrereqTSLevel(level);
  2685. return 0;
  2686. }
  2687. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2688. if (!lua_interface)
  2689. return 0;
  2690. Quest* quest = lua_interface->GetQuest(state);
  2691. if (!quest) {
  2692. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2693. return 0;
  2694. }
  2695. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2696. quest->AddPrereqTradeskillClass(class_id);
  2697. return 0;
  2698. }
  2699. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Quest* quest = lua_interface->GetQuest(state);
  2703. if (quest) {
  2704. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2705. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2706. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2707. quest->AddPrereqFaction(faction_id, min, max);
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Quest* quest = lua_interface->GetQuest(state);
  2715. if (quest) {
  2716. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2717. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2718. if (quantity == 0)
  2719. quantity = 1;
  2720. Item* master_item = master_item_list.GetItem(item_id);
  2721. if (master_item) {
  2722. Item* item = new Item(master_item);
  2723. item->details.count = quantity;
  2724. quest->AddSelectableRewardItem(item);
  2725. }
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Quest* quest = lua_interface->GetQuest(state);
  2733. if (quest) {
  2734. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2735. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2736. if (quantity == 0)
  2737. quantity = 1;
  2738. Item* master_item = master_item_list.GetItem(item_id);
  2739. if (master_item) {
  2740. Item* item = new Item(master_item);
  2741. item->details.count = quantity;
  2742. quest->AddRewardItem(item);
  2743. }
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Quest* quest = lua_interface->GetQuest(state);
  2751. if (quest) {
  2752. int32 copper = lua_interface->GetInt32Value(state, 2);
  2753. int32 silver = lua_interface->GetInt32Value(state, 3);
  2754. int32 gold = lua_interface->GetInt32Value(state, 4);
  2755. int32 plat = lua_interface->GetInt32Value(state, 5);
  2756. quest->AddRewardCoins(copper, silver, gold, plat);
  2757. }
  2758. return 0;
  2759. }
  2760. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2761. if (!lua_interface)
  2762. return 0;
  2763. Quest* quest = lua_interface->GetQuest(state);
  2764. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2765. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  2766. if (quest && faction_id > 0 && amount != 0)
  2767. quest->AddRewardFaction(faction_id, amount);
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Quest* quest = lua_interface->GetQuest(state);
  2774. if (quest) {
  2775. int32 status = lua_interface->GetInt32Value(state, 2);
  2776. quest->SetRewardStatus(status);
  2777. }
  2778. return 0;
  2779. }
  2780. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  2781. if (!lua_interface)
  2782. return 0;
  2783. Quest* quest = lua_interface->GetQuest(state);
  2784. if (quest) {
  2785. string comment = lua_interface->GetStringValue(state, 2);
  2786. quest->SetRewardComment(comment);
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Quest* quest = lua_interface->GetQuest(state);
  2794. if (quest) {
  2795. int32 exp = lua_interface->GetInt32Value(state, 2);
  2796. quest->SetRewardXP(exp);
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  2801. Quest* quest = lua_interface->GetQuest(state);
  2802. if (quest) {
  2803. int32 step = lua_interface->GetInt32Value(state, 2);
  2804. string description = lua_interface->GetStringValue(state, 3);
  2805. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2806. float percentage = lua_interface->GetFloatValue(state, 5);
  2807. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2808. int16 icon = lua_interface->GetInt16Value(state, 7);
  2809. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  2810. const char* taskgroup = 0;
  2811. if (str_taskgroup.length() > 0)
  2812. taskgroup = str_taskgroup.c_str();
  2813. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  2814. if (quest_step && icon && quantity > 0)
  2815. quest_step->SetIcon(icon);
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Quest* quest = lua_interface->GetQuest(state);
  2823. if (quest) {
  2824. int32 step = lua_interface->GetInt32Value(state, 2);
  2825. string description = lua_interface->GetStringValue(state, 3);
  2826. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2827. float percentage = lua_interface->GetFloatValue(state, 5);
  2828. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2829. int16 icon = lua_interface->GetInt16Value(state, 7);
  2830. const char* taskgroup = 0;
  2831. if (str_taskgroup.length() > 0)
  2832. taskgroup = str_taskgroup.c_str();
  2833. int32 npc_id = 0;
  2834. vector<int32>* ids = 0;
  2835. Spawn* spawn = nullptr;
  2836. int i = 0;
  2837. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2838. if (ids == 0)
  2839. ids = new vector<int32>;
  2840. ids->push_back(npc_id);
  2841. i++;
  2842. }
  2843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2844. if (quest_step && icon > 0 && quantity > 0)
  2845. quest_step->SetIcon(icon);
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Quest* quest = lua_interface->GetQuest(state);
  2853. if (quest) {
  2854. int32 step = lua_interface->GetInt32Value(state, 2);
  2855. string description = lua_interface->GetStringValue(state, 3);
  2856. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2857. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2858. int16 icon = lua_interface->GetInt16Value(state, 6);
  2859. const char* taskgroup = 0;
  2860. if (str_taskgroup.length() > 0)
  2861. taskgroup = str_taskgroup.c_str();
  2862. int32 npc_id = 0;
  2863. vector<int32>* ids = 0;
  2864. int i = 0;
  2865. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  2866. if (ids == 0)
  2867. ids = new vector<int32>;
  2868. ids->push_back(npc_id);
  2869. i++;
  2870. }
  2871. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  2872. if (quest_step && icon > 0)
  2873. quest_step->SetIcon(icon);
  2874. if (quest->GetPlayer()) {
  2875. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  2876. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  2877. }
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Quest* quest = lua_interface->GetQuest(state);
  2885. if (quest) {
  2886. int32 step = lua_interface->GetInt32Value(state, 2);
  2887. string description = lua_interface->GetStringValue(state, 3);
  2888. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2889. float percentage = lua_interface->GetFloatValue(state, 5);
  2890. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2891. int16 icon = lua_interface->GetInt16Value(state, 7);
  2892. const char* taskgroup = 0;
  2893. if (str_taskgroup.length() > 0)
  2894. taskgroup = str_taskgroup.c_str();
  2895. int32 item_id = 0;
  2896. vector<int32>* ids = 0;
  2897. int i = 0;
  2898. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2899. if (ids == 0)
  2900. ids = new vector<int32>;
  2901. ids->push_back(item_id);
  2902. i++;
  2903. }
  2904. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2905. if (quest_step && icon > 0 && quantity > 0)
  2906. quest_step->SetIcon(icon);
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Quest* quest = lua_interface->GetQuest(state);
  2914. if (quest) {
  2915. int32 step = lua_interface->GetInt32Value(state, 2);
  2916. string description = lua_interface->GetStringValue(state, 3);
  2917. float max_variation = lua_interface->GetFloatValue(state, 4);
  2918. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2919. int16 icon = lua_interface->GetInt16Value(state, 6);
  2920. const char* taskgroup = 0;
  2921. if (str_taskgroup.length() > 0)
  2922. taskgroup = str_taskgroup.c_str();
  2923. vector<Location>* locations = 0;
  2924. int i = 7;
  2925. while (true) {
  2926. Location loc;
  2927. loc.x = lua_interface->GetFloatValue(state, i);
  2928. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2929. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2931. break;
  2932. if (locations == 0)
  2933. locations = new vector<Location>;
  2934. locations->push_back(loc);
  2935. i += 3;
  2936. }
  2937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2938. if (quest_step && icon > 0)
  2939. quest_step->SetIcon(icon);
  2940. }
  2941. return 0;
  2942. }
  2943. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  2944. if (!lua_interface)
  2945. return 0;
  2946. Quest* quest = lua_interface->GetQuest(state);
  2947. if (quest) {
  2948. int32 step = lua_interface->GetInt32Value(state, 2);
  2949. string description = lua_interface->GetStringValue(state, 3);
  2950. float max_variation = lua_interface->GetFloatValue(state, 4);
  2951. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2952. int16 icon = lua_interface->GetInt16Value(state, 6);
  2953. const char* taskgroup = 0;
  2954. if (str_taskgroup.length() > 0)
  2955. taskgroup = str_taskgroup.c_str();
  2956. vector<Location>* locations = 0;
  2957. int i = 7;
  2958. while (true) {
  2959. Location loc;
  2960. loc.x = lua_interface->GetFloatValue(state, i);
  2961. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2962. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2963. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2964. break;
  2965. if (locations == 0)
  2966. locations = new vector<Location>;
  2967. locations->push_back(loc);
  2968. i += 3;
  2969. }
  2970. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2971. if (quest_step && icon > 0)
  2972. quest_step->SetIcon(icon);
  2973. }
  2974. return 0;
  2975. }
  2976. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  2977. Quest* quest = lua_interface->GetQuest(state);
  2978. if (quest) {
  2979. int32 step = lua_interface->GetInt32Value(state, 2);
  2980. string description = lua_interface->GetStringValue(state, 3);
  2981. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2982. float percentage = lua_interface->GetFloatValue(state, 5);
  2983. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2984. int16 icon = lua_interface->GetInt16Value(state, 7);
  2985. const char* taskgroup = 0;
  2986. if (str_taskgroup.length() > 0)
  2987. taskgroup = str_taskgroup.c_str();
  2988. int32 spell_id = 0;
  2989. vector<int32>* ids = 0;
  2990. int i = 0;
  2991. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2992. if (ids == 0)
  2993. ids = new vector<int32>;
  2994. ids->push_back(spell_id);
  2995. i++;
  2996. }
  2997. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2998. if (quest_step && icon > 0 && quantity > 0)
  2999. quest_step->SetIcon(icon);
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Quest* quest = lua_interface->GetQuest(state);
  3007. if (quest) {
  3008. int32 step = lua_interface->GetInt32Value(state, 2);
  3009. string description = lua_interface->GetStringValue(state, 3);
  3010. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3011. float percentage = lua_interface->GetFloatValue(state, 5);
  3012. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3013. int16 icon = lua_interface->GetInt16Value(state, 7);
  3014. const char* taskgroup = 0;
  3015. if (str_taskgroup.length() > 0)
  3016. taskgroup = str_taskgroup.c_str();
  3017. int32 item_id = 0;
  3018. vector<int32>* ids = 0;
  3019. int i = 0;
  3020. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3021. if (ids == 0)
  3022. ids = new vector<int32>;
  3023. ids->push_back(item_id);
  3024. i++;
  3025. }
  3026. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3027. if (quest_step && icon > 0 && quantity > 0)
  3028. quest_step->SetIcon(icon);
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Quest* quest = lua_interface->GetQuest(state);
  3036. if (quest) {
  3037. int32 step = lua_interface->GetInt32Value(state, 2);
  3038. string description = lua_interface->GetStringValue(state, 3);
  3039. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3040. float percentage = lua_interface->GetFloatValue(state, 5);
  3041. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3042. int16 icon = lua_interface->GetInt16Value(state, 7);
  3043. const char* taskgroup = 0;
  3044. if (str_taskgroup.length() > 0)
  3045. taskgroup = str_taskgroup.c_str();
  3046. int32 item_id = 0;
  3047. vector<int32>* ids = 0;
  3048. int i = 0;
  3049. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3050. if (ids == 0)
  3051. ids = new vector<int32>;
  3052. ids->push_back(item_id);
  3053. i++;
  3054. }
  3055. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3056. if (quest_step && icon > 0 && quantity > 0)
  3057. quest_step->SetIcon(icon);
  3058. }
  3059. return 0;
  3060. }
  3061. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3062. if (!lua_interface)
  3063. return 0;
  3064. Quest* quest = lua_interface->GetQuest(state);
  3065. if (quest) {
  3066. string action = lua_interface->GetStringValue(state, 2);
  3067. if (action.length() > 0)
  3068. quest->SetCompleteAction(action);
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Quest* quest = lua_interface->GetQuest(state);
  3076. if (quest) {
  3077. int32 step = lua_interface->GetInt32Value(state, 2);
  3078. string action = lua_interface->GetStringValue(state, 3);
  3079. if (step > 0 && action.length() > 0)
  3080. quest->AddCompleteAction(step, action);
  3081. }
  3082. return 0;
  3083. }
  3084. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3085. if (!lua_interface)
  3086. return 0;
  3087. Quest* quest = lua_interface->GetQuest(state);
  3088. if (quest) {
  3089. int32 step = lua_interface->GetInt32Value(state, 2);
  3090. string action = lua_interface->GetStringValue(state, 3);
  3091. if (step > 0 && action.length() > 0)
  3092. quest->AddProgressAction(step, action);
  3093. }
  3094. return 0;
  3095. }
  3096. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3097. if (!lua_interface)
  3098. return 0;
  3099. Quest* quest = lua_interface->GetQuest(state);
  3100. string description = lua_interface->GetStringValue(state, 2);
  3101. if (quest && description.length() > 0)
  3102. quest->SetDescription(description);
  3103. return 0;
  3104. }
  3105. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3106. if (!lua_interface)
  3107. return 0;
  3108. Quest* quest = lua_interface->GetQuest(state);
  3109. string description = lua_interface->GetStringValue(state, 2);
  3110. if (quest && description.length() > 0)
  3111. quest->SetCompletedDescription(description);
  3112. return 0;
  3113. }
  3114. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3115. if (!lua_interface)
  3116. return 0;
  3117. Quest* quest = lua_interface->GetQuest(state);
  3118. int32 step = lua_interface->GetInt32Value(state, 2);
  3119. string description = lua_interface->GetStringValue(state, 3);
  3120. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3121. if (quest && step > 0 && description.length() > 0) {
  3122. quest->SetTaskGroupDescription(step, description, display_bullets);
  3123. if (quest->GetPlayer()) {
  3124. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3125. if (client)
  3126. client->SendQuestUpdateStep(quest, step, false);
  3127. }
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Quest* quest = lua_interface->GetQuest(state);
  3135. int32 step = lua_interface->GetInt32Value(state, 2);
  3136. string description = lua_interface->GetStringValue(state, 3);
  3137. if (quest && step > 0 && description.length() > 0) {
  3138. quest->SetStepDescription(step, description);
  3139. if (quest->GetPlayer()) {
  3140. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3141. if (client)
  3142. client->SendQuestUpdateStep(quest, step);
  3143. }
  3144. }
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3148. Quest* quest = lua_interface->GetQuest(state);
  3149. string zone = lua_interface->GetStringValue(state, 2);
  3150. if (quest && zone.length() > 0)
  3151. quest->SetZone(zone);
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Quest* quest = lua_interface->GetQuest(state);
  3158. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3159. if (quest && spawn) {
  3160. if (spawn->IsPlayer()) {
  3161. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3162. if (client)
  3163. client->AddPendingQuestReward(quest);
  3164. }
  3165. }
  3166. return 0;
  3167. }
  3168. int EQ2Emu_lua_Harvest(lua_State* state) {
  3169. if (!lua_interface)
  3170. return 0;
  3171. Spawn* player = lua_interface->GetSpawn(state);
  3172. Spawn* node = lua_interface->GetSpawn(state, 2);
  3173. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3174. Client* client = player->GetZone()->GetClientBySpawn(player);
  3175. if (client) {
  3176. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3177. ((GroundSpawn*)node)->ProcessHarvest(client);
  3178. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3179. player->GetZone()->RemoveSpawn(true, node, true);
  3180. }
  3181. }
  3182. else if (player && player->IsPlayer()) {
  3183. Client* client = player->GetZone()->GetClientBySpawn(player);
  3184. if (client)
  3185. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3186. }
  3187. return 0;
  3188. }
  3189. int EQ2Emu_lua_Bind(lua_State* state) {
  3190. if (!lua_interface)
  3191. return 0;
  3192. Spawn* spawn = lua_interface->GetSpawn(state);
  3193. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3194. float x = lua_interface->GetFloatValue(state, 3);
  3195. float y = lua_interface->GetFloatValue(state, 4);
  3196. float z = lua_interface->GetFloatValue(state, 5);
  3197. float h = lua_interface->GetFloatValue(state, 6);
  3198. if (!spawn) {
  3199. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3200. return 0;
  3201. }
  3202. if (!spawn->IsPlayer()) {
  3203. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3204. return 0;
  3205. }
  3206. if (zone_id == 0) {
  3207. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3208. if (!client) {
  3209. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3210. return 0;
  3211. }
  3212. if (!client->Bind())
  3213. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3214. }
  3215. else {
  3216. Player* player = (Player*)spawn;
  3217. player->GetPlayerInfo()->SetBindZone(zone_id);
  3218. player->GetPlayerInfo()->SetBindX(x);
  3219. player->GetPlayerInfo()->SetBindY(y);
  3220. player->GetPlayerInfo()->SetBindZ(z);
  3221. player->GetPlayerInfo()->SetBindHeading(h);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_Gate(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Spawn* spawn = lua_interface->GetSpawn(state);
  3229. if (spawn) {
  3230. if (spawn->IsPlayer()) {
  3231. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3232. if (client) {
  3233. if (!client->Gate())
  3234. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3235. }
  3236. }
  3237. }
  3238. return 0;
  3239. }
  3240. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3241. if (!lua_interface)
  3242. return 0;
  3243. bool ret = false;
  3244. Spawn* spawn = lua_interface->GetSpawn(state);
  3245. if (spawn) {
  3246. if (spawn->IsPlayer()) {
  3247. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3248. if (client)
  3249. ret = client->BindAllowed();
  3250. }
  3251. }
  3252. lua_interface->SetBooleanValue(state, ret);
  3253. return 1;
  3254. }
  3255. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3256. if (!lua_interface)
  3257. return 0;
  3258. bool ret = false;
  3259. Spawn* spawn = lua_interface->GetSpawn(state);
  3260. if (spawn) {
  3261. if (spawn->IsPlayer()) {
  3262. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3263. if (client)
  3264. ret = client->GateAllowed();
  3265. }
  3266. }
  3267. lua_interface->SetBooleanValue(state, ret);
  3268. return 1;
  3269. }
  3270. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3271. Spawn* spawn = lua_interface->GetSpawn(state);
  3272. if (spawn) {
  3273. lua_interface->SetBooleanValue(state, spawn->Alive());
  3274. return 1;
  3275. }
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* spawn = lua_interface->GetSpawn(state);
  3282. if (spawn && spawn->IsEntity()) {
  3283. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3284. return 1;
  3285. }
  3286. return 0;
  3287. }
  3288. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3289. Spawn* spawn = lua_interface->GetSpawn(state);
  3290. string message = lua_interface->GetStringValue(state, 2);
  3291. string color_str = lua_interface->GetStringValue(state, 3);
  3292. int8 color = CHANNEL_COLOR_WHITE;
  3293. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3294. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3295. if (client) {
  3296. if (color_str.length() > 0) {
  3297. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3298. color = CHANNEL_COLOR_RED;
  3299. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3300. color = CHANNEL_COLOR_YELLOW;
  3301. }
  3302. client->SimpleMessage(color, message.c_str());
  3303. }
  3304. }
  3305. return 0;
  3306. }
  3307. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3308. Spawn* spawn = lua_interface->GetSpawn(state);
  3309. string message = lua_interface->GetStringValue(state, 2);
  3310. int8 red = lua_interface->GetInt8Value(state, 3);
  3311. int8 green = lua_interface->GetInt8Value(state, 4);
  3312. int8 blue = lua_interface->GetInt8Value(state, 5);
  3313. if (!spawn) {
  3314. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3315. return 0;
  3316. }
  3317. int32 words = ::CountWordsInString(message.c_str());
  3318. if (words < 5)
  3319. words = 5;
  3320. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3321. if (client)
  3322. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3326. Spawn* spawn = lua_interface->GetSpawn(state);
  3327. int8 param = lua_interface->GetInt8Value(state, 2);
  3328. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3329. int8 value = lua_interface->GetInt8Value(state, 4);
  3330. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3331. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3332. if (client) {
  3333. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3334. switch (param) {
  3335. case 1: {
  3336. packet->setDataByName("parameter1", param_value);
  3337. break;
  3338. }
  3339. case 2: {
  3340. packet->setDataByName("parameter2", param_value);
  3341. break;
  3342. }
  3343. case 3: {
  3344. packet->setDataByName("parameter3", param_value);
  3345. break;
  3346. }
  3347. case 4: {
  3348. packet->setDataByName("parameter4", param_value);
  3349. break;
  3350. }
  3351. case 5: {
  3352. packet->setDataByName("parameter5", param_value);
  3353. break;
  3354. }
  3355. }
  3356. packet->setDataByName("value", value);
  3357. client->QueuePacket(packet->serialize());
  3358. safe_delete(packet);
  3359. }
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3364. Spawn* spawn = lua_interface->GetSpawn(state);
  3365. if (spawn && spawn->IsPlayer()) {
  3366. if (((Player*)spawn)->GetIsTracking())
  3367. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3368. else
  3369. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3370. }
  3371. return 0;
  3372. }
  3373. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3374. Spawn* player = lua_interface->GetSpawn(state);
  3375. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3376. string name = lua_interface->GetStringValue(state, 3);
  3377. float distance = lua_interface->GetFloatValue(state, 4);
  3378. string command = lua_interface->GetStringValue(state, 5);
  3379. string error_text = lua_interface->GetStringValue(state, 6);
  3380. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3381. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3382. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3383. if (spawn) {
  3384. if (distance == 0)
  3385. distance = 10.0f;
  3386. if (command.length() == 0)
  3387. command = name;
  3388. if (command.length() < 1 && name.length() < 1)
  3389. {
  3390. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3391. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3392. spawn->RemovePrimaryCommands();
  3393. }
  3394. else
  3395. {
  3396. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3397. }
  3398. }
  3399. return 0;
  3400. }
  3401. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3402. if (!lua_interface)
  3403. return 0;
  3404. Spawn* player = lua_interface->GetSpawn(state);
  3405. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3406. int16 tier = lua_interface->GetInt16Value(state, 3);
  3407. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3408. if (player && spell && player->IsPlayer()) {
  3409. Client* client = player->GetZone()->GetClientBySpawn(player);
  3410. if (client) {
  3411. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3412. {
  3413. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3414. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3415. client->GetPlayer()->UnlockSpell(spell);
  3416. client->SendSpellUpdate(spell);
  3417. }
  3418. else
  3419. {
  3420. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3421. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3422. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3423. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3424. client->GetPlayer()->UnlockSpell(spell);
  3425. client->SendSpellUpdate(spell);
  3426. }
  3427. //if (client ) {
  3428. // ((Player*)player)->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), ((Player*)player)->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3429. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3430. if (outapp)
  3431. client->QueuePacket(outapp);
  3432. }
  3433. }
  3434. return 0;
  3435. }
  3436. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3437. if (!lua_interface)
  3438. return 0;
  3439. Spawn* player = lua_interface->GetSpawn(state);
  3440. if (player && player->IsPlayer()) {
  3441. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3442. return 1;
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_Attack(lua_State* state) {
  3447. if (lua_interface) {
  3448. Spawn* npc = lua_interface->GetSpawn(state);
  3449. Spawn* player = lua_interface->GetSpawn(state, 2);
  3450. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3451. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3452. }
  3453. return 0;
  3454. }
  3455. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3456. if (lua_interface) {
  3457. Spawn* target = lua_interface->GetSpawn(state);
  3458. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3459. if (target && target->GetZone())
  3460. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3461. }
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3465. Spawn* player;
  3466. if (lua_interface) {
  3467. player = lua_interface->GetSpawn(state);
  3468. if (player && player->IsPlayer()) {
  3469. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3470. return 1;
  3471. }
  3472. }
  3473. return 0;
  3474. }
  3475. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3476. Spawn* player;
  3477. Client* client;
  3478. if (lua_interface) {
  3479. player = lua_interface->GetSpawn(state);
  3480. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3481. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3482. client->HandInCollections();
  3483. }
  3484. return 0;
  3485. }
  3486. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3487. Spawn* widget;
  3488. if (lua_interface) {
  3489. widget = lua_interface->GetSpawn(state);
  3490. if (widget && widget->IsWidget())
  3491. ((Widget*)widget)->HandleUse(NULL, "");
  3492. }
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3496. Spawn* spawn = 0;
  3497. int32 primary_list = 0;
  3498. int32 secondary_list = 0;
  3499. if (lua_interface) {
  3500. spawn = lua_interface->GetSpawn(state);
  3501. primary_list = lua_interface->GetInt32Value(state, 2);
  3502. secondary_list = lua_interface->GetInt32Value(state, 3);
  3503. if (!spawn->IsNPC()) {
  3504. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3505. return 0;
  3506. }
  3507. NPC* npc = (NPC*)spawn;
  3508. npc->SetPrimarySpellList(primary_list);
  3509. npc->SetSecondarySpellList(secondary_list);
  3510. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3511. }
  3512. return 0;
  3513. }
  3514. int EQ2Emu_lua_GetPet(lua_State* state) {
  3515. if (!lua_interface)
  3516. return 0;
  3517. Spawn* spawn = lua_interface->GetSpawn(state);
  3518. if (spawn) {
  3519. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3520. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3521. return 1;
  3522. }
  3523. }
  3524. return 0;
  3525. }
  3526. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3527. if (!lua_interface)
  3528. return 0;
  3529. Spawn* spawn = lua_interface->GetSpawn(state);
  3530. if (spawn) {
  3531. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3532. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3533. return 1;
  3534. }
  3535. }
  3536. return 0;
  3537. }
  3538. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3539. if (!lua_interface)
  3540. return 0;
  3541. Spawn* spawn = lua_interface->GetSpawn(state);
  3542. if (spawn) {
  3543. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3544. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3545. return 1;
  3546. }
  3547. }
  3548. return 0;
  3549. }
  3550. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3551. if (!lua_interface)
  3552. return 0;
  3553. Spawn* spawn = lua_interface->GetSpawn(state);
  3554. if (spawn) {
  3555. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3556. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3557. return 1;
  3558. }
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_Charm(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Spawn* owner = lua_interface->GetSpawn(state);
  3566. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3567. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3568. if (!luaspell) {
  3569. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  3570. return 0;
  3571. }
  3572. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3573. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3574. pet->SetPet(true);
  3575. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3576. ((NPC*)pet)->SetOwner((Entity*)owner);
  3577. // If owner is player and player does not have a summoned pet set the players charsheet
  3578. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3579. Player* player = (Player*)owner;
  3580. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3581. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3582. player->GetInfoStruct()->pet_movement = 2;
  3583. player->GetInfoStruct()->pet_behavior = 3;
  3584. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3585. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3586. // Make sure the values get sent to the client
  3587. player->SetCharSheetChanged(true);
  3588. }
  3589. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  3590. pet->SetSpawnScript("");
  3591. // Set faction to the same as the owner
  3592. pet->SetFactionID(owner->GetFactionID());
  3593. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3594. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3595. // Clear hate list
  3596. ((NPC*)pet)->Brain()->ClearHate();
  3597. // Set the brain to a pet brain
  3598. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3599. }
  3600. return 0;
  3601. }
  3602. int EQ2Emu_lua_GetGroup(lua_State* state) {
  3603. if (!lua_interface)
  3604. return 0;
  3605. Spawn* spawn = lua_interface->GetSpawn(state);
  3606. if (!spawn) {
  3607. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  3608. return 0;
  3609. }
  3610. vector<Spawn*> groupMembers;
  3611. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  3612. groupMembers = *spawn->GetSpawnGroup();
  3613. }
  3614. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  3615. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  3616. deque<GroupMemberInfo*>::iterator itr;
  3617. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  3618. GroupMemberInfo* info = 0;
  3619. for (itr = members->begin(); itr != members->end(); itr++) {
  3620. info = *itr;
  3621. if (info->client)
  3622. groupMembers.push_back(info->client->GetPlayer());
  3623. }
  3624. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  3625. }
  3626. else
  3627. return 0;
  3628. lua_createtable(state, groupMembers.size(), 0);
  3629. int newTable = lua_gettop(state);
  3630. for (int32 i = 0; i < groupMembers.size(); i++) {
  3631. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  3632. lua_rawseti(state, newTable, i + 1);
  3633. }
  3634. return 1;
  3635. }
  3636. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  3637. if (!lua_interface)
  3638. return 0;
  3639. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  3640. lua_interface->SetOptionWindowValue(state, option_window);
  3641. return 1;
  3642. }
  3643. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  3644. if (!lua_interface)
  3645. return 0;
  3646. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3647. if (option_window) {
  3648. OptionWindowOption option_window_option;
  3649. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  3650. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  3651. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  3652. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  3653. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  3654. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  3655. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  3656. option_window->push_back(option_window_option);
  3657. }
  3658. return 0;
  3659. }
  3660. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  3661. if (!lua_interface)
  3662. return 0;
  3663. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3664. Spawn* player = lua_interface->GetSpawn(state, 2);
  3665. string window_title = lua_interface->GetStringValue(state, 3);
  3666. string cancel_command = lua_interface->GetStringValue(state, 4);
  3667. Client* client = player->GetZone()->GetClientBySpawn(player);
  3668. if (option_window && window_title.length() > 0 && client) {
  3669. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  3670. if (!packet)
  3671. return 0;
  3672. packet->setDataByName("title_text", window_title.c_str());
  3673. if (cancel_command.length() > 0)
  3674. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  3675. packet->setArrayLengthByName("num_selections", option_window->size());
  3676. vector<OptionWindowOption>::iterator itr;
  3677. int8 i = 0;
  3678. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  3679. OptionWindowOption opt = *itr;
  3680. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  3681. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  3682. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  3683. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  3684. if (opt.optionCommand.length() > 0)
  3685. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  3686. if (opt.optionConfirmTitle.length() > 0)
  3687. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  3688. i++;
  3689. }
  3690. client->QueuePacket(packet->serialize());
  3691. safe_delete(option_window);
  3692. safe_delete(packet);
  3693. }
  3694. return 0;
  3695. }
  3696. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  3697. if (!lua_interface)
  3698. return 0;
  3699. Spawn* spawn = lua_interface->GetSpawn(state);
  3700. if (spawn) {
  3701. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  3702. return 1;
  3703. }
  3704. else
  3705. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Spawn* spawn = lua_interface->GetSpawn(state);
  3712. if (spawn) {
  3713. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  3714. return 1;
  3715. }
  3716. else
  3717. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  3718. return 0;
  3719. }
  3720. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  3721. if (!lua_interface)
  3722. return 0;
  3723. Spawn* spawn = lua_interface->GetSpawn(state);
  3724. if (spawn) {
  3725. int8 class_id = spawn->GetTradeskillClass();
  3726. // Need to add 42 for the offset in the array
  3727. class_id += 44;
  3728. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  3729. return 1;
  3730. }
  3731. else
  3732. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3733. return 0;
  3734. }
  3735. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  3736. if (!lua_interface)
  3737. return 0;
  3738. Spawn* spawn = lua_interface->GetSpawn(state);
  3739. int16 level = lua_interface->GetInt8Value(state, 2);
  3740. if (spawn) {
  3741. if (spawn->IsPlayer())
  3742. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  3743. else
  3744. spawn->SetTSLevel(level);
  3745. }
  3746. else
  3747. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3748. return 0;
  3749. }
  3750. int EQ2Emu_lua_SummonPet(lua_State* state) {
  3751. // Check to see if we have a valid lua_interface
  3752. if (!lua_interface)
  3753. return 0;
  3754. // Get the spawn that is getting the pet
  3755. Spawn* spawn = lua_interface->GetSpawn(state);
  3756. // Get the DB ID of the pet
  3757. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3758. // The max level the pet can gain
  3759. int8 max_level = lua_interface->GetInt8Value(state, 3);
  3760. // Get the spell that this command was called from
  3761. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3762. // Check to make sure the spawn pointer is valid
  3763. if (!spawn) {
  3764. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3765. return 0;
  3766. }
  3767. // Check to make sure the spawn is an entity
  3768. if (!spawn->IsEntity()) {
  3769. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3770. return 0;
  3771. }
  3772. // Check to make sure the spawn doesn't already have a pet of this type
  3773. if (((Entity*)spawn)->GetPet()) {
  3774. if (spawn->IsPlayer()) {
  3775. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3776. if (client)
  3777. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  3778. }
  3779. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3780. return 0;
  3781. }
  3782. // Check to see if the DB ID for the pet is set
  3783. if (pet_id == 0) {
  3784. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3785. return 0;
  3786. }
  3787. // Check to see if the pointer to the spell is valid
  3788. if (!luaspell) {
  3789. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3790. return 0;
  3791. }
  3792. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  3793. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3794. if (!pet) {
  3795. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3796. return 0;
  3797. }
  3798. // Check to make sure the pet is an npc
  3799. if (!pet->IsNPC()) {
  3800. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  3801. return 0;
  3802. }
  3803. // Spawn the pet at the same location as the owner
  3804. pet->SetX(spawn->GetX());
  3805. pet->SetY(spawn->GetY());
  3806. pet->SetZ(spawn->GetZ());
  3807. pet->SetLocation(spawn->GetLocation());
  3808. pet->SetHeading(spawn->GetHeading());
  3809. spawn->GetZone()->AddSpawn(pet);
  3810. /*
  3811. const char* spawn_script = world.GetSpawnScript(pet_id);
  3812. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  3813. spawn->SetSpawnScript(string(spawn_script));
  3814. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  3815. }*/
  3816. // Get a random pet name
  3817. string random_pet_name;
  3818. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3819. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3820. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3821. // If player set various values for the char sheet (pet window)
  3822. if (spawn->IsPlayer()) {
  3823. Player* player = (Player*)spawn;
  3824. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3825. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  3826. player->GetInfoStruct()->pet_movement = 2;
  3827. player->GetInfoStruct()->pet_behavior = 3;
  3828. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3829. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3830. // Make sure the values get sent to the client
  3831. player->SetCharSheetChanged(true);
  3832. }
  3833. // Set the pets name
  3834. pet->SetName(random_pet_name.c_str());
  3835. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  3836. if (max_level > 0)
  3837. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  3838. else
  3839. pet->SetLevel(spawn->GetLevel());
  3840. // Set the max level this pet can reach
  3841. ((NPC*)pet)->SetMaxPetLevel(max_level);
  3842. // Set the faction of the pet to the same faction as the owner
  3843. pet->SetFactionID(spawn->GetFactionID());
  3844. // Set the spawn as a pet
  3845. pet->SetPet(true);
  3846. // Give a pointer of the owner to the pet
  3847. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3848. // Give a pointer of the pet to the owner
  3849. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  3850. // Set the pet type
  3851. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  3852. // Set the spell id used to create this pet
  3853. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3854. // Set the spell tier used to create this pet
  3855. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3856. // Set the pets spawn type to 6
  3857. pet->SetSpawnType(6);
  3858. // Set the pets brain
  3859. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3860. // Check to see if the pet has a subtitle
  3861. if (strlen(pet->GetSubTitle()) > 0) {
  3862. // Add the players name to the front of the sub title
  3863. string pet_subtitle;
  3864. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3865. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3866. // Set the pets subtitle to the new one
  3867. pet->SetSubTitle(pet_subtitle.c_str());
  3868. }
  3869. // Add the "Pet Options" entity command to the pet
  3870. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3871. // Set the pet as the return value for this function
  3872. lua_interface->SetSpawnValue(state, pet);
  3873. return 1;
  3874. }
  3875. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  3876. if (!lua_interface)
  3877. return 0;
  3878. Spawn* spawn = lua_interface->GetSpawn(state);
  3879. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3880. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3881. if (!spawn) {
  3882. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3883. return 0;
  3884. }
  3885. if (!spawn->IsEntity()) {
  3886. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3887. return 0;
  3888. }
  3889. if (((Entity*)spawn)->GetDeityPet()) {
  3890. if (spawn->IsPlayer()) {
  3891. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3892. if (client)
  3893. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  3894. }
  3895. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3896. return 0;
  3897. }
  3898. if (pet_id == 0) {
  3899. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3900. return 0;
  3901. }
  3902. if (!luaspell) {
  3903. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3904. return 0;
  3905. }
  3906. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3907. if (!pet) {
  3908. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3909. return 0;
  3910. }
  3911. if (!pet->IsNPC()) {
  3912. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3913. return 0;
  3914. }
  3915. pet->SetX(spawn->GetX());
  3916. pet->SetY(spawn->GetY());
  3917. pet->SetZ(spawn->GetZ());
  3918. pet->SetLocation(spawn->GetLocation());
  3919. pet->SetHeading(spawn->GetHeading());
  3920. spawn->GetZone()->AddSpawn(pet);
  3921. string random_pet_name;
  3922. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3923. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3924. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3925. pet->SetName(random_pet_name.c_str());
  3926. pet->SetLevel(spawn->GetLevel());
  3927. pet->SetFactionID(spawn->GetFactionID());
  3928. pet->SetPet(true);
  3929. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  3930. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3931. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  3932. pet->SetSpawnType(6);
  3933. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3934. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3935. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3936. if (strlen(pet->GetSubTitle()) > 0) {
  3937. string pet_subtitle;
  3938. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3939. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3940. pet->SetSubTitle(pet_subtitle.c_str());
  3941. }
  3942. // deity and cosmetic pets are not attackable
  3943. pet->SetAttackable(false);
  3944. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3945. lua_interface->SetSpawnValue(state, pet);
  3946. return 1;
  3947. }
  3948. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  3949. if (!lua_interface)
  3950. return 0;
  3951. Spawn* spawn = lua_interface->GetSpawn(state);
  3952. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3953. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3954. if (!spawn) {
  3955. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3956. return 0;
  3957. }
  3958. if (!spawn->IsEntity()) {
  3959. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3960. return 0;
  3961. }
  3962. if (((Entity*)spawn)->GetCosmeticPet()) {
  3963. if (spawn->IsPlayer()) {
  3964. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3965. if (client)
  3966. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  3967. }
  3968. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3969. return 0;
  3970. }
  3971. if (pet_id == 0) {
  3972. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3973. return 0;
  3974. }
  3975. if (!luaspell) {
  3976. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3977. return 0;
  3978. }
  3979. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3980. if (!pet) {
  3981. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3982. return 0;
  3983. }
  3984. if (!pet->IsNPC()) {
  3985. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3986. return 0;
  3987. }
  3988. pet->SetX(spawn->GetX());
  3989. pet->SetY(spawn->GetY());
  3990. pet->SetZ(spawn->GetZ());
  3991. pet->SetLocation(spawn->GetLocation());
  3992. pet->SetHeading(spawn->GetHeading());
  3993. spawn->GetZone()->AddSpawn(pet);
  3994. string random_pet_name;
  3995. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3996. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3997. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3998. pet->SetName(random_pet_name.c_str());
  3999. pet->SetLevel(spawn->GetLevel());
  4000. pet->SetFactionID(spawn->GetFactionID());
  4001. pet->SetPet(true);
  4002. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4003. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4004. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4005. pet->SetSpawnType(6);
  4006. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4007. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4008. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4009. if (strlen(pet->GetSubTitle()) > 0) {
  4010. string pet_subtitle;
  4011. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4012. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4013. pet->SetSubTitle(pet_subtitle.c_str());
  4014. }
  4015. pet->SetAttackable(false);
  4016. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4017. lua_interface->SetSpawnValue(state, pet);
  4018. return 1;
  4019. }
  4020. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4021. if (!lua_interface)
  4022. return 0;
  4023. Spawn* spawn = lua_interface->GetSpawn(state);
  4024. if (!spawn) {
  4025. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4026. return 0;
  4027. }
  4028. if (!spawn->IsPet()) {
  4029. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4030. return 0;
  4031. }
  4032. if (!((NPC*)spawn)->IsDismissing())
  4033. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4034. return 0;
  4035. }
  4036. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4037. if (!lua_interface)
  4038. return 0;
  4039. Quest* quest = lua_interface->GetQuest(state);
  4040. if (!quest) {
  4041. lua_interface->LogError("%s: LUA SetQuestFeatherColor command error: valid quest not found, SetQuestFeatherColor can only be called from a quest script", lua_interface->GetScriptName(state));
  4042. return 0;
  4043. }
  4044. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4045. if (feather_color > 0)
  4046. quest->SetFeatherColor(feather_color);
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Spawn* spawn = lua_interface->GetSpawn(state);
  4053. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4054. if (!spawn) {
  4055. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4056. return 0;
  4057. }
  4058. if (!spawn2) {
  4059. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4060. return 0;
  4061. }
  4062. spawn->RemoveSpawnAccess(spawn2);
  4063. return 0;
  4064. }
  4065. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4066. if (!lua_interface)
  4067. return 0;
  4068. ZoneServer* zone = lua_interface->GetZone(state);
  4069. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4070. if (!zone) {
  4071. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4072. return 0;
  4073. }
  4074. if (location_id == 0) {
  4075. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4076. return 0;
  4077. }
  4078. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4079. if (!location) {
  4080. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4081. return 0;
  4082. }
  4083. Spawn* spawn = 0;
  4084. if (location->entities[0]) {
  4085. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4086. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4087. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4088. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4089. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4090. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4091. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4092. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4093. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4094. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4095. if (spawn) {
  4096. const char* script = 0;
  4097. for (int x = 0; x < 3; x++) {
  4098. switch (x) {
  4099. case 0:
  4100. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4101. break;
  4102. case 1:
  4103. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4104. break;
  4105. case 2:
  4106. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4107. break;
  4108. }
  4109. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4110. spawn->SetSpawnScript(string(script));
  4111. break;
  4112. }
  4113. }
  4114. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4115. lua_interface->SetSpawnValue(state, spawn);
  4116. return 1;
  4117. }
  4118. else {
  4119. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4120. safe_delete(spawn);
  4121. }
  4122. }
  4123. return 0;
  4124. }
  4125. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4126. if (!lua_interface)
  4127. return 0;
  4128. Spawn* caster = lua_interface->GetSpawn(state);
  4129. Spawn* target = lua_interface->GetSpawn(state, 2);
  4130. int32 id = lua_interface->GetInt32Value(state, 3);
  4131. string command = lua_interface->GetStringValue(state, 4);
  4132. if (!caster) {
  4133. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4134. return 0;
  4135. }
  4136. if (!target) {
  4137. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4138. return 0;
  4139. }
  4140. if (!caster->IsPlayer()) {
  4141. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4142. return 0;
  4143. }
  4144. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4145. if (!entity_command) {
  4146. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid EntityCommand with the given ID (%u) and name (%s)", lua_interface->GetScriptName(state), id, command.c_str());
  4147. return 0;
  4148. }
  4149. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4150. if (!client) {
  4151. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4152. return 0;
  4153. }
  4154. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. Spawn* spawn = lua_interface->GetSpawn(state);
  4161. if (!spawn) {
  4162. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4163. return 0;
  4164. }
  4165. if (!spawn->IsNPC()) {
  4166. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4167. return 0;
  4168. }
  4169. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4170. return 0;
  4171. }
  4172. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4173. if (!lua_interface)
  4174. return 0;
  4175. Spawn* spawn = lua_interface->GetSpawn(state);
  4176. int16 tick = lua_interface->GetInt16Value(state, 2);
  4177. if (!spawn) {
  4178. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4179. return 0;
  4180. }
  4181. if (!spawn->IsNPC()) {
  4182. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4183. return 0;
  4184. }
  4185. if (tick < 20) {
  4186. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4187. return 0;
  4188. }
  4189. ((NPC*)spawn)->Brain()->SetTick(tick);
  4190. return 0;
  4191. }
  4192. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4193. if (!lua_interface)
  4194. return 0;
  4195. Spawn* spawn = lua_interface->GetSpawn(state);
  4196. Spawn* target = lua_interface->GetSpawn(state, 2);
  4197. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4198. if (!spawn) {
  4199. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4200. return 0;
  4201. }
  4202. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4203. spawn->SetFollowTarget(target, follow_distance);
  4204. return 0;
  4205. }
  4206. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4207. if (!lua_interface)
  4208. return 0;
  4209. Spawn* spawn = lua_interface->GetSpawn(state);
  4210. if (!spawn) {
  4211. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4212. return 0;
  4213. }
  4214. Spawn* target = spawn->GetFollowTarget();
  4215. if (target) {
  4216. lua_interface->SetSpawnValue(state, target);
  4217. return 1;
  4218. }
  4219. return 0;
  4220. }
  4221. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4222. if (!lua_interface)
  4223. return 0;
  4224. Spawn* spawn = lua_interface->GetSpawn(state);
  4225. if (!spawn) {
  4226. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4227. return 0;
  4228. }
  4229. if (spawn->following)
  4230. spawn->following = false;
  4231. else
  4232. spawn->following = true;
  4233. return 0;
  4234. }
  4235. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4236. if (!lua_interface)
  4237. return 0;
  4238. Spawn* spawn = lua_interface->GetSpawn(state);
  4239. if (!spawn) {
  4240. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4241. return 0;
  4242. }
  4243. lua_interface->SetBooleanValue(state, spawn->following);
  4244. return 1;
  4245. }
  4246. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4247. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4248. // I will attempt to explain how this function works for future refrence
  4249. // Fist lets make sure lua_interface is valid, if not return out
  4250. if (!lua_interface)
  4251. return 0;
  4252. // Next we grab the first 2 params same as we usually would
  4253. Spawn* spawn = lua_interface->GetSpawn(state);
  4254. string var = lua_interface->GetStringValue(state, 2);
  4255. // DataType will let us know the value type so we can handle it correctly, we set these ourself so the values I used are made up
  4256. // 1 = Spawn
  4257. // 2 = Zone
  4258. // 3 = Item
  4259. // 4 = Quest
  4260. // 5 = String
  4261. // 6 = nil (null)
  4262. int8 dataType = 0;
  4263. // Define pointers for each potential type
  4264. Spawn* spawnVal = 0;
  4265. ZoneServer* zone = 0;
  4266. Item* item = 0;
  4267. Quest* quest = 0;
  4268. string val;
  4269. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4270. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4271. // options window are also light user data be we do not handle those.
  4272. // We check with lua_islightuserdata(lua_State*, index)
  4273. if (lua_islightuserdata(state, 3)) {
  4274. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4275. // and convert it to LUAUserData*
  4276. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4277. // Check to make sure the data we got is valid, if not give an error
  4278. if (!data || !data->IsCorrectlyInitialized()) {
  4279. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4280. }
  4281. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4282. else if (data->IsSpawn()) {
  4283. spawnVal = data->spawn;
  4284. dataType = 1;
  4285. }
  4286. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4287. else if (data->IsZone()) {
  4288. zone = data->zone;
  4289. dataType = 2;
  4290. }
  4291. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4292. else if (data->IsItem()) {
  4293. item = data->item;
  4294. dataType = 3;
  4295. }
  4296. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4297. else if (data->IsQuest()) {
  4298. quest = data->quest;
  4299. dataType = 4;
  4300. }
  4301. }
  4302. // Wasn't light user data, check if it is nil(null)
  4303. else if (lua_isnil(state, 3)) {
  4304. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4305. dataType = 6;
  4306. }
  4307. // Wasn't light user data or nil (null), must be a string
  4308. else {
  4309. // Set the string and dataType variable
  4310. val = lua_interface->GetStringValue(state, 3);
  4311. dataType = 5;
  4312. }
  4313. // We now have all the params, lets check to make sure they are valid
  4314. if (!spawn) {
  4315. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4316. return 0;
  4317. }
  4318. if (var.length() == 0) {
  4319. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4320. return 0;
  4321. }
  4322. if (dataType == 0) {
  4323. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4324. return 0;
  4325. }
  4326. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4327. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4328. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4329. switch (dataType) {
  4330. case 1:
  4331. // 1 = Spawn
  4332. spawn->AddTempVariable(var, spawnVal);
  4333. break;
  4334. case 2:
  4335. // 2 = Zone
  4336. spawn->AddTempVariable(var, zone);
  4337. break;
  4338. case 3:
  4339. // 3 = Item
  4340. spawn->AddTempVariable(var, item);
  4341. break;
  4342. case 4:
  4343. // 4 = Quest
  4344. spawn->AddTempVariable(var, quest);
  4345. break;
  4346. case 5:
  4347. // 5 = String
  4348. spawn->AddTempVariable(var, val);
  4349. break;
  4350. case 6:
  4351. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4352. spawn->DeleteTempVariable(var);
  4353. break;
  4354. }
  4355. // And we are done so return out
  4356. return 0;
  4357. }
  4358. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4359. if (!lua_interface)
  4360. return 0;
  4361. Spawn* spawn = lua_interface->GetSpawn(state);
  4362. string var = lua_interface->GetStringValue(state, 2);
  4363. if (!spawn) {
  4364. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4365. return 0;
  4366. }
  4367. if (var.length() == 0) {
  4368. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4369. return 0;
  4370. }
  4371. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4372. int8 type = spawn->GetTempVariableType(var);
  4373. Spawn* spawn2 = 0;
  4374. ZoneServer* zone = 0;
  4375. Item* item = 0;
  4376. Quest* quest = 0;
  4377. // Set the lua function return value based on the type of data the variable contains
  4378. switch (type) {
  4379. case 1:
  4380. spawn2 = spawn->GetTempVariableSpawn(var);
  4381. if (!spawn2)
  4382. return 0;
  4383. lua_interface->SetSpawnValue(state, spawn2);
  4384. break;
  4385. case 2:
  4386. zone = spawn->GetTempVariableZone(var);
  4387. if (!zone)
  4388. return 0;
  4389. lua_interface->SetZoneValue(state, zone);
  4390. break;
  4391. case 3:
  4392. item = spawn->GetTempVariableItem(var);
  4393. if (!item)
  4394. return 0;
  4395. lua_interface->SetItemValue(state, item);
  4396. break;
  4397. case 4:
  4398. quest = spawn->GetTempVariableQuest(var);
  4399. if (!quest)
  4400. return 0;
  4401. lua_interface->SetQuestValue(state, quest);
  4402. break;
  4403. case 5:
  4404. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4405. break;
  4406. default:
  4407. // Not a valid type then the variable was not set so return out
  4408. return 0;
  4409. }
  4410. // Return value was set so return out
  4411. return 1;
  4412. }
  4413. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4414. {
  4415. if (!lua_interface)
  4416. return 0;
  4417. Quest* quest = lua_interface->GetQuest(state);
  4418. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4419. string description = lua_interface->GetStringValue(state, 3);
  4420. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4421. if (!quest) {
  4422. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4423. lua_interface->SetBooleanValue(state, false);
  4424. return 1;
  4425. }
  4426. if (!spawn) {
  4427. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4428. lua_interface->SetBooleanValue(state, false);
  4429. return 1;
  4430. }
  4431. if (!spawn->IsPlayer()) {
  4432. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4433. lua_interface->SetBooleanValue(state, false);
  4434. return 1;
  4435. }
  4436. if (item_id == 0) {
  4437. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4438. lua_interface->SetBooleanValue(state, false);
  4439. return 1;
  4440. }
  4441. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4442. if (!client) {
  4443. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4444. lua_interface->SetBooleanValue(state, false);
  4445. return 1;
  4446. }
  4447. Item* item = master_item_list.GetItem(item_id);
  4448. if (!item) {
  4449. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4450. lua_interface->SetBooleanValue(state, false);
  4451. return 1;
  4452. }
  4453. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4454. if (packet) {
  4455. packet->setDataByName("title", "Quest Reward!");
  4456. packet->setDataByName("name", quest->GetName());
  4457. packet->setDataByName("description", description.c_str());
  4458. packet->setDataByName("level", quest->GetLevel());
  4459. packet->setArrayLengthByName("num_rewards", 1);
  4460. packet->setArrayDataByName("reward_id", item->details.item_id);
  4461. if (client->GetVersion() < 860)
  4462. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4463. else if (client->GetVersion() < 1193)
  4464. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4465. else
  4466. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4467. client->QueuePacket(packet->serialize());
  4468. safe_delete(packet);
  4469. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4470. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  4471. return 1;
  4472. }
  4473. lua_interface->SetBooleanValue(state, false);
  4474. return 1;
  4475. }
  4476. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4477. if (!lua_interface)
  4478. return 0;
  4479. Quest* quest = lua_interface->GetQuest(state);
  4480. if (!quest) {
  4481. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4482. return 0;
  4483. }
  4484. quest->SetRepeatable(true);
  4485. return 0;
  4486. }
  4487. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4488. if (!lua_interface)
  4489. return 0;
  4490. Spawn* spawn = lua_interface->GetSpawn(state);
  4491. if (!spawn) {
  4492. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4493. return 0;
  4494. }
  4495. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4496. string ret = classes.GetClassNameCase(base_class);
  4497. if (ret.length() > 0) {
  4498. lua_interface->SetStringValue(state, ret.c_str());
  4499. return 1;
  4500. }
  4501. return 0;
  4502. }
  4503. int EQ2Emu_lua_AddWard(lua_State* state) {
  4504. if (!lua_interface)
  4505. return 0;
  4506. int32 damage = lua_interface->GetInt32Value(state);
  4507. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4508. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4509. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4510. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  4511. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  4512. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  4513. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  4514. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4515. bool ward_was_added = false;
  4516. ZoneServer* zone = spell->caster->GetZone();
  4517. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4518. for (int32 i = 0; i < spell->targets.size(); i++) {
  4519. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4520. if (!target)
  4521. continue;
  4522. if (target->IsEntity()) {
  4523. // If the ward is already active remove it
  4524. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4525. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4526. // Create new ward info
  4527. WardInfo* ward = new WardInfo;
  4528. ward->Spell = spell;
  4529. ward->BaseDamage = damage;
  4530. ward->DamageLeft = damage;
  4531. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  4532. ward->keepWard = keepWard;
  4533. ward->WardType = wardType;
  4534. if (damageAbsorptionPercent > 100)
  4535. damageAbsorptionPercent = 100;
  4536. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  4537. if (damageAbsorptionMaxHealthPercent > 100)
  4538. damageAbsorptionMaxHealthPercent = 100;
  4539. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  4540. ward->RedirectDamagePercent = redirectDamagePercent;
  4541. ward->LastRedirectDamage = 0;
  4542. ward->LastAbsorbedDamage = 0;
  4543. ward->HitCount = 0;
  4544. spell->num_triggers = maxHitCount;
  4545. spell->had_triggers = true;
  4546. spell->cancel_after_all_triggers = false;
  4547. ward->MaxHitCount = maxHitCount;
  4548. if (wardType == WARD_TYPE_MAGICAL)
  4549. ward->DamageType = damageTypes;
  4550. // Add the ward to the entity
  4551. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4552. ward_was_added = true;
  4553. }
  4554. }
  4555. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4556. if (ward_was_added && spell->caster->IsPlayer()) {
  4557. spell->had_dmg_remaining = true;
  4558. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4559. }
  4560. return 0;
  4561. }
  4562. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4563. if (!lua_interface)
  4564. return 0;
  4565. int32 amount = lua_interface->GetInt32Value(state);
  4566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4567. WardInfo* ward = 0;
  4568. ZoneServer* zone = spell->caster->GetZone();
  4569. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4570. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4571. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  4572. ward = target->GetWard(spell->spell->GetSpellID());
  4573. if (ward) {
  4574. ward->DamageLeft += amount;
  4575. if (ward->DamageLeft > ward->BaseDamage)
  4576. ward->DamageLeft = ward->BaseDamage;
  4577. for (int32 i = 0; i < spell->targets.size(); i++) {
  4578. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  4579. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  4580. }
  4581. }
  4582. }
  4583. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4584. if (ward && spell->caster->IsPlayer())
  4585. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  4586. return 0;
  4587. }
  4588. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  4589. if (!lua_interface)
  4590. return 0;
  4591. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4592. if (!spell) {
  4593. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4594. return 0;
  4595. }
  4596. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4597. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4598. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4599. if (ward) {
  4600. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4601. return 1;
  4602. }
  4603. }
  4604. return 0;
  4605. }
  4606. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  4607. if (!lua_interface)
  4608. return 0;
  4609. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4610. if (!spell) {
  4611. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4612. return 0;
  4613. }
  4614. string type = lua_interface->GetStringValue(state, 2);
  4615. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4616. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4617. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4618. if (ward) {
  4619. if (boost::iequals(type, "damageleft"))
  4620. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4621. else if (boost::iequals(type, "basedamage"))
  4622. lua_interface->SetInt32Value(state, ward->BaseDamage);
  4623. else if (boost::iequals(type, "keepward"))
  4624. lua_interface->SetBooleanValue(state, ward->keepWard);
  4625. else if (boost::iequals(type, "wardtype"))
  4626. lua_interface->SetInt32Value(state, ward->WardType);
  4627. else if (boost::iequals(type, "dmgabsorptionpct"))
  4628. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  4629. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  4630. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  4631. else if (boost::iequals(type, "redirectdamagepercent"))
  4632. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  4633. else if (boost::iequals(type, "lastredirectdamage"))
  4634. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  4635. else if (boost::iequals(type, "lastabsorbeddamage"))
  4636. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  4637. else if (boost::iequals(type, "hitcount"))
  4638. lua_interface->SetInt32Value(state, ward->HitCount);
  4639. else if (boost::iequals(type, "maxhitcount"))
  4640. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  4641. else
  4642. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  4643. return 1;
  4644. }
  4645. }
  4646. return 0;
  4647. }
  4648. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  4649. if (!lua_interface)
  4650. return 0;
  4651. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4652. ZoneServer* zone = spell->caster->GetZone();
  4653. Spawn* target = 0;
  4654. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4655. for (int32 i = 0; i < spell->targets.size(); i++) {
  4656. target = zone->GetSpawnByID(spell->targets.at(i));
  4657. if (target && target->IsEntity()) {
  4658. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4659. }
  4660. }
  4661. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_Interrupt(lua_State* state)
  4665. {
  4666. if (!lua_interface)
  4667. return 0;
  4668. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  4669. Spawn* target = lua_interface->GetSpawn(state, 2);
  4670. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4671. if (!caster)
  4672. {
  4673. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  4674. return 0;
  4675. }
  4676. if (!target)
  4677. {
  4678. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  4679. return 0;
  4680. }
  4681. if (!spell) {
  4682. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. if (!target->IsEntity() && !spell)
  4686. {
  4687. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  4688. return 0;
  4689. }
  4690. if (!target && spell) {
  4691. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4692. for (int8 i = 0; i < spell->targets.size(); i++) {
  4693. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  4694. if (!target || !target->IsEntity())
  4695. continue;
  4696. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4697. }
  4698. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4699. }
  4700. else
  4701. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4702. return 0;
  4703. }
  4704. int EQ2Emu_lua_Stealth(lua_State* state) {
  4705. if (!lua_interface)
  4706. return 0;
  4707. int8 type = lua_interface->GetInt8Value(state);
  4708. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4709. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4710. if (!spell) {
  4711. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  4712. return 0;
  4713. }
  4714. ZoneServer* zone = spell->caster->GetZone();
  4715. if (spawn) {
  4716. if (spawn->IsEntity()) {
  4717. if (type == 1) {
  4718. ((Entity*)spawn)->AddStealthSpell(spell);
  4719. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4720. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4721. }
  4722. else if (type == 2) {
  4723. ((Entity*)spawn)->AddInvisSpell(spell);
  4724. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4725. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4726. }
  4727. return 0;
  4728. }
  4729. else {
  4730. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  4731. return 0;
  4732. }
  4733. }
  4734. else {
  4735. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4736. for (int32 i = 0; i < spell->targets.size(); i++) {
  4737. spawn = zone->GetSpawnByID(spell->targets.at(i));
  4738. if (!spawn || !spawn->IsEntity())
  4739. continue;
  4740. if (type == 1) {
  4741. ((Entity*)spawn)->AddStealthSpell(spell);
  4742. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4743. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4744. }
  4745. else if (type == 2) {
  4746. ((Entity*)spawn)->AddInvisSpell(spell);
  4747. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4748. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4749. }
  4750. else {
  4751. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  4752. break;
  4753. }
  4754. }
  4755. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4756. }
  4757. return 0;
  4758. }
  4759. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  4760. if (!lua_interface)
  4761. return 0;
  4762. Spawn* spawn = lua_interface->GetSpawn(state);
  4763. if (!spawn) {
  4764. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  4765. return 0;
  4766. }
  4767. if (spawn->IsEntity()) {
  4768. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  4769. return 1;
  4770. }
  4771. else
  4772. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  4773. return 0;
  4774. }
  4775. int EQ2Emu_lua_IsInvis(lua_State* state) {
  4776. if (!lua_interface)
  4777. return 0;
  4778. Spawn* spawn = lua_interface->GetSpawn(state);
  4779. if (!spawn) {
  4780. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  4781. return 0;
  4782. }
  4783. if (spawn->IsEntity()) {
  4784. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  4785. return 1;
  4786. }
  4787. else
  4788. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  4789. return 0;
  4790. }
  4791. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  4792. if (!lua_interface)
  4793. return 0;
  4794. Spawn* player = lua_interface->GetSpawn(state);
  4795. int32 item_id = lua_interface->GetInt32Value(state, 2);
  4796. if (!player->IsPlayer()) {
  4797. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  4801. return 1;
  4802. }
  4803. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  4804. if (!lua_interface)
  4805. return 0;
  4806. Spawn* player = lua_interface->GetSpawn(state);
  4807. int8 slot = lua_interface->GetInt8Value(state, 2);
  4808. if (!player) {
  4809. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  4810. return 0;
  4811. }
  4812. if (!player->IsPlayer()) {
  4813. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  4814. return 0;
  4815. }
  4816. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  4817. if (!item) {
  4818. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  4819. return 0;
  4820. }
  4821. lua_interface->SetItemValue(state, item);
  4822. return 1;
  4823. }
  4824. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  4825. if (!lua_interface)
  4826. return 0;
  4827. Spawn* player = lua_interface->GetSpawn(state);
  4828. int32 id = lua_interface->GetInt32Value(state, 2);
  4829. if (!player) {
  4830. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4831. return 0;
  4832. }
  4833. if (!player->IsPlayer()) {
  4834. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4835. return 0;
  4836. }
  4837. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  4838. if (!item) {
  4839. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  4840. return 0;
  4841. }
  4842. lua_interface->SetItemValue(state, item);
  4843. return 1;
  4844. }
  4845. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  4846. if (!lua_interface)
  4847. return 0;
  4848. Spawn* player = lua_interface->GetSpawn(state);
  4849. int32 id = lua_interface->GetInt32Value(state, 2);
  4850. int8 count = lua_interface->GetInt8Value(state, 3);
  4851. bool include_bank = lua_interface->GetInt8Value(state, 4);
  4852. if (!player) {
  4853. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. if (!player->IsPlayer()) {
  4857. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4858. return 0;
  4859. }
  4860. if (!count)
  4861. count = 1;
  4862. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  4863. if (!item) {
  4864. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. lua_interface->SetItemValue(state, item);
  4868. return 1;
  4869. }
  4870. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  4871. if (!lua_interface)
  4872. return 0;
  4873. Spawn* spawn = lua_interface->GetSpawn(state);
  4874. int32 anim = lua_interface->GetInt32Value(state, 2);
  4875. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  4876. int8 type = lua_interface->GetInt8Value(state, 4);
  4877. if (!spawn) {
  4878. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  4879. return 0;
  4880. }
  4881. if (spawn2) {
  4882. if (spawn2->IsPlayer()) {
  4883. if (type != 1 && type != 2)
  4884. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  4885. else
  4886. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  4887. return 0;
  4888. }
  4889. else {
  4890. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  4891. return 0;
  4892. }
  4893. }
  4894. else
  4895. spawn->GetZone()->PlayAnimation(spawn, anim);
  4896. return 0;
  4897. }
  4898. int EQ2Emu_lua_IsPet(lua_State* state) {
  4899. if (!lua_interface)
  4900. return 0;
  4901. Spawn* spawn = lua_interface->GetSpawn(state);
  4902. if (!spawn) {
  4903. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4904. return 0;
  4905. }
  4906. lua_interface->SetBooleanValue(state, spawn->IsPet());
  4907. return 1;
  4908. }
  4909. int EQ2Emu_lua_GetOwner(lua_State* state) {
  4910. if (!lua_interface)
  4911. return 0;
  4912. Spawn* spawn = lua_interface->GetSpawn(state);
  4913. if (!spawn) {
  4914. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  4915. return 0;
  4916. }
  4917. if (!spawn->IsNPC()) {
  4918. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  4919. return 0;
  4920. }
  4921. if (((NPC*)spawn)->GetOwner()) {
  4922. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  4923. return 1;
  4924. }
  4925. return 0;
  4926. }
  4927. int EQ2Emu_lua_SetTarget(lua_State* state) {
  4928. if (!lua_interface)
  4929. return 0;
  4930. Spawn* spawn = lua_interface->GetSpawn(state);
  4931. Spawn* target = lua_interface->GetSpawn(state, 2);
  4932. if (!spawn) {
  4933. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4934. return 0;
  4935. }
  4936. if (!spawn) {
  4937. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. spawn->SetTarget(target);
  4941. return 0;
  4942. }
  4943. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  4944. if (!lua_interface)
  4945. return 0;
  4946. Spawn* spawn = lua_interface->GetSpawn(state);
  4947. bool val = lua_interface->GetBooleanValue(state, 2);
  4948. if (!spawn) {
  4949. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  4950. return 0;
  4951. }
  4952. if (!spawn->IsEntity()) {
  4953. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. ((Entity*)spawn)->InCombat(val);
  4957. if (val) {
  4958. spawn->ClearRunningLocations();
  4959. spawn->CalculateRunningLocation(true);
  4960. }
  4961. return 0;
  4962. }
  4963. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  4964. if (!lua_interface)
  4965. return 0;
  4966. Spawn* spawn1 = lua_interface->GetSpawn(state);
  4967. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4968. if (!spawn1) {
  4969. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. if (!spawn2) {
  4973. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4974. return 0;
  4975. }
  4976. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  4977. return 1;
  4978. }
  4979. int EQ2Emu_lua_Runback(lua_State* state) {
  4980. if (!lua_interface)
  4981. return 0;
  4982. Spawn* spawn = lua_interface->GetSpawn(state);
  4983. if (!spawn) {
  4984. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  4985. return 0;
  4986. }
  4987. if (!spawn->IsNPC()) {
  4988. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. ((NPC*)spawn)->Runback();
  4992. return 0;
  4993. }
  4994. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  4995. if (!lua_interface)
  4996. return 0;
  4997. Spawn* spawn = lua_interface->GetSpawn(state);
  4998. if (!spawn) {
  4999. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. if (!spawn->IsNPC()) {
  5003. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5004. return 0;
  5005. }
  5006. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5007. return 1;
  5008. }
  5009. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5010. if (!lua_interface)
  5011. return 0;
  5012. Spawn* spawn = lua_interface->GetSpawn(state);
  5013. if (!spawn) {
  5014. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if (!spawn->IsEntity()) {
  5018. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5022. return 1;
  5023. }
  5024. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5025. if (!lua_interface)
  5026. return 0;
  5027. Spawn* spawn = lua_interface->GetSpawn(state);
  5028. if (!spawn) {
  5029. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5030. return 0;
  5031. }
  5032. if (!spawn->IsEntity()) {
  5033. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5034. return 0;
  5035. }
  5036. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5037. return 1;
  5038. }
  5039. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5040. if (!lua_interface)
  5041. return 0;
  5042. Spawn* spawn = lua_interface->GetSpawn(state);
  5043. if (!spawn) {
  5044. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5045. return 0;
  5046. }
  5047. if (!spawn->IsEntity()) {
  5048. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5049. return 0;
  5050. }
  5051. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5052. return 1;
  5053. }
  5054. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5055. if (!lua_interface)
  5056. return 0;
  5057. Spawn* spawn = lua_interface->GetSpawn(state);
  5058. if (!spawn) {
  5059. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5060. return 0;
  5061. }
  5062. if (!spawn->IsEntity()) {
  5063. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5064. return 0;
  5065. }
  5066. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5067. return 1;
  5068. }
  5069. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5070. if (!lua_interface)
  5071. return 0;
  5072. Spawn* spawn = lua_interface->GetSpawn(state);
  5073. Spawn* target = lua_interface->GetSpawn(state, 2);
  5074. float distance = lua_interface->GetFloatValue(state, 3);
  5075. if (!spawn) {
  5076. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5077. return 0;
  5078. }
  5079. if (!target) {
  5080. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5081. return 0;
  5082. }
  5083. if (!spawn->IsNPC()) {
  5084. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5085. return 0;
  5086. }
  5087. if (!target->IsEntity()) {
  5088. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5089. return 0;
  5090. }
  5091. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5092. return 1;
  5093. }
  5094. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5095. if (!lua_interface)
  5096. return 0;
  5097. Spawn* spawn = lua_interface->GetSpawn(state);
  5098. Spawn* target = lua_interface->GetSpawn(state, 2);
  5099. float distance = lua_interface->GetFloatValue(state, 3);
  5100. if (!spawn) {
  5101. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5102. return 0;
  5103. }
  5104. if (!target) {
  5105. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. if (!spawn->IsNPC()) {
  5109. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5110. return 0;
  5111. }
  5112. if (!target->IsEntity()) {
  5113. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5114. return 0;
  5115. }
  5116. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5117. return 0;
  5118. }
  5119. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5120. if (!lua_interface)
  5121. return 0;
  5122. Spawn* spawn = lua_interface->GetSpawn(state);
  5123. if (!spawn) {
  5124. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. if (!spawn->IsNPC()) {
  5128. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5132. return 1;
  5133. }
  5134. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5135. if (!lua_interface)
  5136. return 0;
  5137. Spawn* spawn = lua_interface->GetSpawn(state);
  5138. if (!spawn) {
  5139. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5140. return 0;
  5141. }
  5142. if (!spawn->IsNPC()) {
  5143. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5144. return 0;
  5145. }
  5146. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5147. return 1;
  5148. }
  5149. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5150. if (!lua_interface)
  5151. return 0;
  5152. Spawn* spawn = lua_interface->GetSpawn(state);
  5153. if (!spawn) {
  5154. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5155. return 0;
  5156. }
  5157. if (!spawn->IsNPC()) {
  5158. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5159. return 0;
  5160. }
  5161. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5162. if (hated) {
  5163. lua_interface->SetSpawnValue(state, hated);
  5164. return 1;
  5165. }
  5166. return 0;
  5167. }
  5168. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5169. if (!lua_interface)
  5170. return 0;
  5171. Spawn* spawn = lua_interface->GetSpawn(state);
  5172. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5173. if (!spawn) {
  5174. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5175. return 0;
  5176. }
  5177. if (!spawn->IsNPC()) {
  5178. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5179. return 0;
  5180. }
  5181. if (!hated) {
  5182. ((NPC*)spawn)->Brain()->ClearHate();
  5183. return 0;
  5184. }
  5185. else
  5186. {
  5187. if (!hated->IsEntity()) {
  5188. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5189. return 0;
  5190. }
  5191. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5192. return 0;
  5193. }
  5194. return 0;
  5195. }
  5196. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5197. if (!lua_interface)
  5198. return 0;
  5199. Spawn* spawn = lua_interface->GetSpawn(state);
  5200. if (!spawn) {
  5201. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (!spawn->IsNPC()) {
  5205. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5206. return 0;
  5207. }
  5208. ((NPC*)spawn)->Brain()->ClearEncounter();
  5209. return 0;
  5210. }
  5211. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5212. if (!lua_interface)
  5213. return 0;
  5214. Spawn* spawn = lua_interface->GetSpawn(state);
  5215. if (!spawn) {
  5216. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5217. return 0;
  5218. }
  5219. if (!spawn->IsNPC()) {
  5220. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5221. return 0;
  5222. }
  5223. // Temp list to store hate list
  5224. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5225. if (encounterList->size() == 0) {
  5226. safe_delete(encounterList);
  5227. return 0;
  5228. }
  5229. lua_createtable(state, encounterList->size(), 0);
  5230. int newTable = lua_gettop(state);
  5231. for (int32 i = 0; i < encounterList->size(); i++) {
  5232. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5233. if (temp)
  5234. lua_interface->SetSpawnValue(state, temp);
  5235. lua_rawseti(state, newTable, i + 1);
  5236. }
  5237. safe_delete(encounterList);
  5238. return 1;
  5239. }
  5240. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5241. if (!lua_interface)
  5242. return 0;
  5243. Spawn* spawn = lua_interface->GetSpawn(state);
  5244. if (!spawn) {
  5245. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5246. return 0;
  5247. }
  5248. if (!spawn->IsNPC()) {
  5249. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5250. return 0;
  5251. }
  5252. // Temp list to store hate list
  5253. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5254. if (hateList->size() == 0) {
  5255. safe_delete(hateList);
  5256. return 0;
  5257. }
  5258. lua_createtable(state, hateList->size(), 0);
  5259. int newTable = lua_gettop(state);
  5260. for (int32 i = 0; i < hateList->size(); i++) {
  5261. lua_interface->SetSpawnValue(state, hateList->at(i));
  5262. lua_rawseti(state, newTable, i + 1);
  5263. }
  5264. safe_delete(hateList);
  5265. return 1;
  5266. }
  5267. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5268. if (!lua_interface)
  5269. return 0;
  5270. Spawn* spawn = lua_interface->GetSpawn(state);
  5271. if (!spawn) {
  5272. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5273. return 0;
  5274. }
  5275. if (spawn->IsPlayer()) {
  5276. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5277. lua_interface->SetBooleanValue(state, true);
  5278. else
  5279. lua_interface->SetBooleanValue(state, false);
  5280. return 1;
  5281. }
  5282. else {
  5283. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5284. return 1;
  5285. }
  5286. }
  5287. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5288. if (!lua_interface)
  5289. return 0;
  5290. Quest* quest = lua_interface->GetQuest(state);
  5291. if (!quest) {
  5292. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5293. return 0;
  5294. }
  5295. quest->SetCompletedFlag(true);
  5296. return 0;
  5297. }
  5298. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5299. if (!lua_interface)
  5300. return 0;
  5301. Spawn* spawn = lua_interface->GetSpawn(state);
  5302. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5303. int8 tier = lua_interface->GetInt8Value(state, 3);
  5304. if (!spawn) {
  5305. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5306. return 0;
  5307. }
  5308. if (!spawn->IsEntity()) {
  5309. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5310. return 0;
  5311. }
  5312. if (spellID == 0) {
  5313. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5314. return 0;
  5315. }
  5316. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5317. if (effect) {
  5318. if (tier > 0) {
  5319. // If a tier was passed chec to see if it is the same as the effect
  5320. if (tier == effect->tier)
  5321. lua_interface->SetBooleanValue(state, true);
  5322. else
  5323. lua_interface->SetBooleanValue(state, false);
  5324. return 1;
  5325. }
  5326. else {
  5327. // Have an effect but no tier was passed so return true
  5328. lua_interface->SetBooleanValue(state, true);
  5329. }
  5330. return 1;
  5331. }
  5332. // no effect so return false
  5333. lua_interface->SetBooleanValue(state, false);
  5334. return 1;
  5335. }
  5336. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5337. if (!lua_interface)
  5338. return 0;
  5339. Spawn* spawn = lua_interface->GetSpawn(state);
  5340. int32 id = lua_interface->GetInt32Value(state, 2);
  5341. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5342. Spawn* spawn2 = 0;
  5343. vector<Spawn*> list;
  5344. if (!spawn) {
  5345. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5346. return 0;
  5347. }
  5348. //If zone not provided, use spawn's zone
  5349. if (!zone)
  5350. zone = spawn->GetZone();
  5351. list = zone->GetSpawnsByID(id);
  5352. if (list.size() == 0) {
  5353. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5354. return 0;
  5355. }
  5356. vector<Spawn*>::iterator itr = list.begin();
  5357. for (int8 i = 0; i < list.size(); i++) {
  5358. spawn2 = itr[i];
  5359. if (spawn2)
  5360. spawn2->AddAllowAccessSpawn(spawn);
  5361. }
  5362. return 0;
  5363. }
  5364. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5365. if (!lua_interface)
  5366. return 0;
  5367. Spawn* spawn = lua_interface->GetSpawn(state);
  5368. int32 id = lua_interface->GetInt32Value(state, 2);
  5369. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5370. Spawn* spawn2 = 0;
  5371. if (!spawn) {
  5372. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5373. return 0;
  5374. }
  5375. //If zone not provided, use spawn's zone
  5376. if (!zone)
  5377. zone = spawn->GetZone();
  5378. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5379. vector<Spawn*>::iterator itr = list.begin();
  5380. if (list.size() == 0) {
  5381. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5382. return 0;
  5383. }
  5384. for (int8 i = 0; i < list.size(); i++) {
  5385. spawn2 = itr[i];
  5386. if (spawn2)
  5387. spawn2->RemoveSpawnAccess(spawn);
  5388. }
  5389. return 0;
  5390. }
  5391. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5392. if (!lua_interface)
  5393. return 0;
  5394. Quest* quest = lua_interface->GetQuest(state);
  5395. if (!quest) {
  5396. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5397. return 0;
  5398. }
  5399. quest->SetYellowName(true);
  5400. return 0;
  5401. }
  5402. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5403. if (!lua_interface)
  5404. return 0;
  5405. Spawn* spawn = lua_interface->GetSpawn(state);
  5406. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5407. if (!spawn) {
  5408. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5409. return 0;
  5410. }
  5411. if (!spawn->IsPlayer()) {
  5412. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5413. return 0;
  5414. }
  5415. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5416. return 1;
  5417. }
  5418. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5419. if (!lua_interface)
  5420. return 0;
  5421. Spawn* spawn = lua_interface->GetSpawn(state);
  5422. if (!spawn) {
  5423. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. if (!spawn->IsPlayer()) {
  5427. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. ZoneServer* zone = spawn->GetZone();
  5431. if (!zone) {
  5432. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. Instance_Type iType = zone->GetInstanceType();
  5436. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5437. iType == GROUP_LOCKOUT_INSTANCE ||
  5438. iType == RAID_LOCKOUT_INSTANCE ||
  5439. iType == SOLO_PERSIST_INSTANCE ||
  5440. iType == GROUP_PERSIST_INSTANCE ||
  5441. iType == RAID_PERSIST_INSTANCE) {
  5442. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5443. if (data) {
  5444. // Check to see if the timer has already been set, if it has return out.
  5445. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5446. return 0;
  5447. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5448. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5449. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5450. if (client) {
  5451. string time_msg = "";
  5452. int32 time = data->success_lockout_time;
  5453. int16 hour;
  5454. int8 min;
  5455. int8 sec;
  5456. hour = time / 3600;
  5457. time = time % 3600;
  5458. min = time / 60;
  5459. time = time % 60;
  5460. sec = time;
  5461. if (hour > 0) {
  5462. char temp[10];
  5463. sprintf(temp, " %i", hour);
  5464. time_msg.append(temp);
  5465. time_msg.append(" hour");
  5466. time_msg.append((hour > 1) ? "s" : "");
  5467. }
  5468. if (min > 0) {
  5469. char temp[5];
  5470. sprintf(temp, " %i", min);
  5471. time_msg.append(temp);
  5472. time_msg.append(" minute");
  5473. time_msg.append((min > 1) ? "s" : "");
  5474. }
  5475. // Only add seconds if minutes and hours are 0
  5476. if (hour == 0 && min == 0 && sec > 0) {
  5477. char temp[5];
  5478. sprintf(temp, " %i", sec);
  5479. time_msg.append(temp);
  5480. time_msg.append(" second");
  5481. time_msg.append((sec > 1) ? "s" : "");
  5482. }
  5483. client->Message(CHANNEL_COLOR_YELLOW, "The success zone reuse timer for %s has been set. You can return in%s.", data->zone_name.c_str(), time_msg.c_str());
  5484. }
  5485. }
  5486. else
  5487. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5488. }
  5489. else
  5490. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5491. return 0;
  5492. }
  5493. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5494. if (!lua_interface)
  5495. return 0;
  5496. Spawn* spawn = lua_interface->GetSpawn(state);
  5497. if (!spawn) {
  5498. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5499. return 0;
  5500. }
  5501. if (!spawn->IsPlayer()) {
  5502. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. ZoneServer* zone = spawn->GetZone();
  5506. if (!zone) {
  5507. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. Instance_Type iType = zone->GetInstanceType();
  5511. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5512. iType == GROUP_LOCKOUT_INSTANCE ||
  5513. iType == RAID_LOCKOUT_INSTANCE ||
  5514. iType == SOLO_PERSIST_INSTANCE ||
  5515. iType == GROUP_PERSIST_INSTANCE ||
  5516. iType == RAID_PERSIST_INSTANCE) {
  5517. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5518. if (data) {
  5519. // Check to see if the timer has already been set, if it has return out.
  5520. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5521. return 0;
  5522. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5523. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5524. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5525. if (client) {
  5526. string time_msg = "";
  5527. int32 time = data->failure_lockout_time;
  5528. int16 hour;
  5529. int8 min;
  5530. int8 sec;
  5531. hour = time / 3600;
  5532. time = time % 3600;
  5533. min = time / 60;
  5534. time = time % 60;
  5535. sec = time;
  5536. if (hour > 0) {
  5537. char temp[10];
  5538. sprintf(temp, " %i", hour);
  5539. time_msg.append(temp);
  5540. time_msg.append(" hour");
  5541. time_msg.append((hour > 1) ? "s" : "");
  5542. }
  5543. if (min > 0) {
  5544. char temp[5];
  5545. sprintf(temp, " %i", min);
  5546. time_msg.append(temp);
  5547. time_msg.append(" minute");
  5548. time_msg.append((min > 1) ? "s" : "");
  5549. }
  5550. // Only add seconds if minutes and hours are 0
  5551. if (hour == 0 && min == 0 && sec > 0) {
  5552. char temp[5];
  5553. sprintf(temp, " %i", sec);
  5554. time_msg.append(temp);
  5555. time_msg.append(" second");
  5556. time_msg.append((sec > 1) ? "s" : "");
  5557. }
  5558. client->Message(CHANNEL_COLOR_YELLOW, "The failure zone reuse timer for %s has been set. You can return in%s", data->zone_name.c_str(), time_msg.c_str());
  5559. }
  5560. }
  5561. else
  5562. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5563. }
  5564. else
  5565. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5566. return 0;
  5567. }
  5568. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5569. if (!lua_interface)
  5570. return 0;
  5571. Spawn* spawn = lua_interface->GetSpawn(state);
  5572. if (!spawn) {
  5573. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  5577. return 1;
  5578. }
  5579. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  5580. if (!lua_interface)
  5581. return 0;
  5582. Spawn* player = lua_interface->GetSpawn(state);
  5583. Spawn* ground = lua_interface->GetSpawn(state, 2);
  5584. if (!player) {
  5585. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. if (!player->IsPlayer()) {
  5589. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  5590. return 0;
  5591. }
  5592. if (!ground) {
  5593. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5594. return 0;
  5595. }
  5596. if (!ground->IsGroundSpawn()) {
  5597. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  5598. return 0;
  5599. }
  5600. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5601. if (!groundspawn_entries) {
  5602. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5603. return 0;
  5604. }
  5605. Skill* skill = 0;
  5606. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  5607. if (collection_skill == "Collecting")
  5608. skill = ((Player*)player)->GetSkillByName("Gathering");
  5609. else
  5610. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  5611. if (!skill) {
  5612. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  5613. return 0;
  5614. }
  5615. vector<GroundSpawnEntry*>::iterator itr;
  5616. GroundSpawnEntry* entry = 0;
  5617. bool can_harvest = false;
  5618. sint32 min_skill = -1;
  5619. // first, iterate through groundspawn_entries, discard tables player cannot use
  5620. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  5621. {
  5622. entry = *itr;
  5623. if (min_skill == -1 || entry->min_skill_level < min_skill)
  5624. min_skill = entry->min_skill_level;
  5625. // if player lacks skill, skip table
  5626. if (entry->min_skill_level > skill->current_val)
  5627. continue;
  5628. // if bonus, but player lacks level, skip table
  5629. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  5630. continue;
  5631. can_harvest = true;
  5632. break;
  5633. }
  5634. lua_interface->SetBooleanValue(state, can_harvest);
  5635. // If false, send the message to the client
  5636. if (!can_harvest) {
  5637. Client* client = player->GetZone()->GetClientBySpawn(player);
  5638. if (client) {
  5639. string msg = "You do not have enough skill to ";
  5640. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  5641. msg.append("gather");
  5642. else if (collection_skill == "Mining")
  5643. msg.append("mine");
  5644. else if (collection_skill == "Trapping")
  5645. msg.append("trap");
  5646. else if (collection_skill == "Foresting")
  5647. msg.append("forest");
  5648. else if (collection_skill == "Fishing")
  5649. msg.append("catch");
  5650. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  5651. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  5652. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  5653. }
  5654. }
  5655. return 1;
  5656. }
  5657. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  5658. if (!lua_interface)
  5659. return 0;
  5660. Spawn* player = lua_interface->GetSpawn(state);
  5661. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  5662. if (!player) {
  5663. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  5664. return 0;
  5665. }
  5666. if (!player->IsPlayer()) {
  5667. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  5671. lua_interface->SetBooleanValue(state, ret);
  5672. return 1;
  5673. }
  5674. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  5675. // Check to see if we have a valid lua_interface
  5676. if (!lua_interface)
  5677. return 0;
  5678. // Get the spawn that is getting the pet
  5679. Spawn* spawn = lua_interface->GetSpawn(state);
  5680. Spawn* target = lua_interface->GetSpawn(state, 2);
  5681. // Get the DB ID of the pet
  5682. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  5683. float x = lua_interface->GetFloatValue(state, 4);
  5684. float y = lua_interface->GetFloatValue(state, 5);
  5685. float z = lua_interface->GetFloatValue(state, 6);
  5686. // Get the spell that this command was called from
  5687. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5688. // Check to make sure the spawn pointer is valid
  5689. if (!spawn) {
  5690. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5691. return 0;
  5692. }
  5693. // Check to make sure the spawn is an entity
  5694. if (!spawn->IsEntity()) {
  5695. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5696. return 0;
  5697. }
  5698. if (!target) {
  5699. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  5700. return 0;
  5701. }
  5702. if (!target->IsEntity()) {
  5703. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  5704. return 0;
  5705. }
  5706. // Check to see if the DB ID for the pet is set
  5707. if (pet_id == 0) {
  5708. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. // Check to see if the pointer to the spell is valid
  5712. if (!luaspell) {
  5713. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5717. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5718. if (!pet) {
  5719. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  5720. return 0;
  5721. }
  5722. // Check to make sure the pet is an npc
  5723. if (!pet->IsNPC()) {
  5724. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  5725. return 0;
  5726. }
  5727. if (x == 0)
  5728. x = spawn->GetX();
  5729. if (y == 0)
  5730. y = spawn->GetY();
  5731. if (z == 0)
  5732. z = spawn->GetZ();
  5733. // Spawn the pet at the same location as the owner
  5734. pet->SetX(x);
  5735. pet->SetY(y);
  5736. pet->SetZ(z);
  5737. pet->SetLocation(spawn->GetLocation());
  5738. pet->SetHeading(spawn->GetHeading());
  5739. spawn->GetZone()->AddSpawn(pet);
  5740. /*
  5741. const char* spawn_script = world.GetSpawnScript(pet_id);
  5742. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5743. spawn->SetSpawnScript(string(spawn_script));
  5744. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5745. }*/
  5746. // Get a random pet name
  5747. string random_pet_name;
  5748. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5749. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5750. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5751. // Set the pets name
  5752. pet->SetName(random_pet_name.c_str());
  5753. // Set the level of the pet to the owners level
  5754. pet->SetLevel(spawn->GetLevel());
  5755. // Set the faction of the pet to the same faction as the owner
  5756. pet->SetFactionID(spawn->GetFactionID());
  5757. // Set the spawn as a pet
  5758. pet->SetPet(true);
  5759. // Give a pointer of the owner to the pet
  5760. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5761. // Set the pet type
  5762. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  5763. // Set the spell id used to create this pet
  5764. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5765. // Set the spell tier used to create this pet
  5766. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5767. // Set the pets spawn type to 6
  5768. pet->SetSpawnType(6);
  5769. // Set the pets brain
  5770. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  5771. // Check to see if the pet has a subtitle
  5772. if (strlen(pet->GetSubTitle()) > 0) {
  5773. // Add the players name to the front of the sub title
  5774. string pet_subtitle;
  5775. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5776. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5777. // Set the pets subtitle to the new one
  5778. pet->SetSubTitle(pet_subtitle.c_str());
  5779. }
  5780. // Set the pet as the return value for this function
  5781. lua_interface->SetSpawnValue(state, pet);
  5782. return 1;
  5783. }
  5784. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  5785. if (!lua_interface)
  5786. return 0;
  5787. Spawn* spawn = lua_interface->GetSpawn(state);
  5788. Spawn* player = lua_interface->GetSpawn(state, 2);
  5789. float max_distance = lua_interface->GetFloatValue(state, 3);
  5790. string type = lua_interface->GetStringValue(state, 4);
  5791. if (!spawn || (spawn && spawn->IsPlayer())) {
  5792. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. if (!player || (player && !player->IsPlayer())) {
  5796. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  5797. return 0;
  5798. }
  5799. Client* client = 0;
  5800. if (player->GetZone())
  5801. client = player->GetZone()->GetClientBySpawn(player);
  5802. if (!client) {
  5803. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  5804. return 0;
  5805. }
  5806. //Set max_distance to default if not set or not proper value
  5807. if (max_distance <= 0)
  5808. max_distance = 500;
  5809. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  5810. if (packet) {
  5811. float unknown2_3 = 0;
  5812. int8 placement_mode = 0;
  5813. if (type == "wall") {
  5814. placement_mode = 2;
  5815. unknown2_3 = 150;
  5816. }
  5817. else if (type == "ceiling")
  5818. placement_mode = 1;
  5819. packet->setDataByName("placement_mode", placement_mode);
  5820. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  5821. packet->setDataByName("model_type", spawn->GetModelType());
  5822. packet->setDataByName("unknown", 1); //size
  5823. packet->setDataByName("unknown2", 1); //size 2
  5824. packet->setDataByName("unknown2", .5, 1); //size 3
  5825. packet->setDataByName("unknown2", 3, 2);
  5826. packet->setDataByName("unknown2", unknown2_3, 3);
  5827. packet->setDataByName("max_distance", max_distance);
  5828. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  5829. client->QueuePacket(packet->serialize());
  5830. safe_delete(packet);
  5831. }
  5832. return 0;
  5833. }
  5834. int EQ2Emu_lua_GetItemType(lua_State* state) {
  5835. if (!lua_interface)
  5836. return 0;
  5837. Item* item = lua_interface->GetItem(state);
  5838. if (!item) {
  5839. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  5840. return 0;
  5841. }
  5842. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  5843. return 1;
  5844. }
  5845. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  5846. if (!lua_interface)
  5847. return 0;
  5848. Spawn* spawn = lua_interface->GetSpawn(state);
  5849. if (!spawn) {
  5850. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  5851. return 0;
  5852. }
  5853. if (spawn->GetZone())
  5854. spawn->GetZone()->AddTransportSpawn(spawn);
  5855. return 0;
  5856. }
  5857. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  5858. if (!lua_interface)
  5859. return 0;
  5860. Skill* skill = lua_interface->GetSkill(state);
  5861. if (!skill) {
  5862. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. lua_interface->SetInt32Value(state, skill->current_val);
  5866. return 1;
  5867. }
  5868. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Skill* skill = lua_interface->GetSkill(state);
  5872. if (!skill) {
  5873. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5874. return 0;
  5875. }
  5876. lua_interface->SetInt32Value(state, skill->max_val);
  5877. return 1;
  5878. }
  5879. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  5880. if (!lua_interface)
  5881. return 0;
  5882. Skill* skill = lua_interface->GetSkill(state);
  5883. if (!skill) {
  5884. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  5885. return 0;
  5886. }
  5887. lua_interface->SetStringValue(state, skill->name.data.c_str());
  5888. return 1;
  5889. }
  5890. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  5891. if (!lua_interface)
  5892. return 0;
  5893. Skill* skill = lua_interface->GetSkill(state);
  5894. int16 value = lua_interface->GetInt16Value(state, 2);
  5895. if (!skill) {
  5896. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. skill->max_val = value;
  5900. if (skill->max_val < skill->current_val)
  5901. skill->current_val = skill->max_val;
  5902. return 0;
  5903. }
  5904. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  5905. if (!lua_interface)
  5906. return 0;
  5907. Skill* skill = lua_interface->GetSkill(state);
  5908. int16 value = lua_interface->GetInt16Value(state, 2);
  5909. if (!skill) {
  5910. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5911. return 0;
  5912. }
  5913. if (value > skill->max_val)
  5914. skill->current_val = skill->max_val;
  5915. else
  5916. skill->current_val = value;
  5917. return 0;
  5918. }
  5919. int EQ2Emu_lua_GetSkill(lua_State* state) {
  5920. if (!lua_interface)
  5921. return 0;
  5922. Spawn* spawn = lua_interface->GetSpawn(state);
  5923. string name = lua_interface->GetStringValue(state, 2);
  5924. if (!spawn) {
  5925. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. if (!spawn->IsEntity()) {
  5929. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  5933. if (skill) {
  5934. lua_interface->SetSkillValue(state, skill);
  5935. return 1;
  5936. }
  5937. return 0;
  5938. }
  5939. int EQ2Emu_lua_AddProc(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. Spawn* spawn = lua_interface->GetSpawn(state);
  5943. int8 type = lua_interface->GetInt8Value(state, 2);
  5944. float chance = lua_interface->GetFloatValue(state, 3);
  5945. Item* item = lua_interface->GetItem(state, 4);
  5946. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  5947. LuaSpell* spell = 0;
  5948. if (!spawn && (!spell || !use_all_spelltargets)) {
  5949. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5950. return 0;
  5951. }
  5952. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  5953. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. if (!item)
  5957. spell = lua_interface->GetCurrentSpell(state);
  5958. if (!item && !spell) {
  5959. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5960. return 0;
  5961. }
  5962. if (spell && use_all_spelltargets) {
  5963. Spawn* target;
  5964. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5965. for (int8 i = 0; i < spell->targets.size(); i++) {
  5966. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5967. if (!target || !target->IsEntity())
  5968. continue;
  5969. ((Entity*)target)->AddProc(type, chance, item, spell);
  5970. }
  5971. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5972. }
  5973. else
  5974. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  5975. return 0;
  5976. }
  5977. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  5978. if (!lua_interface)
  5979. return 0;
  5980. Spawn* spawn = lua_interface->GetSpawn(state);
  5981. Item* item = lua_interface->GetItem(state, 2);
  5982. LuaSpell* spell = 0;
  5983. if (!spawn) {
  5984. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5985. return 0;
  5986. }
  5987. if (!spawn->IsEntity()) {
  5988. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5989. return 0;
  5990. }
  5991. if (!item)
  5992. spell = lua_interface->GetCurrentSpell(state);
  5993. if (!item && !spell) {
  5994. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (spell) {
  5998. Spawn* target;
  5999. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6000. for (int8 i = 0; i < spell->targets.size(); i++) {
  6001. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6002. if (!target || !target->IsEntity())
  6003. continue;
  6004. ((Entity*)target)->RemoveProc(item, spell);
  6005. }
  6006. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6007. spell->caster->RemoveProc(item, spell);
  6008. }
  6009. else
  6010. ((Entity*)spawn)->RemoveProc(item, spell);
  6011. return 0;
  6012. }
  6013. int EQ2Emu_lua_Knockback(lua_State* state) {
  6014. if (!lua_interface)
  6015. return 0;
  6016. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6017. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6018. int32 duration = lua_interface->GetInt32Value(state, 3);
  6019. float vertical = lua_interface->GetFloatValue(state, 4);
  6020. float horizontal = lua_interface->GetFloatValue(state, 5);
  6021. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6022. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6023. if (!target_spawn) {
  6024. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6025. return 0;
  6026. }
  6027. if (!spawn) {
  6028. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6032. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6033. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6034. if (packet) {
  6035. packet->setDataByName("target_x", target_spawn->GetX());
  6036. packet->setDataByName("target_y", target_spawn->GetY());
  6037. packet->setDataByName("target_z", target_spawn->GetZ());
  6038. packet->setDataByName("vertical_movement", vertical);
  6039. packet->setDataByName("horizontal_movement", horizontal);
  6040. if (use_heading)
  6041. packet->setDataByName("use_player_heading", 1);
  6042. client->QueuePacket(packet->serialize());
  6043. }
  6044. safe_delete(packet);
  6045. }
  6046. return 0;
  6047. }
  6048. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6049. if (!lua_interface)
  6050. return 0;
  6051. Spawn* spawn = lua_interface->GetSpawn(state);
  6052. if (!spawn) {
  6053. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6057. return 1;
  6058. }
  6059. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* caster = lua_interface->GetSpawn(state);
  6063. Spawn* target = lua_interface->GetSpawn(state, 2);
  6064. string name = lua_interface->GetStringValue(state, 3);
  6065. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6066. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6067. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6068. string success_msg = lua_interface->GetStringValue(state, 7);
  6069. string effect_msg = lua_interface->GetStringValue(state, 8);
  6070. if (!caster) {
  6071. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6072. return 0;
  6073. }
  6074. if (!caster->IsEntity()) {
  6075. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6076. return 0;
  6077. }
  6078. if (!target) {
  6079. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. if (!target->IsEntity()) {
  6083. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. if (name.length() == 0) {
  6087. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6088. return 0;
  6089. }
  6090. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6091. return 0;
  6092. }
  6093. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6094. if (!lua_interface)
  6095. return 0;
  6096. string name = lua_interface->GetStringValue(state);
  6097. if (name.length() == 0) {
  6098. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6099. return 0;
  6100. }
  6101. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6102. if (!skill) {
  6103. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6104. return 0;
  6105. }
  6106. lua_interface->SetInt32Value(state, skill->skill_id);
  6107. return 1;
  6108. }
  6109. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6110. if (!lua_interface)
  6111. return 0;
  6112. Spawn* spawn = lua_interface->GetSpawn(state);
  6113. if (!spawn) {
  6114. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6115. return 0;
  6116. }
  6117. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6118. return 1;
  6119. }
  6120. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6121. if (!lua_interface)
  6122. return 0;
  6123. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6124. if (!luaspell) {
  6125. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6126. return 0;
  6127. }
  6128. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6129. return 1;
  6130. }
  6131. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6132. if (!lua_interface)
  6133. return 0;
  6134. Spawn* spawn = lua_interface->GetSpawn(state);
  6135. Spawn* target = lua_interface->GetSpawn(state, 2);
  6136. if (!spawn) {
  6137. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. if (!spawn->IsEntity()) {
  6141. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6142. return 0;
  6143. }
  6144. if (!target) {
  6145. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6149. return 1;
  6150. }
  6151. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6152. if (!lua_interface)
  6153. return 0;
  6154. Spawn* spawn = lua_interface->GetSpawn(state);
  6155. Spawn* target = lua_interface->GetSpawn(state, 2);
  6156. if (!spawn) {
  6157. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!spawn->IsEntity()) {
  6161. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!target) {
  6165. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6169. return 1;
  6170. }
  6171. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6172. if (!lua_interface)
  6173. return 0;
  6174. Item* item = lua_interface->GetItem(state);
  6175. if (!item) {
  6176. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. lua_interface->SetInt32Value(state, item->details.count);
  6180. return 1;
  6181. }
  6182. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6183. if (!lua_interface)
  6184. return 0;
  6185. Item* item = lua_interface->GetItem(state);
  6186. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6187. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6188. if (!item) {
  6189. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (!owner) {
  6193. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. if (!owner->IsPlayer()) {
  6197. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. if (item->stack_count < new_count) {
  6201. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. if (new_count > 0) {
  6205. item->details.count = new_count;
  6206. item->save_needed = true;
  6207. }
  6208. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6209. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6210. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6211. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6212. else
  6213. {
  6214. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6215. return 0;
  6216. }
  6217. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6218. if (!client)
  6219. return 0;
  6220. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6221. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6222. if (app)
  6223. client->QueuePacket(app);
  6224. return 0;
  6225. }
  6226. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. int32 time = lua_interface->GetInt32Value(state);
  6230. string function = lua_interface->GetStringValue(state, 2);
  6231. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6232. Spawn* target = lua_interface->GetSpawn(state, 4);
  6233. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6234. if (time == 0) {
  6235. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (function.length() == 0) {
  6239. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (!spell) {
  6243. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. SpellScriptTimer* timer = new SpellScriptTimer;
  6247. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6248. #ifdef WIN32
  6249. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6250. #else
  6251. bzero(timer, sizeof(SpellScriptTimer));
  6252. #endif*/
  6253. timer->caster = 0;
  6254. timer->deleteWhenDone = false;
  6255. timer->target = 0;
  6256. timer->time = Timer::GetCurrentTime2() + time;
  6257. timer->customFunction = function;
  6258. timer->spell = spell;
  6259. if (caster)
  6260. timer->caster = caster->GetID();
  6261. if (target)
  6262. timer->target = target->GetID();
  6263. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6264. return 0;
  6265. }
  6266. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6267. if (!lua_interface)
  6268. return 0;
  6269. float hp_perc = lua_interface->GetFloatValue(state);
  6270. float power_perc = lua_interface->GetFloatValue(state, 2);
  6271. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6272. Spawn* target = lua_interface->GetSpawn(state, 4);
  6273. string heal_name = lua_interface->GetStringValue(state, 5);
  6274. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6275. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6276. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6277. if (!spell) {
  6278. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. Entity* caster = spell->caster;
  6282. if (!caster) {
  6283. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6284. return 0;
  6285. }
  6286. Client* client = 0;
  6287. PendingResurrection* rez = 0;
  6288. ZoneServer* zone = spell->caster->GetZone();
  6289. if (!target) {
  6290. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6291. if (spell->targets.size() > 0) {
  6292. vector<int32> spell_targets = spell->targets;
  6293. for (int8 i = 0; i < spell_targets.size(); i++) {
  6294. target = zone->GetSpawnByID(spell_targets.at(i));
  6295. if (!target)
  6296. continue;
  6297. if (!target->IsPlayer())
  6298. continue;
  6299. client = target->GetZone()->GetClientBySpawn(target);
  6300. if (!client)
  6301. continue;
  6302. rez = client->GetCurrentRez();
  6303. if (rez->active)
  6304. continue;
  6305. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6306. rez->active = true;
  6307. rez->caster = caster;
  6308. rez->expire_timer = new Timer;
  6309. int32 duration = spell->spell->GetSpellDuration();
  6310. rez->expire_timer->Start(duration * 100);
  6311. rez->hp_perc = hp_perc;
  6312. rez->mp_perc = power_perc;
  6313. rez->range = spell->spell->GetSpellData()->range;
  6314. rez->spell_name = spell->spell->GetName();
  6315. if (heal_name.length() > 0)
  6316. rez->heal_name = heal_name;
  6317. else
  6318. rez->heal_name = rez->spell_name;
  6319. rez->no_calcs = no_calcs;
  6320. rez->crit_mod = crit_mod;
  6321. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6322. if (send_window)
  6323. client->SendResurrectionWindow();
  6324. else {
  6325. target->GetZone()->ResurrectSpawn(target, client);
  6326. rez->should_delete = true;
  6327. }
  6328. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6329. }
  6330. }
  6331. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6332. }
  6333. else {
  6334. client = target->GetZone()->GetClientBySpawn(target);
  6335. if (!client)
  6336. return 0;
  6337. rez = client->GetCurrentRez();
  6338. if (rez->active)
  6339. return 0;
  6340. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6341. rez->active = true;
  6342. rez->caster = caster;
  6343. rez->expire_timer = new Timer;
  6344. int32 duration = spell->spell->GetSpellDuration();
  6345. rez->expire_timer->Start(duration * 100);
  6346. rez->hp_perc = hp_perc;
  6347. rez->mp_perc = power_perc;
  6348. rez->range = spell->spell->GetSpellData()->range;
  6349. rez->spell_name = spell->spell->GetName();
  6350. if (heal_name.length() > 0)
  6351. rez->heal_name = heal_name;
  6352. else
  6353. rez->heal_name = rez->spell_name;
  6354. rez->no_calcs = no_calcs;
  6355. rez->crit_mod = crit_mod;
  6356. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6357. if (send_window)
  6358. client->SendResurrectionWindow();
  6359. else {
  6360. target->GetZone()->ResurrectSpawn(target, client);
  6361. rez->should_delete = true;
  6362. }
  6363. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6364. }
  6365. return 0;
  6366. }
  6367. int EQ2Emu_lua_SetVision(lua_State* state) {
  6368. if (!lua_interface)
  6369. return 0;
  6370. Spawn* spawn = lua_interface->GetSpawn(state);
  6371. int8 vision = lua_interface->GetInt8Value(state, 2);
  6372. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6373. if (!spawn) {
  6374. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6375. return 0;
  6376. }
  6377. if (!spawn->IsEntity()) {
  6378. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6379. return 0;
  6380. }
  6381. if (spell && spell->targets.size() > 0) {
  6382. ZoneServer* zone = spell->caster->GetZone();
  6383. for (int8 i = 0; i < spell->targets.size(); i++) {
  6384. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6385. if (target->IsEntity()) {
  6386. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6387. if (target->IsPlayer())
  6388. ((Player*)target)->SetCharSheetChanged(true);
  6389. }
  6390. }
  6391. }
  6392. else {
  6393. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6394. if (spawn->IsPlayer())
  6395. ((Player*)spawn)->SetCharSheetChanged(true);
  6396. }
  6397. return 0;
  6398. }
  6399. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6400. if (!lua_interface)
  6401. return 0;
  6402. Spawn* spawn = lua_interface->GetSpawn(state);
  6403. float intensity = lua_interface->GetFloatValue(state, 2);
  6404. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6405. if (!spawn) {
  6406. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6407. return 0;
  6408. }
  6409. if (!spawn->IsEntity()) {
  6410. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (spell && spell->targets.size() > 0) {
  6414. ZoneServer* zone = spell->caster->GetZone();
  6415. for (int8 i = 0; i < spell->targets.size(); i++) {
  6416. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6417. if (target && target->IsEntity()) {
  6418. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6419. if (target->IsPlayer())
  6420. ((Player*)target)->SetCharSheetChanged(true);
  6421. }
  6422. }
  6423. }
  6424. else {
  6425. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6426. if (spawn->IsPlayer())
  6427. ((Player*)spawn)->SetCharSheetChanged(true);
  6428. }
  6429. return 0;
  6430. }
  6431. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6432. if (!lua_interface)
  6433. return 0;
  6434. Spawn* spawn = lua_interface->GetSpawn(state);
  6435. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6436. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6437. if (!spawn) {
  6438. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. if (!spawn->IsEntity()) {
  6442. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. if (spell && spell->targets.size() > 0) {
  6446. ZoneServer* zone = spell->caster->GetZone();
  6447. for (int8 i = 0; i < spell->targets.size(); i++) {
  6448. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6449. if (target->IsEntity()) {
  6450. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6451. if (target->IsPlayer())
  6452. ((Player*)target)->SetCharSheetChanged(true);
  6453. }
  6454. }
  6455. }
  6456. else {
  6457. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6458. if (spawn->IsPlayer())
  6459. ((Player*)spawn)->SetCharSheetChanged(true);
  6460. }
  6461. return 0;
  6462. }
  6463. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6464. if (!lua_interface)
  6465. return 0;
  6466. Item* item = lua_interface->GetItem(state);
  6467. int8 type = lua_interface->GetInt32Value(state, 2);
  6468. if (!item) {
  6469. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. if (type == 1)
  6473. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6474. else if (type == 2)
  6475. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6476. return 1;
  6477. }
  6478. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6479. if (!lua_interface)
  6480. return 0;
  6481. Spawn* target = lua_interface->GetSpawn(state);
  6482. float val = lua_interface->GetFloatValue(state, 2);
  6483. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6484. // Added from Gangrenous post
  6485. if (spell && spell->resisted)
  6486. return 0;
  6487. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6488. if (val > 1.0f)
  6489. val = 1.0f - (val / 100.0f);
  6490. if (spell && spell->spell && spell->targets.size() > 0) {
  6491. ZoneServer* zone = spell->caster->GetZone();
  6492. for (int32 i = 0; i != spell->targets.size(); i++) {
  6493. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6494. if (spawn && spawn->IsEntity()) {
  6495. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6496. if (spawn->IsPlayer())
  6497. ((Player*)spawn)->SetCharSheetChanged(true);
  6498. }
  6499. }
  6500. }
  6501. else {
  6502. if (target && target->IsEntity()) {
  6503. ((Entity*)target)->SetSpeedMultiplier(val);
  6504. if (target->IsPlayer())
  6505. ((Player*)target)->SetCharSheetChanged(true);
  6506. }
  6507. }
  6508. return 0;
  6509. }
  6510. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6511. if (!lua_interface)
  6512. return 0;
  6513. Spawn* spawn = lua_interface->GetSpawn(state);
  6514. int16 model = lua_interface->GetInt16Value(state, 2);
  6515. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6516. if (spell && spell->spell && spell->targets.size() > 0) {
  6517. ZoneServer* zone = spell->caster->GetZone();
  6518. for (int32 i = 0; i < spell->targets.size(); i++) {
  6519. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6520. if (target)
  6521. target->SetIllusionModel(model);
  6522. }
  6523. }
  6524. else {
  6525. if (!spawn) {
  6526. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. spawn->SetIllusionModel(model);
  6530. }
  6531. return 0;
  6532. }
  6533. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6534. if (!lua_interface)
  6535. return 0;
  6536. Spawn* spawn = lua_interface->GetSpawn(state);
  6537. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6538. if (spell && spell->spell && spell->targets.size() > 0) {
  6539. ZoneServer* zone = spell->caster->GetZone();
  6540. for (int32 i = 0; i < spell->targets.size(); i++) {
  6541. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6542. if (target)
  6543. target->SetIllusionModel(0);
  6544. }
  6545. }
  6546. else {
  6547. if (!spawn) {
  6548. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. spawn->SetIllusionModel(0);
  6552. }
  6553. return 0;
  6554. }
  6555. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6556. if (!lua_interface)
  6557. return 0;
  6558. Spawn* caster = lua_interface->GetSpawn(state);
  6559. Spawn* target = lua_interface->GetSpawn(state, 2);
  6560. float chance = lua_interface->GetFloatValue(state, 3);
  6561. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6562. if (!caster) {
  6563. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6564. return 0;
  6565. }
  6566. if (!caster->IsEntity()) {
  6567. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  6568. return 0;
  6569. }
  6570. if (!target) {
  6571. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!target->IsEntity()) {
  6575. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  6576. return 0;
  6577. }
  6578. if (chance <= 0) {
  6579. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  6580. return 0;
  6581. }
  6582. if (!spell) {
  6583. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6584. return 0;
  6585. }
  6586. if (((Entity*)caster)->GetThreatTransfer()) {
  6587. return 0;
  6588. }
  6589. ThreatTransfer* transfer = new ThreatTransfer;
  6590. transfer->Target = target->GetID();
  6591. transfer->Amount = chance;
  6592. transfer->Spell = spell;
  6593. ((Entity*)caster)->SetThreatTransfer(transfer);
  6594. return 0;
  6595. }
  6596. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  6597. if (!lua_interface)
  6598. return 0;
  6599. Spawn* spawn = lua_interface->GetSpawn(state);
  6600. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6601. if (!spawn) {
  6602. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6603. return 0;
  6604. }
  6605. if (!spell) {
  6606. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  6610. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  6611. safe_delete(transfer);
  6612. ((Entity*)spawn)->SetThreatTransfer(0);
  6613. }
  6614. return 0;
  6615. }
  6616. int EQ2Emu_lua_CureByType(lua_State* state) {
  6617. if (!lua_interface)
  6618. return 0;
  6619. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6620. if (!spell) {
  6621. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. int8 cure_count = lua_interface->GetInt8Value(state);
  6625. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6626. string cure_name = lua_interface->GetStringValue(state, 3);
  6627. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6628. Spawn* target = lua_interface->GetSpawn(state, 5);
  6629. if (target) {
  6630. if (!target->IsEntity()) {
  6631. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6632. return 0;
  6633. }
  6634. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6635. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6636. }
  6637. else {
  6638. ZoneServer* zone = spell->caster->GetZone();
  6639. vector<int32> targets = spell->targets;
  6640. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6641. for (int8 i = 0; i < targets.size(); i++) {
  6642. target = zone->GetSpawnByID(targets.at(i));
  6643. if (!target || !target->IsEntity())
  6644. continue;
  6645. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6646. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6647. }
  6648. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6649. }
  6650. return 0;
  6651. }
  6652. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  6653. if (!lua_interface)
  6654. return 0;
  6655. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6656. if (!spell) {
  6657. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6658. return 0;
  6659. }
  6660. int8 cure_count = lua_interface->GetInt8Value(state);
  6661. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6662. string cure_name = lua_interface->GetStringValue(state, 3);
  6663. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6664. Spawn* target = lua_interface->GetSpawn(state, 5);
  6665. if (target) {
  6666. if (!target->IsEntity()) {
  6667. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (((Entity*)target)->GetDetCount() > 0)
  6671. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6672. }
  6673. else {
  6674. ZoneServer* zone = spell->caster->GetZone();
  6675. vector<int32> targets = spell->targets;
  6676. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6677. for (int8 i = 0; i < targets.size(); i++) {
  6678. target = zone->GetSpawnByID(targets.at(i));
  6679. if (!target || !target->IsEntity())
  6680. continue;
  6681. if (((Entity*)target)->GetDetCount() > 0)
  6682. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6683. }
  6684. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6685. }
  6686. return 0;
  6687. }
  6688. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  6689. if (!lua_interface)
  6690. return 0;
  6691. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6692. if (!spell) {
  6693. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  6694. return 0;
  6695. }
  6696. if (!spell->caster) {
  6697. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  6698. return 0;
  6699. }
  6700. if (!spell->caster->GetZone()) {
  6701. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6705. return 0;
  6706. }
  6707. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  6708. if (!lua_interface)
  6709. return 0;
  6710. Spawn* spawn = lua_interface->GetSpawn(state);
  6711. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6712. if (!spell) {
  6713. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6714. return 0;
  6715. }
  6716. if (spawn && spawn->IsEntity())
  6717. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6718. else {
  6719. ZoneServer* zone = spell->caster->GetZone();
  6720. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6721. for (int32 i = 0; i < spell->targets.size(); i++) {
  6722. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6723. if (!spawn || !spawn->IsEntity())
  6724. continue;
  6725. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6726. }
  6727. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6728. }
  6729. return 0;
  6730. }
  6731. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  6732. if (!lua_interface)
  6733. return 0;
  6734. Spawn* spawn = lua_interface->GetSpawn(state);
  6735. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6736. if (!spell) {
  6737. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  6738. return 0;
  6739. }
  6740. if (spawn && spawn->IsEntity())
  6741. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6742. else {
  6743. ZoneServer* zone = spell->caster->GetZone();
  6744. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6745. for (int32 i = 0; i < spell->targets.size(); i++) {
  6746. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6747. if (!spawn || !spawn->IsEntity())
  6748. continue;
  6749. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6750. }
  6751. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6752. }
  6753. return 0;
  6754. }
  6755. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  6756. if (!lua_interface)
  6757. return 0;
  6758. Spawn* caster = lua_interface->GetSpawn(state);
  6759. int8 class_id = lua_interface->GetInt8Value(state, 2);
  6760. if (!caster) {
  6761. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  6762. return 0;
  6763. }
  6764. if (!caster->IsPlayer()) {
  6765. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. Spawn* target = caster->GetTarget();
  6769. if (!target) {
  6770. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  6774. if (!client) {
  6775. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  6776. return 0;
  6777. }
  6778. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  6779. if (ho) {
  6780. ho->SetTarget(target->GetID());
  6781. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  6782. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  6783. if (((Entity*)caster)->GetGroupMemberInfo()) {
  6784. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6785. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  6786. deque<GroupMemberInfo*>::iterator itr;
  6787. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  6788. for (itr = members->begin(); itr != members->end(); itr++) {
  6789. if ((*itr)->client)
  6790. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  6791. }
  6792. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  6793. }
  6794. else
  6795. safe_delete(ho);
  6796. }
  6797. else {
  6798. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6799. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  6800. }
  6801. else
  6802. safe_delete(ho);
  6803. }
  6804. }
  6805. return 0;
  6806. }
  6807. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  6808. if (!lua_interface)
  6809. return 0;
  6810. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6811. if (!spell) {
  6812. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6813. return 0;
  6814. }
  6815. int16 triggerCount = lua_interface->GetInt16Value(state);
  6816. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  6817. if (!triggerCount) {
  6818. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. spell->num_triggers = triggerCount;
  6822. spell->had_triggers = true;
  6823. spell->cancel_after_all_triggers = cancel_after_triggers;
  6824. return 0;
  6825. }
  6826. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  6827. if (!lua_interface)
  6828. return 0;
  6829. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6830. if (!spell) {
  6831. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6832. return 0;
  6833. }
  6834. lua_interface->SetInt32Value(state, spell->num_triggers);
  6835. return 1;
  6836. }
  6837. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  6838. if (!lua_interface)
  6839. return 0;
  6840. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6841. if (!spell) {
  6842. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6843. return 0;
  6844. }
  6845. int16 remove_count = lua_interface->GetInt16Value(state);
  6846. if (!remove_count)
  6847. remove_count = 1;
  6848. if (remove_count >= spell->num_triggers) {
  6849. spell->num_triggers = 0;
  6850. if (spell->cancel_after_all_triggers)
  6851. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6852. }
  6853. else {
  6854. spell->num_triggers -= remove_count;
  6855. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  6856. }
  6857. return 0;
  6858. }
  6859. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  6860. if (!lua_interface)
  6861. return 0;
  6862. Spawn* spawn = lua_interface->GetSpawn(state);
  6863. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  6864. if (!spawn) {
  6865. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  6866. return 0;
  6867. }
  6868. if (!copy_spawn) {
  6869. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  6870. return 0;
  6871. }
  6872. spawn->CopySpawnAppearance(copy_spawn);
  6873. return 0;
  6874. }
  6875. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  6876. if (!lua_interface)
  6877. return 0;
  6878. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6879. int8 type = lua_interface->GetInt8Value(state);
  6880. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6881. if (!spell) {
  6882. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6883. return 0;
  6884. }
  6885. if (spawn) {
  6886. if (!spawn->IsEntity()) {
  6887. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6888. return 0;
  6889. }
  6890. Entity* entity = ((Entity*)spawn);
  6891. switch (type) {
  6892. case IMMUNITY_TYPE_AOE:
  6893. entity->AddAOEImmunity(spell);
  6894. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6895. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6896. break;
  6897. case IMMUNITY_TYPE_STUN:
  6898. entity->AddStunImmunity(spell);
  6899. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6900. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6901. break;
  6902. case IMMUNITY_TYPE_ROOT:
  6903. entity->AddRootImmunity(spell);
  6904. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6905. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6906. break;
  6907. case IMMUNITY_TYPE_DAZE:
  6908. entity->AddDazeImmunity(spell);
  6909. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6910. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6911. break;
  6912. case IMMUNITY_TYPE_FEAR:
  6913. entity->AddFearImmunity(spell);
  6914. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6915. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6916. break;
  6917. case IMMUNITY_TYPE_MEZ:
  6918. entity->AddMezImmunity(spell);
  6919. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6920. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6921. break;
  6922. case IMMUNITY_TYPE_STIFLE:
  6923. entity->AddStifleImmunity(spell);
  6924. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6925. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6926. break;
  6927. default:
  6928. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6929. }
  6930. }
  6931. else {
  6932. bool should_break = false;
  6933. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6934. for (int8 i = 0; i < spell->targets.size(); i++) {
  6935. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6936. if (!spawn || !spawn->IsEntity())
  6937. continue;
  6938. Entity* entity = ((Entity*)spawn);
  6939. switch (type) {
  6940. case IMMUNITY_TYPE_AOE:
  6941. entity->AddAOEImmunity(spell);
  6942. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6943. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6944. break;
  6945. case IMMUNITY_TYPE_STUN:
  6946. entity->AddStunImmunity(spell);
  6947. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6948. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6949. break;
  6950. case IMMUNITY_TYPE_ROOT:
  6951. entity->AddRootImmunity(spell);
  6952. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6953. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6954. break;
  6955. case IMMUNITY_TYPE_DAZE:
  6956. entity->AddDazeImmunity(spell);
  6957. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6958. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6959. break;
  6960. case IMMUNITY_TYPE_FEAR:
  6961. entity->AddFearImmunity(spell);
  6962. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6963. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6964. break;
  6965. case IMMUNITY_TYPE_MEZ:
  6966. entity->AddMezImmunity(spell);
  6967. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6968. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6969. break;
  6970. case IMMUNITY_TYPE_STIFLE:
  6971. entity->AddStifleImmunity(spell);
  6972. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6973. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6974. break;
  6975. default:
  6976. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6977. should_break = true;
  6978. }
  6979. if (should_break)
  6980. break;
  6981. }
  6982. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6983. }
  6984. return 0;
  6985. }
  6986. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  6987. if (!lua_interface)
  6988. return 0;
  6989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6990. int8 type = lua_interface->GetInt8Value(state);
  6991. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6992. if (!spell) {
  6993. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6994. return 0;
  6995. }
  6996. if (spawn) {
  6997. if (!spawn->IsEntity()) {
  6998. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6999. return 0;
  7000. }
  7001. Entity* entity = ((Entity*)spawn);
  7002. switch (type) {
  7003. case IMMUNITY_TYPE_AOE:
  7004. entity->RemoveAOEImmunity(spell);
  7005. break;
  7006. case IMMUNITY_TYPE_STUN:
  7007. entity->RemoveStunImmunity(spell);
  7008. break;
  7009. case IMMUNITY_TYPE_ROOT:
  7010. entity->RemoveRootImmunity(spell);
  7011. break;
  7012. case IMMUNITY_TYPE_DAZE:
  7013. entity->RemoveDazeImmunity(spell);
  7014. break;
  7015. case IMMUNITY_TYPE_FEAR:
  7016. entity->RemoveFearImmunity(spell);
  7017. break;
  7018. case IMMUNITY_TYPE_MEZ:
  7019. entity->RemoveMezImmunity(spell);
  7020. break;
  7021. case IMMUNITY_TYPE_STIFLE:
  7022. entity->RemoveStifleImmunity(spell);
  7023. break;
  7024. default:
  7025. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7026. }
  7027. }
  7028. else {
  7029. bool should_break = false;
  7030. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7031. for (int8 i = 0; i < spell->targets.size(); i++) {
  7032. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7033. if (!spawn || !spawn->IsEntity())
  7034. continue;
  7035. Entity* entity = ((Entity*)spawn);
  7036. switch (type) {
  7037. case IMMUNITY_TYPE_AOE:
  7038. entity->RemoveAOEImmunity(spell);
  7039. break;
  7040. case IMMUNITY_TYPE_STUN:
  7041. entity->RemoveStunImmunity(spell);
  7042. break;
  7043. case IMMUNITY_TYPE_ROOT:
  7044. entity->RemoveRootImmunity(spell);
  7045. break;
  7046. case IMMUNITY_TYPE_DAZE:
  7047. entity->RemoveDazeImmunity(spell);
  7048. break;
  7049. case IMMUNITY_TYPE_FEAR:
  7050. entity->RemoveFearImmunity(spell);
  7051. break;
  7052. case IMMUNITY_TYPE_MEZ:
  7053. entity->RemoveMezImmunity(spell);
  7054. break;
  7055. case IMMUNITY_TYPE_STIFLE:
  7056. entity->RemoveStifleImmunity(spell);
  7057. break;
  7058. default:
  7059. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7060. should_break = true;
  7061. }
  7062. if (should_break)
  7063. break;
  7064. }
  7065. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7066. }
  7067. return 0;
  7068. }
  7069. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7070. if (!lua_interface)
  7071. return 0;
  7072. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7073. if (!spell) {
  7074. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7075. return 0;
  7076. }
  7077. float snare = lua_interface->GetFloatValue(state);
  7078. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7079. // convert the val to the speed multipler value (100 - val)
  7080. float val = 100.0 - snare;
  7081. val /= 100.0;
  7082. if (spawn) {
  7083. if (!spawn->IsEntity()) {
  7084. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. ((Entity*)spawn)->SetSnareValue(spell, val);
  7088. }
  7089. else {
  7090. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7091. for (int8 i = 0; i < spell->targets.size(); i++) {
  7092. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7093. if (!spawn || !spawn->IsEntity())
  7094. continue;
  7095. ((Entity*)spawn)->SetSnareValue(spell, val);
  7096. }
  7097. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7098. }
  7099. return 0;
  7100. }
  7101. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7102. if (!lua_interface)
  7103. return 0;
  7104. Spawn* spawn = lua_interface->GetSpawn(state);
  7105. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7106. if (!spawn) {
  7107. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7108. return 0;
  7109. }
  7110. if (race_id == 0) {
  7111. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7115. return 1;
  7116. }
  7117. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7118. if (!lua_interface)
  7119. return 0;
  7120. Spawn* spawn = lua_interface->GetSpawn(state);
  7121. if (!spawn) {
  7122. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7123. return 0;
  7124. }
  7125. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7126. return 1;
  7127. }
  7128. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7129. if (!lua_interface)
  7130. return 0;
  7131. Spawn* spawn = lua_interface->GetSpawn(state);
  7132. if (!spawn) {
  7133. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7137. return 1;
  7138. }
  7139. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7140. if (!lua_interface)
  7141. return 0;
  7142. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7143. if (!spell) {
  7144. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7145. return 0;
  7146. }
  7147. lua_interface->SetStringValue(state, spell->spell->GetName());
  7148. return 1;
  7149. }
  7150. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7151. if (!lua_interface)
  7152. return 0;
  7153. Quest* quest = lua_interface->GetQuest(state);
  7154. if (!quest) {
  7155. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7156. return 0;
  7157. }
  7158. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7159. return 1;
  7160. }
  7161. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7162. if (!lua_interface)
  7163. return 0;
  7164. Quest* quest = lua_interface->GetQuest(state);
  7165. int32 flags = lua_interface->GetInt32Value(state, 2);
  7166. if (!quest) {
  7167. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7168. return 0;
  7169. }
  7170. quest->SetQuestFlags(flags);
  7171. return 0;
  7172. }
  7173. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7174. if (!lua_interface)
  7175. return 0;
  7176. Quest* quest = lua_interface->GetQuest(state);
  7177. Spawn* player = lua_interface->GetSpawn(state, 2);
  7178. int32 step = lua_interface->GetInt32Value(state, 3);
  7179. int32 duration = lua_interface->GetInt32Value(state, 4);
  7180. string action = lua_interface->GetStringValue(state, 5);
  7181. if (!quest) {
  7182. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7183. return 0;
  7184. }
  7185. if (!player) {
  7186. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7187. return 0;
  7188. }
  7189. if (!player->IsPlayer()) {
  7190. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7191. return 0;
  7192. }
  7193. if (step == 0) {
  7194. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7195. return 0;
  7196. }
  7197. if (duration == 0) {
  7198. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (action.length() == 0) {
  7202. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. Client* client = player->GetZone()->GetClientBySpawn(player);
  7206. if (!client) {
  7207. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7208. return 0;
  7209. }
  7210. quest->SetTimerStep(step);
  7211. quest->AddFailedAction(step, action);
  7212. quest->SetStepTimer(duration);
  7213. client->AddQuestTimer(quest->GetQuestID());
  7214. return 0;
  7215. }
  7216. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7217. if (!lua_interface)
  7218. return 0;
  7219. Quest* quest = lua_interface->GetQuest(state);
  7220. Spawn* player = lua_interface->GetSpawn(state, 2);
  7221. if (!quest) {
  7222. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7223. return 0;
  7224. }
  7225. if (!player) {
  7226. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7227. return 0;
  7228. }
  7229. if (!player->IsPlayer()) {
  7230. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7231. return 0;
  7232. }
  7233. Client* client = player->GetZone()->GetClientBySpawn(player);
  7234. if (!client) {
  7235. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7236. return 0;
  7237. }
  7238. quest->SetTimerStep(0);
  7239. quest->SetStepTimer(0);
  7240. client->RemoveQuestTimer(quest->GetQuestID());
  7241. return 0;
  7242. }
  7243. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7244. if (!lua_interface)
  7245. return 0;
  7246. Spawn* player = lua_interface->GetSpawn(state);
  7247. Quest* quest = lua_interface->GetQuest(state, 2);
  7248. int32 step = lua_interface->GetInt32Value(state, 3);
  7249. if (!player) {
  7250. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!player->IsPlayer()) {
  7254. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!quest) {
  7258. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (step == 0) {
  7262. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. Client* client = player->GetZone()->GetClientBySpawn(player);
  7266. if (!client) {
  7267. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (quest->RemoveQuestStep(step, client)) {
  7271. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7272. client->GetCurrentZone()->SendQuestUpdates(client);
  7273. }
  7274. else
  7275. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7276. return 0;
  7277. }
  7278. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7279. if (!lua_interface)
  7280. return 0;
  7281. Quest* quest = lua_interface->GetQuest(state, 1);
  7282. int32 step = lua_interface->GetInt32Value(state, 2);
  7283. string desc = lua_interface->GetStringValue(state, 3);
  7284. string task_group = lua_interface->GetStringValue(state, 4);
  7285. if (!quest) {
  7286. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7287. return 0;
  7288. }
  7289. if (step == 0) {
  7290. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. QuestStep* quest_step = quest->GetQuestStep(step);
  7294. if (!quest_step) {
  7295. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7296. return 0;
  7297. }
  7298. quest_step->SetStepProgress(0);
  7299. quest_step->SetTaskGroup(task_group);
  7300. quest_step->SetDescription(desc);
  7301. return 0;
  7302. }
  7303. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7304. if (!lua_interface)
  7305. return 0;
  7306. Quest* quest = lua_interface->GetQuest(state);
  7307. int32 step = lua_interface->GetInt32Value(state, 2);
  7308. string action = lua_interface->GetStringValue(state, 3);
  7309. if (!quest) {
  7310. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. if (step == 0) {
  7314. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (action.length() == 0) {
  7318. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. quest->AddFailedAction(step, action);
  7322. return 0;
  7323. }
  7324. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7325. if (!lua_interface)
  7326. return 0;
  7327. Spawn* player = lua_interface->GetSpawn(state);
  7328. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7329. int32 step = lua_interface->GetInt32Value(state, 3);
  7330. if (!player) {
  7331. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7332. return 0;
  7333. }
  7334. if (!player->IsPlayer()) {
  7335. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. if (quest_id == 0) {
  7339. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. if (step == 0) {
  7343. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7344. return 0;
  7345. }
  7346. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7347. if (!quest) {
  7348. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7349. return 0;
  7350. }
  7351. quest->StepFailed(step);
  7352. return 0;
  7353. }
  7354. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7355. if (!lua_interface)
  7356. return 0;
  7357. Spawn* player = lua_interface->GetSpawn(state);
  7358. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7359. if (!player) {
  7360. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7361. return 0;
  7362. }
  7363. if (!player->IsPlayer()) {
  7364. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7365. return 0;
  7366. }
  7367. if (quest_id == 0) {
  7368. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7372. if (!quest) {
  7373. lua_interface->SetInt32Value(state, 0);
  7374. return 1;
  7375. }
  7376. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7377. return 1;
  7378. }
  7379. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7380. if (!lua_interface)
  7381. return 0;
  7382. string name = lua_interface->GetStringValue(state);
  7383. string value = lua_interface->GetStringValue(state, 2);
  7384. string comment = lua_interface->GetStringValue(state, 3);
  7385. if (name.length() == 0) {
  7386. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7387. return 0;
  7388. }
  7389. if (value.length() == 0) {
  7390. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7391. return 0;
  7392. }
  7393. string varname = string("lua_").append(name);
  7394. Variable* var = variables.FindVariable(varname);
  7395. if (var)
  7396. var->SetValue(value.c_str());
  7397. else {
  7398. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7399. variables.AddVariable(var);
  7400. }
  7401. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7402. return 0;
  7403. }
  7404. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7405. if (!lua_interface)
  7406. return 0;
  7407. string name = lua_interface->GetStringValue(state);
  7408. if (name.length() == 0) {
  7409. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. string varname = string("lua_").append(name);
  7413. Variable* var = variables.FindVariable(varname);
  7414. if (var)
  7415. lua_interface->SetStringValue(state, var->GetValue());
  7416. else
  7417. lua_interface->SetStringValue(state, "NULL");
  7418. return 1;
  7419. }
  7420. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7421. if (!lua_interface)
  7422. return 0;
  7423. Spawn* player = lua_interface->GetSpawn(state);
  7424. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7425. if (!player) {
  7426. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. if (!player->IsPlayer()) {
  7430. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7431. return 0;
  7432. }
  7433. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7434. return 1;
  7435. }
  7436. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7437. if (!lua_interface)
  7438. return 0;
  7439. Spawn* player = lua_interface->GetSpawn(state);
  7440. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7441. if (!player) {
  7442. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7443. return 0;
  7444. }
  7445. if (!player->IsPlayer()) {
  7446. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. Language* language = master_languages_list.GetLanguage(language_id);
  7450. if (language)
  7451. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7452. return 0;
  7453. }
  7454. int EQ2Emu_lua_IsNight(lua_State* state) {
  7455. if (!lua_interface)
  7456. return 0;
  7457. ZoneServer* zone = lua_interface->GetZone(state);
  7458. if (!zone) {
  7459. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7460. return 0;
  7461. }
  7462. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7463. return 1;
  7464. }
  7465. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7466. if (!lua_interface)
  7467. return 0;
  7468. Spawn* spawn = lua_interface->GetSpawn(state);
  7469. if (!spawn) {
  7470. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7471. return 0;
  7472. }
  7473. if (!spawn->IsWidget()) {
  7474. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. ((Widget*)spawn)->SetMultiFloorLift(true);
  7478. if (spawn->GetZone())
  7479. spawn->GetZone()->AddTransportSpawn(spawn);
  7480. return 0;
  7481. }
  7482. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7483. if (!lua_interface)
  7484. return 0;
  7485. Spawn* player = lua_interface->GetSpawn(state);
  7486. int32 path = lua_interface->GetInt32Value(state, 2);
  7487. if (!player) {
  7488. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7489. return 0;
  7490. }
  7491. if (!player->IsPlayer()) {
  7492. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7493. return 0;
  7494. }
  7495. if (path == 0) {
  7496. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. Client* client = player->GetZone()->GetClientBySpawn(player);
  7500. if (!client) {
  7501. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7502. return 0;
  7503. }
  7504. client->SetPendingFlightPath(path);
  7505. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  7506. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  7507. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  7508. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", client->GetVersion());
  7509. if (packet) {
  7510. client->QueuePacket(packet->serialize());
  7511. safe_delete(packet);
  7512. }
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Spawn* player = lua_interface->GetSpawn(state);
  7519. if (!player) {
  7520. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7521. return 0;
  7522. }
  7523. if (!player->IsPlayer()) {
  7524. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7525. return 0;
  7526. }
  7527. Client* client = player->GetZone()->GetClientBySpawn(player);
  7528. if (!client) {
  7529. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. client->EndAutoMount();
  7533. return 0;
  7534. }
  7535. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7536. if (!lua_interface)
  7537. return 0;
  7538. Spawn* player = lua_interface->GetSpawn(state);
  7539. if (!player) {
  7540. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  7541. return 0;
  7542. }
  7543. if (!player->IsPlayer()) {
  7544. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7545. return 0;
  7546. }
  7547. Client* client = player->GetZone()->GetClientBySpawn(player);
  7548. if (!client) {
  7549. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7550. return 0;
  7551. }
  7552. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7553. return 1;
  7554. }
  7555. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7556. if (!lua_interface)
  7557. return 0;
  7558. Spawn* player = lua_interface->GetSpawn(state);
  7559. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7560. int32 value = lua_interface->GetInt32Value(state, 3);
  7561. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7562. if (!player) {
  7563. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7564. return 0;
  7565. }
  7566. if (!player->IsPlayer()) {
  7567. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7568. return 0;
  7569. }
  7570. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7571. return 0;
  7572. }
  7573. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  7574. if (!lua_interface)
  7575. return 0;
  7576. Spawn* player = lua_interface->GetSpawn(state);
  7577. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7578. if (!player) {
  7579. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. if (!player->IsPlayer()) {
  7583. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7584. return 0;
  7585. }
  7586. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  7587. if (!hd)
  7588. return 0;
  7589. lua_interface->SetInt32Value(state, hd->Value);
  7590. lua_interface->SetInt32Value(state, hd->Value2);
  7591. return 2;
  7592. }
  7593. int EQ2Emu_lua_SetGridID(lua_State* state) {
  7594. if (!lua_interface)
  7595. return 0;
  7596. Spawn* spawn = lua_interface->GetSpawn(state);
  7597. int32 grid = lua_interface->GetInt32Value(state, 2);
  7598. if (!spawn) {
  7599. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7600. return 0;
  7601. }
  7602. if (grid == 0) {
  7603. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  7604. return 0;
  7605. }
  7606. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  7607. return 0;
  7608. }
  7609. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  7610. if (!lua_interface)
  7611. return 0;
  7612. Spawn* spawn = lua_interface->GetSpawn(state);
  7613. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7614. int32 value1 = lua_interface->GetInt32Value(state, 3);
  7615. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7616. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  7617. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  7618. if (!spawn) {
  7619. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7620. return 0;
  7621. }
  7622. //Add this quest to the list of required quests for this spawn
  7623. spawn->SetRequiredHistory(event_id, value1, value2);
  7624. //If private spawn value set
  7625. if (private_spawn) {
  7626. //Set the spawn to be private when not granted access via history
  7627. spawn->AddAllowAccessSpawn(spawn);
  7628. spawn->SetPrivateQuestSpawn(true);
  7629. }
  7630. //This value will override vis_flags in the vis packet
  7631. if (flag_override > 0)
  7632. spawn->SetQuestsRequiredOverride(flag_override);
  7633. return 0;
  7634. }
  7635. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  7636. if (!lua_interface)
  7637. return 0;
  7638. Spawn* player = lua_interface->GetSpawn(state);
  7639. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7640. int32 step_id = lua_interface->GetInt32Value(state, 3);
  7641. if (!player) {
  7642. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. if (!player->IsPlayer()) {
  7646. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  7647. return 0;
  7648. }
  7649. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  7650. return 1;
  7651. }
  7652. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  7653. if (!lua_interface)
  7654. return 0;
  7655. Spawn* player = lua_interface->GetSpawn(state);
  7656. int8 level = lua_interface->GetInt8Value(state, 2);
  7657. if (!player) {
  7658. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (!player->IsPlayer()) {
  7662. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. if (level == 0) {
  7666. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  7667. return 0;
  7668. }
  7669. Client* client = player->GetZone()->GetClientBySpawn(player);
  7670. if (!client) {
  7671. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  7672. return 0;
  7673. }
  7674. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  7675. client->GetPlayer()->SetXP(1);
  7676. client->GetPlayer()->SetNeededXP();
  7677. return 0;
  7678. }
  7679. int EQ2Emu_lua_AddCoin(lua_State* state) {
  7680. if (!lua_interface)
  7681. return 0;
  7682. Spawn* player = lua_interface->GetSpawn(state);
  7683. int32 amount = lua_interface->GetInt32Value(state, 2);
  7684. if (!player) {
  7685. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (!player->IsPlayer()) {
  7689. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7690. return 0;
  7691. }
  7692. if (amount == 0) {
  7693. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. ((Player*)player)->AddCoins(amount);
  7697. return 0;
  7698. }
  7699. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  7700. if (!lua_interface)
  7701. return 0;
  7702. Spawn* player = lua_interface->GetSpawn(state);
  7703. int32 amount = lua_interface->GetInt32Value(state, 2);
  7704. if (!player) {
  7705. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if (!player->IsPlayer()) {
  7709. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7710. return 0;
  7711. }
  7712. if (amount == 0) {
  7713. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7714. return 0;
  7715. }
  7716. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  7717. return 1;
  7718. }
  7719. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  7720. if (!lua_interface)
  7721. return 0;
  7722. ZoneServer* zone = lua_interface->GetZone(state);
  7723. if (!zone) {
  7724. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7725. return 0;
  7726. }
  7727. vector<Entity*> players = zone->GetPlayers();
  7728. if (players.size() == 0)
  7729. return 0;
  7730. lua_createtable(state, players.size(), 0);
  7731. int newTable = lua_gettop(state);
  7732. for (int32 i = 0; i < players.size(); i++) {
  7733. lua_interface->SetSpawnValue(state, players.at(i));
  7734. lua_rawseti(state, newTable, i + 1);
  7735. }
  7736. return 1;
  7737. }
  7738. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  7739. if (!lua_interface)
  7740. return 0;
  7741. ZoneServer* zone = lua_interface->GetZone(state, 1);
  7742. if (!zone) {
  7743. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7744. return 0;
  7745. }
  7746. int32 group_id = lua_interface->GetInt32Value(state, 2);
  7747. //Map of <placement_id, location_id>
  7748. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  7749. map<int32, int32>::iterator itr;
  7750. vector<Spawn*> group;
  7751. for (itr = locs->begin(); itr != locs->end(); itr++) {
  7752. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  7753. if (!location) {
  7754. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  7755. return 0;
  7756. }
  7757. Spawn* spawn = 0;
  7758. if (location->entities[0]) {
  7759. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  7760. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  7761. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  7762. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  7763. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  7764. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  7765. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  7766. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  7767. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  7768. spawn = zone->AddSignSpawn(location, location->entities[0]);
  7769. if (spawn) {
  7770. const char* script = 0;
  7771. for (int x = 0; x < 3; x++) {
  7772. switch (x) {
  7773. case 0:
  7774. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  7775. break;
  7776. case 1:
  7777. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  7778. break;
  7779. case 2:
  7780. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  7781. break;
  7782. }
  7783. if (script && lua_interface->GetSpawnScript(script) != 0) {
  7784. spawn->SetSpawnScript(string(script));
  7785. break;
  7786. }
  7787. }
  7788. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7789. lua_interface->SetSpawnValue(state, spawn);
  7790. group.push_back(spawn);
  7791. }
  7792. else {
  7793. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  7794. safe_delete(spawn);
  7795. }
  7796. }
  7797. }
  7798. if (!group.empty()) {
  7799. lua_createtable(state, group.size(), 0);
  7800. int newTable = lua_gettop(state);
  7801. for (int32 i = 0; i < group.size(); i++) {
  7802. lua_interface->SetSpawnValue(state, group[i]);
  7803. lua_rawseti(state, newTable, i + 1);
  7804. }
  7805. }
  7806. else
  7807. lua_pushnil(state);
  7808. return 1;
  7809. }
  7810. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  7811. if (!lua_interface)
  7812. return 0;
  7813. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7814. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  7815. int16 leeway = lua_interface->GetInt16Value(state, 3);
  7816. if (!spawn) {
  7817. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  7818. return 0;
  7819. }
  7820. if (anim_id == 0) {
  7821. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  7822. return 0;
  7823. }
  7824. if (leeway == 0)
  7825. leeway = 5000;
  7826. spawn->SetSpawnAnim(anim_id);
  7827. spawn->SetSpawnAnimLeeway(leeway);
  7828. return 0;
  7829. }
  7830. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  7831. if (!lua_interface)
  7832. return 0;
  7833. Spawn* player = lua_interface->GetSpawn(state);
  7834. if (!player) {
  7835. return 0;
  7836. }
  7837. Client* client = player->GetZone()->GetClientBySpawn(player);
  7838. if (!client) {
  7839. return 0;
  7840. }
  7841. lua_interface->SetInt32Value(state, client->GetVersion());
  7842. return 1;
  7843. }
  7844. int EQ2Emu_lua_GetItemID(lua_State* state) {
  7845. if (!lua_interface)
  7846. return 0;
  7847. Item* item = lua_interface->GetItem(state);
  7848. if (!item) {
  7849. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  7850. return 0;
  7851. }
  7852. lua_interface->SetInt32Value(state, item->details.item_id);
  7853. return 1;
  7854. }
  7855. int EQ2Emu_lua_IsEntity(lua_State* state) {
  7856. if (!lua_interface)
  7857. return 0;
  7858. Spawn* spawn = lua_interface->GetSpawn(state);
  7859. if (!spawn) {
  7860. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  7861. return 0;
  7862. }
  7863. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  7864. return 1;
  7865. }
  7866. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  7867. if (!lua_interface)
  7868. return 0;
  7869. Spawn* spawn = lua_interface->GetSpawn(state);
  7870. if (!spawn) {
  7871. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  7872. return 0;
  7873. }
  7874. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  7875. return 1;
  7876. }
  7877. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  7878. if (!lua_interface)
  7879. return 0;
  7880. Spawn* spawn = lua_interface->GetSpawn(state);
  7881. if (!spawn) {
  7882. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  7883. return 0;
  7884. }
  7885. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  7886. return 1;
  7887. }
  7888. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  7889. if (!lua_interface)
  7890. return 0;
  7891. Spawn* spawn = lua_interface->GetSpawn(state);
  7892. if (!spawn) {
  7893. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  7897. return 1;
  7898. }
  7899. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  7900. if (!lua_interface)
  7901. return 0;
  7902. Spawn* spawn = lua_interface->GetSpawn(state);
  7903. float pct = lua_interface->GetFloatValue(state, 2);
  7904. if (!spawn) {
  7905. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. if (pct == 0) {
  7909. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  7913. lua_interface->SetInt32Value(state, amount);
  7914. return 1;
  7915. }
  7916. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  7917. if (!lua_interface)
  7918. return 0;
  7919. Spawn* spawn = lua_interface->GetSpawn(state);
  7920. float pct = lua_interface->GetFloatValue(state, 2);
  7921. if (!spawn) {
  7922. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. if (pct == 0) {
  7926. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  7927. return 0;
  7928. }
  7929. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  7930. lua_interface->SetInt32Value(state, amount);
  7931. return 1;
  7932. }
  7933. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  7934. if (!lua_interface)
  7935. return 0;
  7936. Spawn* spawn = lua_interface->GetSpawn(state);
  7937. if (!spawn) {
  7938. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. if (!spawn->IsPlayer()) {
  7942. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  7943. return 0;
  7944. }
  7945. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  7946. return 1;
  7947. }
  7948. int EQ2Emu_lua_Evac(lua_State* state) {
  7949. if (!lua_interface)
  7950. return 0;
  7951. Spawn* target = lua_interface->GetSpawn(state);
  7952. if (target) {
  7953. float x = target->GetZone()->GetSafeX();
  7954. float y = target->GetZone()->GetSafeY();
  7955. float z = target->GetZone()->GetSafeZ();
  7956. float h = target->GetZone()->GetSafeHeading();
  7957. target->SetX(x);
  7958. target->SetY(y);
  7959. target->SetZ(z);
  7960. target->SetHeading(h);
  7961. target->SetSpawnOrigX(target->GetX());
  7962. target->SetSpawnOrigY(target->GetY());
  7963. target->SetSpawnOrigZ(target->GetZ());
  7964. target->SetSpawnOrigHeading(target->GetHeading());
  7965. if (target->IsPlayer()) {
  7966. Client* client = target->GetZone()->GetClientBySpawn(target);
  7967. if (client) {
  7968. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7969. if (packet)
  7970. {
  7971. packet->setDataByName("x", x);
  7972. packet->setDataByName("y", y);
  7973. packet->setDataByName("z", z);
  7974. client->QueuePacket(packet->serialize());
  7975. safe_delete(packet);
  7976. }
  7977. }
  7978. }
  7979. }
  7980. else {
  7981. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7982. ZoneServer* zone = spell->caster->GetZone();
  7983. float x = spell->caster->GetZone()->GetSafeX();
  7984. float y = spell->caster->GetZone()->GetSafeY();
  7985. float z = spell->caster->GetZone()->GetSafeZ();
  7986. float h = spell->caster->GetZone()->GetSafeHeading();
  7987. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7988. for (int32 i = 0; i < spell->targets.size(); i++) {
  7989. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  7990. if (!target2)
  7991. continue;
  7992. target2->SetX(x);
  7993. target2->SetY(y);
  7994. target2->SetZ(z);
  7995. target2->SetHeading(h);
  7996. target2->SetSpawnOrigX(target2->GetX());
  7997. target2->SetSpawnOrigY(target2->GetY());
  7998. target2->SetSpawnOrigZ(target2->GetZ());
  7999. target2->SetSpawnOrigHeading(target2->GetHeading());
  8000. if (target2->IsPlayer()) {
  8001. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8002. if (client) {
  8003. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8004. if (packet)
  8005. {
  8006. packet->setDataByName("x", x);
  8007. packet->setDataByName("y", y);
  8008. packet->setDataByName("z", z);
  8009. client->QueuePacket(packet->serialize());
  8010. safe_delete(packet);
  8011. }
  8012. }
  8013. }
  8014. }
  8015. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8016. }
  8017. return 0;
  8018. }
  8019. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8020. if (!lua_interface)
  8021. return 0;
  8022. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8023. if (!luaspell) {
  8024. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. int8 tier = luaspell->spell->GetSpellTier();
  8028. lua_interface->SetInt32Value(state, tier);
  8029. return 1;
  8030. }
  8031. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8032. if (!lua_interface)
  8033. return 0;
  8034. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8035. if (!luaspell) {
  8036. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8037. return 0;
  8038. }
  8039. int32 spell_id = luaspell->spell->GetSpellID();
  8040. lua_interface->SetInt32Value(state, spell_id);
  8041. return 1;
  8042. }
  8043. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8044. if (!lua_interface)
  8045. return 0;
  8046. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8047. if (!spawn) {
  8048. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8049. return 0;
  8050. }
  8051. if (!spawn->IsPlayer()) {
  8052. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8053. return 0;
  8054. }
  8055. ZoneServer* zone = spawn->GetZone();
  8056. if (!zone) {
  8057. return 0;
  8058. }
  8059. Client* client = zone->GetClientBySpawn(spawn);
  8060. if (!client) {
  8061. return 0;
  8062. }
  8063. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8064. return 0;
  8065. }
  8066. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8067. if (!lua_interface)
  8068. return 0;
  8069. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8070. if (!spawn) {
  8071. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. if (!spawn->IsPlayer()) {
  8075. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. ZoneServer* zone = spawn->GetZone();
  8079. if (!zone) {
  8080. return 0;
  8081. }
  8082. Client* client = zone->GetClientBySpawn(spawn);
  8083. if (!client) {
  8084. return 0;
  8085. }
  8086. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8087. return 0;
  8088. }
  8089. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8090. if (!lua_interface)
  8091. return 0;
  8092. Spawn* caster = lua_interface->GetSpawn(state);
  8093. Spawn* target = lua_interface->GetSpawn(state, 2);
  8094. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8095. string spell_name = lua_interface->GetStringValue(state, 4);
  8096. if (!caster) {
  8097. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (!caster->IsEntity()) {
  8101. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (!target) {
  8105. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. if (!target->IsEntity()) {
  8109. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8113. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8114. return 0;
  8115. }
  8116. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8117. if (!lua_interface)
  8118. return 0;
  8119. Spawn* spawn = lua_interface->GetSpawn(state);
  8120. Spawn* target = lua_interface->GetSpawn(state, 2);
  8121. if (spawn && target)
  8122. return spawn->CheckLoS(target);
  8123. return 0;
  8124. }
  8125. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8126. if (!lua_interface)
  8127. return 0;
  8128. Spawn* spawn = lua_interface->GetSpawn(state);
  8129. float x = lua_interface->GetFloatValue(state, 2);
  8130. float y = lua_interface->GetFloatValue(state, 3);
  8131. float z = lua_interface->GetFloatValue(state, 4);
  8132. if (spawn)
  8133. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8134. return 0;
  8135. }
  8136. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8137. if (!lua_interface)
  8138. return 0;
  8139. ZoneServer* zone = lua_interface->GetZone(state);
  8140. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8141. if (zone)
  8142. zone->SetExpansionFlag(xpackFlag);
  8143. return 0;
  8144. }
  8145. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8146. if (!lua_interface)
  8147. return 0;
  8148. ZoneServer* zone = lua_interface->GetZone(state);
  8149. if (zone) {
  8150. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8151. return 1;
  8152. }
  8153. return 0;
  8154. }
  8155. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  8156. if (!lua_interface)
  8157. return 0;
  8158. Spawn* spawn = lua_interface->GetSpawn(state);
  8159. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  8160. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  8161. float distance = lua_interface->GetFloatValue(state, 4);
  8162. string in_range_function = lua_interface->GetStringValue(state, 5);
  8163. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  8164. if (spawn && distance > 0 && in_range_function.length() > 0)
  8165. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  8166. return 0;
  8167. }
  8168. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  8169. if (!lua_interface)
  8170. return 0;
  8171. Spawn* spawn = lua_interface->GetSpawn(state);
  8172. Spawn* target = lua_interface->GetSpawn(state, 2);
  8173. if (spawn && target)
  8174. {
  8175. if (spawn->IsPlayer() && target->IsEntity())
  8176. {
  8177. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  8178. return 1;
  8179. }
  8180. else if (spawn->IsEntity() && target->IsEntity())
  8181. {
  8182. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  8183. return 1;
  8184. }
  8185. }
  8186. return 0;
  8187. }
  8188. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  8189. if (!lua_interface)
  8190. return 0;
  8191. Spawn* spawn = lua_interface->GetSpawn(state);
  8192. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  8193. if (spawn && spawn->IsEntity())
  8194. {
  8195. ((Entity*)spawn)->SetSeeInvisSpell(val);
  8196. if (spawn->IsPlayer())
  8197. {
  8198. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  8199. if (client)
  8200. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  8201. }
  8202. }
  8203. return 0;
  8204. }
  8205. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  8206. if (!lua_interface)
  8207. return 0;
  8208. Spawn* spawn = lua_interface->GetSpawn(state);
  8209. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  8210. if (spawn && spawn->IsEntity())
  8211. {
  8212. ((Entity*)spawn)->SetSeeHideSpell(val);
  8213. if (spawn->IsPlayer())
  8214. {
  8215. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  8216. if (client)
  8217. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  8218. }
  8219. }
  8220. return 0;
  8221. }
  8222. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  8223. {
  8224. if (!lua_interface)
  8225. return 0;
  8226. Spawn* player = lua_interface->GetSpawn(state);
  8227. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8228. string command = lua_interface->GetStringValue(state, 3);
  8229. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  8230. if (spawn && player && player->IsPlayer())
  8231. {
  8232. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  8233. bool res = false;
  8234. if (cmd)
  8235. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  8236. lua_interface->SetBooleanValue(state, res);
  8237. return 1;
  8238. }
  8239. return 0;
  8240. }
  8241. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  8242. {
  8243. if (!lua_interface)
  8244. return 0;
  8245. Spawn* spawn = lua_interface->GetSpawn(state);
  8246. string command = lua_interface->GetStringValue(state, 2);
  8247. if (spawn && command.length() > 0)
  8248. spawn->RemovePrimaryEntityCommand(command.c_str());
  8249. return 0;
  8250. }
  8251. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  8252. Spawn* spawn = lua_interface->GetSpawn(state);
  8253. float distance = lua_interface->GetFloatValue(state, 2);
  8254. string command = lua_interface->GetStringValue(state, 3);
  8255. Spawn* player = lua_interface->GetSpawn(state, 4);
  8256. if (spawn) {
  8257. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  8258. }
  8259. return 0;
  8260. }