LuaFunctions.cpp 343 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205
  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 "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include <boost/algorithm/string/predicate.hpp>
  36. #include <sstream>
  37. #include <boost/algorithm/string.hpp>
  38. extern MasterFactionList master_faction_list;
  39. extern WorldDatabase database;
  40. extern LuaInterface* lua_interface;
  41. extern ConfigReader configReader;
  42. extern MasterQuestList master_quest_list;
  43. extern MasterItemList master_item_list;
  44. extern MasterSpellList master_spell_list;
  45. extern World world;
  46. extern Commands commands;
  47. extern ZoneList zone_list;
  48. extern Races races;
  49. extern Classes classes;
  50. extern Variables variables;
  51. extern MasterSkillList master_skill_list;
  52. extern MasterHeroicOPList master_ho_list;
  53. extern MasterRaceTypeList race_types_list;
  54. extern MasterLanguagesList master_languages_list;
  55. extern RuleManager rule_manager;
  56. vector<string> ParseString(string strVal, char delim) {
  57. stringstream ss(strVal);
  58. vector<string> ret;
  59. while (ss.good())
  60. {
  61. string substr;
  62. getline(ss, substr, delim);
  63. ret.push_back(substr);
  64. }
  65. return ret;
  66. }
  67. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  68. stringstream ss(strVal);
  69. vector<unsigned int> ret;
  70. while (ss.good())
  71. {
  72. string substr;
  73. getline(ss, substr, delim);
  74. stringstream valss(substr);
  75. unsigned int val = 0;
  76. valss >> val;
  77. ret.push_back(val);
  78. }
  79. return ret;
  80. }
  81. map<string, signed int> ParseStringMap(string strVal, char delim) {
  82. vector<string> pairs = ParseString(strVal, delim);
  83. vector<string>::iterator itr;
  84. map<string, signed int> ret;
  85. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  86. vector<string> keyvaluepair = ParseString(*itr, ':');
  87. if (keyvaluepair.size() == 2) {
  88. stringstream valss(keyvaluepair[1]);
  89. int32 val = 0;
  90. valss >> val;
  91. ret[keyvaluepair[0]] = val;
  92. }
  93. }
  94. return ret;
  95. }
  96. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  97. vector<string> pairs = ParseString(strVal, delim);
  98. vector<string>::iterator itr;
  99. map<unsigned int, unsigned short> ret;
  100. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  101. vector<string> keyvaluepair = ParseString(*itr, ':');
  102. int32 key = 0;
  103. if (keyvaluepair.size() > 0) {
  104. stringstream keyss(keyvaluepair[0]);
  105. keyss >> key;
  106. }
  107. if (keyvaluepair.size() == 1) {
  108. ret[key] = 1;
  109. }
  110. else if (keyvaluepair.size() == 2) {
  111. stringstream valss(keyvaluepair[1]);
  112. unsigned short val = 0;
  113. valss >> val;
  114. ret[key] = val;
  115. }
  116. }
  117. return ret;
  118. }
  119. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  120. vector<string> pairs = ParseString(strVal, delim);
  121. vector<string>::iterator itr;
  122. map<unsigned int, signed int> ret;
  123. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  124. vector<string> keyvaluepair = ParseString(*itr, ':');
  125. int32 key = 0;
  126. if (keyvaluepair.size() > 0) {
  127. stringstream keyss(keyvaluepair[0]);
  128. keyss >> key;
  129. }
  130. if (keyvaluepair.size() == 1) {
  131. ret[key] = 1;
  132. }
  133. else if (keyvaluepair.size() == 2) {
  134. stringstream valss(keyvaluepair[1]);
  135. signed int val = 0;
  136. valss >> val;
  137. ret[key] = val;
  138. }
  139. }
  140. return ret;
  141. }
  142. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  143. if (!lua_interface)
  144. return 0;
  145. Spawn* spawn = lua_interface->GetSpawn(state);
  146. string mp3_string = lua_interface->GetStringValue(state, 2);
  147. string text_string = lua_interface->GetStringValue(state, 3);
  148. string emote_string = lua_interface->GetStringValue(state, 4);
  149. int32 key1 = lua_interface->GetInt32Value(state, 5);
  150. int32 key2 = lua_interface->GetInt32Value(state, 6);
  151. Spawn* player = lua_interface->GetSpawn(state, 7);
  152. int8 language = lua_interface->GetInt8Value(state, 8);
  153. if (spawn) {
  154. const char* mp3 = 0;
  155. const char* text = 0;
  156. const char* emote = 0;
  157. if (mp3_string.length() > 0)
  158. mp3 = mp3_string.c_str();
  159. if (text_string.length() > 0)
  160. text = text_string.c_str();
  161. if (emote_string.length() > 0)
  162. emote = emote_string.c_str();
  163. Client* client = 0;
  164. if (player && player->IsPlayer())
  165. client = spawn->GetZone()->GetClientBySpawn(player);
  166. if (client) {
  167. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  168. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  169. }
  170. else
  171. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. return 0;
  174. }
  175. int EQ2Emu_lua_PlaySound(lua_State* state) {
  176. if (!lua_interface)
  177. return 0;
  178. Spawn* spawn = lua_interface->GetSpawn(state);
  179. string sound_string = lua_interface->GetStringValue(state, 2);
  180. float x = lua_interface->GetFloatValue(state, 3);
  181. float y = lua_interface->GetFloatValue(state, 4);
  182. float z = lua_interface->GetFloatValue(state, 5);
  183. Spawn* player = lua_interface->GetSpawn(state, 6);
  184. if (spawn && sound_string.length() > 0) {
  185. Client* client = 0;
  186. if (player && player->IsPlayer())
  187. client = spawn->GetZone()->GetClientBySpawn(player);
  188. if (client)
  189. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  190. else
  191. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  192. }
  193. return 0;
  194. }
  195. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  196. if (!lua_interface)
  197. return 0;
  198. Spawn* spawn = lua_interface->GetSpawn(state);
  199. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  200. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  201. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  202. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  203. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  204. if (!spawn) {
  205. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  206. return 0;
  207. }
  208. if (quest_id > 0) {
  209. //Add this quest to the list of required quests for this spawn
  210. spawn->SetQuestsRequired(quest_id, quest_step);
  211. //If private spawn value set
  212. if (private_spawn) {
  213. //Set the spawn to be private when not granted access through this quest
  214. spawn->AddAllowAccessSpawn(spawn);
  215. spawn->SetPrivateQuestSpawn(true);
  216. }
  217. //This value allows access after a quest step, or the whole quest has been completed
  218. if (continued_access)
  219. spawn->SetQuestsRequiredContinuedAccess(true);
  220. //This value will override vis_flags in the vis packet
  221. if (flag_override > 0)
  222. spawn->SetQuestsRequiredOverride(flag_override);
  223. }
  224. return 0;
  225. }
  226. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  227. if (!lua_interface)
  228. return 0;
  229. Spawn* spawn = lua_interface->GetSpawn(state);
  230. float max_distance = lua_interface->GetFloatValue(state, 2);
  231. string variable = lua_interface->GetStringValue(state, 3);
  232. string value = lua_interface->GetStringValue(state, 4);
  233. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  234. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  235. return 0;
  236. }
  237. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  238. if (!lua_interface)
  239. return 0;
  240. Client* client = 0;
  241. Spawn* player = lua_interface->GetSpawn(state);
  242. if (!player) {
  243. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  244. return 0;
  245. }
  246. if (!player->IsPlayer()) {
  247. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  248. return 0;
  249. }
  250. if (player->GetZone())
  251. client = player->GetZone()->GetClientBySpawn(player);
  252. if (!client) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  254. return 0;
  255. }
  256. float intensity = lua_interface->GetFloatValue(state, 2);
  257. int8 direction = lua_interface->GetInt8Value(state, 3);
  258. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  259. if (packet) {
  260. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  261. v1 = *(float *)(a1 + 4);
  262. if ( v1 > 0.0 )
  263. v2 = fminf(v1, 1.0);
  264. else
  265. v2 = 0.1;
  266. */
  267. packet->setDataByName("intensity", intensity);
  268. if ( client->GetVersion() > 546 )
  269. packet->setDataByName("direction", direction);
  270. client->QueuePacket(packet->serialize());
  271. safe_delete(packet);
  272. }
  273. return 0;
  274. }
  275. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  276. if (!lua_interface)
  277. return 0;
  278. Spawn* dead = lua_interface->GetSpawn(state);
  279. Spawn* killer = lua_interface->GetSpawn(state, 2);
  280. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  281. if (dead && dead->Alive() && dead->GetZone())
  282. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  283. return 0;
  284. }
  285. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  286. if (!lua_interface)
  287. return 0;
  288. Spawn* spawn = lua_interface->GetSpawn(state);
  289. float max_distance = lua_interface->GetFloatValue(state, 2);
  290. bool include_players = lua_interface->GetInt8Value(state, 3);
  291. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  292. if (max_distance > 0 && spawn && spawn->GetZone())
  293. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  294. return 0;
  295. }
  296. int EQ2Emu_lua_Despawn(lua_State* state) {
  297. if (!lua_interface)
  298. return 0;
  299. Spawn* spawn = lua_interface->GetSpawn(state);
  300. int32 delay = lua_interface->GetInt32Value(state, 2);
  301. if (spawn && spawn->GetZone())
  302. spawn->GetZone()->Despawn(spawn, delay);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  310. if (spawn) {
  311. spawn->info_changed = true;
  312. spawn->SetShowHandIcon(displayHandIcon);
  313. }
  314. return 0;
  315. }
  316. //this function is used to force an update packet to be sent.
  317. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  318. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. if (spawn) {
  323. spawn->vis_changed = true;
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  329. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. if (spawn) {
  334. spawn->info_changed = true;
  335. }
  336. return 0;
  337. }
  338. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  339. if (!lua_interface)
  340. return 0;
  341. Spawn* spawn = lua_interface->GetSpawn(state);
  342. int32 new_state = lua_interface->GetInt32Value(state, 2);
  343. if (spawn) {
  344. spawn->GetZone()->SendStateCommand(spawn, new_state);
  345. }
  346. return 0;
  347. }
  348. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  349. if (!lua_interface)
  350. return 0;
  351. Spawn* spawn = lua_interface->GetSpawn(state);
  352. string variable = lua_interface->GetStringValue(state, 2);
  353. string value = lua_interface->GetStringValue(state, 3);
  354. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  355. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  356. int32 type = commands.GetSpawnSetType(variable);
  357. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  358. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  359. return 0;
  360. }
  361. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  362. if (!lua_interface)
  363. return 0;
  364. Spawn* spawn = lua_interface->GetSpawn(state);
  365. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  366. if (spawn && spawn_id > 0) {
  367. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  368. if (closest_spawn) {
  369. lua_interface->SetSpawnValue(state, closest_spawn);
  370. return 1;
  371. }
  372. }
  373. return 0;
  374. }
  375. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  376. if (!lua_interface)
  377. return 0;
  378. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  379. int32 position = lua_interface->GetInt32Value(state, 2);
  380. if (spawnList) {
  381. if (spawnList->size() > position) {
  382. lua_interface->SetSpawnValue(state, spawnList->at(position));
  383. return 1;
  384. }
  385. else {
  386. return 0;
  387. }
  388. return spawnList->size();
  389. }
  390. return 0;
  391. }
  392. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  393. if (!lua_interface)
  394. return 0;
  395. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  396. if (spawnList) {
  397. return spawnList->size();
  398. }
  399. return 0;
  400. }
  401. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  402. if (!lua_interface)
  403. return 0;
  404. vector<Spawn*>* spawnList = new vector<Spawn*>();
  405. lua_interface->SetSpawnListValue(state, spawnList);
  406. return 1;
  407. }
  408. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  409. if (!lua_interface)
  410. return 0;
  411. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  412. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  413. if (spawnList) {
  414. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  415. if (it == spawnList->end())
  416. spawnList->push_back(spawn);
  417. }
  418. return 0;
  419. }
  420. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  421. if (!lua_interface)
  422. return 0;
  423. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  424. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  425. if (spawnList) {
  426. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  427. if(it != spawnList->end())
  428. spawnList->erase(it);
  429. }
  430. return 0;
  431. }
  432. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  433. if (!lua_interface)
  434. return 0;
  435. Spawn* spawn = lua_interface->GetSpawn(state);
  436. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  437. if (spawn) {
  438. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  439. if (spawns.size() > 0) {
  440. vector<Spawn*>* spawnList = new vector<Spawn*>();
  441. vector<Spawn*>::iterator itr;
  442. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  443. spawnList->push_back(*itr);
  444. }
  445. lua_interface->SetSpawnListValue(state, spawnList);
  446. return 1;
  447. }
  448. }
  449. return 0;
  450. }
  451. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  452. if (!lua_interface)
  453. return 0;
  454. string variable_name = lua_interface->GetStringValue(state);
  455. Variable* var = variables.FindVariable(variable_name);
  456. if (var) {
  457. lua_interface->SetStringValue(state, var->GetValue());
  458. return 1;
  459. }
  460. return 0;
  461. }
  462. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  463. if (!lua_interface)
  464. return 0;
  465. int32 total_coins = lua_interface->GetInt32Value(state);
  466. if (total_coins == 0) {
  467. lua_interface->SetStringValue(state, "0 copper");
  468. return 1;
  469. }
  470. char tmp[64] = { 0 };
  471. string message = "";
  472. int32 val = 0;
  473. if (total_coins >= 1000000) {
  474. val = total_coins / 1000000;
  475. total_coins -= 1000000 * val;
  476. sprintf(tmp, " %u Platinum", val);
  477. message.append(tmp);
  478. memset(tmp, 0, 64);
  479. }
  480. if (total_coins >= 10000) {
  481. val = total_coins / 10000;
  482. total_coins -= 10000 * val;
  483. sprintf(tmp, " %u Gold", val);
  484. message.append(tmp);
  485. memset(tmp, 0, 64);
  486. }
  487. if (total_coins >= 100) {
  488. val = total_coins / 100;
  489. total_coins -= 100 * val;
  490. sprintf(tmp, " %u Silver", val);
  491. message.append(tmp);
  492. memset(tmp, 0, 64);
  493. }
  494. if (total_coins > 0) {
  495. sprintf(tmp, " %u Copper", (int32)total_coins);
  496. message.append(tmp);
  497. }
  498. lua_interface->SetStringValue(state, message.c_str());
  499. return 1;
  500. }
  501. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  502. ZoneServer* zone = lua_interface->GetZone(state);
  503. int32 group_id = lua_interface->GetInt32Value(state, 2);
  504. if (zone) {
  505. Spawn* spawn = zone->GetSpawnGroup(group_id);
  506. if (spawn) {
  507. lua_interface->SetSpawnValue(state, spawn);
  508. return 1;
  509. }
  510. }
  511. return 0;
  512. }
  513. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  514. ZoneServer* zone = lua_interface->GetZone(state);
  515. int32 location_id = lua_interface->GetInt32Value(state, 2);
  516. if (zone) {
  517. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  518. if (spawn) {
  519. lua_interface->SetSpawnValue(state, spawn);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  526. Spawn* spawn = lua_interface->GetSpawn(state);
  527. if (spawn) {
  528. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  529. return 1;
  530. }
  531. return 0;
  532. }
  533. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  534. Spawn* spawn = lua_interface->GetSpawn(state);
  535. if (spawn) {
  536. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  537. return 1;
  538. }
  539. return 0;
  540. }
  541. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  542. Spawn* spawn = lua_interface->GetSpawn(state);
  543. if (spawn) {
  544. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  550. Spawn* spawn = lua_interface->GetSpawn(state);
  551. if (spawn) {
  552. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  553. return 1;
  554. }
  555. return 0;
  556. }
  557. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  558. Player* player = (Player*)lua_interface->GetSpawn(state);
  559. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  560. if (player && player->IsPlayer() && faction_id > 0) {
  561. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  562. return 1;
  563. }
  564. return 0;
  565. }
  566. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  567. if (!lua_interface)
  568. return 0;
  569. Spawn* spawn = lua_interface->GetSpawn(state);
  570. int32 value = lua_interface->GetInt32Value(state, 2);
  571. if (spawn) {
  572. spawn->SetFactionID(value);
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  577. Spawn* spawn = lua_interface->GetSpawn(state);
  578. if (spawn) {
  579. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  580. return 1;
  581. }
  582. return 0;
  583. }
  584. int EQ2Emu_lua_GetGender(lua_State* state) {
  585. Spawn* spawn = lua_interface->GetSpawn(state);
  586. if (spawn) {
  587. lua_interface->SetInt32Value(state, spawn->GetGender());
  588. return 1;
  589. }
  590. return 0;
  591. }
  592. int EQ2Emu_lua_GetTarget(lua_State* state) {
  593. Spawn* spawn = lua_interface->GetSpawn(state);
  594. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  595. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  596. return 1;
  597. }
  598. return 0;
  599. }
  600. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  601. if (!lua_interface)
  602. return 0;
  603. Spawn* spawn = lua_interface->GetSpawn(state);
  604. string mp3_string = lua_interface->GetStringValue(state, 2);
  605. int32 key1 = lua_interface->GetInt32Value(state, 3);
  606. int32 key2 = lua_interface->GetInt32Value(state, 4);
  607. Spawn* player = lua_interface->GetSpawn(state, 5);
  608. if (spawn && mp3_string.length() > 0) {
  609. Client* client = 0;
  610. if (player && player->IsPlayer())
  611. client = spawn->GetZone()->GetClientBySpawn(player);
  612. if (client) {
  613. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  614. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  615. }
  616. else
  617. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  618. }
  619. return 0;
  620. }
  621. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  622. if (!lua_interface)
  623. return 0;
  624. Spawn* spawn = lua_interface->GetSpawn(state);
  625. if (spawn) {
  626. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  627. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  629. return 3;
  630. }
  631. return 0;
  632. }
  633. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  634. if (!lua_interface)
  635. return 0;
  636. Spawn* spawn = lua_interface->GetSpawn(state);
  637. if (spawn) {
  638. int32 item_id = lua_interface->GetInt32Value(state, 2);
  639. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  640. return 1;
  641. }
  642. return 0;
  643. }
  644. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  645. if (!lua_interface)
  646. return 0;
  647. Spawn* spawn = lua_interface->GetSpawn(state);
  648. if (spawn && spawn->IsEntity()) {
  649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  650. int16 charges = lua_interface->GetInt16Value(state, 3);
  651. if (charges == 0)
  652. charges = 1;
  653. ((Entity*)spawn)->AddLootItem(item_id, charges);
  654. }
  655. return 0;
  656. }
  657. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  658. if (!lua_interface)
  659. return 0;
  660. Spawn* spawn = lua_interface->GetSpawn(state);
  661. if (spawn && spawn->IsEntity()) {
  662. int32 item_id = lua_interface->GetInt32Value(state, 2);
  663. spawn->LootItem(item_id);
  664. }
  665. return 0;
  666. }
  667. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  668. if (!lua_interface)
  669. return 0;
  670. Spawn* spawn = lua_interface->GetSpawn(state);
  671. if (spawn) {
  672. int32 val = lua_interface->GetInt32Value(state, 2);
  673. spawn->AddLootCoins(val);
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* entity = lua_interface->GetSpawn(state);
  681. Spawn* player = lua_interface->GetSpawn(state, 2);
  682. if (entity && player && player->IsPlayer()) {
  683. int32 coins = lua_interface->GetInt32Value(state, 3);
  684. vector<Item*>* items = 0;
  685. int i = 0;
  686. int32 item_id = 0;
  687. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  688. if (items == 0)
  689. items = new vector<Item*>;
  690. if (master_item_list.GetItem(item_id))
  691. items->push_back(master_item_list.GetItem(item_id));
  692. i++;
  693. }
  694. Client* client = 0;
  695. client = player->GetZone()->GetClientBySpawn(player);
  696. if (client)
  697. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  698. if(coins > 0)
  699. entity->AddLootCoins(coins);
  700. safe_delete(items);
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  705. if (!lua_interface)
  706. return 0;
  707. Spawn* entity = lua_interface->GetSpawn(state);
  708. Spawn* player = lua_interface->GetSpawn(state, 2);
  709. int32 item_id = lua_interface->GetInt32Value(state, 3);
  710. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  711. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  717. if (!lua_interface)
  718. return 0;
  719. Spawn* entity = lua_interface->GetSpawn(state);
  720. Spawn* player = lua_interface->GetSpawn(state, 2);
  721. if (entity && player && player->IsPlayer()) {
  722. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  723. return 1;
  724. }
  725. return 0;
  726. }
  727. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  728. if (!lua_interface)
  729. return 0;
  730. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  731. safe_delete(conversation);
  732. conversation = new vector<ConversationOption>();
  733. lua_interface->SetConversationValue(state, conversation);
  734. return 1;
  735. }
  736. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  737. if (!lua_interface)
  738. return 0;
  739. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  740. if (conversation) {
  741. ConversationOption conv_option;
  742. conv_option.option = lua_interface->GetStringValue(state, 2);
  743. conv_option.function = lua_interface->GetStringValue(state, 3);
  744. if (conv_option.option.length() > 0)
  745. conversation->push_back(conv_option);
  746. }
  747. return 0;
  748. }
  749. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  750. if (!lua_interface)
  751. return 0;
  752. Spawn* npc = lua_interface->GetSpawn(state);
  753. Spawn* player = lua_interface->GetSpawn(state, 2);
  754. if (npc && player && player->IsPlayer() && player->GetZone()) {
  755. Client* client = player->GetZone()->GetClientBySpawn(player);
  756. if (client) {
  757. int32 conversation_id = client->GetConversationID(npc, 0);
  758. client->CloseDialog(conversation_id);
  759. }
  760. }
  761. return 0;
  762. }
  763. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  764. if (!lua_interface)
  765. return 0;
  766. Item* item = lua_interface->GetItem(state);
  767. Spawn* player = lua_interface->GetSpawn(state, 2);
  768. if (item && player && player->IsPlayer() && player->GetZone()) {
  769. Client* client = player->GetZone()->GetClientBySpawn(player);
  770. if (client) {
  771. int32 conversation_id = client->GetConversationID(0, item);
  772. client->CloseDialog(conversation_id);
  773. }
  774. }
  775. return 0;
  776. }
  777. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  778. if (!lua_interface)
  779. return 0;
  780. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  781. Spawn* spawn = 0;
  782. Item* item = 0;
  783. int8 type = lua_interface->GetInt8Value(state, 2);
  784. if (type == 1 || type == 3)
  785. spawn = lua_interface->GetSpawn(state, 3);
  786. else if (type == 2 || type == 4)
  787. item = lua_interface->GetItem(state, 3);
  788. Spawn* player = lua_interface->GetSpawn(state, 4);
  789. string text = lua_interface->GetStringValue(state, 5);
  790. string mp3 = lua_interface->GetStringValue(state, 6);
  791. int32 key1 = lua_interface->GetInt32Value(state, 7);
  792. int32 key2 = lua_interface->GetInt32Value(state, 8);
  793. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  794. Client* client = player->GetZone()->GetClientBySpawn(player);
  795. if (client) {
  796. if (spawn) {
  797. // Need to do this so the function works the same as it did before
  798. if (type == 1)
  799. type++;
  800. if (mp3.length() > 0)
  801. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  802. else
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  804. }
  805. else {
  806. if (mp3.length() > 0)
  807. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  808. else
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  810. }
  811. }
  812. }
  813. safe_delete(conversation);
  814. lua_interface->SetConversationValue(state, NULL);
  815. return 0;
  816. }
  817. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  818. if(!lua_interface)
  819. return 0;
  820. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  821. Item* item = lua_interface->GetItem(state, 2);
  822. Spawn* player = lua_interface->GetSpawn(state, 3);
  823. string text = lua_interface->GetStringValue(state, 4);
  824. string mp3 = lua_interface->GetStringValue(state, 5);
  825. int32 key1 = lua_interface->GetInt32Value(state, 6);
  826. int32 key2 = lua_interface->GetInt32Value(state, 7);
  827. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  828. Client* client = player->GetZone()->GetClientBySpawn(player);
  829. if(client){
  830. if(mp3.length() > 0)
  831. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  832. else
  833. client->DisplayConversation(item, conversation, (char*)text.c_str());
  834. }
  835. safe_delete(conversation);
  836. }
  837. return 0;
  838. }*/
  839. int EQ2Emu_lua_StartConversation(lua_State* state) {
  840. if (!lua_interface)
  841. return 0;
  842. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  843. Spawn* npc = lua_interface->GetSpawn(state, 2);
  844. Spawn* player = lua_interface->GetSpawn(state, 3);
  845. string text = lua_interface->GetStringValue(state, 4);
  846. string mp3 = lua_interface->GetStringValue(state, 5);
  847. int32 key1 = lua_interface->GetInt32Value(state, 6);
  848. int32 key2 = lua_interface->GetInt32Value(state, 7);
  849. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  850. Client* client = npc->GetZone()->GetClientBySpawn(player);
  851. if (mp3.length() > 0)
  852. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  853. else
  854. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  855. safe_delete(conversation);
  856. lua_interface->SetConversationValue(state, NULL);
  857. }
  858. else
  859. 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);
  860. return 0;
  861. }
  862. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  863. if (!lua_interface)
  864. return 0;
  865. Spawn* spawn = lua_interface->GetSpawn(state);
  866. float distance = lua_interface->GetFloatValue(state, 2);
  867. string in_range_function = lua_interface->GetStringValue(state, 3);
  868. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  869. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  870. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  871. return 0;
  872. }
  873. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  874. ZoneServer* zone = lua_interface->GetZone(state);
  875. float x = lua_interface->GetFloatValue(state, 2);
  876. float y = lua_interface->GetFloatValue(state, 3);
  877. float z = lua_interface->GetFloatValue(state, 4);
  878. float max_variation = lua_interface->GetFloatValue(state, 5);
  879. string in_range_function = lua_interface->GetStringValue(state, 6);
  880. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  881. if (zone && in_range_function.length() > 0)
  882. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  883. return 0;
  884. }
  885. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  886. if (!lua_interface)
  887. return 0;
  888. Spawn* spawn = lua_interface->GetSpawn(state);
  889. if (spawn && spawn->IsEntity()) {
  890. int32 val = lua_interface->GetInt32Value(state, 2);
  891. ((Entity*)spawn)->SetLootCoins(val);
  892. }
  893. return 0;
  894. }
  895. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  896. if (!lua_interface)
  897. return 0;
  898. Spawn* spawn = lua_interface->GetSpawn(state);
  899. if (spawn && spawn->IsEntity()) {
  900. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  901. return 1;
  902. }
  903. return 0;
  904. }
  905. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  906. if (!lua_interface)
  907. return 0;
  908. Spawn* spawn = lua_interface->GetSpawn(state);
  909. float x = lua_interface->GetFloatValue(state, 2);
  910. float y = lua_interface->GetFloatValue(state, 3);
  911. float z = lua_interface->GetFloatValue(state, 4);
  912. float speed = lua_interface->GetFloatValue(state, 5);
  913. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  914. string function = lua_interface->GetStringValue(state, 7);
  915. if (spawn) {
  916. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  917. spawn->GetZone()->AddMovementNPC(spawn);
  918. }
  919. lua_interface->ResetFunctionStack(state);
  920. return 0;
  921. }
  922. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  923. if (!lua_interface)
  924. return 0;
  925. Spawn* spawn = lua_interface->GetSpawn(state);
  926. if (spawn) {
  927. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  928. return 1;
  929. }
  930. return 0;
  931. }
  932. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  933. if (!lua_interface)
  934. return 0;
  935. Spawn* spawn = lua_interface->GetSpawn(state);
  936. Spawn* target = lua_interface->GetSpawn(state, 2);
  937. if (spawn && target) {
  938. if (spawn->IsEntity())
  939. // ((Entity*)spawn)->FaceTarget(target);
  940. static_cast<Entity*>(spawn)->FaceTarget(target);
  941. }
  942. lua_interface->ResetFunctionStack(state);
  943. return 0;
  944. }
  945. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. float x = lua_interface->GetFloatValue(state, 2);
  950. float y = lua_interface->GetFloatValue(state, 3);
  951. float z = lua_interface->GetFloatValue(state, 4);
  952. float speed = lua_interface->GetFloatValue(state, 5);
  953. string lua_function = lua_interface->GetStringValue(state, 6);
  954. bool more_points = lua_interface->GetBooleanValue(state, 7);
  955. if (spawn) {
  956. if (speed == 0)
  957. speed = spawn->GetSpeed();
  958. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  959. }
  960. lua_interface->ResetFunctionStack(state);
  961. return 0;
  962. }
  963. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  964. if (!lua_interface)
  965. return 0;
  966. Spawn* spawn = lua_interface->GetSpawn(state);
  967. if (spawn) {
  968. spawn->ClearRunningLocations();
  969. }
  970. return 0;
  971. }
  972. int EQ2Emu_lua_Say(lua_State* state) {
  973. if (!lua_interface)
  974. return 0;
  975. Spawn* spawn = lua_interface->GetSpawn(state);
  976. string message = lua_interface->GetStringValue(state, 2);
  977. Spawn* player = lua_interface->GetSpawn(state, 3);
  978. int32 language = lua_interface->GetInt32Value(state, 4);
  979. if (spawn && message.length() > 0) {
  980. Client* client = 0;
  981. if (player && player->IsPlayer())
  982. client = spawn->GetZone()->GetClientBySpawn(player);
  983. if (client)
  984. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  985. else
  986. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  987. }
  988. lua_interface->ResetFunctionStack(state);
  989. return 0;
  990. }
  991. int EQ2Emu_lua_Shout(lua_State* state) {
  992. if (!lua_interface)
  993. return 0;
  994. Spawn* spawn = lua_interface->GetSpawn(state);
  995. string message = lua_interface->GetStringValue(state, 2);
  996. Spawn* player = lua_interface->GetSpawn(state, 3);
  997. if (spawn && message.length() > 0) {
  998. Client* client = 0;
  999. if (player && player->IsPlayer())
  1000. client = spawn->GetZone()->GetClientBySpawn(player);
  1001. if (client)
  1002. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1003. else
  1004. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1005. }
  1006. lua_interface->ResetFunctionStack(state);
  1007. return 0;
  1008. }
  1009. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1010. if (!lua_interface)
  1011. return 0;
  1012. Spawn* spawn = lua_interface->GetSpawn(state);
  1013. string message = lua_interface->GetStringValue(state, 2);
  1014. Spawn* player = lua_interface->GetSpawn(state, 3);
  1015. if (spawn && message.length() > 0) {
  1016. Client* client = 0;
  1017. if (player && player->IsPlayer())
  1018. client = spawn->GetZone()->GetClientBySpawn(player);
  1019. if (client)
  1020. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1021. else
  1022. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1023. }
  1024. lua_interface->ResetFunctionStack(state);
  1025. return 0;
  1026. }
  1027. int EQ2Emu_lua_Emote(lua_State* state) {
  1028. if (!lua_interface)
  1029. return 0;
  1030. Spawn* spawn = lua_interface->GetSpawn(state);
  1031. string message = lua_interface->GetStringValue(state, 2);
  1032. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1033. Spawn* player = lua_interface->GetSpawn(state, 4);
  1034. char* to = 0;
  1035. if (spawn2)
  1036. to = spawn2->GetName();
  1037. if (spawn && message.length() > 0) {
  1038. Client* client = 0;
  1039. if (player && player->IsPlayer())
  1040. client = spawn->GetZone()->GetClientBySpawn(player);
  1041. if (client)
  1042. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1043. else
  1044. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1045. }
  1046. lua_interface->ResetFunctionStack(state);
  1047. return 0;
  1048. }
  1049. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1050. if (!lua_interface)
  1051. return 0;
  1052. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1053. if (!luaspell)
  1054. return 0;
  1055. Spawn* caster = luaspell->caster;
  1056. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1057. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1058. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1059. Spawn* target = lua_interface->GetSpawn(state, 4);
  1060. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1061. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1062. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1063. lua_interface->ResetFunctionStack(state);
  1064. if (caster && caster->IsEntity()) {
  1065. bool success = false;
  1066. luaspell->resisted = false;
  1067. if (target) {
  1068. float distance = caster->GetDistance(target, true);
  1069. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1070. success = true;
  1071. }
  1072. if (luaspell->targets.size() > 0) {
  1073. Spawn* target = 0;
  1074. ZoneServer* zone = luaspell->caster->GetZone();
  1075. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1076. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1077. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1078. float distance = caster->GetDistance(target, true);
  1079. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1080. }
  1081. }
  1082. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1083. success = true;
  1084. }
  1085. if (success) {
  1086. if (caster->GetZone())
  1087. caster->GetZone()->TriggerCharSheetTimer();
  1088. }
  1089. }
  1090. return 0;
  1091. }
  1092. int EQ2Emu_lua_AddItem(lua_State* state) {
  1093. if (!lua_interface)
  1094. return 0;
  1095. Spawn* spawn = lua_interface->GetSpawn(state);
  1096. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1097. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1098. // default of 1 quantity to add
  1099. if (quantity == 0)
  1100. quantity = 1;
  1101. if (spawn && spawn->IsPlayer()) {
  1102. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1103. if (client && item_id > 0) {
  1104. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1105. return 1;
  1106. }
  1107. }
  1108. lua_interface->SetBooleanValue(state, false);
  1109. return 1;
  1110. }
  1111. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1112. if (!lua_interface)
  1113. return 0;
  1114. Spawn* spawn = lua_interface->GetSpawn(state);
  1115. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1116. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1117. string location = lua_interface->GetStringValue(state, 4);
  1118. if (spawn && spawn->IsPlayer()) {
  1119. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1120. if (client && item_id > 0) {
  1121. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1122. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1123. else
  1124. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1125. if (send_messages) {
  1126. Item* item = master_item_list.GetItem(item_id);
  1127. if (item) {
  1128. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1129. string popup_text = "You receive " + item->name;
  1130. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1131. }
  1132. }
  1133. return 1;
  1134. }
  1135. }
  1136. lua_interface->SetBooleanValue(state, false);
  1137. return 1;
  1138. }
  1139. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1140. Spawn* spawn = lua_interface->GetSpawn(state);
  1141. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1142. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1143. // default of 1 to remove
  1144. if (quantity == 0)
  1145. quantity = 1;
  1146. Client* client;
  1147. Item* item;
  1148. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1149. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1150. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1151. if (client->RemoveItem(item, quantity)) {
  1152. lua_interface->SetBooleanValue(state, true);
  1153. return 1;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. lua_interface->SetBooleanValue(state, false);
  1159. return 1;
  1160. }
  1161. int EQ2Emu_lua_HasItem(lua_State* state) {
  1162. Spawn* player = lua_interface->GetSpawn(state);
  1163. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1164. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1165. if (player && player->IsPlayer()) {
  1166. bool hasItem = false;
  1167. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1168. if (!hasItem)
  1169. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1170. lua_interface->SetBooleanValue(state, hasItem);
  1171. return 1;
  1172. }
  1173. lua_interface->SetBooleanValue(state, false);
  1174. return 1;
  1175. }
  1176. int EQ2Emu_lua_Spawn(lua_State* state) {
  1177. if (!lua_interface)
  1178. return 0;
  1179. ZoneServer* zone = lua_interface->GetZone(state);
  1180. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1181. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1182. float x = lua_interface->GetFloatValue(state, 4);
  1183. float y = lua_interface->GetFloatValue(state, 5);
  1184. float z = lua_interface->GetFloatValue(state, 6);
  1185. float heading = lua_interface->GetFloatValue(state, 7);
  1186. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1187. Spawn* spawn = zone->GetSpawn(spawn_id);
  1188. if (!spawn)
  1189. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1190. else {
  1191. spawn->SetX(x);
  1192. spawn->SetZ(z);
  1193. spawn->SetY(y,true,true);
  1194. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1195. spawn->SetHeading(heading);
  1196. if (restricted_npc)
  1197. spawn->AddAllowAccessSpawn(spawn);
  1198. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1199. bool scriptActive = false;
  1200. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1201. scriptActive = true;
  1202. spawn->SetSpawnScript(string(spawn_script));
  1203. }
  1204. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1205. zone->AddSpawn(spawn);
  1206. if (scriptActive) {
  1207. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1208. }
  1209. lua_interface->SetSpawnValue(state, spawn);
  1210. return 1;
  1211. }
  1212. }
  1213. else {
  1214. string output = "Invalid paramaters to LUA Spawn command: \n";
  1215. if (!zone)
  1216. output = output.append("\t").append("Missing zone reference. \n");
  1217. if (spawn_id == 0)
  1218. output = output.append("\t").append("Missing spawn_id.");
  1219. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1220. }
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. ZoneServer* zone = lua_interface->GetZone(state);
  1227. if (zone) {
  1228. lua_interface->SetStringValue(state, zone->GetZoneName());
  1229. return 1;
  1230. }
  1231. return 0;
  1232. }
  1233. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1234. if (!lua_interface)
  1235. return 0;
  1236. ZoneServer* zone = lua_interface->GetZone(state);
  1237. if (zone) {
  1238. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1239. return 1;
  1240. }
  1241. return 0;
  1242. }
  1243. int EQ2Emu_lua_GetZone(lua_State* state) {
  1244. if (!lua_interface)
  1245. return 0;
  1246. int32 zone_id = lua_interface->GetInt32Value(state);
  1247. ZoneServer* zone = 0;
  1248. if (zone_id > 0)
  1249. zone = zone_list.Get(zone_id);
  1250. else {
  1251. string zone_name = lua_interface->GetStringValue(state);
  1252. if (zone_name.length() > 0) {
  1253. zone = zone_list.Get(zone_name.c_str());
  1254. }
  1255. else {
  1256. Spawn* spawn = lua_interface->GetSpawn(state);
  1257. if (spawn)
  1258. zone = spawn->GetZone();
  1259. }
  1260. }
  1261. if (zone) {
  1262. lua_interface->SetZoneValue(state, zone);
  1263. return 1;
  1264. }
  1265. return 0;
  1266. }
  1267. int EQ2Emu_lua_AddHate(lua_State* state) {
  1268. Spawn* entity = lua_interface->GetSpawn(state);
  1269. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1270. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1271. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1272. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1273. if (entity && entity->IsEntity() && amount != 0) {
  1274. if (luaspell) {
  1275. ZoneServer* zone = luaspell->caster->GetZone();
  1276. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1277. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1278. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1279. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1280. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1281. if (send_packet)
  1282. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1283. }
  1284. }
  1285. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1286. }
  1287. else if (npc && npc->IsNPC() && npc->GetZone())
  1288. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1289. }
  1290. return 0;
  1291. }
  1292. int EQ2Emu_lua_Zone(lua_State* state) {
  1293. if (!lua_interface)
  1294. return 0;
  1295. ZoneServer* zone = lua_interface->GetZone(state);
  1296. Spawn* player = lua_interface->GetSpawn(state, 2);
  1297. Client* client = 0;
  1298. if (player && player->IsPlayer())
  1299. client = player->GetZone()->GetClientBySpawn(player);
  1300. float x = lua_interface->GetFloatValue(state, 3);
  1301. float y = lua_interface->GetFloatValue(state, 4);
  1302. float z = lua_interface->GetFloatValue(state, 5);
  1303. float heading = lua_interface->GetFloatValue(state, 6);
  1304. if (zone && client) {
  1305. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1306. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1307. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1308. {
  1309. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1310. return 0;
  1311. }
  1312. if (x != 0 || y != 0 || z != 0) {
  1313. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1314. player->SetX(x);
  1315. player->SetY(y);
  1316. player->SetZ(z);
  1317. player->SetHeading(heading);
  1318. client->Zone(zone->GetZoneName(), false);
  1319. }
  1320. else
  1321. client->Zone(zone->GetZoneName());
  1322. }
  1323. else
  1324. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1325. return 0;
  1326. }
  1327. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1328. if (!lua_interface)
  1329. return 0;
  1330. Spawn* spawn = lua_interface->GetSpawn(state);
  1331. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1332. if (spawn && spawn2)
  1333. spawn->AddAllowAccessSpawn(spawn2);
  1334. return 0;
  1335. }
  1336. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1337. if (!lua_interface)
  1338. return 0;
  1339. Spawn* target = lua_interface->GetSpawn(state);
  1340. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1341. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1342. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1343. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1344. if (!target) {
  1345. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1346. return 0;
  1347. }
  1348. if (!target->IsEntity()) {
  1349. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1350. return 0;
  1351. }
  1352. if (spell_id <= 0) {
  1353. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1354. return 0;
  1355. }
  1356. if (caster && !caster->IsEntity()) {
  1357. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1358. return 0;
  1359. }
  1360. if (spell_tier == 0)
  1361. spell_tier = 1;
  1362. if (!caster)
  1363. caster = target;
  1364. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1365. return 0;
  1366. }
  1367. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1368. if (!lua_interface)
  1369. return 0;
  1370. Spawn* target = lua_interface->GetSpawn(state);
  1371. int32 target_id = 0;
  1372. if (target)
  1373. target_id = target->GetID();
  1374. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1375. if (!luaspell)
  1376. return 0;
  1377. Spawn* caster = luaspell->caster;
  1378. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1379. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1380. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1381. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1382. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1383. //lua_interface->ResetFunctionStack(state);
  1384. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1385. vector<int16> faction_req;
  1386. vector<int16> race_req;
  1387. int32 class_req = 0;
  1388. int32 i = 0;
  1389. int8 f = 0;
  1390. int8 r = 0;
  1391. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1392. if (class_id < 100) {
  1393. class_req += pow(2.0, double(class_id - 1));
  1394. }
  1395. else if (class_id > 100 && class_id < 1000) {
  1396. race_req.push_back(class_id);
  1397. r++;
  1398. }
  1399. else {
  1400. faction_req.push_back(class_id);
  1401. f++;
  1402. }
  1403. i++;
  1404. }
  1405. if (caster && caster->IsEntity()) {
  1406. bool race_match = false;
  1407. bool success = false;
  1408. luaspell->resisted = false;
  1409. if (luaspell->initial_target == target_id) {
  1410. int xxx = 0;
  1411. }
  1412. if (luaspell->targets.size() > 0) {
  1413. ZoneServer* zone = luaspell->caster->GetZone();
  1414. Spawn* target = 0;
  1415. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1416. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1417. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1418. if (race_req.size() > 0) {
  1419. for (int8 i = 0; i < race_req.size(); i++) {
  1420. int32 xxx = target->GetLuaRaceId();
  1421. if (target->GetLuaRaceId() == race_req[i]) {
  1422. race_match = true;
  1423. }
  1424. }
  1425. }
  1426. else
  1427. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1428. if (race_match == true) {
  1429. float distance = caster->GetDistance(target, true);
  1430. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1431. }
  1432. }
  1433. }
  1434. success = true;
  1435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1436. }
  1437. else if (target) {
  1438. //check class and race/faction here
  1439. if (race_req.size() > 0) {
  1440. for (int8 i = 0; i < race_req.size(); i++) {
  1441. if (target->GetLuaRaceId() == race_req[i]) {
  1442. race_match = true;
  1443. }
  1444. }
  1445. }
  1446. else
  1447. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1448. if (race_match == true) {
  1449. float distance = caster->GetDistance(target, true);
  1450. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1451. success = true;
  1452. }
  1453. }
  1454. if (success) {
  1455. Spell* spell = luaspell->spell;
  1456. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1457. ((Player*)caster)->InCombat(true);
  1458. if (caster->GetZone())
  1459. caster->GetZone()->TriggerCharSheetTimer();
  1460. }
  1461. }
  1462. }
  1463. return 0;
  1464. }
  1465. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1466. if (!lua_interface)
  1467. return 0;
  1468. Spawn* spawn = lua_interface->GetSpawn(state);
  1469. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1470. lua_interface->ResetFunctionStack(state);
  1471. if (spawn && value != 0) {
  1472. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1473. spawn->SetPower(spawn->GetTotalPower());
  1474. else
  1475. spawn->SetPower(spawn->GetPower() + value);
  1476. }
  1477. return 0;
  1478. }
  1479. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1480. if (!lua_interface)
  1481. return 0;
  1482. Spawn* spawn = lua_interface->GetSpawn(state);
  1483. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1484. lua_interface->ResetFunctionStack(state);
  1485. if (spawn && value != 0) {
  1486. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1487. spawn->SetHP(spawn->GetTotalHP());
  1488. else
  1489. spawn->SetHP(spawn->GetHP() + value);
  1490. }
  1491. return 0;
  1492. }
  1493. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1494. if (!lua_interface)
  1495. return 0;
  1496. Spawn* spawn = lua_interface->GetSpawn(state);
  1497. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (spawn && value != 0) {
  1500. spawn->SetPower(spawn->GetPower() + value);
  1501. if (value > spawn->GetTotalHPBase())
  1502. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1503. }
  1504. return 0;
  1505. }
  1506. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1507. if (!lua_interface)
  1508. return 0;
  1509. Spawn* spawn = lua_interface->GetSpawn(state);
  1510. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1511. lua_interface->ResetFunctionStack(state);
  1512. if (spawn && value != 0) {
  1513. spawn->SetHP(spawn->GetHP() + value);
  1514. if (value > spawn->GetTotalHPBase())
  1515. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1516. }
  1517. return 0;
  1518. }
  1519. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1520. if (!lua_interface)
  1521. return 0;
  1522. Spawn* spawn = lua_interface->GetSpawn(state);
  1523. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1524. lua_interface->ResetFunctionStack(state);
  1525. if (spawn) {
  1526. spawn->SetHP(value);
  1527. if (value > spawn->GetTotalHPBase())
  1528. spawn->SetTotalHP(value);
  1529. }
  1530. return 0;
  1531. }
  1532. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1533. if (!lua_interface)
  1534. return 0;
  1535. Spawn* spawn = lua_interface->GetSpawn(state);
  1536. float value = lua_interface->GetFloatValue(state, 2);
  1537. lua_interface->ResetFunctionStack(state);
  1538. if (spawn && spawn->IsEntity() && value > 0)
  1539. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1540. if (spawn->IsPlayer())
  1541. ((Player*)spawn)->SetCharSheetChanged(true);
  1542. return 0;
  1543. }
  1544. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1545. if (!lua_interface)
  1546. return 0;
  1547. Spawn* spawn = lua_interface->GetSpawn(state);
  1548. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1549. lua_interface->ResetFunctionStack(state);
  1550. if (spawn && spawn->IsEntity() && value > 0)
  1551. ((Entity*)spawn)->SetTotalHPBase(value);
  1552. return 0;
  1553. }
  1554. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1555. if (!lua_interface)
  1556. return 0;
  1557. Spawn* spawn = lua_interface->GetSpawn(state);
  1558. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1559. lua_interface->ResetFunctionStack(state);
  1560. if (spawn && value > 0) {
  1561. spawn->SetPower(value);
  1562. if (value > spawn->GetTotalPowerBase())
  1563. spawn->SetTotalPower(value);
  1564. }
  1565. return 0;
  1566. }
  1567. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1568. if (!lua_interface)
  1569. return 0;
  1570. Spawn* spawn = lua_interface->GetSpawn(state);
  1571. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1572. lua_interface->ResetFunctionStack(state);
  1573. if (spawn && spawn->IsEntity() && value > 0)
  1574. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1578. if (!lua_interface)
  1579. return 0;
  1580. Spawn* spawn = lua_interface->GetSpawn(state);
  1581. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1582. lua_interface->ResetFunctionStack(state);
  1583. if (spawn && spawn->IsEntity() && value > 0)
  1584. ((Entity*)spawn)->SetTotalPowerBase(value);
  1585. return 0;
  1586. }
  1587. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1588. if (!lua_interface)
  1589. return 0;
  1590. Spawn* spawn = lua_interface->GetSpawn(state);
  1591. float x = lua_interface->GetFloatValue(state, 2);
  1592. float y = lua_interface->GetFloatValue(state, 3);
  1593. float z = lua_interface->GetFloatValue(state, 4);
  1594. float heading = lua_interface->GetFloatValue(state, 5);
  1595. lua_interface->ResetFunctionStack(state);
  1596. if (spawn) {
  1597. spawn->SetX(x);
  1598. spawn->SetY(y);
  1599. spawn->SetZ(z);
  1600. if (heading != 0)
  1601. spawn->SetHeading(heading);
  1602. spawn->SetSpawnOrigX(spawn->GetX());
  1603. spawn->SetSpawnOrigY(spawn->GetY());
  1604. spawn->SetSpawnOrigZ(spawn->GetZ());
  1605. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1606. if (spawn->IsPlayer()) {
  1607. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1608. if (client) {
  1609. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1610. client->QueuePacket(packet);
  1611. }
  1612. }
  1613. }
  1614. return 0;
  1615. }
  1616. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1617. if (!lua_interface)
  1618. return 0;
  1619. Spawn* spawn = lua_interface->GetSpawn(state);
  1620. float value = lua_interface->GetFloatValue(state, 2);
  1621. lua_interface->ResetFunctionStack(state);
  1622. if (spawn) {
  1623. spawn->SetHeading(value);
  1624. if (spawn->IsPlayer()) {
  1625. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1626. if (client) {
  1627. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1628. client->QueuePacket(packet);
  1629. }
  1630. }
  1631. }
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. int16 value = lua_interface->GetInt16Value(state, 2);
  1639. lua_interface->ResetFunctionStack(state);
  1640. if (spawn)
  1641. spawn->SetModelType(value);
  1642. return 0;
  1643. }
  1644. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1645. if (!lua_interface)
  1646. return 0;
  1647. Spawn* spawn = lua_interface->GetSpawn(state);
  1648. int8 value = lua_interface->GetInt8Value(state, 2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. if (spawn) {
  1651. if (spawn->IsPlayer())
  1652. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1653. else
  1654. spawn->SetAdventureClass(value);
  1655. }
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. int8 value = lua_interface->GetInt8Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn) {
  1665. spawn->SetTradeskillClass(value);
  1666. if (spawn->IsEntity()) {
  1667. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1668. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1669. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1670. }
  1671. if (spawn->IsPlayer())
  1672. ((Player*)spawn)->SetCharSheetChanged(true);
  1673. }
  1674. return 0;
  1675. }
  1676. int EQ2Emu_lua_SetMount(lua_State* state) {
  1677. if (!lua_interface)
  1678. return 0;
  1679. Spawn* spawn = lua_interface->GetSpawn(state);
  1680. int16 value = lua_interface->GetInt16Value(state, 2);
  1681. if (spawn && spawn->IsEntity()) {
  1682. ((Entity*)spawn)->SetMount(value);
  1683. EQ2_Color color;
  1684. color.red = 255;
  1685. color.green = 255;
  1686. color.blue = 255;
  1687. ((Entity*)spawn)->SetMountColor(&color);
  1688. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1689. }
  1690. return 0;
  1691. }
  1692. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1693. if (!lua_interface)
  1694. return 0;
  1695. Spawn* spawn = lua_interface->GetSpawn(state);
  1696. EQ2_Color mount_color;
  1697. EQ2_Color saddle_color;
  1698. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1699. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1700. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1701. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1702. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1703. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1704. if (spawn && spawn->IsEntity()) {
  1705. ((Entity*)spawn)->SetMountColor(&mount_color);
  1706. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1707. }
  1708. return 0;
  1709. }
  1710. int EQ2Emu_lua_GetMount(lua_State* state) {
  1711. if (!lua_interface)
  1712. return 0;
  1713. Spawn* spawn = lua_interface->GetSpawn(state);
  1714. if (spawn && spawn->IsEntity()) {
  1715. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1716. return 1;
  1717. }
  1718. return 0;
  1719. }
  1720. int EQ2Emu_lua_GetRace(lua_State* state) {
  1721. if (!lua_interface)
  1722. return 0;
  1723. Spawn* spawn = lua_interface->GetSpawn(state);
  1724. if (spawn)
  1725. {
  1726. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1727. lua_interface->SetInt32Value(state, spawn->GetRace());
  1728. return 1;
  1729. }
  1730. return 0;
  1731. }
  1732. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1733. if (!lua_interface)
  1734. return 0;
  1735. Spawn* spawn = lua_interface->GetSpawn(state);
  1736. if (spawn) {
  1737. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1738. return 1;
  1739. }
  1740. return 0;
  1741. }
  1742. int EQ2Emu_lua_GetClass(lua_State* state) {
  1743. Spawn* spawn = lua_interface->GetSpawn(state);
  1744. if (spawn) {
  1745. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1746. return 1;
  1747. }
  1748. return 0;
  1749. }
  1750. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. if (spawn) {
  1753. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1754. return 1;
  1755. }
  1756. return 0;
  1757. }
  1758. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1759. if (!lua_interface)
  1760. return 0;
  1761. Spawn* spawn = lua_interface->GetSpawn(state);
  1762. float value = lua_interface->GetFloatValue(state, 2);
  1763. lua_interface->ResetFunctionStack(state);
  1764. if (spawn) {
  1765. spawn->SetSpeed(value);
  1766. ((Entity*)spawn)->SetSpeed(value);
  1767. if (spawn->IsPlayer()) {
  1768. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1769. if (client) {
  1770. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1771. if (packet) {
  1772. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1773. packet->setDataByName("speed", value);
  1774. packet->setDataByName("size", 0.51);
  1775. EQ2Packet* app = packet->serialize();
  1776. client->QueuePacket(app);
  1777. safe_delete(packet);
  1778. }
  1779. }
  1780. }
  1781. }
  1782. return 0;
  1783. }
  1784. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1785. if (!lua_interface)
  1786. return 0;
  1787. Spawn* spawn = lua_interface->GetSpawn(state);
  1788. const int16 type = lua_interface->GetInt16Value(state, 2);
  1789. const float value = lua_interface->GetFloatValue(state, 3);
  1790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1791. int64 class_req = 0;
  1792. int32 class_id = 0;
  1793. vector<int16> faction_req;
  1794. vector<int16> race_req;
  1795. int32 i = 0;
  1796. int8 f = 0;
  1797. int8 r = 0;
  1798. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1799. if (class_id < 100) {
  1800. class_req += pow(2.0, double(class_id - 1));
  1801. }
  1802. else if (class_id > 100 && class_id < 1000) {
  1803. race_req.push_back(class_id);
  1804. r++;
  1805. }
  1806. else {
  1807. faction_req.push_back(class_id);
  1808. f++;
  1809. }
  1810. i++;
  1811. }
  1812. if (value != 0 && type >= 0) {
  1813. if (luaspell && luaspell->spell && luaspell->caster) {
  1814. ZoneServer* zone = luaspell->caster->GetZone();
  1815. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1816. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1817. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1818. if (target) {
  1819. if (target->IsPlayer()) {
  1820. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1821. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1822. if (((Player*)target)->GetGroupMemberInfo())
  1823. ((Player*)target)->UpdateGroupMemberInfo();
  1824. ((Player*)target)->SetCharSheetChanged(true);
  1825. }
  1826. else if (target->IsNPC())
  1827. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1828. else
  1829. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1830. }
  1831. }
  1832. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1833. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1834. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1835. }
  1836. else if (spawn && spawn->IsEntity()) {
  1837. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1838. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1839. if (spawn->IsPlayer())
  1840. ((Player*)spawn)->SetCharSheetChanged(true);
  1841. }
  1842. else
  1843. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1844. }
  1845. else
  1846. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. int16 type = lua_interface->GetInt16Value(state, 2);
  1854. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1855. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1856. if (!spawn) {
  1857. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1858. return 0;
  1859. }
  1860. if (!spawn->IsEntity()) {
  1861. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1862. return 0;
  1863. }
  1864. if (value == 0) {
  1865. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1866. return 0;
  1867. }
  1868. if (!luaspell || !luaspell->spell) {
  1869. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1870. return 0;
  1871. }
  1872. int32 class_req = 0;
  1873. vector<int16> faction_req;
  1874. vector<int16> race_req;
  1875. int32 class_id = 0;
  1876. int32 i = 0;
  1877. int8 f = 0;
  1878. int8 r = 0;
  1879. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1880. if (class_id < 100) {
  1881. class_req += pow(2.0, double(class_id - 1));
  1882. }
  1883. else if (class_id > 100 && class_id < 1000) {
  1884. race_req.push_back(class_id);
  1885. r++;
  1886. }
  1887. else {
  1888. faction_req.push_back(class_id);
  1889. f++;
  1890. }
  1891. i++;
  1892. }
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1894. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1895. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1896. if (spawn->IsPlayer())
  1897. ((Player*)spawn)->SetCharSheetChanged(true);
  1898. return 0;
  1899. }
  1900. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1901. if (!lua_interface)
  1902. return 0;
  1903. Spawn* spawn = lua_interface->GetSpawn(state);
  1904. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1905. if (luaspell && luaspell->spell) {
  1906. ZoneServer* zone = luaspell->caster->GetZone();
  1907. Spawn* target = 0;
  1908. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1909. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1910. target = zone->GetSpawnByID(luaspell->targets[i]);
  1911. if (target && target->IsEntity()) {
  1912. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1913. if (target->IsPlayer())
  1914. ((Player*)target)->SetCharSheetChanged(true);
  1915. }
  1916. }
  1917. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1918. }
  1919. else if (spawn && spawn->IsEntity()) {
  1920. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1921. if (spawn->IsPlayer())
  1922. ((Player*)spawn)->SetCharSheetChanged(true);
  1923. }
  1924. return 0;
  1925. }
  1926. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1927. if (!lua_interface)
  1928. return 0;
  1929. Spawn* spawn = lua_interface->GetSpawn(state);
  1930. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1931. float value = lua_interface->GetFloatValue(state, 3);
  1932. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1933. if (value != 0) {
  1934. int32 spell_id = 0;
  1935. if (luaspell && luaspell->spell && luaspell->caster) {
  1936. spell_id = luaspell->spell->GetSpellID();
  1937. ZoneServer* zone = luaspell->caster->GetZone();
  1938. Spawn* target = 0;
  1939. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1940. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1941. target = zone->GetSpawnByID(luaspell->targets[i]);
  1942. if (target && target->Alive()) {
  1943. if (target->IsPlayer()) {
  1944. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1945. Client* client = target->GetZone()->GetClientBySpawn(target);
  1946. if (client) {
  1947. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1948. if (packet)
  1949. client->QueuePacket(packet);
  1950. }
  1951. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1952. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1953. }
  1954. else if (target->IsNPC()) {
  1955. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1956. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1957. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1958. }
  1959. else
  1960. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1961. }
  1962. }
  1963. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1964. }
  1965. else if (spawn) {
  1966. if (spawn->IsPlayer()) {
  1967. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1968. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1969. if (client) {
  1970. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1971. if (packet)
  1972. client->QueuePacket(packet);
  1973. }
  1974. }
  1975. else if (spawn->IsNPC())
  1976. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1977. else
  1978. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1979. }
  1980. }
  1981. else
  1982. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1983. return 0;
  1984. }
  1985. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1986. if (!lua_interface)
  1987. return 0;
  1988. Spawn* spawn = lua_interface->GetSpawn(state);
  1989. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1990. if (spawn && spawn->IsPlayer()) {
  1991. int32 spell_id = 0;
  1992. if (luaspell && luaspell->spell) {
  1993. spell_id = luaspell->spell->GetSpellID();
  1994. ZoneServer* zone = luaspell->caster->GetZone();
  1995. Spawn* target = 0;
  1996. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1997. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1998. target = zone->GetSpawnByID(luaspell->targets[i]);
  1999. if (target) {
  2000. if (target->IsPlayer()) {
  2001. ((Player*)target)->RemoveSkillBonus(spell_id);
  2002. Client* client = target->GetZone()->GetClientBySpawn(target);
  2003. if (client) {
  2004. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2005. if (packet)
  2006. client->QueuePacket(packet);
  2007. }
  2008. }
  2009. else if (target->IsNPC())
  2010. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2011. else
  2012. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2013. }
  2014. }
  2015. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2016. }
  2017. else if (spawn) {
  2018. if (spawn->IsPlayer()) {
  2019. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2020. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2021. if (client) {
  2022. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2023. if (packet)
  2024. client->QueuePacket(packet);
  2025. }
  2026. }
  2027. else if (spawn->IsNPC())
  2028. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2029. else
  2030. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2031. }
  2032. }
  2033. return 0;
  2034. }
  2035. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2036. if (!lua_interface)
  2037. return 0;
  2038. Spawn* spawn = lua_interface->GetSpawn(state);
  2039. int8 type = lua_interface->GetInt32Value(state, 2);
  2040. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2041. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2042. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2043. ZoneServer* zone = luaspell->caster->GetZone();
  2044. Spawn* target = 0;
  2045. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2046. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2047. target = zone->GetSpawnByID(luaspell->targets[i]);
  2048. if (target && target->IsEntity()) {
  2049. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2050. ((Entity*)target)->AddMezSpell(luaspell);
  2051. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2052. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2053. if (target->IsNPC())
  2054. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2055. }
  2056. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2057. ((Entity*)target)->AddStifleSpell(luaspell);
  2058. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2059. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2060. if (target->IsNPC())
  2061. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2062. }
  2063. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2064. ((Entity*)target)->AddDazeSpell(luaspell);
  2065. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2066. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2067. if (target->IsNPC())
  2068. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2069. }
  2070. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2071. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2072. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2073. ((Entity*)target)->AddStunSpell(luaspell);
  2074. if (target->IsNPC())
  2075. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2076. }
  2077. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2078. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2079. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2080. ((Entity*)target)->AddRootSpell(luaspell);
  2081. if (target->IsNPC())
  2082. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2083. }
  2084. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2085. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2086. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2087. ((Entity*)target)->AddFearSpell(luaspell);
  2088. if (target->IsNPC())
  2089. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2090. }
  2091. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2092. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2093. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2094. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2095. }
  2096. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2097. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2098. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2099. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2100. }
  2101. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2102. ((Entity*)target)->AddSnareSpell(luaspell);
  2103. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2104. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2105. if (target->IsNPC())
  2106. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2107. }
  2108. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2109. ((Entity*)target)->AddFlightSpell(luaspell);
  2110. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2111. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2112. }
  2113. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2114. ((Entity*)target)->AddGlideSpell(luaspell);
  2115. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2116. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2117. }
  2118. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2119. ((Entity*)target)->AddSafefallSpell(luaspell);
  2120. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2121. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2122. }
  2123. else
  2124. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2128. }
  2129. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2130. }
  2131. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2132. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2133. ((Entity*)spawn)->AddMezSpell(luaspell);
  2134. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2135. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2136. }
  2137. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2138. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2139. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2140. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2141. }
  2142. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2143. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2144. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2145. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2146. }
  2147. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2148. ((Entity*)spawn)->AddStunSpell(luaspell);
  2149. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2150. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2151. }
  2152. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2153. ((Entity*)spawn)->AddRootSpell(luaspell);
  2154. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2155. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2156. }
  2157. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2158. ((Entity*)spawn)->AddFearSpell(luaspell);
  2159. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2160. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2161. }
  2162. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2163. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2164. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2165. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2166. }
  2167. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2168. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2169. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2170. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2171. }
  2172. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2173. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2176. }
  2177. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2178. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2181. }
  2182. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2183. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2184. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2185. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2186. }
  2187. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2188. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2189. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2190. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2191. }
  2192. else
  2193. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2194. }
  2195. else
  2196. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2197. return 0;
  2198. }
  2199. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2200. if (!lua_interface)
  2201. return 0;
  2202. Spawn* spawn = lua_interface->GetSpawn(state);
  2203. int8 type = lua_interface->GetInt8Value(state, 2);
  2204. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2205. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2206. if (spawn && spawn->IsEntity()) {
  2207. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2208. ZoneServer* zone = luaspell->caster->GetZone();
  2209. Spawn* target = 0;
  2210. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2211. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2212. target = zone->GetSpawnByID(luaspell->targets[i]);
  2213. if (target) {
  2214. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2215. ((Entity*)target)->RemoveMezSpell(luaspell);
  2216. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2217. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2219. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2221. ((Entity*)target)->RemoveStunSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2223. ((Entity*)target)->RemoveRootSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2225. ((Entity*)target)->RemoveFearSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2227. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2229. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2231. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2233. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2235. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2236. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2237. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2238. else
  2239. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2240. }
  2241. }
  2242. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2243. }
  2244. else if (only_remove_spawn) {
  2245. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2246. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2247. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2248. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2249. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2250. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2251. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2252. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2253. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2254. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2255. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2256. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2257. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2258. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2259. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2260. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2261. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2262. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2263. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2264. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2265. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2266. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2267. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2268. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2269. else
  2270. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2271. }
  2272. }
  2273. return 0;
  2274. }
  2275. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2276. if (!lua_interface)
  2277. return 0;
  2278. Spawn* spawn = lua_interface->GetSpawn(state);
  2279. int8 type = lua_interface->GetInt8Value(state, 2);
  2280. bool hasEffect = false;
  2281. if (!spawn)
  2282. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2283. else if (!spawn->IsEntity())
  2284. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2285. else if (type < CONTROL_MAX_EFFECTS)
  2286. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2287. else
  2288. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2289. lua_interface->SetBooleanValue(state, hasEffect);
  2290. return 1;
  2291. }
  2292. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2293. if (!lua_interface)
  2294. return 0;
  2295. Spawn* spawn = lua_interface->GetSpawn(state);
  2296. float distance = 0.0f;
  2297. if (!spawn)
  2298. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2299. else if (!spawn->IsNPC())
  2300. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2301. else
  2302. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2303. lua_interface->SetFloatValue(state, distance);
  2304. return 1;
  2305. }
  2306. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2307. if (!lua_interface)
  2308. return 0;
  2309. Spawn* spawn = lua_interface->GetSpawn(state);
  2310. float distance = 0.0f;
  2311. if (!spawn)
  2312. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2313. else if (!spawn->IsNPC())
  2314. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2315. else
  2316. distance = ((NPC*)spawn)->GetAggroRadius();
  2317. lua_interface->SetFloatValue(state, distance);
  2318. return 1;
  2319. }
  2320. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2321. if (!lua_interface)
  2322. return 0;
  2323. Spawn* spawn = lua_interface->GetSpawn(state);
  2324. float distance = lua_interface->GetFloatValue(state, 2);
  2325. bool override = lua_interface->GetBooleanValue(state, 3);
  2326. bool result = false;
  2327. lua_interface->ResetFunctionStack(state);
  2328. if (!spawn)
  2329. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2330. else if (!spawn->IsNPC())
  2331. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2332. else
  2333. {
  2334. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2335. result = true;
  2336. }
  2337. lua_interface->SetBooleanValue(state, result);
  2338. return 1;
  2339. }
  2340. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2341. if (!lua_interface)
  2342. return 0;
  2343. Spawn* spawn = lua_interface->GetSpawn(state);
  2344. int16 value = lua_interface->GetInt16Value(state, 2);
  2345. if (spawn && spawn->IsEntity()) {
  2346. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2347. if (spawn->IsPlayer())
  2348. ((Player*)spawn)->SetCharSheetChanged(true);
  2349. }
  2350. return 0;
  2351. }
  2352. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2353. if (!lua_interface)
  2354. return 0;
  2355. Spawn* spawn = lua_interface->GetSpawn(state);
  2356. int16 value = lua_interface->GetInt16Value(state, 2);
  2357. if (spawn && spawn->IsEntity()) {
  2358. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2359. if (spawn->IsPlayer())
  2360. ((Player*)spawn)->SetCharSheetChanged(true);
  2361. }
  2362. return 0;
  2363. }
  2364. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2365. if (!lua_interface)
  2366. return 0;
  2367. Spawn* spawn = lua_interface->GetSpawn(state);
  2368. int16 value = lua_interface->GetInt16Value(state, 2);
  2369. if (spawn && spawn->IsEntity()) {
  2370. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2371. if (spawn->IsPlayer())
  2372. ((Player*)spawn)->SetCharSheetChanged(true);
  2373. }
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2377. if (!lua_interface)
  2378. return 0;
  2379. Spawn* spawn = lua_interface->GetSpawn(state);
  2380. int16 value = lua_interface->GetInt16Value(state, 2);
  2381. if (spawn && spawn->IsEntity()) {
  2382. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2383. if (spawn->IsPlayer())
  2384. ((Player*)spawn)->SetCharSheetChanged(true);
  2385. }
  2386. return 0;
  2387. }
  2388. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2389. if (!lua_interface)
  2390. return 0;
  2391. Spawn* spawn = lua_interface->GetSpawn(state);
  2392. int16 value = lua_interface->GetInt16Value(state, 2);
  2393. if (spawn && spawn->IsEntity()) {
  2394. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2395. if (spawn->IsPlayer())
  2396. ((Player*)spawn)->SetCharSheetChanged(true);
  2397. }
  2398. return 0;
  2399. }
  2400. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2401. if (!lua_interface)
  2402. return 0;
  2403. Spawn* spawn = lua_interface->GetSpawn(state);
  2404. int8 value = lua_interface->GetInt8Value(state, 2);
  2405. if (spawn && spawn->IsEntity()) {
  2406. ((Entity*)spawn)->SetDeity(value);
  2407. if (spawn->IsPlayer())
  2408. ((Player*)spawn)->SetCharSheetChanged(true);
  2409. }
  2410. lua_interface->ResetFunctionStack(state);
  2411. return 0;
  2412. }
  2413. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2414. if (!lua_interface)
  2415. return 0;
  2416. Spawn* spawn = lua_interface->GetSpawn(state);
  2417. if (spawn && spawn->IsEntity()) {
  2418. int8 deity = ((Entity*)spawn)->GetDeity();
  2419. lua_interface->SetInt32Value(state, deity);
  2420. return 1;
  2421. }
  2422. return 0;
  2423. }
  2424. int EQ2Emu_lua_SetInt(lua_State* state) {
  2425. if (!lua_interface)
  2426. return 0;
  2427. Spawn* spawn = lua_interface->GetSpawn(state);
  2428. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2429. if (spawn && spawn->IsEntity()) {
  2430. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2431. if (spawn->IsPlayer())
  2432. ((Player*)spawn)->SetCharSheetChanged(true);
  2433. }
  2434. return 0;
  2435. }
  2436. int EQ2Emu_lua_SetWis(lua_State* state) {
  2437. if (!lua_interface)
  2438. return 0;
  2439. Spawn* spawn = lua_interface->GetSpawn(state);
  2440. float value = lua_interface->GetFloatValue(state, 2);
  2441. if (spawn && spawn->IsEntity()) {
  2442. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2443. if (spawn->IsPlayer())
  2444. ((Player*)spawn)->SetCharSheetChanged(true);
  2445. }
  2446. return 0;
  2447. }
  2448. int EQ2Emu_lua_SetSta(lua_State* state) {
  2449. if (!lua_interface)
  2450. return 0;
  2451. Spawn* spawn = lua_interface->GetSpawn(state);
  2452. float value = lua_interface->GetFloatValue(state, 2);
  2453. if (spawn && spawn->IsEntity()) {
  2454. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2455. if (spawn->IsPlayer())
  2456. ((Player*)spawn)->SetCharSheetChanged(true);
  2457. }
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_SetStr(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. float value = lua_interface->GetFloatValue(state, 2);
  2465. if (spawn && spawn->IsEntity()) {
  2466. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2467. if (spawn->IsPlayer())
  2468. ((Player*)spawn)->SetCharSheetChanged(true);
  2469. }
  2470. return 0;
  2471. }
  2472. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2473. if (!lua_interface)
  2474. return 0;
  2475. Spawn* spawn = lua_interface->GetSpawn(state);
  2476. float value = lua_interface->GetFloatValue(state, 2);
  2477. if (spawn && spawn->IsEntity()) {
  2478. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2479. if (spawn->IsPlayer())
  2480. ((Player*)spawn)->SetCharSheetChanged(true);
  2481. }
  2482. return 0;
  2483. }
  2484. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2485. if (!lua_interface)
  2486. return 0;
  2487. Spawn* spawn = lua_interface->GetSpawn(state);
  2488. if (spawn) {
  2489. lua_interface->SetInt32Value(state, spawn->GetHP());
  2490. return 1;
  2491. }
  2492. return 0;
  2493. }
  2494. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2495. if (!lua_interface)
  2496. return 0;
  2497. Spawn* spawn = lua_interface->GetSpawn(state);
  2498. if (spawn) {
  2499. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2500. return 1;
  2501. }
  2502. return 0;
  2503. }
  2504. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2505. if (!lua_interface)
  2506. return 0;
  2507. Spawn* spawn = lua_interface->GetSpawn(state);
  2508. if (spawn) {
  2509. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2510. return 1;
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_GetName(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. if (spawn) {
  2519. lua_interface->SetStringValue(state, spawn->GetName());
  2520. return 1;
  2521. }
  2522. return 0;
  2523. }
  2524. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2525. Spawn* spawn = lua_interface->GetSpawn(state);
  2526. if (spawn) {
  2527. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2528. return 1;
  2529. }
  2530. return 0;
  2531. }
  2532. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2533. if (!lua_interface)
  2534. return 0;
  2535. Spawn* spawn = lua_interface->GetSpawn(state);
  2536. if (spawn) {
  2537. lua_interface->SetInt32Value(state, spawn->GetPower());
  2538. return 1;
  2539. }
  2540. return 0;
  2541. }
  2542. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2543. if (!lua_interface)
  2544. return 0;
  2545. Spawn* spawn = lua_interface->GetSpawn(state);
  2546. if (spawn) {
  2547. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2548. return 1;
  2549. }
  2550. return 0;
  2551. }
  2552. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2553. if (!lua_interface)
  2554. return 0;
  2555. Spawn* spawn = lua_interface->GetSpawn(state);
  2556. if (spawn) {
  2557. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2558. return 1;
  2559. }
  2560. return 0;
  2561. }
  2562. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2563. if (!lua_interface)
  2564. return 0;
  2565. Spawn* spawn = lua_interface->GetSpawn(state);
  2566. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2567. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2568. if (spawn && spawn2) {
  2569. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2570. lua_interface->SetFloatValue(state, distance);
  2571. return 1;
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_GetX(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. if (spawn) {
  2580. lua_interface->SetFloatValue(state, spawn->GetX());
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_GetY(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* spawn = lua_interface->GetSpawn(state);
  2589. if (spawn) {
  2590. lua_interface->SetFloatValue(state, spawn->GetY());
  2591. return 1;
  2592. }
  2593. return 0;
  2594. }
  2595. int EQ2Emu_lua_GetZ(lua_State* state) {
  2596. if (!lua_interface)
  2597. return 0;
  2598. Spawn* spawn = lua_interface->GetSpawn(state);
  2599. if (spawn) {
  2600. lua_interface->SetFloatValue(state, spawn->GetZ());
  2601. return 1;
  2602. }
  2603. return 0;
  2604. }
  2605. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2606. if (!lua_interface)
  2607. return 0;
  2608. Spawn* spawn = lua_interface->GetSpawn(state);
  2609. if (spawn) {
  2610. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2611. return 1;
  2612. }
  2613. return 0;
  2614. }
  2615. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2616. if (!lua_interface)
  2617. return 0;
  2618. Spawn* spawn = lua_interface->GetSpawn(state);
  2619. if (spawn) {
  2620. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2621. return 1;
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. if (spawn) {
  2630. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2631. return 1;
  2632. }
  2633. return 0;
  2634. }
  2635. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2636. if (!lua_interface)
  2637. return 0;
  2638. Spawn* spawn = lua_interface->GetSpawn(state);
  2639. if (spawn && spawn->IsEntity()) {
  2640. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2641. return 1;
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_GetInt(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. if (spawn && spawn->IsEntity()) {
  2650. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2651. return 1;
  2652. }
  2653. return 0;
  2654. }
  2655. int EQ2Emu_lua_GetWis(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Spawn* spawn = lua_interface->GetSpawn(state);
  2659. if (spawn && spawn->IsEntity()) {
  2660. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2661. return 1;
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_GetSta(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. if (spawn && spawn->IsEntity()) {
  2670. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2671. return 1;
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_GetStr(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Spawn* spawn = lua_interface->GetSpawn(state);
  2679. if (spawn && spawn->IsEntity()) {
  2680. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2681. return 1;
  2682. }
  2683. return 0;
  2684. }
  2685. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2686. if (!lua_interface)
  2687. return 0;
  2688. Spawn* spawn = lua_interface->GetSpawn(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2691. return 1;
  2692. }
  2693. return 0;
  2694. }
  2695. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2696. if (!lua_interface)
  2697. return 0;
  2698. Spawn* spawn = lua_interface->GetSpawn(state);
  2699. if (spawn && spawn->IsEntity()) {
  2700. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2701. return 1;
  2702. }
  2703. return 0;
  2704. }
  2705. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2706. if (!lua_interface)
  2707. return 0;
  2708. Spawn* spawn = lua_interface->GetSpawn(state);
  2709. if (spawn && spawn->IsEntity()) {
  2710. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2711. return 1;
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. if (spawn && spawn->IsEntity()) {
  2720. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2721. return 1;
  2722. }
  2723. return 0;
  2724. }
  2725. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2726. if (!lua_interface)
  2727. return 0;
  2728. Spawn* spawn = lua_interface->GetSpawn(state);
  2729. if (spawn && spawn->IsEntity()) {
  2730. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2731. return 1;
  2732. }
  2733. return 0;
  2734. }
  2735. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2736. if (!lua_interface)
  2737. return 0;
  2738. Spawn* spawn = lua_interface->GetSpawn(state);
  2739. if (spawn && spawn->IsEntity()) {
  2740. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2741. return 1;
  2742. }
  2743. return 0;
  2744. }
  2745. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2746. if (!lua_interface)
  2747. return 0;
  2748. Spawn* player = lua_interface->GetSpawn(state);
  2749. if (!player || !player->IsPlayer()) {
  2750. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2751. return 0;
  2752. }
  2753. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2754. if (quest_id <= 0) {
  2755. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2756. return 0;
  2757. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2758. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2759. return 0;
  2760. }
  2761. int32 step = lua_interface->GetInt32Value(state, 3);
  2762. if (step > 0) {
  2763. Client* client = player->GetZone()->GetClientBySpawn(player);
  2764. if (client)
  2765. client->AddPendingQuestUpdate(quest_id, step);
  2766. } else {
  2767. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2768. }
  2769. return 0;
  2770. }
  2771. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2772. Spawn* player = lua_interface->GetSpawn(state);
  2773. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2774. int32 step = lua_interface->GetInt32Value(state, 3);
  2775. int32 progress = lua_interface->GetInt32Value(state, 4);
  2776. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2777. Client* client = player->GetZone()->GetClientBySpawn(player);
  2778. if (client)
  2779. client->AddPendingQuestUpdate(quest_id, step, progress);
  2780. }
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* player = lua_interface->GetSpawn(state);
  2787. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2788. if (player && player->IsPlayer() && quest_id > 0) {
  2789. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2790. return 1;
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Spawn* player = lua_interface->GetSpawn(state);
  2798. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2799. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2800. if (player && player->IsPlayer() && quest_id > 0) {
  2801. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* player = lua_interface->GetSpawn(state);
  2810. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2811. if (player && player->IsPlayer() && quest_id > 0) {
  2812. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2813. return 1;
  2814. }
  2815. return 0;
  2816. }
  2817. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2818. if (!lua_interface)
  2819. return 0;
  2820. Quest* quest = lua_interface->GetQuest(state);
  2821. string name = lua_interface->GetStringValue(state, 2);
  2822. string type = lua_interface->GetStringValue(state, 3);
  2823. string zone = lua_interface->GetStringValue(state, 4);
  2824. int16 level = lua_interface->GetInt16Value(state, 5);
  2825. string description = lua_interface->GetStringValue(state, 6);
  2826. bool load = true;
  2827. if (!quest) {
  2828. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2829. load = false;
  2830. }
  2831. if (load && name.length() == 0) {
  2832. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2833. load = false;
  2834. }
  2835. if (load && type.length() == 0) {
  2836. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2837. load = false;
  2838. }
  2839. if (load && zone.length() == 0) {
  2840. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2841. load = false;
  2842. }
  2843. if (load && description.length() == 0) {
  2844. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2845. load = false;
  2846. }
  2847. if (load && level == 0) {
  2848. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2849. load = false;
  2850. }
  2851. if (load)
  2852. quest->RegisterQuest(name, type, zone, level, description);
  2853. return 0;
  2854. }
  2855. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2856. if (!lua_interface)
  2857. return 0;
  2858. Quest* quest = lua_interface->GetQuest(state);
  2859. if (quest) {
  2860. int8 level = lua_interface->GetInt16Value(state, 2);
  2861. quest->SetPrereqLevel(level);
  2862. }
  2863. return 0;
  2864. }
  2865. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2866. if (!lua_interface)
  2867. return 0;
  2868. Quest* quest = lua_interface->GetQuest(state);
  2869. if (quest) {
  2870. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2871. quest->AddPrereqQuest(quest_id);
  2872. }
  2873. return 0;
  2874. }
  2875. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2876. if (!lua_interface)
  2877. return 0;
  2878. Quest* quest = lua_interface->GetQuest(state);
  2879. if (quest) {
  2880. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2881. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2882. if (quantity == 0)
  2883. quantity = 1;
  2884. Item* master_item = master_item_list.GetItem(item_id);
  2885. if (master_item) {
  2886. Item* item = new Item(master_item);
  2887. item->details.count = quantity;
  2888. quest->AddPrereqItem(item);
  2889. }
  2890. }
  2891. return 0;
  2892. }
  2893. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2894. if (!lua_interface)
  2895. return 0;
  2896. Spawn* player = lua_interface->GetSpawn(state);
  2897. if(!player || !player->IsPlayer()) {
  2898. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2899. return 0;
  2900. }
  2901. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2902. if (quest_id > 0) {
  2903. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2904. return 1;
  2905. } else {
  2906. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Quest* quest = lua_interface->GetQuest(state);
  2914. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2915. if (quest && spawn_id > 0)
  2916. quest->SetQuestReturnNPC(spawn_id);
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Spawn* spawn = lua_interface->GetSpawn(state);
  2923. if (!spawn) {
  2924. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2925. return 0;
  2926. }
  2927. int32 time = lua_interface->GetInt32Value(state, 2);
  2928. if (time <= 0) {
  2929. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2930. return 0;
  2931. }
  2932. string function = lua_interface->GetStringValue(state, 3);
  2933. if (function.length() == 0) {
  2934. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2935. return 0;
  2936. }
  2937. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2938. Spawn* player = lua_interface->GetSpawn(state, 5);
  2939. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2940. timer->timer = Timer::GetCurrentTime2() + time;
  2941. timer->function = function;
  2942. timer->spawn = spawn->GetID();
  2943. timer->player = player ? player->GetID() : 0;
  2944. if (max_count == 0)
  2945. max_count = 1;
  2946. timer->max_count = max_count;
  2947. timer->current_count = 0;
  2948. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* player = lua_interface->GetSpawn(state);
  2955. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2956. if (player && player->IsPlayer() && quest_id > 0) {
  2957. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* player = lua_interface->GetSpawn(state);
  2966. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2967. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2968. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2969. if (quest)
  2970. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2971. return 1;
  2972. }
  2973. return 0;
  2974. }
  2975. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2976. if (!lua_interface)
  2977. return 0;
  2978. Spawn* player = lua_interface->GetSpawn(state);
  2979. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2980. if (player && player->IsPlayer() && quest_id > 0) {
  2981. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2982. return 1;
  2983. }
  2984. return 0;
  2985. }
  2986. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2987. if (!lua_interface)
  2988. return 0;
  2989. Spawn* npc = lua_interface->GetSpawn(state);
  2990. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2991. if (npc && !npc->IsPlayer() && quest_id > 0)
  2992. npc->AddProvidedQuest(quest_id);
  2993. return 0;
  2994. }
  2995. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2996. if (!lua_interface)
  2997. return 0;
  2998. Spawn* npc = lua_interface->GetSpawn(state);
  2999. Spawn* player = lua_interface->GetSpawn(state, 2);
  3000. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3001. bool forced = lua_interface->GetBooleanValue(state, 4);
  3002. /* NPC is allowed to be null */
  3003. if (player && player->IsPlayer() && quest_id > 0) {
  3004. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  3005. if (master_quest) {
  3006. Client* client = player->GetZone()->GetClientBySpawn(player);
  3007. if (!client) {
  3008. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3009. }
  3010. Quest* quest = new Quest(master_quest);
  3011. if (!quest) {
  3012. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3013. }
  3014. if (client && quest) {
  3015. if (npc)
  3016. quest->SetQuestGiver(npc->GetDatabaseID());
  3017. else
  3018. quest->SetQuestGiver(0);
  3019. client->AddPendingQuest(quest, forced);
  3020. }
  3021. }
  3022. else {
  3023. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3024. }
  3025. }
  3026. else {
  3027. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Quest* quest = lua_interface->GetQuest(state);
  3035. if (quest) {
  3036. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3037. quest->AddPrereqClass(class_id);
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Quest* quest = lua_interface->GetQuest(state);
  3045. if (quest) {
  3046. int8 race = lua_interface->GetInt8Value(state, 2);
  3047. quest->AddPrereqRace(race);
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Quest* quest = lua_interface->GetQuest(state);
  3055. if (quest) {
  3056. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3057. quest->AddPrereqModelType(model_type);
  3058. }
  3059. return 0;
  3060. }
  3061. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3062. if (!lua_interface)
  3063. return 0;
  3064. Quest* quest = lua_interface->GetQuest(state);
  3065. if (!quest) {
  3066. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3067. return 0;
  3068. }
  3069. int8 level = lua_interface->GetInt8Value(state, 2);
  3070. quest->SetPrereqTSLevel(level);
  3071. return 0;
  3072. }
  3073. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3074. if (!lua_interface)
  3075. return 0;
  3076. Quest* quest = lua_interface->GetQuest(state);
  3077. if (!quest) {
  3078. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3079. return 0;
  3080. }
  3081. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3082. quest->AddPrereqTradeskillClass(class_id);
  3083. return 0;
  3084. }
  3085. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3086. if (!lua_interface)
  3087. return 0;
  3088. Quest* quest = lua_interface->GetQuest(state);
  3089. if (quest) {
  3090. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3091. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3092. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3093. quest->AddPrereqFaction(faction_id, min, max);
  3094. }
  3095. return 0;
  3096. }
  3097. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3098. if (!lua_interface)
  3099. return 0;
  3100. Quest* quest = lua_interface->GetQuest(state);
  3101. if (quest) {
  3102. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3103. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3104. if (quantity == 0)
  3105. quantity = 1;
  3106. Item* master_item = master_item_list.GetItem(item_id);
  3107. if (master_item) {
  3108. Item* item = new Item(master_item);
  3109. item->details.count = quantity;
  3110. quest->AddSelectableRewardItem(item);
  3111. }
  3112. }
  3113. return 0;
  3114. }
  3115. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3116. if (!lua_interface)
  3117. return 0;
  3118. Quest* quest = lua_interface->GetQuest(state);
  3119. if (quest) {
  3120. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3121. vector<Item*>* items = quest->GetRewardItems();
  3122. if (items) {
  3123. vector<Item*>::iterator itr;
  3124. for (itr = items->begin(); itr != items->end(); itr++) {
  3125. if (*itr && (*itr)->details.item_id == item_id) {
  3126. lua_interface->SetBooleanValue(state, true);
  3127. return 1;
  3128. }
  3129. }
  3130. }
  3131. }
  3132. lua_interface->SetBooleanValue(state, false);
  3133. return 1;
  3134. }
  3135. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3136. if (!lua_interface)
  3137. return 0;
  3138. Quest* quest = lua_interface->GetQuest(state);
  3139. if (quest) {
  3140. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3141. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3142. if (quantity == 0)
  3143. quantity = 1;
  3144. Item* master_item = master_item_list.GetItem(item_id);
  3145. if (master_item) {
  3146. Item* item = new Item(master_item);
  3147. item->details.count = quantity;
  3148. quest->AddRewardItem(item);
  3149. }
  3150. }
  3151. return 0;
  3152. }
  3153. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3154. if (!lua_interface)
  3155. return 0;
  3156. Quest* quest = lua_interface->GetQuest(state);
  3157. if (quest) {
  3158. int32 copper = lua_interface->GetInt32Value(state, 2);
  3159. int32 silver = lua_interface->GetInt32Value(state, 3);
  3160. int32 gold = lua_interface->GetInt32Value(state, 4);
  3161. int32 plat = lua_interface->GetInt32Value(state, 5);
  3162. quest->AddRewardCoins(copper, silver, gold, plat);
  3163. }
  3164. return 0;
  3165. }
  3166. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3167. if (!lua_interface)
  3168. return 0;
  3169. Quest* quest = lua_interface->GetQuest(state);
  3170. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3171. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3172. if (quest && faction_id > 0 && amount != 0)
  3173. quest->AddRewardFaction(faction_id, amount);
  3174. return 0;
  3175. }
  3176. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3177. if (!lua_interface)
  3178. return 0;
  3179. Quest* quest = lua_interface->GetQuest(state);
  3180. if (quest) {
  3181. int32 status = lua_interface->GetInt32Value(state, 2);
  3182. quest->SetRewardStatus(status);
  3183. }
  3184. return 0;
  3185. }
  3186. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3187. if (!lua_interface)
  3188. return 0;
  3189. Quest* quest = lua_interface->GetQuest(state);
  3190. if (quest) {
  3191. string comment = lua_interface->GetStringValue(state, 2);
  3192. quest->SetRewardComment(comment);
  3193. }
  3194. return 0;
  3195. }
  3196. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3197. if (!lua_interface)
  3198. return 0;
  3199. Quest* quest = lua_interface->GetQuest(state);
  3200. if (quest) {
  3201. int32 exp = lua_interface->GetInt32Value(state, 2);
  3202. quest->SetRewardXP(exp);
  3203. }
  3204. return 0;
  3205. }
  3206. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3207. Quest* quest = lua_interface->GetQuest(state);
  3208. if (quest) {
  3209. int32 step = lua_interface->GetInt32Value(state, 2);
  3210. string description = lua_interface->GetStringValue(state, 3);
  3211. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3212. float percentage = lua_interface->GetFloatValue(state, 5);
  3213. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3214. int16 icon = lua_interface->GetInt16Value(state, 7);
  3215. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3216. const char* taskgroup = 0;
  3217. if (str_taskgroup.length() > 0)
  3218. taskgroup = str_taskgroup.c_str();
  3219. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3220. if (quest_step && icon && quantity > 0)
  3221. quest_step->SetIcon(icon);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Quest* quest = lua_interface->GetQuest(state);
  3229. if (quest) {
  3230. int32 step = lua_interface->GetInt32Value(state, 2);
  3231. string description = lua_interface->GetStringValue(state, 3);
  3232. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3233. float percentage = lua_interface->GetFloatValue(state, 5);
  3234. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3235. int16 icon = lua_interface->GetInt16Value(state, 7);
  3236. const char* taskgroup = 0;
  3237. if (str_taskgroup.length() > 0)
  3238. taskgroup = str_taskgroup.c_str();
  3239. int32 npc_id = 0;
  3240. vector<int32>* ids = 0;
  3241. Spawn* spawn = nullptr;
  3242. int i = 0;
  3243. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3244. if (ids == 0)
  3245. ids = new vector<int32>;
  3246. ids->push_back(npc_id);
  3247. i++;
  3248. }
  3249. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3250. if (quest_step && icon > 0 && quantity > 0)
  3251. quest_step->SetIcon(icon);
  3252. if (quest->GetPlayer()) {
  3253. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3254. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3255. }
  3256. }
  3257. return 0;
  3258. }
  3259. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3260. if (!lua_interface)
  3261. return 0;
  3262. Quest* quest = lua_interface->GetQuest(state);
  3263. if (quest) {
  3264. int32 step = lua_interface->GetInt32Value(state, 2);
  3265. string description = lua_interface->GetStringValue(state, 3);
  3266. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3267. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3268. int16 icon = lua_interface->GetInt16Value(state, 6);
  3269. const char* taskgroup = 0;
  3270. if (str_taskgroup.length() > 0)
  3271. taskgroup = str_taskgroup.c_str();
  3272. int32 npc_id = 0;
  3273. vector<int32>* ids = 0;
  3274. int i = 0;
  3275. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3276. if (ids == 0)
  3277. ids = new vector<int32>;
  3278. ids->push_back(npc_id);
  3279. i++;
  3280. }
  3281. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3282. if (quest_step && icon > 0)
  3283. quest_step->SetIcon(icon);
  3284. if (quest->GetPlayer()) {
  3285. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3286. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3287. }
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Quest* quest = lua_interface->GetQuest(state);
  3295. if (quest) {
  3296. int32 step = lua_interface->GetInt32Value(state, 2);
  3297. string description = lua_interface->GetStringValue(state, 3);
  3298. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3299. float percentage = lua_interface->GetFloatValue(state, 5);
  3300. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3301. int16 icon = lua_interface->GetInt16Value(state, 7);
  3302. const char* taskgroup = 0;
  3303. if (str_taskgroup.length() > 0)
  3304. taskgroup = str_taskgroup.c_str();
  3305. int32 item_id = 0;
  3306. vector<int32>* ids = 0;
  3307. int i = 0;
  3308. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3309. if (ids == 0)
  3310. ids = new vector<int32>;
  3311. ids->push_back(item_id);
  3312. i++;
  3313. }
  3314. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3315. if (quest_step && icon > 0 && quantity > 0)
  3316. quest_step->SetIcon(icon);
  3317. if (quest->GetPlayer()) {
  3318. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3319. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3320. }
  3321. }
  3322. return 0;
  3323. }
  3324. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3325. if (!lua_interface)
  3326. return 0;
  3327. Quest* quest = lua_interface->GetQuest(state);
  3328. if (quest) {
  3329. int32 step = lua_interface->GetInt32Value(state, 2);
  3330. string description = lua_interface->GetStringValue(state, 3);
  3331. float max_variation = lua_interface->GetFloatValue(state, 4);
  3332. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3333. int16 icon = lua_interface->GetInt16Value(state, 6);
  3334. const char* taskgroup = 0;
  3335. if (str_taskgroup.length() > 0)
  3336. taskgroup = str_taskgroup.c_str();
  3337. vector<Location>* locations = 0;
  3338. int i = 7;
  3339. while (true) {
  3340. Location loc;
  3341. loc.x = lua_interface->GetFloatValue(state, i);
  3342. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3343. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3344. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3345. break;
  3346. if (locations == 0)
  3347. locations = new vector<Location>;
  3348. locations->push_back(loc);
  3349. i += 3;
  3350. }
  3351. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3352. if (quest_step && icon > 0)
  3353. quest_step->SetIcon(icon);
  3354. if (quest->GetPlayer()) {
  3355. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3356. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3357. }
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 step = lua_interface->GetInt32Value(state, 2);
  3367. string description = lua_interface->GetStringValue(state, 3);
  3368. float max_variation = lua_interface->GetFloatValue(state, 4);
  3369. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3370. int16 icon = lua_interface->GetInt16Value(state, 6);
  3371. const char* taskgroup = 0;
  3372. if (str_taskgroup.length() > 0)
  3373. taskgroup = str_taskgroup.c_str();
  3374. vector<Location>* locations = 0;
  3375. int i = 7;
  3376. while (true) {
  3377. Location loc;
  3378. loc.x = lua_interface->GetFloatValue(state, i);
  3379. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3380. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3381. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3382. break;
  3383. if (locations == 0)
  3384. locations = new vector<Location>;
  3385. locations->push_back(loc);
  3386. i += 3;
  3387. }
  3388. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3389. if (quest_step && icon > 0)
  3390. quest_step->SetIcon(icon);
  3391. if (quest->GetPlayer()) {
  3392. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3393. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3394. }
  3395. }
  3396. return 0;
  3397. }
  3398. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. if (quest) {
  3401. int32 step = lua_interface->GetInt32Value(state, 2);
  3402. string description = lua_interface->GetStringValue(state, 3);
  3403. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3404. float percentage = lua_interface->GetFloatValue(state, 5);
  3405. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3406. int16 icon = lua_interface->GetInt16Value(state, 7);
  3407. const char* taskgroup = 0;
  3408. if (str_taskgroup.length() > 0)
  3409. taskgroup = str_taskgroup.c_str();
  3410. int32 spell_id = 0;
  3411. vector<int32>* ids = 0;
  3412. int i = 0;
  3413. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3414. if (ids == 0)
  3415. ids = new vector<int32>;
  3416. ids->push_back(spell_id);
  3417. i++;
  3418. }
  3419. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3420. if (quest_step && icon > 0 && quantity > 0)
  3421. quest_step->SetIcon(icon);
  3422. if (quest->GetPlayer()) {
  3423. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3424. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3425. }
  3426. }
  3427. return 0;
  3428. }
  3429. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3430. if (!lua_interface)
  3431. return 0;
  3432. Quest* quest = lua_interface->GetQuest(state);
  3433. if (quest) {
  3434. int32 step = lua_interface->GetInt32Value(state, 2);
  3435. string description = lua_interface->GetStringValue(state, 3);
  3436. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3437. float percentage = lua_interface->GetFloatValue(state, 5);
  3438. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3439. int16 icon = lua_interface->GetInt16Value(state, 7);
  3440. const char* taskgroup = 0;
  3441. if (str_taskgroup.length() > 0)
  3442. taskgroup = str_taskgroup.c_str();
  3443. int32 item_id = 0;
  3444. vector<int32>* ids = 0;
  3445. int i = 0;
  3446. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3447. if (ids == 0)
  3448. ids = new vector<int32>;
  3449. ids->push_back(item_id);
  3450. i++;
  3451. }
  3452. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3453. if (quest_step && icon > 0 && quantity > 0)
  3454. quest_step->SetIcon(icon);
  3455. if (quest->GetPlayer()) {
  3456. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3457. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3458. }
  3459. }
  3460. return 0;
  3461. }
  3462. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3463. if (!lua_interface)
  3464. return 0;
  3465. Quest* quest = lua_interface->GetQuest(state);
  3466. if (quest) {
  3467. int32 step = lua_interface->GetInt32Value(state, 2);
  3468. string description = lua_interface->GetStringValue(state, 3);
  3469. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3470. float percentage = lua_interface->GetFloatValue(state, 5);
  3471. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3472. int16 icon = lua_interface->GetInt16Value(state, 7);
  3473. const char* taskgroup = 0;
  3474. if (str_taskgroup.length() > 0)
  3475. taskgroup = str_taskgroup.c_str();
  3476. int32 item_id = 0;
  3477. vector<int32>* ids = 0;
  3478. int i = 0;
  3479. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3480. if (ids == 0)
  3481. ids = new vector<int32>;
  3482. ids->push_back(item_id);
  3483. i++;
  3484. }
  3485. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3486. if (quest_step && icon > 0 && quantity > 0)
  3487. quest_step->SetIcon(icon);
  3488. if (quest->GetPlayer()) {
  3489. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3490. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3491. }
  3492. }
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. if (quest) {
  3500. string action = lua_interface->GetStringValue(state, 2);
  3501. if (action.length() > 0)
  3502. quest->SetCompleteAction(action);
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Quest* quest = lua_interface->GetQuest(state);
  3510. if (quest) {
  3511. int32 step = lua_interface->GetInt32Value(state, 2);
  3512. string action = lua_interface->GetStringValue(state, 3);
  3513. if (step > 0 && action.length() > 0)
  3514. quest->AddCompleteAction(step, action);
  3515. }
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. if (quest) {
  3523. int32 step = lua_interface->GetInt32Value(state, 2);
  3524. string action = lua_interface->GetStringValue(state, 3);
  3525. if (step > 0 && action.length() > 0)
  3526. quest->AddProgressAction(step, action);
  3527. }
  3528. return 0;
  3529. }
  3530. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3531. if (!lua_interface)
  3532. return 0;
  3533. Quest* quest = lua_interface->GetQuest(state);
  3534. string description = lua_interface->GetStringValue(state, 2);
  3535. if (quest && description.length() > 0)
  3536. quest->SetDescription(description);
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Quest* quest = lua_interface->GetQuest(state);
  3543. string description = lua_interface->GetStringValue(state, 2);
  3544. if (quest && description.length() > 0)
  3545. quest->SetCompletedDescription(description);
  3546. return 0;
  3547. }
  3548. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3549. if (!lua_interface)
  3550. return 0;
  3551. Quest* quest = lua_interface->GetQuest(state);
  3552. int32 step = lua_interface->GetInt32Value(state, 2);
  3553. string description = lua_interface->GetStringValue(state, 3);
  3554. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3555. if (quest && step > 0 && description.length() > 0) {
  3556. quest->SetTaskGroupDescription(step, description, display_bullets);
  3557. if (quest->GetPlayer()) {
  3558. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3559. if (client)
  3560. client->SendQuestUpdateStep(quest, step, false);
  3561. }
  3562. }
  3563. return 0;
  3564. }
  3565. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Quest* quest = lua_interface->GetQuest(state);
  3569. int32 step = lua_interface->GetInt32Value(state, 2);
  3570. string description = lua_interface->GetStringValue(state, 3);
  3571. if (quest && step > 0 && description.length() > 0) {
  3572. quest->SetStepDescription(step, description);
  3573. if (quest->GetPlayer()) {
  3574. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3575. if (client)
  3576. client->SendQuestUpdateStepImmediately(quest, step);
  3577. }
  3578. }
  3579. return 0;
  3580. }
  3581. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3582. Quest* quest = lua_interface->GetQuest(state);
  3583. string zone = lua_interface->GetStringValue(state, 2);
  3584. if (quest && zone.length() > 0)
  3585. quest->SetZone(zone);
  3586. return 0;
  3587. }
  3588. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3589. if (!lua_interface)
  3590. return 0;
  3591. Quest* quest = lua_interface->GetQuest(state);
  3592. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3593. int32 coin = lua_interface->GetInt32Value(state, 3);
  3594. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3595. string rewards_str = lua_interface->GetStringValue(state, 5);
  3596. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3597. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3598. string text = lua_interface->GetStringValue(state, 8);
  3599. int32 source_id = 0;
  3600. if (playerSpawn && playerSpawn->IsPlayer()) {
  3601. Player* player = (Player*)playerSpawn;
  3602. Client* client = player->GetZone()->GetClientBySpawn(player);
  3603. if (client) {
  3604. vector<Item*> reward_items;
  3605. vector<Item*> selectable_reward_items;
  3606. if (rewards_str.length() > 0) {
  3607. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3608. map<unsigned int, unsigned short>::iterator itr;
  3609. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3610. if (itr->first > 0) {
  3611. Item* item = new Item(master_item_list.GetItem(itr->first));
  3612. if (item) {
  3613. if (itr->second > 0)
  3614. item->details.count = itr->second;
  3615. reward_items.push_back(item);
  3616. }
  3617. }
  3618. }
  3619. }
  3620. if (select_rewards_str.length() > 0) {
  3621. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3622. map<unsigned int, unsigned short>::iterator itr;
  3623. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3624. if (itr->first > 0) {
  3625. Item* item = new Item(master_item_list.GetItem(itr->first));
  3626. if (item) {
  3627. if (itr->second > 0)
  3628. item->stack_count = itr->second;
  3629. selectable_reward_items.push_back(item);
  3630. }
  3631. }
  3632. }
  3633. }
  3634. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3635. const char* reward_type = "Quest Reward!";
  3636. if (!quest)
  3637. reward_type = "Reward!";
  3638. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3639. }
  3640. }
  3641. return 0;
  3642. }
  3643. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3644. if (!lua_interface)
  3645. return 0;
  3646. Quest* quest = lua_interface->GetQuest(state);
  3647. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3648. if (quest && spawn) {
  3649. if (spawn->IsPlayer()) {
  3650. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3651. if (client)
  3652. client->AddPendingQuestReward(quest);
  3653. }
  3654. }
  3655. return 0;
  3656. }
  3657. int EQ2Emu_lua_Harvest(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Spawn* player = lua_interface->GetSpawn(state);
  3661. Spawn* node = lua_interface->GetSpawn(state, 2);
  3662. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3663. Client* client = player->GetZone()->GetClientBySpawn(player);
  3664. if (client) {
  3665. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3666. ((GroundSpawn*)node)->ProcessHarvest(client);
  3667. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3668. player->GetZone()->RemoveSpawn(node, true);
  3669. }
  3670. }
  3671. else if (player && player->IsPlayer()) {
  3672. Client* client = player->GetZone()->GetClientBySpawn(player);
  3673. if (client)
  3674. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3675. }
  3676. return 0;
  3677. }
  3678. int EQ2Emu_lua_Bind(lua_State* state) {
  3679. if (!lua_interface)
  3680. return 0;
  3681. Spawn* spawn = lua_interface->GetSpawn(state);
  3682. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3683. float x = lua_interface->GetFloatValue(state, 3);
  3684. float y = lua_interface->GetFloatValue(state, 4);
  3685. float z = lua_interface->GetFloatValue(state, 5);
  3686. float h = lua_interface->GetFloatValue(state, 6);
  3687. if (!spawn) {
  3688. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3689. return 0;
  3690. }
  3691. if (!spawn->IsPlayer()) {
  3692. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3693. return 0;
  3694. }
  3695. if (zone_id == 0) {
  3696. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3697. if (!client) {
  3698. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3699. return 0;
  3700. }
  3701. if (!client->Bind())
  3702. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3703. }
  3704. else {
  3705. Player* player = (Player*)spawn;
  3706. player->GetPlayerInfo()->SetBindZone(zone_id);
  3707. player->GetPlayerInfo()->SetBindX(x);
  3708. player->GetPlayerInfo()->SetBindY(y);
  3709. player->GetPlayerInfo()->SetBindZ(z);
  3710. player->GetPlayerInfo()->SetBindHeading(h);
  3711. }
  3712. return 0;
  3713. }
  3714. int EQ2Emu_lua_Gate(lua_State* state) {
  3715. if (!lua_interface)
  3716. return 0;
  3717. Spawn* spawn = lua_interface->GetSpawn(state);
  3718. if (spawn) {
  3719. if (spawn->IsPlayer()) {
  3720. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3721. if (client) {
  3722. if (!client->Gate())
  3723. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3724. }
  3725. }
  3726. }
  3727. return 0;
  3728. }
  3729. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3730. if (!lua_interface)
  3731. return 0;
  3732. bool ret = false;
  3733. Spawn* spawn = lua_interface->GetSpawn(state);
  3734. if (spawn) {
  3735. if (spawn->IsPlayer()) {
  3736. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3737. if (client)
  3738. ret = client->BindAllowed();
  3739. }
  3740. }
  3741. lua_interface->SetBooleanValue(state, ret);
  3742. return 1;
  3743. }
  3744. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. bool ret = false;
  3748. Spawn* spawn = lua_interface->GetSpawn(state);
  3749. if (spawn) {
  3750. if (spawn->IsPlayer()) {
  3751. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3752. if (client)
  3753. ret = client->GateAllowed();
  3754. }
  3755. }
  3756. lua_interface->SetBooleanValue(state, ret);
  3757. return 1;
  3758. }
  3759. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3760. Spawn* spawn = lua_interface->GetSpawn(state);
  3761. if (spawn) {
  3762. lua_interface->SetBooleanValue(state, spawn->Alive());
  3763. return 1;
  3764. }
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Spawn* spawn = lua_interface->GetSpawn(state);
  3771. if (spawn && spawn->IsEntity()) {
  3772. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3773. return 1;
  3774. }
  3775. return 0;
  3776. }
  3777. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3778. Spawn* spawn = lua_interface->GetSpawn(state);
  3779. string message = lua_interface->GetStringValue(state, 2);
  3780. string color_str = lua_interface->GetStringValue(state, 3);
  3781. int8 color = CHANNEL_NARRATIVE;
  3782. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3783. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3784. if (client) {
  3785. if (color_str.length() > 0) {
  3786. // leave for backwards compat, but all future should just use the number
  3787. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3788. color = CHANNEL_COLOR_RED;
  3789. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3790. color = CHANNEL_COLOR_YELLOW;
  3791. else
  3792. {
  3793. // use a number to specify the channel as per Commands/Commands.h defines
  3794. color = (int8)atoul(color_str.c_str());
  3795. }
  3796. }
  3797. client->SimpleMessage(color, message.c_str());
  3798. }
  3799. }
  3800. return 0;
  3801. }
  3802. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3803. Spawn* spawn = lua_interface->GetSpawn(state);
  3804. string message = lua_interface->GetStringValue(state, 2);
  3805. int8 red = lua_interface->GetInt8Value(state, 3);
  3806. int8 green = lua_interface->GetInt8Value(state, 4);
  3807. int8 blue = lua_interface->GetInt8Value(state, 5);
  3808. if (!spawn) {
  3809. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3810. return 0;
  3811. }
  3812. int32 words = ::CountWordsInString(message.c_str());
  3813. if (words < 5)
  3814. words = 5;
  3815. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3816. if (client)
  3817. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3818. return 0;
  3819. }
  3820. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3821. Spawn* spawn = lua_interface->GetSpawn(state);
  3822. int8 param = lua_interface->GetInt8Value(state, 2);
  3823. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3824. int8 value = lua_interface->GetInt8Value(state, 4);
  3825. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3826. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3827. if (client) {
  3828. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3829. switch (param) {
  3830. case 1: {
  3831. packet->setDataByName("parameter1", param_value);
  3832. break;
  3833. }
  3834. case 2: {
  3835. packet->setDataByName("parameter2", param_value);
  3836. break;
  3837. }
  3838. case 3: {
  3839. packet->setDataByName("parameter3", param_value);
  3840. break;
  3841. }
  3842. case 4: {
  3843. packet->setDataByName("parameter4", param_value);
  3844. break;
  3845. }
  3846. case 5: {
  3847. packet->setDataByName("parameter5", param_value);
  3848. break;
  3849. }
  3850. }
  3851. packet->setDataByName("value", value);
  3852. client->QueuePacket(packet->serialize());
  3853. safe_delete(packet);
  3854. }
  3855. }
  3856. return 0;
  3857. }
  3858. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3859. Spawn* spawn = lua_interface->GetSpawn(state);
  3860. if (spawn && spawn->IsPlayer()) {
  3861. if (((Player*)spawn)->GetIsTracking())
  3862. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3863. else
  3864. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3865. }
  3866. return 0;
  3867. }
  3868. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3869. Spawn* player = lua_interface->GetSpawn(state);
  3870. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3871. string name = lua_interface->GetStringValue(state, 3);
  3872. float distance = lua_interface->GetFloatValue(state, 4);
  3873. string command = lua_interface->GetStringValue(state, 5);
  3874. string error_text = lua_interface->GetStringValue(state, 6);
  3875. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3876. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3877. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3878. if (spawn) {
  3879. if (distance == 0)
  3880. distance = 10.0f;
  3881. if (command.length() == 0)
  3882. command = name;
  3883. if (command.length() < 1 && name.length() < 1)
  3884. {
  3885. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3886. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3887. spawn->RemovePrimaryCommands();
  3888. }
  3889. else
  3890. {
  3891. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3892. }
  3893. }
  3894. return 0;
  3895. }
  3896. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3897. if (!lua_interface)
  3898. return 0;
  3899. Spawn* player = lua_interface->GetSpawn(state);
  3900. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3901. int16 tier = lua_interface->GetInt16Value(state, 3);
  3902. if (player && player->IsPlayer()) {
  3903. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3904. return 1;
  3905. }
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Spawn* player = lua_interface->GetSpawn(state);
  3912. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3913. int16 tier = lua_interface->GetInt16Value(state, 3);
  3914. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3915. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3916. bool add_to_hotbar = true;
  3917. if (num_args > 4) {
  3918. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3919. }
  3920. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3921. if (player && spell && player->IsPlayer()) {
  3922. Client* client = player->GetClient();
  3923. if (client) {
  3924. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3925. {
  3926. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3927. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3928. client->GetPlayer()->UnlockSpell(spell);
  3929. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3930. }
  3931. else
  3932. {
  3933. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3934. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3935. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3936. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3937. client->GetPlayer()->UnlockSpell(spell);
  3938. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3939. }
  3940. //if (client ) {
  3941. // ((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);
  3942. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3943. if (outapp)
  3944. client->QueuePacket(outapp);
  3945. }
  3946. }
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Spawn* player = lua_interface->GetSpawn(state);
  3953. if (player && player->IsPlayer()) {
  3954. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3955. return 1;
  3956. }
  3957. return 0;
  3958. }
  3959. int EQ2Emu_lua_Attack(lua_State* state) {
  3960. if (lua_interface) {
  3961. Spawn* npc = lua_interface->GetSpawn(state);
  3962. Spawn* player = lua_interface->GetSpawn(state, 2);
  3963. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3964. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3965. }
  3966. return 0;
  3967. }
  3968. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3969. if (lua_interface) {
  3970. Spawn* target = lua_interface->GetSpawn(state);
  3971. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3972. if (target && target->GetZone())
  3973. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3978. Spawn* player;
  3979. if (lua_interface) {
  3980. player = lua_interface->GetSpawn(state);
  3981. if (player && player->IsPlayer()) {
  3982. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3983. return 1;
  3984. }
  3985. }
  3986. return 0;
  3987. }
  3988. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3989. Spawn* player;
  3990. Client* client;
  3991. if (lua_interface) {
  3992. player = lua_interface->GetSpawn(state);
  3993. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3994. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3995. client->HandInCollections();
  3996. }
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4000. Spawn* widget;
  4001. if (lua_interface) {
  4002. widget = lua_interface->GetSpawn(state);
  4003. if (widget && widget->IsWidget())
  4004. ((Widget*)widget)->HandleUse(NULL, "");
  4005. }
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4009. Spawn* spawn = 0;
  4010. int32 primary_list = 0;
  4011. int32 secondary_list = 0;
  4012. if (lua_interface) {
  4013. spawn = lua_interface->GetSpawn(state);
  4014. primary_list = lua_interface->GetInt32Value(state, 2);
  4015. secondary_list = lua_interface->GetInt32Value(state, 3);
  4016. if (!spawn->IsNPC()) {
  4017. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4018. return 0;
  4019. }
  4020. NPC* npc = (NPC*)spawn;
  4021. npc->SetPrimarySpellList(primary_list);
  4022. npc->SetSecondarySpellList(secondary_list);
  4023. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4024. }
  4025. return 0;
  4026. }
  4027. int EQ2Emu_lua_GetPet(lua_State* state) {
  4028. if (!lua_interface)
  4029. return 0;
  4030. Spawn* spawn = lua_interface->GetSpawn(state);
  4031. if (spawn) {
  4032. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4033. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4034. return 1;
  4035. }
  4036. }
  4037. return 0;
  4038. }
  4039. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4040. if (!lua_interface)
  4041. return 0;
  4042. Spawn* spawn = lua_interface->GetSpawn(state);
  4043. if (spawn) {
  4044. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4045. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4046. return 1;
  4047. }
  4048. }
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Spawn* spawn = lua_interface->GetSpawn(state);
  4055. if (spawn) {
  4056. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4057. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4058. return 1;
  4059. }
  4060. }
  4061. return 0;
  4062. }
  4063. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4064. if (!lua_interface)
  4065. return 0;
  4066. Spawn* spawn = lua_interface->GetSpawn(state);
  4067. if (spawn) {
  4068. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4069. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4070. return 1;
  4071. }
  4072. }
  4073. return 0;
  4074. }
  4075. int EQ2Emu_lua_Charm(lua_State* state) {
  4076. if (!lua_interface)
  4077. return 0;
  4078. Spawn* owner = lua_interface->GetSpawn(state);
  4079. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4080. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4081. if (!luaspell) {
  4082. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4083. return 0;
  4084. }
  4085. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4086. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4087. pet->SetPet(true);
  4088. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4089. ((NPC*)pet)->SetOwner((Entity*)owner);
  4090. // If owner is player and player does not have a summoned pet set the players charsheet
  4091. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4092. Player* player = (Player*)owner;
  4093. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4094. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4095. player->GetInfoStruct()->pet_movement = 2;
  4096. player->GetInfoStruct()->pet_behavior = 3;
  4097. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4098. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4099. // Make sure the values get sent to the client
  4100. player->SetCharSheetChanged(true);
  4101. }
  4102. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4103. pet->SetSpawnScript("");
  4104. // Set faction to the same as the owner
  4105. pet->SetFactionID(owner->GetFactionID());
  4106. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4107. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4108. // Clear hate list
  4109. ((NPC*)pet)->Brain()->ClearHate();
  4110. // Set the brain to a pet brain
  4111. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4112. }
  4113. return 0;
  4114. }
  4115. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4116. if (!lua_interface)
  4117. return 0;
  4118. Spawn* spawn = lua_interface->GetSpawn(state);
  4119. if (!spawn) {
  4120. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4121. return 0;
  4122. }
  4123. vector<Spawn*> groupMembers;
  4124. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4125. groupMembers = *spawn->GetSpawnGroup();
  4126. }
  4127. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4128. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4129. deque<GroupMemberInfo*>::iterator itr;
  4130. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4131. if (group)
  4132. {
  4133. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4134. deque<GroupMemberInfo*>* members = group->GetMembers();
  4135. GroupMemberInfo* info = 0;
  4136. for (itr = members->begin(); itr != members->end(); itr++) {
  4137. info = *itr;
  4138. if (info->client)
  4139. groupMembers.push_back(info->client->GetPlayer());
  4140. }
  4141. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4142. }
  4143. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4144. }
  4145. else
  4146. return 0;
  4147. lua_createtable(state, groupMembers.size(), 0);
  4148. int newTable = lua_gettop(state);
  4149. for (int32 i = 0; i < groupMembers.size(); i++) {
  4150. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4151. lua_rawseti(state, newTable, i + 1);
  4152. }
  4153. return 1;
  4154. }
  4155. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4159. lua_interface->SetOptionWindowValue(state, option_window);
  4160. return 1;
  4161. }
  4162. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4163. if (!lua_interface)
  4164. return 0;
  4165. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4166. if (option_window) {
  4167. OptionWindowOption option_window_option;
  4168. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4169. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4170. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4171. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4172. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4173. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4174. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4175. option_window->push_back(option_window_option);
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4183. Spawn* player = lua_interface->GetSpawn(state, 2);
  4184. string window_title = lua_interface->GetStringValue(state, 3);
  4185. string cancel_command = lua_interface->GetStringValue(state, 4);
  4186. Client* client = player->GetZone()->GetClientBySpawn(player);
  4187. if (option_window && window_title.length() > 0 && client) {
  4188. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4189. if (!packet)
  4190. return 0;
  4191. packet->setDataByName("title_text", window_title.c_str());
  4192. if (cancel_command.length() > 0)
  4193. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4194. packet->setArrayLengthByName("num_selections", option_window->size());
  4195. vector<OptionWindowOption>::iterator itr;
  4196. int8 i = 0;
  4197. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4198. OptionWindowOption opt = *itr;
  4199. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4200. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4201. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4202. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4203. if (opt.optionCommand.length() > 0)
  4204. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4205. if (opt.optionConfirmTitle.length() > 0)
  4206. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4207. i++;
  4208. }
  4209. client->QueuePacket(packet->serialize());
  4210. safe_delete(option_window);
  4211. safe_delete(packet);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4216. if (!lua_interface)
  4217. return 0;
  4218. Spawn* spawn = lua_interface->GetSpawn(state);
  4219. if (spawn) {
  4220. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4221. return 1;
  4222. }
  4223. else
  4224. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4225. return 0;
  4226. }
  4227. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4228. if (!lua_interface)
  4229. return 0;
  4230. Spawn* spawn = lua_interface->GetSpawn(state);
  4231. if (spawn) {
  4232. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4233. return 1;
  4234. }
  4235. else
  4236. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* spawn = lua_interface->GetSpawn(state);
  4243. if (spawn) {
  4244. int8 class_id = spawn->GetTradeskillClass();
  4245. // Need to add 42 for the offset in the array
  4246. class_id += 44;
  4247. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4248. return 1;
  4249. }
  4250. else
  4251. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4252. return 0;
  4253. }
  4254. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4255. if (!lua_interface)
  4256. return 0;
  4257. Spawn* spawn = lua_interface->GetSpawn(state);
  4258. int16 level = lua_interface->GetInt8Value(state, 2);
  4259. if (spawn) {
  4260. if (spawn->IsPlayer())
  4261. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4262. else
  4263. spawn->SetTSLevel(level);
  4264. }
  4265. else
  4266. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4267. return 0;
  4268. }
  4269. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4270. if (!lua_interface)
  4271. return 0;
  4272. Spawn* spawn = lua_interface->GetSpawn(state);
  4273. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4274. if (spawn) {
  4275. spawn->SetAttackable(attackable);
  4276. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4277. }
  4278. return 0;
  4279. }
  4280. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4281. // Check to see if we have a valid lua_interface
  4282. if (!lua_interface)
  4283. return 0;
  4284. // Get the spawn that is getting the pet
  4285. Spawn* spawn = lua_interface->GetSpawn(state);
  4286. // Get the DB ID of the pet
  4287. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4288. // The max level the pet can gain
  4289. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4290. // Get the spell that this command was called from
  4291. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4292. // Check to make sure the spawn pointer is valid
  4293. if (!spawn) {
  4294. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4295. return 0;
  4296. }
  4297. // Check to make sure the spawn is an entity
  4298. if (!spawn->IsEntity()) {
  4299. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4300. return 0;
  4301. }
  4302. // Check to make sure the spawn doesn't already have a pet of this type
  4303. if (((Entity*)spawn)->GetPet()) {
  4304. if (spawn->IsPlayer()) {
  4305. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4306. if (client)
  4307. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4308. }
  4309. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4310. return 0;
  4311. }
  4312. // Check to see if the DB ID for the pet is set
  4313. if (pet_id == 0) {
  4314. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4315. return 0;
  4316. }
  4317. // Check to see if the pointer to the spell is valid
  4318. if (!luaspell) {
  4319. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4320. return 0;
  4321. }
  4322. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4323. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4324. if (!pet) {
  4325. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4326. return 0;
  4327. }
  4328. // Check to make sure the pet is an npc
  4329. if (!pet->IsNPC()) {
  4330. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4331. return 0;
  4332. }
  4333. // Spawn the pet at the same location as the owner
  4334. pet->SetX(spawn->GetX());
  4335. pet->SetY(spawn->GetY());
  4336. pet->SetZ(spawn->GetZ());
  4337. pet->SetLocation(spawn->GetLocation());
  4338. pet->SetHeading(spawn->GetHeading());
  4339. spawn->GetZone()->AddSpawn(pet);
  4340. /*
  4341. const char* spawn_script = world.GetSpawnScript(pet_id);
  4342. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4343. spawn->SetSpawnScript(string(spawn_script));
  4344. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4345. }*/
  4346. // Get a random pet name
  4347. string random_pet_name;
  4348. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4349. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4350. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4351. // If player set various values for the char sheet (pet window)
  4352. if (spawn->IsPlayer()) {
  4353. Player* player = (Player*)spawn;
  4354. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4355. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4356. player->GetInfoStruct()->pet_movement = 2;
  4357. player->GetInfoStruct()->pet_behavior = 3;
  4358. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4359. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4360. // Make sure the values get sent to the client
  4361. player->SetCharSheetChanged(true);
  4362. }
  4363. // Set the pets name
  4364. pet->SetName(random_pet_name.c_str());
  4365. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4366. if (max_level > 0)
  4367. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4368. else
  4369. pet->SetLevel(spawn->GetLevel());
  4370. // Set the max level this pet can reach
  4371. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4372. // Set the faction of the pet to the same faction as the owner
  4373. pet->SetFactionID(spawn->GetFactionID());
  4374. // Set the spawn as a pet
  4375. pet->SetPet(true);
  4376. // Give a pointer of the owner to the pet
  4377. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4378. // Give a pointer of the pet to the owner
  4379. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4380. // Set the pet type
  4381. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4382. // Set the spell id used to create this pet
  4383. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4384. // Set the spell tier used to create this pet
  4385. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4386. // Set the pets spawn type to 6
  4387. pet->SetSpawnType(6);
  4388. // Set the pets brain
  4389. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4390. // Check to see if the pet has a subtitle
  4391. if (strlen(pet->GetSubTitle()) > 0) {
  4392. // Add the players name to the front of the sub title
  4393. string pet_subtitle;
  4394. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4395. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4396. // Set the pets subtitle to the new one
  4397. pet->SetSubTitle(pet_subtitle.c_str());
  4398. }
  4399. // Add the "Pet Options" entity command to the pet
  4400. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4401. // Set the pet as the return value for this function
  4402. lua_interface->SetSpawnValue(state, pet);
  4403. return 1;
  4404. }
  4405. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4406. if (!lua_interface)
  4407. return 0;
  4408. Spawn* spawn = lua_interface->GetSpawn(state);
  4409. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4410. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4411. if (!spawn) {
  4412. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4413. return 0;
  4414. }
  4415. if (!spawn->IsEntity()) {
  4416. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4417. return 0;
  4418. }
  4419. if (((Entity*)spawn)->GetDeityPet()) {
  4420. if (spawn->IsPlayer()) {
  4421. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4422. if (client)
  4423. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4424. }
  4425. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4426. return 0;
  4427. }
  4428. if (pet_id == 0) {
  4429. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4430. return 0;
  4431. }
  4432. if (!luaspell) {
  4433. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4434. return 0;
  4435. }
  4436. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4437. if (!pet) {
  4438. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4439. return 0;
  4440. }
  4441. if (!pet->IsNPC()) {
  4442. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4443. return 0;
  4444. }
  4445. pet->SetX(spawn->GetX());
  4446. pet->SetY(spawn->GetY());
  4447. pet->SetZ(spawn->GetZ());
  4448. pet->SetLocation(spawn->GetLocation());
  4449. pet->SetHeading(spawn->GetHeading());
  4450. spawn->GetZone()->AddSpawn(pet);
  4451. string random_pet_name;
  4452. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4453. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4454. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4455. pet->SetName(random_pet_name.c_str());
  4456. pet->SetLevel(spawn->GetLevel());
  4457. pet->SetFactionID(spawn->GetFactionID());
  4458. pet->SetPet(true);
  4459. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4460. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4461. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4462. pet->SetSpawnType(6);
  4463. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4464. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4465. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4466. if (strlen(pet->GetSubTitle()) > 0) {
  4467. string pet_subtitle;
  4468. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4469. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4470. pet->SetSubTitle(pet_subtitle.c_str());
  4471. }
  4472. // deity and cosmetic pets are not attackable
  4473. pet->SetAttackable(false);
  4474. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4475. lua_interface->SetSpawnValue(state, pet);
  4476. return 1;
  4477. }
  4478. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4483. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4484. if (!spawn) {
  4485. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4486. return 0;
  4487. }
  4488. if (!spawn->IsEntity()) {
  4489. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4490. return 0;
  4491. }
  4492. if (((Entity*)spawn)->GetCosmeticPet()) {
  4493. if (spawn->IsPlayer()) {
  4494. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4495. if (client)
  4496. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4497. }
  4498. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4499. return 0;
  4500. }
  4501. if (pet_id == 0) {
  4502. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4503. return 0;
  4504. }
  4505. if (!luaspell) {
  4506. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4507. return 0;
  4508. }
  4509. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4510. if (!pet) {
  4511. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4512. return 0;
  4513. }
  4514. if (!pet->IsNPC()) {
  4515. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4516. return 0;
  4517. }
  4518. pet->SetX(spawn->GetX());
  4519. pet->SetY(spawn->GetY());
  4520. pet->SetZ(spawn->GetZ());
  4521. pet->SetLocation(spawn->GetLocation());
  4522. pet->SetHeading(spawn->GetHeading());
  4523. spawn->GetZone()->AddSpawn(pet);
  4524. string random_pet_name;
  4525. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4526. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4527. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4528. pet->SetName(random_pet_name.c_str());
  4529. pet->SetLevel(spawn->GetLevel());
  4530. pet->SetFactionID(spawn->GetFactionID());
  4531. pet->SetPet(true);
  4532. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4533. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4534. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4535. pet->SetSpawnType(6);
  4536. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4537. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4538. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4539. if (strlen(pet->GetSubTitle()) > 0) {
  4540. string pet_subtitle;
  4541. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4542. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4543. pet->SetSubTitle(pet_subtitle.c_str());
  4544. }
  4545. pet->SetAttackable(false);
  4546. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4547. lua_interface->SetSpawnValue(state, pet);
  4548. return 1;
  4549. }
  4550. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4551. if (!lua_interface)
  4552. return 0;
  4553. Spawn* spawn = lua_interface->GetSpawn(state);
  4554. if (!spawn) {
  4555. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4556. return 0;
  4557. }
  4558. if (!spawn->IsPet()) {
  4559. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4560. return 0;
  4561. }
  4562. if (!((NPC*)spawn)->IsDismissing())
  4563. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Quest* quest = lua_interface->GetQuest(state);
  4570. if (!quest) {
  4571. 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));
  4572. return 0;
  4573. }
  4574. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4575. if (feather_color > 0)
  4576. quest->SetFeatherColor(feather_color);
  4577. return 0;
  4578. }
  4579. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* spawn = lua_interface->GetSpawn(state);
  4583. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4584. if (!spawn) {
  4585. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4586. return 0;
  4587. }
  4588. if (!spawn2) {
  4589. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4590. return 0;
  4591. }
  4592. spawn->RemoveSpawnAccess(spawn2);
  4593. return 0;
  4594. }
  4595. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4596. if (!lua_interface)
  4597. return 0;
  4598. ZoneServer* zone = lua_interface->GetZone(state);
  4599. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4600. if (!zone) {
  4601. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4602. return 0;
  4603. }
  4604. if (location_id == 0) {
  4605. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4606. return 0;
  4607. }
  4608. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4609. if (!location) {
  4610. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4611. return 0;
  4612. }
  4613. Spawn* spawn = 0;
  4614. if (location->entities[0]) {
  4615. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4616. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4617. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4618. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4619. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4620. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4621. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4622. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4623. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4624. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4625. if (spawn) {
  4626. const char* script = 0;
  4627. for (int x = 0; x < 3; x++) {
  4628. switch (x) {
  4629. case 0:
  4630. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4631. break;
  4632. case 1:
  4633. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4634. break;
  4635. case 2:
  4636. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4637. break;
  4638. }
  4639. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4640. spawn->SetSpawnScript(string(script));
  4641. break;
  4642. }
  4643. }
  4644. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4645. lua_interface->SetSpawnValue(state, spawn);
  4646. return 1;
  4647. }
  4648. else {
  4649. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4650. safe_delete(spawn);
  4651. }
  4652. }
  4653. return 0;
  4654. }
  4655. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4656. if (!lua_interface)
  4657. return 0;
  4658. Spawn* caster = lua_interface->GetSpawn(state);
  4659. Spawn* target = lua_interface->GetSpawn(state, 2);
  4660. int32 id = lua_interface->GetInt32Value(state, 3);
  4661. string command = lua_interface->GetStringValue(state, 4);
  4662. if (!caster) {
  4663. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4664. return 0;
  4665. }
  4666. if (!target) {
  4667. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. if (!caster->IsPlayer()) {
  4671. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4672. return 0;
  4673. }
  4674. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4675. if (!entity_command) {
  4676. 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());
  4677. return 0;
  4678. }
  4679. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4680. if (!client) {
  4681. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4685. return 0;
  4686. }
  4687. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4688. if (!lua_interface)
  4689. return 0;
  4690. Spawn* spawn = lua_interface->GetSpawn(state);
  4691. if (!spawn) {
  4692. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4693. return 0;
  4694. }
  4695. if (!spawn->IsNPC()) {
  4696. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4697. return 0;
  4698. }
  4699. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4700. return 0;
  4701. }
  4702. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4703. if (!lua_interface)
  4704. return 0;
  4705. Spawn* spawn = lua_interface->GetSpawn(state);
  4706. int16 tick = lua_interface->GetInt16Value(state, 2);
  4707. if (!spawn) {
  4708. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4709. return 0;
  4710. }
  4711. if (!spawn->IsNPC()) {
  4712. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4713. return 0;
  4714. }
  4715. if (tick < 20) {
  4716. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. ((NPC*)spawn)->Brain()->SetTick(tick);
  4720. return 0;
  4721. }
  4722. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. Spawn* spawn = lua_interface->GetSpawn(state);
  4726. Spawn* target = lua_interface->GetSpawn(state, 2);
  4727. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4728. if (!spawn) {
  4729. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4730. return 0;
  4731. }
  4732. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4733. spawn->SetFollowTarget(target, follow_distance);
  4734. return 0;
  4735. }
  4736. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4737. if (!lua_interface)
  4738. return 0;
  4739. Spawn* spawn = lua_interface->GetSpawn(state);
  4740. if (!spawn) {
  4741. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4742. return 0;
  4743. }
  4744. Spawn* target = spawn->GetFollowTarget();
  4745. if (target) {
  4746. lua_interface->SetSpawnValue(state, target);
  4747. return 1;
  4748. }
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. Spawn* spawn = lua_interface->GetSpawn(state);
  4755. if (!spawn) {
  4756. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. if (spawn->following)
  4760. spawn->following = false;
  4761. else
  4762. spawn->following = true;
  4763. return 0;
  4764. }
  4765. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4766. if (!lua_interface)
  4767. return 0;
  4768. Spawn* spawn = lua_interface->GetSpawn(state);
  4769. if (!spawn) {
  4770. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4771. return 0;
  4772. }
  4773. lua_interface->SetBooleanValue(state, spawn->following);
  4774. return 1;
  4775. }
  4776. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4777. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4778. // I will attempt to explain how this function works for future refrence
  4779. // Fist lets make sure lua_interface is valid, if not return out
  4780. if (!lua_interface)
  4781. return 0;
  4782. // Next we grab the first 2 params same as we usually would
  4783. Spawn* spawn = lua_interface->GetSpawn(state);
  4784. string var = lua_interface->GetStringValue(state, 2);
  4785. // 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
  4786. // 1 = Spawn
  4787. // 2 = Zone
  4788. // 3 = Item
  4789. // 4 = Quest
  4790. // 5 = String
  4791. // 6 = nil (null)
  4792. int8 dataType = 0;
  4793. // Define pointers for each potential type
  4794. Spawn* spawnVal = 0;
  4795. ZoneServer* zone = 0;
  4796. Item* item = 0;
  4797. Quest* quest = 0;
  4798. string val;
  4799. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4800. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4801. // options window are also light user data be we do not handle those.
  4802. // We check with lua_islightuserdata(lua_State*, index)
  4803. if (lua_islightuserdata(state, 3)) {
  4804. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4805. // and convert it to LUAUserData*
  4806. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4807. // Check to make sure the data we got is valid, if not give an error
  4808. if (!data || !data->IsCorrectlyInitialized()) {
  4809. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4810. }
  4811. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4812. else if (data->IsSpawn()) {
  4813. spawnVal = data->spawn;
  4814. dataType = 1;
  4815. }
  4816. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4817. else if (data->IsZone()) {
  4818. zone = data->zone;
  4819. dataType = 2;
  4820. }
  4821. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4822. else if (data->IsItem()) {
  4823. item = data->item;
  4824. dataType = 3;
  4825. }
  4826. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4827. else if (data->IsQuest()) {
  4828. quest = data->quest;
  4829. dataType = 4;
  4830. }
  4831. }
  4832. // Wasn't light user data, check if it is nil(null)
  4833. else if (lua_isnil(state, 3)) {
  4834. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4835. dataType = 6;
  4836. }
  4837. // Wasn't light user data or nil (null), must be a string
  4838. else {
  4839. // Set the string and dataType variable
  4840. val = lua_interface->GetStringValue(state, 3);
  4841. dataType = 5;
  4842. }
  4843. // We now have all the params, lets check to make sure they are valid
  4844. if (!spawn) {
  4845. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4846. return 0;
  4847. }
  4848. if (var.length() == 0) {
  4849. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. if (dataType == 0) {
  4853. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4857. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4858. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4859. switch (dataType) {
  4860. case 1:
  4861. // 1 = Spawn
  4862. spawn->AddTempVariable(var, spawnVal);
  4863. break;
  4864. case 2:
  4865. // 2 = Zone
  4866. spawn->AddTempVariable(var, zone);
  4867. break;
  4868. case 3:
  4869. // 3 = Item
  4870. spawn->AddTempVariable(var, item);
  4871. break;
  4872. case 4:
  4873. // 4 = Quest
  4874. spawn->AddTempVariable(var, quest);
  4875. break;
  4876. case 5:
  4877. // 5 = String
  4878. spawn->AddTempVariable(var, val);
  4879. break;
  4880. case 6:
  4881. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4882. spawn->DeleteTempVariable(var);
  4883. break;
  4884. }
  4885. // And we are done so return out
  4886. return 0;
  4887. }
  4888. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4889. if (!lua_interface)
  4890. return 0;
  4891. Spawn* spawn = lua_interface->GetSpawn(state);
  4892. string var = lua_interface->GetStringValue(state, 2);
  4893. if (!spawn) {
  4894. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4895. return 0;
  4896. }
  4897. if (var.length() == 0) {
  4898. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4899. return 0;
  4900. }
  4901. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4902. int8 type = spawn->GetTempVariableType(var);
  4903. Spawn* spawn2 = 0;
  4904. ZoneServer* zone = 0;
  4905. Item* item = 0;
  4906. Quest* quest = 0;
  4907. // Set the lua function return value based on the type of data the variable contains
  4908. switch (type) {
  4909. case 1:
  4910. spawn2 = spawn->GetTempVariableSpawn(var);
  4911. if (!spawn2)
  4912. return 0;
  4913. lua_interface->SetSpawnValue(state, spawn2);
  4914. break;
  4915. case 2:
  4916. zone = spawn->GetTempVariableZone(var);
  4917. if (!zone)
  4918. return 0;
  4919. lua_interface->SetZoneValue(state, zone);
  4920. break;
  4921. case 3:
  4922. item = spawn->GetTempVariableItem(var);
  4923. if (!item)
  4924. return 0;
  4925. lua_interface->SetItemValue(state, item);
  4926. break;
  4927. case 4:
  4928. quest = spawn->GetTempVariableQuest(var);
  4929. if (!quest)
  4930. return 0;
  4931. lua_interface->SetQuestValue(state, quest);
  4932. break;
  4933. case 5:
  4934. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4935. break;
  4936. default:
  4937. // Not a valid type then the variable was not set so return out
  4938. return 0;
  4939. }
  4940. // Return value was set so return out
  4941. return 1;
  4942. }
  4943. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4944. {
  4945. if (!lua_interface)
  4946. return 0;
  4947. Quest* quest = lua_interface->GetQuest(state);
  4948. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4949. string description = lua_interface->GetStringValue(state, 3);
  4950. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4951. if (!quest) {
  4952. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4953. lua_interface->SetBooleanValue(state, false);
  4954. return 1;
  4955. }
  4956. if (!spawn) {
  4957. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4958. lua_interface->SetBooleanValue(state, false);
  4959. return 1;
  4960. }
  4961. if (!spawn->IsPlayer()) {
  4962. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4963. lua_interface->SetBooleanValue(state, false);
  4964. return 1;
  4965. }
  4966. if (item_id == 0) {
  4967. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4968. lua_interface->SetBooleanValue(state, false);
  4969. return 1;
  4970. }
  4971. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4972. if (!client) {
  4973. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4974. lua_interface->SetBooleanValue(state, false);
  4975. return 1;
  4976. }
  4977. Item* item = master_item_list.GetItem(item_id);
  4978. if (!item) {
  4979. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4980. lua_interface->SetBooleanValue(state, false);
  4981. return 1;
  4982. }
  4983. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4984. if (packet) {
  4985. packet->setDataByName("title", "Quest Reward!");
  4986. packet->setDataByName("name", quest->GetName());
  4987. packet->setDataByName("description", description.c_str());
  4988. packet->setDataByName("level", quest->GetLevel());
  4989. packet->setArrayLengthByName("num_rewards", 1);
  4990. packet->setArrayDataByName("reward_id", item->details.item_id);
  4991. if (client->GetVersion() < 860)
  4992. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4993. else if (client->GetVersion() < 1193)
  4994. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4995. else
  4996. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4997. client->QueuePacket(packet->serialize());
  4998. safe_delete(packet);
  4999. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5000. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5001. return 1;
  5002. }
  5003. lua_interface->SetBooleanValue(state, false);
  5004. return 1;
  5005. }
  5006. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5007. if (!lua_interface)
  5008. return 0;
  5009. Quest* quest = lua_interface->GetQuest(state);
  5010. if (!quest) {
  5011. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. quest->SetRepeatable(true);
  5015. return 0;
  5016. }
  5017. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5018. if (!lua_interface)
  5019. return 0;
  5020. Spawn* spawn = lua_interface->GetSpawn(state);
  5021. if (!spawn) {
  5022. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5026. string ret = classes.GetClassNameCase(base_class);
  5027. if (ret.length() > 0) {
  5028. lua_interface->SetStringValue(state, ret.c_str());
  5029. return 1;
  5030. }
  5031. return 0;
  5032. }
  5033. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5034. if (!lua_interface)
  5035. return 0;
  5036. Spawn* player = lua_interface->GetSpawn(state);
  5037. if (player && player->IsPlayer()) {
  5038. Client* client = player->GetClient();
  5039. if (client)
  5040. client->SendWaypoints();
  5041. }
  5042. return 0;
  5043. }
  5044. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5045. if (!lua_interface)
  5046. return 0;
  5047. Spawn* player = lua_interface->GetSpawn(state);
  5048. string name = lua_interface->GetStringValue(state, 2);
  5049. int32 type = lua_interface->GetInt32Value(state, 3);
  5050. if (type == 0)
  5051. type = 2;
  5052. if (name.length() > 0) {
  5053. if (player && player->IsPlayer()) {
  5054. Client* client = player->GetClient();
  5055. if (client)
  5056. client->AddWaypoint(name, type);
  5057. }
  5058. }
  5059. return 0;
  5060. }
  5061. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5062. if (!lua_interface)
  5063. return 0;
  5064. Spawn* player = lua_interface->GetSpawn(state);
  5065. string name = lua_interface->GetStringValue(state, 2);
  5066. if (name.length() > 0) {
  5067. if (player && player->IsPlayer()) {
  5068. Client* client = player->GetClient();
  5069. if (client)
  5070. client->RemoveWaypoint(name);
  5071. }
  5072. }
  5073. return 0;
  5074. }
  5075. int EQ2Emu_lua_AddWard(lua_State* state) {
  5076. if (!lua_interface)
  5077. return 0;
  5078. int32 damage = lua_interface->GetInt32Value(state);
  5079. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5080. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5081. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5082. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5083. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5084. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5085. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5086. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5087. bool ward_was_added = false;
  5088. ZoneServer* zone = spell->caster->GetZone();
  5089. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5090. for (int32 i = 0; i < spell->targets.size(); i++) {
  5091. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5092. if (!target)
  5093. continue;
  5094. if (target->IsEntity()) {
  5095. // If the ward is already active remove it
  5096. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5097. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5098. // Create new ward info
  5099. WardInfo* ward = new WardInfo;
  5100. ward->Spell = spell;
  5101. ward->BaseDamage = damage;
  5102. ward->DamageLeft = damage;
  5103. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5104. ward->keepWard = keepWard;
  5105. ward->WardType = wardType;
  5106. if (damageAbsorptionPercent > 100)
  5107. damageAbsorptionPercent = 100;
  5108. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5109. if (damageAbsorptionMaxHealthPercent > 100)
  5110. damageAbsorptionMaxHealthPercent = 100;
  5111. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5112. ward->RedirectDamagePercent = redirectDamagePercent;
  5113. ward->LastRedirectDamage = 0;
  5114. ward->LastAbsorbedDamage = 0;
  5115. ward->HitCount = 0;
  5116. spell->num_triggers = maxHitCount;
  5117. spell->had_triggers = true;
  5118. spell->cancel_after_all_triggers = false;
  5119. ward->MaxHitCount = maxHitCount;
  5120. if (wardType == WARD_TYPE_MAGICAL)
  5121. ward->DamageType = damageTypes;
  5122. // Add the ward to the entity
  5123. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5124. ward_was_added = true;
  5125. }
  5126. }
  5127. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5128. if (ward_was_added && spell->caster->IsPlayer()) {
  5129. spell->had_dmg_remaining = true;
  5130. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5131. }
  5132. return 0;
  5133. }
  5134. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5135. if (!lua_interface)
  5136. return 0;
  5137. int32 amount = lua_interface->GetInt32Value(state);
  5138. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5139. WardInfo* ward = 0;
  5140. ZoneServer* zone = spell->caster->GetZone();
  5141. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5142. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5143. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5144. ward = target->GetWard(spell->spell->GetSpellID());
  5145. if (ward) {
  5146. ward->DamageLeft += amount;
  5147. if (ward->DamageLeft > ward->BaseDamage)
  5148. ward->DamageLeft = ward->BaseDamage;
  5149. for (int32 i = 0; i < spell->targets.size(); i++) {
  5150. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5151. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5152. }
  5153. }
  5154. }
  5155. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5156. if (ward && spell->caster->IsPlayer())
  5157. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5164. if (!spell) {
  5165. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5169. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5170. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5171. if (ward) {
  5172. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5173. return 1;
  5174. }
  5175. }
  5176. return 0;
  5177. }
  5178. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5179. if (!lua_interface)
  5180. return 0;
  5181. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5182. if (!spell) {
  5183. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5184. return 0;
  5185. }
  5186. string type = lua_interface->GetStringValue(state, 2);
  5187. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5188. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5189. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5190. if (ward) {
  5191. if (boost::iequals(type, "damageleft"))
  5192. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5193. else if (boost::iequals(type, "basedamage"))
  5194. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5195. else if (boost::iequals(type, "keepward"))
  5196. lua_interface->SetBooleanValue(state, ward->keepWard);
  5197. else if (boost::iequals(type, "wardtype"))
  5198. lua_interface->SetInt32Value(state, ward->WardType);
  5199. else if (boost::iequals(type, "dmgabsorptionpct"))
  5200. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5201. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5202. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5203. else if (boost::iequals(type, "redirectdamagepercent"))
  5204. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5205. else if (boost::iequals(type, "lastredirectdamage"))
  5206. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5207. else if (boost::iequals(type, "lastabsorbeddamage"))
  5208. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5209. else if (boost::iequals(type, "hitcount"))
  5210. lua_interface->SetInt32Value(state, ward->HitCount);
  5211. else if (boost::iequals(type, "maxhitcount"))
  5212. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5213. else
  5214. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5215. return 1;
  5216. }
  5217. }
  5218. return 0;
  5219. }
  5220. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5221. if (!lua_interface)
  5222. return 0;
  5223. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5224. ZoneServer* zone = spell->caster->GetZone();
  5225. Spawn* target = 0;
  5226. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5227. for (int32 i = 0; i < spell->targets.size(); i++) {
  5228. target = zone->GetSpawnByID(spell->targets.at(i));
  5229. if (target && target->IsEntity()) {
  5230. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5231. }
  5232. }
  5233. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5234. return 0;
  5235. }
  5236. int EQ2Emu_lua_Interrupt(lua_State* state)
  5237. {
  5238. if (!lua_interface)
  5239. return 0;
  5240. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5241. Spawn* target = lua_interface->GetSpawn(state, 2);
  5242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5243. if (!caster)
  5244. {
  5245. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5246. return 0;
  5247. }
  5248. if (!target)
  5249. {
  5250. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5251. return 0;
  5252. }
  5253. if (!spell) {
  5254. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5255. return 0;
  5256. }
  5257. if (!target->IsEntity() && !spell)
  5258. {
  5259. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5260. return 0;
  5261. }
  5262. if (!target && spell) {
  5263. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5264. for (int8 i = 0; i < spell->targets.size(); i++) {
  5265. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5266. if (!target || !target->IsEntity())
  5267. continue;
  5268. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5269. }
  5270. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5271. }
  5272. else
  5273. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5274. return 0;
  5275. }
  5276. int EQ2Emu_lua_Stealth(lua_State* state) {
  5277. if (!lua_interface)
  5278. return 0;
  5279. int8 type = lua_interface->GetInt8Value(state);
  5280. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5281. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5282. if (!spell) {
  5283. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. ZoneServer* zone = spell->caster->GetZone();
  5287. if (spawn) {
  5288. if (spawn->IsEntity()) {
  5289. if (type == 1) {
  5290. ((Entity*)spawn)->AddStealthSpell(spell);
  5291. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5292. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5293. }
  5294. else if (type == 2) {
  5295. ((Entity*)spawn)->AddInvisSpell(spell);
  5296. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5297. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5298. }
  5299. return 0;
  5300. }
  5301. else {
  5302. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. }
  5306. else {
  5307. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5308. for (int32 i = 0; i < spell->targets.size(); i++) {
  5309. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5310. if (!spawn || !spawn->IsEntity())
  5311. continue;
  5312. if (type == 1) {
  5313. ((Entity*)spawn)->AddStealthSpell(spell);
  5314. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5315. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5316. }
  5317. else if (type == 2) {
  5318. ((Entity*)spawn)->AddInvisSpell(spell);
  5319. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5320. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5321. }
  5322. else {
  5323. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5324. break;
  5325. }
  5326. }
  5327. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5328. }
  5329. return 0;
  5330. }
  5331. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5332. if (!lua_interface)
  5333. return 0;
  5334. Spawn* spawn = lua_interface->GetSpawn(state);
  5335. if (!spawn) {
  5336. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5337. return 0;
  5338. }
  5339. if (spawn->IsEntity()) {
  5340. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5341. return 1;
  5342. }
  5343. else
  5344. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5345. return 0;
  5346. }
  5347. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5348. if (!lua_interface)
  5349. return 0;
  5350. Spawn* spawn = lua_interface->GetSpawn(state);
  5351. if (!spawn) {
  5352. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5353. return 0;
  5354. }
  5355. if (spawn->IsEntity()) {
  5356. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5357. return 1;
  5358. }
  5359. else
  5360. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5361. return 0;
  5362. }
  5363. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5364. if (!lua_interface)
  5365. return 0;
  5366. Spawn* player = lua_interface->GetSpawn(state);
  5367. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5368. if (!player->IsPlayer()) {
  5369. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5370. return 0;
  5371. }
  5372. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5373. return 1;
  5374. }
  5375. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5376. if (!lua_interface)
  5377. return 0;
  5378. Spawn* player = lua_interface->GetSpawn(state);
  5379. int8 slot = lua_interface->GetInt8Value(state, 2);
  5380. if (!player) {
  5381. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5382. return 0;
  5383. }
  5384. if (!player->IsPlayer()) {
  5385. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5386. return 0;
  5387. }
  5388. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5389. if (!item) {
  5390. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5391. return 0;
  5392. }
  5393. lua_interface->SetItemValue(state, item);
  5394. return 1;
  5395. }
  5396. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5397. if (!lua_interface)
  5398. return 0;
  5399. Spawn* player = lua_interface->GetSpawn(state);
  5400. int32 id = lua_interface->GetInt32Value(state, 2);
  5401. if (!player) {
  5402. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. if (!player->IsPlayer()) {
  5406. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5407. return 0;
  5408. }
  5409. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5410. if (!item) {
  5411. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5412. return 0;
  5413. }
  5414. lua_interface->SetItemValue(state, item);
  5415. return 1;
  5416. }
  5417. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Spawn* player = lua_interface->GetSpawn(state);
  5421. int32 id = lua_interface->GetInt32Value(state, 2);
  5422. int8 count = lua_interface->GetInt8Value(state, 3);
  5423. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5424. if (!player) {
  5425. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5426. return 0;
  5427. }
  5428. if (!player->IsPlayer()) {
  5429. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5430. return 0;
  5431. }
  5432. if (!count)
  5433. count = 1;
  5434. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5435. if (!item) {
  5436. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. lua_interface->SetItemValue(state, item);
  5440. return 1;
  5441. }
  5442. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* spawn = lua_interface->GetSpawn(state);
  5446. int32 anim = lua_interface->GetInt32Value(state, 2);
  5447. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5448. int8 type = lua_interface->GetInt8Value(state, 4);
  5449. if (!spawn) {
  5450. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5451. return 0;
  5452. }
  5453. if (spawn2) {
  5454. if (spawn2->IsPlayer()) {
  5455. if (type != 1 && type != 2)
  5456. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5457. else
  5458. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5459. return 0;
  5460. }
  5461. else {
  5462. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5463. return 0;
  5464. }
  5465. }
  5466. else
  5467. spawn->GetZone()->PlayAnimation(spawn, anim);
  5468. return 0;
  5469. }
  5470. int EQ2Emu_lua_IsPet(lua_State* state) {
  5471. if (!lua_interface)
  5472. return 0;
  5473. Spawn* spawn = lua_interface->GetSpawn(state);
  5474. if (!spawn) {
  5475. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5476. return 0;
  5477. }
  5478. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5479. return 1;
  5480. }
  5481. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5482. if (!lua_interface)
  5483. return 0;
  5484. Spawn* spawn = lua_interface->GetSpawn(state);
  5485. if (!spawn) {
  5486. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5487. return 0;
  5488. }
  5489. if (!spawn->IsNPC()) {
  5490. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5491. return 0;
  5492. }
  5493. if (((NPC*)spawn)->GetOwner()) {
  5494. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5495. return 1;
  5496. }
  5497. return 0;
  5498. }
  5499. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* spawn = lua_interface->GetSpawn(state);
  5503. Spawn* target = lua_interface->GetSpawn(state, 2);
  5504. if (!spawn) {
  5505. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5506. return 0;
  5507. }
  5508. if (!spawn) {
  5509. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5510. return 0;
  5511. }
  5512. spawn->SetTarget(target);
  5513. return 0;
  5514. }
  5515. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5516. if (!lua_interface)
  5517. return 0;
  5518. Spawn* spawn = lua_interface->GetSpawn(state);
  5519. bool val = lua_interface->GetBooleanValue(state, 2);
  5520. if (!spawn) {
  5521. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5522. return 0;
  5523. }
  5524. if (!spawn->IsEntity()) {
  5525. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5526. return 0;
  5527. }
  5528. ((Entity*)spawn)->InCombat(val);
  5529. if (val) {
  5530. spawn->ClearRunningLocations();
  5531. spawn->CalculateRunningLocation(true);
  5532. }
  5533. return 0;
  5534. }
  5535. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5539. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5540. if (!spawn1) {
  5541. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5542. return 0;
  5543. }
  5544. if (!spawn2) {
  5545. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5549. return 1;
  5550. }
  5551. int EQ2Emu_lua_Runback(lua_State* state) {
  5552. if (!lua_interface)
  5553. return 0;
  5554. Spawn* spawn = lua_interface->GetSpawn(state);
  5555. if (!spawn) {
  5556. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5557. return 0;
  5558. }
  5559. if (!spawn->IsNPC()) {
  5560. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5561. return 0;
  5562. }
  5563. ((NPC*)spawn)->Runback();
  5564. return 0;
  5565. }
  5566. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5567. if (!lua_interface)
  5568. return 0;
  5569. Spawn* spawn = lua_interface->GetSpawn(state);
  5570. if (!spawn) {
  5571. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5572. return 0;
  5573. }
  5574. if (!spawn->IsNPC()) {
  5575. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5576. return 0;
  5577. }
  5578. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5579. return 1;
  5580. }
  5581. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5582. if (!lua_interface)
  5583. return 0;
  5584. Spawn* spawn = lua_interface->GetSpawn(state);
  5585. if (!spawn) {
  5586. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5587. return 0;
  5588. }
  5589. if (!spawn->IsEntity()) {
  5590. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5594. return 1;
  5595. }
  5596. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5597. if (!lua_interface)
  5598. return 0;
  5599. Spawn* spawn = lua_interface->GetSpawn(state);
  5600. if (!spawn) {
  5601. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. if (!spawn->IsEntity()) {
  5605. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5606. return 0;
  5607. }
  5608. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5609. return 1;
  5610. }
  5611. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5612. if (!lua_interface)
  5613. return 0;
  5614. Spawn* spawn = lua_interface->GetSpawn(state);
  5615. if (!spawn) {
  5616. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5617. return 0;
  5618. }
  5619. if (!spawn->IsEntity()) {
  5620. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5621. return 0;
  5622. }
  5623. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5624. return 1;
  5625. }
  5626. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5627. if (!lua_interface)
  5628. return 0;
  5629. Spawn* spawn = lua_interface->GetSpawn(state);
  5630. if (!spawn) {
  5631. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5632. return 0;
  5633. }
  5634. if (!spawn->IsEntity()) {
  5635. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5639. return 1;
  5640. }
  5641. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5642. if (!lua_interface)
  5643. return 0;
  5644. Spawn* spawn = lua_interface->GetSpawn(state);
  5645. Spawn* target = lua_interface->GetSpawn(state, 2);
  5646. float distance = lua_interface->GetFloatValue(state, 3);
  5647. if (!spawn) {
  5648. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. if (!target) {
  5652. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5653. return 0;
  5654. }
  5655. if (!spawn->IsNPC()) {
  5656. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. if (!target->IsEntity()) {
  5660. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5664. return 1;
  5665. }
  5666. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5667. if (!lua_interface)
  5668. return 0;
  5669. Spawn* spawn = lua_interface->GetSpawn(state);
  5670. Spawn* target = lua_interface->GetSpawn(state, 2);
  5671. float distance = lua_interface->GetFloatValue(state, 3);
  5672. if (!spawn) {
  5673. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5674. return 0;
  5675. }
  5676. if (!target) {
  5677. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5678. return 0;
  5679. }
  5680. if (!spawn->IsNPC()) {
  5681. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5682. return 0;
  5683. }
  5684. if (!target->IsEntity()) {
  5685. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5686. return 0;
  5687. }
  5688. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5689. return 0;
  5690. }
  5691. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5692. if (!lua_interface)
  5693. return 0;
  5694. Spawn* spawn = lua_interface->GetSpawn(state);
  5695. if (!spawn) {
  5696. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5697. return 0;
  5698. }
  5699. if (!spawn->IsNPC()) {
  5700. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5704. return 1;
  5705. }
  5706. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5707. if (!lua_interface)
  5708. return 0;
  5709. Spawn* spawn = lua_interface->GetSpawn(state);
  5710. if (!spawn) {
  5711. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5712. return 0;
  5713. }
  5714. if (!spawn->IsNPC()) {
  5715. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5716. return 0;
  5717. }
  5718. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5719. return 1;
  5720. }
  5721. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5722. if (!lua_interface)
  5723. return 0;
  5724. Spawn* spawn = lua_interface->GetSpawn(state);
  5725. if (!spawn) {
  5726. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5727. return 0;
  5728. }
  5729. if (!spawn->IsNPC()) {
  5730. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5731. return 0;
  5732. }
  5733. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5734. if (hated) {
  5735. lua_interface->SetSpawnValue(state, hated);
  5736. return 1;
  5737. }
  5738. return 0;
  5739. }
  5740. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5741. if (!lua_interface)
  5742. return 0;
  5743. Spawn* spawn = lua_interface->GetSpawn(state);
  5744. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5745. if (!spawn) {
  5746. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5747. return 0;
  5748. }
  5749. if (!spawn->IsNPC()) {
  5750. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5751. return 0;
  5752. }
  5753. if (!hated) {
  5754. ((NPC*)spawn)->Brain()->ClearHate();
  5755. return 0;
  5756. }
  5757. else
  5758. {
  5759. if (!hated->IsEntity()) {
  5760. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5761. return 0;
  5762. }
  5763. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5764. return 0;
  5765. }
  5766. return 0;
  5767. }
  5768. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5769. if (!lua_interface)
  5770. return 0;
  5771. Spawn* spawn = lua_interface->GetSpawn(state);
  5772. if (!spawn) {
  5773. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. if (!spawn->IsNPC()) {
  5777. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. ((NPC*)spawn)->Brain()->ClearEncounter();
  5781. return 0;
  5782. }
  5783. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5784. if (!lua_interface)
  5785. return 0;
  5786. Spawn* spawn = lua_interface->GetSpawn(state);
  5787. if (!spawn) {
  5788. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5789. return 0;
  5790. }
  5791. if (!spawn->IsNPC()) {
  5792. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. // Temp list to store hate list
  5796. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5797. if (encounterList->size() == 0) {
  5798. safe_delete(encounterList);
  5799. return 0;
  5800. }
  5801. lua_createtable(state, encounterList->size(), 0);
  5802. int newTable = lua_gettop(state);
  5803. for (int32 i = 0; i < encounterList->size(); i++) {
  5804. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5805. if (temp)
  5806. lua_interface->SetSpawnValue(state, temp);
  5807. lua_rawseti(state, newTable, i + 1);
  5808. }
  5809. safe_delete(encounterList);
  5810. return 1;
  5811. }
  5812. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5813. if (!lua_interface)
  5814. return 0;
  5815. Spawn* spawn = lua_interface->GetSpawn(state);
  5816. if (!spawn) {
  5817. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. if (!spawn->IsNPC()) {
  5821. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. // Temp list to store hate list
  5825. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5826. if (hateList->size() == 0) {
  5827. safe_delete(hateList);
  5828. return 0;
  5829. }
  5830. lua_createtable(state, hateList->size(), 0);
  5831. int newTable = lua_gettop(state);
  5832. for (int32 i = 0; i < hateList->size(); i++) {
  5833. lua_interface->SetSpawnValue(state, hateList->at(i));
  5834. lua_rawseti(state, newTable, i + 1);
  5835. }
  5836. safe_delete(hateList);
  5837. return 1;
  5838. }
  5839. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5840. if (!lua_interface)
  5841. return 0;
  5842. Spawn* spawn = lua_interface->GetSpawn(state);
  5843. if (!spawn) {
  5844. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5845. return 0;
  5846. }
  5847. if (spawn->IsPlayer()) {
  5848. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5849. lua_interface->SetBooleanValue(state, true);
  5850. else
  5851. lua_interface->SetBooleanValue(state, false);
  5852. return 1;
  5853. }
  5854. else {
  5855. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5856. return 1;
  5857. }
  5858. }
  5859. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Quest* quest = lua_interface->GetQuest(state);
  5863. if (!quest) {
  5864. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5865. return 0;
  5866. }
  5867. quest->SetCompletedFlag(true);
  5868. return 0;
  5869. }
  5870. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5871. if (!lua_interface)
  5872. return 0;
  5873. Spawn* spawn = lua_interface->GetSpawn(state);
  5874. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5875. int8 tier = lua_interface->GetInt8Value(state, 3);
  5876. if (!spawn) {
  5877. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. if (!spawn->IsEntity()) {
  5881. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5882. return 0;
  5883. }
  5884. if (spellID == 0) {
  5885. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5886. return 0;
  5887. }
  5888. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5889. if (effect) {
  5890. if (tier > 0) {
  5891. // If a tier was passed chec to see if it is the same as the effect
  5892. if (tier == effect->tier)
  5893. lua_interface->SetBooleanValue(state, true);
  5894. else
  5895. lua_interface->SetBooleanValue(state, false);
  5896. return 1;
  5897. }
  5898. else {
  5899. // Have an effect but no tier was passed so return true
  5900. lua_interface->SetBooleanValue(state, true);
  5901. }
  5902. return 1;
  5903. }
  5904. // no effect so return false
  5905. lua_interface->SetBooleanValue(state, false);
  5906. return 1;
  5907. }
  5908. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5909. if (!lua_interface)
  5910. return 0;
  5911. Spawn* spawn = lua_interface->GetSpawn(state);
  5912. int32 id = lua_interface->GetInt32Value(state, 2);
  5913. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5914. Spawn* spawn2 = 0;
  5915. vector<Spawn*> list;
  5916. if (!spawn) {
  5917. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. //If zone not provided, use spawn's zone
  5921. if (!zone)
  5922. zone = spawn->GetZone();
  5923. list = zone->GetSpawnsByID(id);
  5924. if (list.size() == 0) {
  5925. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. vector<Spawn*>::iterator itr = list.begin();
  5929. for (int8 i = 0; i < list.size(); i++) {
  5930. spawn2 = itr[i];
  5931. if (spawn2)
  5932. spawn2->AddAllowAccessSpawn(spawn);
  5933. }
  5934. return 0;
  5935. }
  5936. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5937. if (!lua_interface)
  5938. return 0;
  5939. Spawn* spawn = lua_interface->GetSpawn(state);
  5940. int32 id = lua_interface->GetInt32Value(state, 2);
  5941. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5942. Spawn* spawn2 = 0;
  5943. if (!spawn) {
  5944. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. //If zone not provided, use spawn's zone
  5948. if (!zone)
  5949. zone = spawn->GetZone();
  5950. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5951. vector<Spawn*>::iterator itr = list.begin();
  5952. if (list.size() == 0) {
  5953. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. for (int8 i = 0; i < list.size(); i++) {
  5957. spawn2 = itr[i];
  5958. if (spawn2)
  5959. spawn2->RemoveSpawnAccess(spawn);
  5960. }
  5961. return 0;
  5962. }
  5963. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5964. if (!lua_interface)
  5965. return 0;
  5966. Quest* quest = lua_interface->GetQuest(state);
  5967. if (!quest) {
  5968. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. quest->SetYellowName(true);
  5972. return 0;
  5973. }
  5974. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5975. if (!lua_interface)
  5976. return 0;
  5977. Spawn* spawn = lua_interface->GetSpawn(state);
  5978. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5979. if (!spawn) {
  5980. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. if (!spawn->IsPlayer()) {
  5984. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5985. return 0;
  5986. }
  5987. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5988. return 1;
  5989. }
  5990. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5991. if (!lua_interface)
  5992. return 0;
  5993. Spawn* spawn = lua_interface->GetSpawn(state);
  5994. if (!spawn) {
  5995. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5996. return 0;
  5997. }
  5998. if (!spawn->IsPlayer()) {
  5999. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6000. return 0;
  6001. }
  6002. ZoneServer* zone = spawn->GetZone();
  6003. if (!zone) {
  6004. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6005. return 0;
  6006. }
  6007. Instance_Type iType = zone->GetInstanceType();
  6008. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6009. iType == GROUP_LOCKOUT_INSTANCE ||
  6010. iType == RAID_LOCKOUT_INSTANCE ||
  6011. iType == SOLO_PERSIST_INSTANCE ||
  6012. iType == GROUP_PERSIST_INSTANCE ||
  6013. iType == RAID_PERSIST_INSTANCE) {
  6014. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6015. if (data) {
  6016. // Check to see if the timer has already been set, if it has return out.
  6017. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6018. return 0;
  6019. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6020. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6021. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6022. if (client) {
  6023. string time_msg = "";
  6024. int32 time = data->success_lockout_time;
  6025. int16 hour;
  6026. int8 min;
  6027. int8 sec;
  6028. hour = time / 3600;
  6029. time = time % 3600;
  6030. min = time / 60;
  6031. time = time % 60;
  6032. sec = time;
  6033. if (hour > 0) {
  6034. char temp[10];
  6035. sprintf(temp, " %i", hour);
  6036. time_msg.append(temp);
  6037. time_msg.append(" hour");
  6038. time_msg.append((hour > 1) ? "s" : "");
  6039. }
  6040. if (min > 0) {
  6041. char temp[5];
  6042. sprintf(temp, " %i", min);
  6043. time_msg.append(temp);
  6044. time_msg.append(" minute");
  6045. time_msg.append((min > 1) ? "s" : "");
  6046. }
  6047. // Only add seconds if minutes and hours are 0
  6048. if (hour == 0 && min == 0 && sec > 0) {
  6049. char temp[5];
  6050. sprintf(temp, " %i", sec);
  6051. time_msg.append(temp);
  6052. time_msg.append(" second");
  6053. time_msg.append((sec > 1) ? "s" : "");
  6054. }
  6055. 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());
  6056. }
  6057. }
  6058. else
  6059. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6060. }
  6061. else
  6062. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6066. if (!lua_interface)
  6067. return 0;
  6068. Spawn* spawn = lua_interface->GetSpawn(state);
  6069. if (!spawn) {
  6070. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. if (!spawn->IsPlayer()) {
  6074. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. ZoneServer* zone = spawn->GetZone();
  6078. if (!zone) {
  6079. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. Instance_Type iType = zone->GetInstanceType();
  6083. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6084. iType == GROUP_LOCKOUT_INSTANCE ||
  6085. iType == RAID_LOCKOUT_INSTANCE ||
  6086. iType == SOLO_PERSIST_INSTANCE ||
  6087. iType == GROUP_PERSIST_INSTANCE ||
  6088. iType == RAID_PERSIST_INSTANCE) {
  6089. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6090. if (data) {
  6091. // Check to see if the timer has already been set, if it has return out.
  6092. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6093. return 0;
  6094. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6095. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6096. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6097. if (client) {
  6098. string time_msg = "";
  6099. int32 time = data->failure_lockout_time;
  6100. int16 hour;
  6101. int8 min;
  6102. int8 sec;
  6103. hour = time / 3600;
  6104. time = time % 3600;
  6105. min = time / 60;
  6106. time = time % 60;
  6107. sec = time;
  6108. if (hour > 0) {
  6109. char temp[10];
  6110. sprintf(temp, " %i", hour);
  6111. time_msg.append(temp);
  6112. time_msg.append(" hour");
  6113. time_msg.append((hour > 1) ? "s" : "");
  6114. }
  6115. if (min > 0) {
  6116. char temp[5];
  6117. sprintf(temp, " %i", min);
  6118. time_msg.append(temp);
  6119. time_msg.append(" minute");
  6120. time_msg.append((min > 1) ? "s" : "");
  6121. }
  6122. // Only add seconds if minutes and hours are 0
  6123. if (hour == 0 && min == 0 && sec > 0) {
  6124. char temp[5];
  6125. sprintf(temp, " %i", sec);
  6126. time_msg.append(temp);
  6127. time_msg.append(" second");
  6128. time_msg.append((sec > 1) ? "s" : "");
  6129. }
  6130. 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());
  6131. }
  6132. }
  6133. else
  6134. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6135. }
  6136. else
  6137. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6141. if (!lua_interface)
  6142. return 0;
  6143. Spawn* spawn = lua_interface->GetSpawn(state);
  6144. if (!spawn) {
  6145. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6149. return 1;
  6150. }
  6151. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6152. if (!lua_interface)
  6153. return 0;
  6154. Spawn* player = lua_interface->GetSpawn(state);
  6155. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6156. if (!player) {
  6157. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!player->IsPlayer()) {
  6161. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!ground) {
  6165. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!ground->IsGroundSpawn()) {
  6169. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6173. if (!groundspawn_entries) {
  6174. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6175. return 0;
  6176. }
  6177. Skill* skill = 0;
  6178. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6179. if (collection_skill == "Collecting")
  6180. skill = ((Player*)player)->GetSkillByName("Gathering");
  6181. else
  6182. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6183. if (!skill) {
  6184. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6185. return 0;
  6186. }
  6187. vector<GroundSpawnEntry*>::iterator itr;
  6188. GroundSpawnEntry* entry = 0;
  6189. bool can_harvest = false;
  6190. sint32 min_skill = -1;
  6191. // first, iterate through groundspawn_entries, discard tables player cannot use
  6192. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6193. {
  6194. entry = *itr;
  6195. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6196. min_skill = entry->min_skill_level;
  6197. // if player lacks skill, skip table
  6198. if (entry->min_skill_level > skill->current_val)
  6199. continue;
  6200. // if bonus, but player lacks level, skip table
  6201. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6202. continue;
  6203. can_harvest = true;
  6204. break;
  6205. }
  6206. lua_interface->SetBooleanValue(state, can_harvest);
  6207. // If false, send the message to the client
  6208. if (!can_harvest) {
  6209. Client* client = player->GetZone()->GetClientBySpawn(player);
  6210. if (client) {
  6211. string msg = "You do not have enough skill to ";
  6212. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6213. msg.append("gather");
  6214. else if (collection_skill == "Mining")
  6215. msg.append("mine");
  6216. else if (collection_skill == "Trapping")
  6217. msg.append("trap");
  6218. else if (collection_skill == "Foresting")
  6219. msg.append("forest");
  6220. else if (collection_skill == "Fishing")
  6221. msg.append("catch");
  6222. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6223. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6224. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6225. }
  6226. }
  6227. return 1;
  6228. }
  6229. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6230. if (!lua_interface)
  6231. return 0;
  6232. Spawn* player = lua_interface->GetSpawn(state);
  6233. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6234. if (!player) {
  6235. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (!player->IsPlayer()) {
  6239. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6243. lua_interface->SetBooleanValue(state, ret);
  6244. return 1;
  6245. }
  6246. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6247. // Check to see if we have a valid lua_interface
  6248. if (!lua_interface)
  6249. return 0;
  6250. // Get the spawn that is getting the pet
  6251. Spawn* spawn = lua_interface->GetSpawn(state);
  6252. Spawn* target = lua_interface->GetSpawn(state, 2);
  6253. // Get the DB ID of the pet
  6254. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6255. float x = lua_interface->GetFloatValue(state, 4);
  6256. float y = lua_interface->GetFloatValue(state, 5);
  6257. float z = lua_interface->GetFloatValue(state, 6);
  6258. // Get the spell that this command was called from
  6259. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6260. // Check to make sure the spawn pointer is valid
  6261. if (!spawn) {
  6262. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. // Check to make sure the spawn is an entity
  6266. if (!spawn->IsEntity()) {
  6267. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. if (!target) {
  6271. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if (!target->IsEntity()) {
  6275. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. // Check to see if the DB ID for the pet is set
  6279. if (pet_id == 0) {
  6280. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. // Check to see if the pointer to the spell is valid
  6284. if (!luaspell) {
  6285. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6286. return 0;
  6287. }
  6288. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6289. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6290. if (!pet) {
  6291. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6292. return 0;
  6293. }
  6294. // Check to make sure the pet is an npc
  6295. if (!pet->IsNPC()) {
  6296. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6297. return 0;
  6298. }
  6299. if (x == 0)
  6300. x = spawn->GetX();
  6301. if (y == 0)
  6302. y = spawn->GetY();
  6303. if (z == 0)
  6304. z = spawn->GetZ();
  6305. // Spawn the pet at the same location as the owner
  6306. pet->SetX(x);
  6307. pet->SetY(y);
  6308. pet->SetZ(z);
  6309. pet->SetLocation(spawn->GetLocation());
  6310. pet->SetHeading(spawn->GetHeading());
  6311. spawn->GetZone()->AddSpawn(pet);
  6312. /*
  6313. const char* spawn_script = world.GetSpawnScript(pet_id);
  6314. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6315. spawn->SetSpawnScript(string(spawn_script));
  6316. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6317. }*/
  6318. // Get a random pet name
  6319. string random_pet_name;
  6320. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6321. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6322. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6323. // Set the pets name
  6324. pet->SetName(random_pet_name.c_str());
  6325. // Set the level of the pet to the owners level
  6326. pet->SetLevel(spawn->GetLevel());
  6327. // Set the faction of the pet to the same faction as the owner
  6328. pet->SetFactionID(spawn->GetFactionID());
  6329. // Set the spawn as a pet
  6330. pet->SetPet(true);
  6331. // Give a pointer of the owner to the pet
  6332. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6333. // Set the pet type
  6334. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6335. // Set the spell id used to create this pet
  6336. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6337. // Set the spell tier used to create this pet
  6338. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6339. // Set the pets spawn type to 6
  6340. pet->SetSpawnType(6);
  6341. // Set the pets brain
  6342. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6343. // Check to see if the pet has a subtitle
  6344. if (strlen(pet->GetSubTitle()) > 0) {
  6345. // Add the players name to the front of the sub title
  6346. string pet_subtitle;
  6347. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6348. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6349. // Set the pets subtitle to the new one
  6350. pet->SetSubTitle(pet_subtitle.c_str());
  6351. }
  6352. // Set the pet as the return value for this function
  6353. lua_interface->SetSpawnValue(state, pet);
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. Spawn* player = lua_interface->GetSpawn(state, 2);
  6361. float max_distance = lua_interface->GetFloatValue(state, 3);
  6362. string type = lua_interface->GetStringValue(state, 4);
  6363. if (!spawn || (spawn && spawn->IsPlayer())) {
  6364. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6365. return 0;
  6366. }
  6367. if (!player || (player && !player->IsPlayer())) {
  6368. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. Client* client = 0;
  6372. if (player->GetZone())
  6373. client = player->GetZone()->GetClientBySpawn(player);
  6374. if (!client) {
  6375. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. //Set max_distance to default if not set or not proper value
  6379. if (max_distance <= 0)
  6380. max_distance = 500;
  6381. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6382. if (packet) {
  6383. float unknown2_3 = 0;
  6384. int8 placement_mode = 0;
  6385. if (type == "wall") {
  6386. placement_mode = 2;
  6387. unknown2_3 = 150;
  6388. }
  6389. else if (type == "ceiling")
  6390. placement_mode = 1;
  6391. packet->setDataByName("placement_mode", placement_mode);
  6392. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6393. packet->setDataByName("model_type", spawn->GetModelType());
  6394. packet->setDataByName("unknown", 1); //size
  6395. packet->setDataByName("unknown2", 1); //size 2
  6396. packet->setDataByName("unknown2", .5, 1); //size 3
  6397. packet->setDataByName("unknown2", 3, 2);
  6398. packet->setDataByName("unknown2", unknown2_3, 3);
  6399. packet->setDataByName("max_distance", max_distance);
  6400. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6401. client->QueuePacket(packet->serialize());
  6402. safe_delete(packet);
  6403. }
  6404. return 0;
  6405. }
  6406. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Item* item = lua_interface->GetItem(state);
  6410. if (!item) {
  6411. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6415. return 1;
  6416. }
  6417. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6418. if (!lua_interface)
  6419. return 0;
  6420. Spawn* spawn = lua_interface->GetSpawn(state);
  6421. if (!spawn) {
  6422. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. if (spawn->GetZone())
  6426. spawn->GetZone()->AddTransportSpawn(spawn);
  6427. return 0;
  6428. }
  6429. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6430. if (!lua_interface)
  6431. return 0;
  6432. Skill* skill = lua_interface->GetSkill(state);
  6433. if (!skill) {
  6434. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. lua_interface->SetInt32Value(state, skill->current_val);
  6438. return 1;
  6439. }
  6440. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6441. if (!lua_interface)
  6442. return 0;
  6443. Skill* skill = lua_interface->GetSkill(state);
  6444. if (!skill) {
  6445. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6446. return 0;
  6447. }
  6448. lua_interface->SetInt32Value(state, skill->max_val);
  6449. return 1;
  6450. }
  6451. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6452. if (!lua_interface)
  6453. return 0;
  6454. Skill* skill = lua_interface->GetSkill(state);
  6455. if (!skill) {
  6456. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6460. return 1;
  6461. }
  6462. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6463. if (!lua_interface)
  6464. return 0;
  6465. Skill* skill = lua_interface->GetSkill(state);
  6466. int16 value = lua_interface->GetInt16Value(state, 2);
  6467. if (!skill) {
  6468. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6469. return 0;
  6470. }
  6471. skill->max_val = value;
  6472. if (skill->max_val < skill->current_val)
  6473. skill->current_val = skill->max_val;
  6474. return 0;
  6475. }
  6476. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6477. if (!lua_interface)
  6478. return 0;
  6479. Skill* skill = lua_interface->GetSkill(state);
  6480. int16 value = lua_interface->GetInt16Value(state, 2);
  6481. if (!skill) {
  6482. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (value > skill->max_val)
  6486. skill->current_val = skill->max_val;
  6487. else
  6488. skill->current_val = value;
  6489. return 0;
  6490. }
  6491. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6492. if (!lua_interface)
  6493. return 0;
  6494. Spawn* player = lua_interface->GetSpawn(state);
  6495. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6496. if (skill_id > 0 && player && player->IsPlayer()) {
  6497. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6498. return 1;
  6499. }
  6500. return 0;
  6501. }
  6502. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6503. if (!lua_interface)
  6504. return 0;
  6505. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6506. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6507. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6508. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6509. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6510. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6511. if (player_spawn && player_spawn->IsPlayer()) {
  6512. Player* player = (Player*)player_spawn;
  6513. bool added = false;
  6514. if (!player->skill_list.HasSkill(skill_id)) {
  6515. player->AddSkill(skill_id, current_val, max_val, true);
  6516. added = true;
  6517. }
  6518. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  6519. Client* client = player->GetClient();
  6520. if (client) {
  6521. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6522. if (packet)
  6523. client->QueuePacket(packet);
  6524. }
  6525. }
  6526. if (added) {
  6527. lua_interface->SetBooleanValue(state, true);
  6528. return 1;
  6529. }
  6530. }
  6531. else {
  6532. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6533. }
  6534. }
  6535. else {
  6536. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6537. }
  6538. lua_interface->SetBooleanValue(state, false);
  6539. return 1;
  6540. }
  6541. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6542. if (!lua_interface)
  6543. return 0;
  6544. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6545. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6546. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6547. if (skill_id > 0) {
  6548. if (player_spawn && player_spawn->IsPlayer()) {
  6549. Player* player = (Player*)player_spawn;
  6550. if (player->skill_list.HasSkill(skill_id)) {
  6551. player->RemovePlayerSkill(skill_id);
  6552. if (!more_to_remove) {
  6553. Client* client = player->GetClient();
  6554. if (client) {
  6555. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6556. if (packet)
  6557. client->QueuePacket(packet);
  6558. }
  6559. }
  6560. }
  6561. }
  6562. else {
  6563. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6564. }
  6565. }
  6566. else {
  6567. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6568. }
  6569. return 0;
  6570. }
  6571. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6572. if (!lua_interface)
  6573. return 0;
  6574. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6575. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6576. int16 amount = lua_interface->GetInt8Value(state, 3);
  6577. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6578. if (amount > 0 && skill_type < 100) {
  6579. if (player_spawn && player_spawn->IsPlayer()) {
  6580. Player* player = (Player*)player_spawn;
  6581. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6582. if (!more_to_increase) {
  6583. Client* client = player->GetClient();
  6584. if (client) {
  6585. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6586. if (packet)
  6587. client->QueuePacket(packet);
  6588. }
  6589. }
  6590. }
  6591. else {
  6592. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6593. }
  6594. }
  6595. else {
  6596. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6597. }
  6598. return 0;
  6599. }
  6600. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6601. if (!lua_interface)
  6602. return 0;
  6603. Spawn* spawn = lua_interface->GetSpawn(state);
  6604. string name = lua_interface->GetStringValue(state, 2);
  6605. if (!spawn) {
  6606. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. if (!spawn->IsEntity()) {
  6610. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6611. return 0;
  6612. }
  6613. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6614. if (skill) {
  6615. lua_interface->SetSkillValue(state, skill);
  6616. return 1;
  6617. }
  6618. return 0;
  6619. }
  6620. int EQ2Emu_lua_AddProc(lua_State* state) {
  6621. if (!lua_interface)
  6622. return 0;
  6623. Spawn* spawn = lua_interface->GetSpawn(state);
  6624. int8 type = lua_interface->GetInt8Value(state, 2);
  6625. float chance = lua_interface->GetFloatValue(state, 3);
  6626. Item* item = lua_interface->GetItem(state, 4);
  6627. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6628. LuaSpell* spell = 0;
  6629. if (!spawn && (!spell || !use_all_spelltargets)) {
  6630. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6631. return 0;
  6632. }
  6633. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6634. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6635. return 0;
  6636. }
  6637. if (!item)
  6638. spell = lua_interface->GetCurrentSpell(state);
  6639. if (!item && !spell) {
  6640. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. if (spell && use_all_spelltargets) {
  6644. Spawn* target;
  6645. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6646. for (int8 i = 0; i < spell->targets.size(); i++) {
  6647. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6648. if (!target || !target->IsEntity())
  6649. continue;
  6650. ((Entity*)target)->AddProc(type, chance, item, spell);
  6651. }
  6652. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6653. }
  6654. else
  6655. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6656. return 0;
  6657. }
  6658. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6659. if (!lua_interface)
  6660. return 0;
  6661. Spawn* spawn = lua_interface->GetSpawn(state);
  6662. Item* item = lua_interface->GetItem(state, 2);
  6663. LuaSpell* spell = 0;
  6664. if (!spawn) {
  6665. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6666. return 0;
  6667. }
  6668. if (!spawn->IsEntity()) {
  6669. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6670. return 0;
  6671. }
  6672. if (!item)
  6673. spell = lua_interface->GetCurrentSpell(state);
  6674. if (!item && !spell) {
  6675. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. if (spell) {
  6679. Spawn* target;
  6680. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6681. for (int8 i = 0; i < spell->targets.size(); i++) {
  6682. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6683. if (!target || !target->IsEntity())
  6684. continue;
  6685. ((Entity*)target)->RemoveProc(item, spell);
  6686. }
  6687. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6688. spell->caster->RemoveProc(item, spell);
  6689. }
  6690. else
  6691. ((Entity*)spawn)->RemoveProc(item, spell);
  6692. return 0;
  6693. }
  6694. int EQ2Emu_lua_Knockback(lua_State* state) {
  6695. if (!lua_interface)
  6696. return 0;
  6697. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6698. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6699. int32 duration = lua_interface->GetInt32Value(state, 3);
  6700. float vertical = lua_interface->GetFloatValue(state, 4);
  6701. float horizontal = lua_interface->GetFloatValue(state, 5);
  6702. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6703. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6704. if (!target_spawn) {
  6705. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (!spawn) {
  6709. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6713. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6714. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6715. if (packet) {
  6716. packet->setDataByName("target_x", target_spawn->GetX());
  6717. packet->setDataByName("target_y", target_spawn->GetY());
  6718. packet->setDataByName("target_z", target_spawn->GetZ());
  6719. packet->setDataByName("vertical_movement", vertical);
  6720. packet->setDataByName("horizontal_movement", horizontal);
  6721. if (use_heading)
  6722. packet->setDataByName("use_player_heading", 1);
  6723. client->QueuePacket(packet->serialize());
  6724. }
  6725. safe_delete(packet);
  6726. }
  6727. return 0;
  6728. }
  6729. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6730. if (!lua_interface)
  6731. return 0;
  6732. Spawn* spawn = lua_interface->GetSpawn(state);
  6733. if (!spawn) {
  6734. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6738. return 1;
  6739. }
  6740. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6741. if (!lua_interface)
  6742. return 0;
  6743. Spawn* caster = lua_interface->GetSpawn(state);
  6744. Spawn* target = lua_interface->GetSpawn(state, 2);
  6745. string name = lua_interface->GetStringValue(state, 3);
  6746. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6747. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6748. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6749. string success_msg = lua_interface->GetStringValue(state, 7);
  6750. string effect_msg = lua_interface->GetStringValue(state, 8);
  6751. if (!caster) {
  6752. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6753. return 0;
  6754. }
  6755. if (!caster->IsEntity()) {
  6756. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6757. return 0;
  6758. }
  6759. if (!target) {
  6760. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6761. return 0;
  6762. }
  6763. if (!target->IsEntity()) {
  6764. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6765. return 0;
  6766. }
  6767. if (name.length() == 0) {
  6768. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6772. return 0;
  6773. }
  6774. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6775. if (!lua_interface)
  6776. return 0;
  6777. string name = lua_interface->GetStringValue(state);
  6778. if (name.length() == 0) {
  6779. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6783. if (!skill) {
  6784. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6785. return 0;
  6786. }
  6787. lua_interface->SetInt32Value(state, skill->skill_id);
  6788. return 1;
  6789. }
  6790. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6791. if (!lua_interface)
  6792. return 0;
  6793. Spawn* spawn = lua_interface->GetSpawn(state);
  6794. if (!spawn) {
  6795. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6796. return 0;
  6797. }
  6798. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6799. return 1;
  6800. }
  6801. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6802. if (!lua_interface)
  6803. return 0;
  6804. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6805. if (!luaspell) {
  6806. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6807. return 0;
  6808. }
  6809. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6810. return 1;
  6811. }
  6812. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6813. if (!lua_interface)
  6814. return 0;
  6815. Spawn* spawn = lua_interface->GetSpawn(state);
  6816. Spawn* target = lua_interface->GetSpawn(state, 2);
  6817. if (!spawn) {
  6818. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. if (!spawn->IsEntity()) {
  6822. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6823. return 0;
  6824. }
  6825. if (!target) {
  6826. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6830. return 1;
  6831. }
  6832. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6833. if (!lua_interface)
  6834. return 0;
  6835. Spawn* spawn = lua_interface->GetSpawn(state);
  6836. Spawn* target = lua_interface->GetSpawn(state, 2);
  6837. if (!spawn) {
  6838. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6839. return 0;
  6840. }
  6841. if (!spawn->IsEntity()) {
  6842. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6843. return 0;
  6844. }
  6845. if (!target) {
  6846. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6847. return 0;
  6848. }
  6849. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6850. return 1;
  6851. }
  6852. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6853. if (!lua_interface)
  6854. return 0;
  6855. Item* item = lua_interface->GetItem(state);
  6856. if (!item) {
  6857. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6858. return 0;
  6859. }
  6860. lua_interface->SetInt32Value(state, item->details.count);
  6861. return 1;
  6862. }
  6863. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6864. if (!lua_interface)
  6865. return 0;
  6866. Item* item = lua_interface->GetItem(state);
  6867. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6868. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6869. if (!item) {
  6870. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6871. return 0;
  6872. }
  6873. if (!owner) {
  6874. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6875. return 0;
  6876. }
  6877. if (!owner->IsPlayer()) {
  6878. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. if (item->stack_count < new_count) {
  6882. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6883. return 0;
  6884. }
  6885. if (new_count > 0) {
  6886. item->details.count = new_count;
  6887. item->save_needed = true;
  6888. }
  6889. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6890. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6891. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6892. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6893. else
  6894. {
  6895. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6896. return 0;
  6897. }
  6898. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6899. if (!client)
  6900. return 0;
  6901. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6902. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6903. if (app)
  6904. client->QueuePacket(app);
  6905. return 0;
  6906. }
  6907. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6908. if (!lua_interface)
  6909. return 0;
  6910. int32 time = lua_interface->GetInt32Value(state);
  6911. string function = lua_interface->GetStringValue(state, 2);
  6912. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6913. Spawn* target = lua_interface->GetSpawn(state, 4);
  6914. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6915. if (time == 0) {
  6916. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6917. return 0;
  6918. }
  6919. if (function.length() == 0) {
  6920. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. if (!spell) {
  6924. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6925. return 0;
  6926. }
  6927. SpellScriptTimer* timer = new SpellScriptTimer;
  6928. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6929. #ifdef WIN32
  6930. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6931. #else
  6932. bzero(timer, sizeof(SpellScriptTimer));
  6933. #endif*/
  6934. timer->caster = 0;
  6935. timer->deleteWhenDone = false;
  6936. timer->target = 0;
  6937. timer->time = Timer::GetCurrentTime2() + time;
  6938. timer->customFunction = function;
  6939. timer->spell = spell;
  6940. if (caster)
  6941. timer->caster = caster->GetID();
  6942. if (target)
  6943. timer->target = target->GetID();
  6944. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6945. return 0;
  6946. }
  6947. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6948. if (!lua_interface)
  6949. return 0;
  6950. float hp_perc = lua_interface->GetFloatValue(state);
  6951. float power_perc = lua_interface->GetFloatValue(state, 2);
  6952. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6953. Spawn* target = lua_interface->GetSpawn(state, 4);
  6954. string heal_name = lua_interface->GetStringValue(state, 5);
  6955. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6956. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6957. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6958. if (!spell) {
  6959. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6960. return 0;
  6961. }
  6962. Entity* caster = spell->caster;
  6963. if (!caster) {
  6964. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6965. return 0;
  6966. }
  6967. Client* client = 0;
  6968. PendingResurrection* rez = 0;
  6969. ZoneServer* zone = spell->caster->GetZone();
  6970. if (!target) {
  6971. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6972. if (spell->targets.size() > 0) {
  6973. vector<int32> spell_targets = spell->targets;
  6974. for (int8 i = 0; i < spell_targets.size(); i++) {
  6975. target = zone->GetSpawnByID(spell_targets.at(i));
  6976. if (!target)
  6977. continue;
  6978. if (!target->IsPlayer())
  6979. continue;
  6980. client = target->GetZone()->GetClientBySpawn(target);
  6981. if (!client)
  6982. continue;
  6983. rez = client->GetCurrentRez();
  6984. if (rez->active)
  6985. continue;
  6986. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6987. rez->active = true;
  6988. rez->caster = caster;
  6989. rez->expire_timer = new Timer;
  6990. int32 duration = spell->spell->GetSpellDuration();
  6991. rez->expire_timer->Start(duration * 100);
  6992. rez->hp_perc = hp_perc;
  6993. rez->mp_perc = power_perc;
  6994. rez->range = spell->spell->GetSpellData()->range;
  6995. rez->spell_name = spell->spell->GetName();
  6996. if (heal_name.length() > 0)
  6997. rez->heal_name = heal_name;
  6998. else
  6999. rez->heal_name = rez->spell_name;
  7000. rez->no_calcs = no_calcs;
  7001. rez->crit_mod = crit_mod;
  7002. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7003. if (send_window)
  7004. client->SendResurrectionWindow();
  7005. else {
  7006. target->GetZone()->ResurrectSpawn(target, client);
  7007. rez->should_delete = true;
  7008. }
  7009. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7010. }
  7011. }
  7012. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7013. }
  7014. else {
  7015. client = target->GetZone()->GetClientBySpawn(target);
  7016. if (!client)
  7017. return 0;
  7018. rez = client->GetCurrentRez();
  7019. if (rez->active)
  7020. return 0;
  7021. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7022. rez->active = true;
  7023. rez->caster = caster;
  7024. rez->expire_timer = new Timer;
  7025. int32 duration = spell->spell->GetSpellDuration();
  7026. rez->expire_timer->Start(duration * 100);
  7027. rez->hp_perc = hp_perc;
  7028. rez->mp_perc = power_perc;
  7029. rez->range = spell->spell->GetSpellData()->range;
  7030. rez->spell_name = spell->spell->GetName();
  7031. if (heal_name.length() > 0)
  7032. rez->heal_name = heal_name;
  7033. else
  7034. rez->heal_name = rez->spell_name;
  7035. rez->no_calcs = no_calcs;
  7036. rez->crit_mod = crit_mod;
  7037. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7038. if (send_window)
  7039. client->SendResurrectionWindow();
  7040. else {
  7041. target->GetZone()->ResurrectSpawn(target, client);
  7042. rez->should_delete = true;
  7043. }
  7044. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7045. }
  7046. return 0;
  7047. }
  7048. int EQ2Emu_lua_SetVision(lua_State* state) {
  7049. if (!lua_interface)
  7050. return 0;
  7051. Spawn* spawn = lua_interface->GetSpawn(state);
  7052. int8 vision = lua_interface->GetInt8Value(state, 2);
  7053. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7054. if (!spawn) {
  7055. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7056. return 0;
  7057. }
  7058. if (!spawn->IsEntity()) {
  7059. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7060. return 0;
  7061. }
  7062. if (spell && spell->targets.size() > 0) {
  7063. ZoneServer* zone = spell->caster->GetZone();
  7064. for (int8 i = 0; i < spell->targets.size(); i++) {
  7065. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7066. if (target->IsEntity()) {
  7067. ((Entity*)target)->GetInfoStruct()->vision = vision;
  7068. if (target->IsPlayer())
  7069. ((Player*)target)->SetCharSheetChanged(true);
  7070. }
  7071. }
  7072. }
  7073. else {
  7074. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  7075. if (spawn->IsPlayer())
  7076. ((Player*)spawn)->SetCharSheetChanged(true);
  7077. }
  7078. return 0;
  7079. }
  7080. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7081. if (!lua_interface)
  7082. return 0;
  7083. Spawn* spawn = lua_interface->GetSpawn(state);
  7084. float intensity = lua_interface->GetFloatValue(state, 2);
  7085. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7086. if (!spawn) {
  7087. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7088. return 0;
  7089. }
  7090. if (!spawn->IsEntity()) {
  7091. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7092. return 0;
  7093. }
  7094. if (spell && spell->targets.size() > 0) {
  7095. ZoneServer* zone = spell->caster->GetZone();
  7096. for (int8 i = 0; i < spell->targets.size(); i++) {
  7097. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7098. if (target && target->IsEntity()) {
  7099. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  7100. if (target->IsPlayer())
  7101. ((Player*)target)->SetCharSheetChanged(true);
  7102. }
  7103. }
  7104. }
  7105. else {
  7106. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  7107. if (spawn->IsPlayer())
  7108. ((Player*)spawn)->SetCharSheetChanged(true);
  7109. }
  7110. return 0;
  7111. }
  7112. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7113. if (!lua_interface)
  7114. return 0;
  7115. Spawn* spawn = lua_interface->GetSpawn(state);
  7116. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7117. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7118. if (!spawn) {
  7119. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7120. return 0;
  7121. }
  7122. if (!spawn->IsEntity()) {
  7123. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. if (spell && spell->targets.size() > 0) {
  7127. ZoneServer* zone = spell->caster->GetZone();
  7128. for (int8 i = 0; i < spell->targets.size(); i++) {
  7129. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7130. if (target->IsEntity()) {
  7131. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7132. if (target->IsPlayer())
  7133. ((Player*)target)->SetCharSheetChanged(true);
  7134. }
  7135. }
  7136. }
  7137. else {
  7138. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7139. if (spawn->IsPlayer())
  7140. ((Player*)spawn)->SetCharSheetChanged(true);
  7141. }
  7142. return 0;
  7143. }
  7144. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7145. if (!lua_interface)
  7146. return 0;
  7147. Item* item = lua_interface->GetItem(state);
  7148. int8 type = lua_interface->GetInt32Value(state, 2);
  7149. if (!item) {
  7150. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. if (type == 1)
  7154. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7155. else if (type == 2)
  7156. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7157. return 1;
  7158. }
  7159. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7160. if (!lua_interface)
  7161. return 0;
  7162. Spawn* target = lua_interface->GetSpawn(state);
  7163. float val = lua_interface->GetFloatValue(state, 2);
  7164. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7165. // Added from Gangrenous post
  7166. if (spell && spell->resisted)
  7167. return 0;
  7168. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7169. if (val > 1.0f)
  7170. val = 1.0f - (val / 100.0f);
  7171. if (spell && spell->spell && spell->targets.size() > 0) {
  7172. ZoneServer* zone = spell->caster->GetZone();
  7173. for (int32 i = 0; i != spell->targets.size(); i++) {
  7174. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7175. if (spawn && spawn->IsEntity()) {
  7176. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7177. if (spawn->IsPlayer())
  7178. ((Player*)spawn)->SetCharSheetChanged(true);
  7179. }
  7180. }
  7181. }
  7182. else {
  7183. if (target && target->IsEntity()) {
  7184. ((Entity*)target)->SetSpeedMultiplier(val);
  7185. if (target->IsPlayer())
  7186. ((Player*)target)->SetCharSheetChanged(true);
  7187. }
  7188. }
  7189. return 0;
  7190. }
  7191. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7192. if (!lua_interface)
  7193. return 0;
  7194. Spawn* spawn = lua_interface->GetSpawn(state);
  7195. int16 model = lua_interface->GetInt16Value(state, 2);
  7196. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7197. if (spell && spell->spell && spell->targets.size() > 0) {
  7198. ZoneServer* zone = spell->caster->GetZone();
  7199. for (int32 i = 0; i < spell->targets.size(); i++) {
  7200. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7201. if (target)
  7202. target->SetIllusionModel(model);
  7203. }
  7204. }
  7205. else {
  7206. if (!spawn) {
  7207. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7208. return 0;
  7209. }
  7210. spawn->SetIllusionModel(model);
  7211. }
  7212. return 0;
  7213. }
  7214. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7215. if (!lua_interface)
  7216. return 0;
  7217. Spawn* spawn = lua_interface->GetSpawn(state);
  7218. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7219. if (spell && spell->spell && spell->targets.size() > 0) {
  7220. ZoneServer* zone = spell->caster->GetZone();
  7221. for (int32 i = 0; i < spell->targets.size(); i++) {
  7222. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7223. if (target)
  7224. target->SetIllusionModel(0);
  7225. }
  7226. }
  7227. else {
  7228. if (!spawn) {
  7229. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7230. return 0;
  7231. }
  7232. spawn->SetIllusionModel(0);
  7233. }
  7234. return 0;
  7235. }
  7236. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7237. if (!lua_interface)
  7238. return 0;
  7239. Spawn* caster = lua_interface->GetSpawn(state);
  7240. Spawn* target = lua_interface->GetSpawn(state, 2);
  7241. float chance = lua_interface->GetFloatValue(state, 3);
  7242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7243. if (!caster) {
  7244. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. if (!caster->IsEntity()) {
  7248. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. if (!target) {
  7252. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. if (!target->IsEntity()) {
  7256. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (chance <= 0) {
  7260. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. if (!spell) {
  7264. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7265. return 0;
  7266. }
  7267. if (((Entity*)caster)->GetThreatTransfer()) {
  7268. return 0;
  7269. }
  7270. ThreatTransfer* transfer = new ThreatTransfer;
  7271. transfer->Target = target->GetID();
  7272. transfer->Amount = chance;
  7273. transfer->Spell = spell;
  7274. ((Entity*)caster)->SetThreatTransfer(transfer);
  7275. return 0;
  7276. }
  7277. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. Spawn* spawn = lua_interface->GetSpawn(state);
  7281. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7282. if (!spawn) {
  7283. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7284. return 0;
  7285. }
  7286. if (!spell) {
  7287. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7288. return 0;
  7289. }
  7290. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7291. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7292. ((Entity*)spawn)->SetThreatTransfer(0);
  7293. safe_delete(transfer);
  7294. }
  7295. return 0;
  7296. }
  7297. int EQ2Emu_lua_CureByType(lua_State* state) {
  7298. if (!lua_interface)
  7299. return 0;
  7300. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7301. if (!spell) {
  7302. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. int8 cure_count = lua_interface->GetInt8Value(state);
  7306. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7307. string cure_name = lua_interface->GetStringValue(state, 3);
  7308. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7309. Spawn* target = lua_interface->GetSpawn(state, 5);
  7310. if (target) {
  7311. if (!target->IsEntity()) {
  7312. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7313. return 0;
  7314. }
  7315. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7316. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7317. }
  7318. else {
  7319. ZoneServer* zone = spell->caster->GetZone();
  7320. vector<int32> targets = spell->targets;
  7321. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7322. for (int8 i = 0; i < targets.size(); i++) {
  7323. target = zone->GetSpawnByID(targets.at(i));
  7324. if (!target || !target->IsEntity())
  7325. continue;
  7326. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7327. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7328. }
  7329. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7330. }
  7331. return 0;
  7332. }
  7333. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7334. if (!lua_interface)
  7335. return 0;
  7336. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7337. if (!spell) {
  7338. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7339. return 0;
  7340. }
  7341. int8 cure_count = lua_interface->GetInt8Value(state);
  7342. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7343. string cure_name = lua_interface->GetStringValue(state, 3);
  7344. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7345. Spawn* target = lua_interface->GetSpawn(state, 5);
  7346. if (target) {
  7347. if (!target->IsEntity()) {
  7348. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7349. return 0;
  7350. }
  7351. if (((Entity*)target)->GetDetCount() > 0)
  7352. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7353. }
  7354. else {
  7355. ZoneServer* zone = spell->caster->GetZone();
  7356. vector<int32> targets = spell->targets;
  7357. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7358. for (int8 i = 0; i < targets.size(); i++) {
  7359. target = zone->GetSpawnByID(targets.at(i));
  7360. if (!target || !target->IsEntity())
  7361. continue;
  7362. if (((Entity*)target)->GetDetCount() > 0)
  7363. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7364. }
  7365. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7366. }
  7367. return 0;
  7368. }
  7369. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7370. if (!lua_interface)
  7371. return 0;
  7372. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7373. if (!spell) {
  7374. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7375. return 0;
  7376. }
  7377. if (!spell->caster) {
  7378. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. if (!spell->caster->GetZone()) {
  7382. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7383. return 0;
  7384. }
  7385. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7386. return 0;
  7387. }
  7388. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7389. if (!lua_interface)
  7390. return 0;
  7391. Spawn* spawn = lua_interface->GetSpawn(state);
  7392. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7393. if (!spell) {
  7394. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7395. return 0;
  7396. }
  7397. if (spawn && spawn->IsEntity())
  7398. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7399. else {
  7400. ZoneServer* zone = spell->caster->GetZone();
  7401. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7402. for (int32 i = 0; i < spell->targets.size(); i++) {
  7403. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7404. if (!spawn || !spawn->IsEntity())
  7405. continue;
  7406. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7407. }
  7408. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7409. }
  7410. return 0;
  7411. }
  7412. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7413. if (!lua_interface)
  7414. return 0;
  7415. Spawn* spawn = lua_interface->GetSpawn(state);
  7416. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7417. if (!spell) {
  7418. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7419. return 0;
  7420. }
  7421. if (spawn && spawn->IsEntity())
  7422. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7423. else {
  7424. ZoneServer* zone = spell->caster->GetZone();
  7425. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7426. for (int32 i = 0; i < spell->targets.size(); i++) {
  7427. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7428. if (!spawn || !spawn->IsEntity())
  7429. continue;
  7430. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7431. }
  7432. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7433. }
  7434. return 0;
  7435. }
  7436. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7437. if (!lua_interface)
  7438. return 0;
  7439. Spawn* caster = lua_interface->GetSpawn(state);
  7440. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7441. if (!caster) {
  7442. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7443. return 0;
  7444. }
  7445. if (!caster->IsPlayer()) {
  7446. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. Spawn* target = caster->GetTarget();
  7450. if (!target) {
  7451. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7452. return 0;
  7453. }
  7454. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7455. if (!client) {
  7456. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7457. return 0;
  7458. }
  7459. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7460. if (ho) {
  7461. ho->SetTarget(target->GetID());
  7462. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7463. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7464. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7465. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7466. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7467. deque<GroupMemberInfo*>::iterator itr;
  7468. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7469. if (group)
  7470. {
  7471. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7472. deque<GroupMemberInfo*>* members = group->GetMembers();
  7473. for (itr = members->begin(); itr != members->end(); itr++) {
  7474. if ((*itr)->client)
  7475. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7476. }
  7477. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7478. }
  7479. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7480. }
  7481. else
  7482. safe_delete(ho);
  7483. }
  7484. else {
  7485. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7486. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7487. }
  7488. else
  7489. safe_delete(ho);
  7490. }
  7491. }
  7492. return 0;
  7493. }
  7494. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7495. if (!lua_interface)
  7496. return 0;
  7497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7498. if (!spell) {
  7499. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. int16 triggerCount = lua_interface->GetInt16Value(state);
  7503. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7504. if (!triggerCount) {
  7505. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7506. return 0;
  7507. }
  7508. spell->num_triggers = triggerCount;
  7509. spell->had_triggers = true;
  7510. spell->cancel_after_all_triggers = cancel_after_triggers;
  7511. return 0;
  7512. }
  7513. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7514. if (!lua_interface)
  7515. return 0;
  7516. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7517. if (!spell) {
  7518. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. lua_interface->SetInt32Value(state, spell->num_triggers);
  7522. return 1;
  7523. }
  7524. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7528. if (!spell) {
  7529. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. int16 remove_count = lua_interface->GetInt16Value(state);
  7533. if (!remove_count)
  7534. remove_count = 1;
  7535. if (remove_count >= spell->num_triggers) {
  7536. spell->num_triggers = 0;
  7537. if (spell->cancel_after_all_triggers)
  7538. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7539. }
  7540. else {
  7541. spell->num_triggers -= remove_count;
  7542. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7543. }
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. Spawn* spawn = lua_interface->GetSpawn(state);
  7550. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7551. if (!spawn) {
  7552. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7553. return 0;
  7554. }
  7555. if (!copy_spawn) {
  7556. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. spawn->CopySpawnAppearance(copy_spawn);
  7560. return 0;
  7561. }
  7562. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7563. if (!lua_interface)
  7564. return 0;
  7565. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7566. int8 type = lua_interface->GetInt8Value(state);
  7567. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7568. if (!spell) {
  7569. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7570. return 0;
  7571. }
  7572. if (spawn) {
  7573. if (!spawn->IsEntity()) {
  7574. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7575. return 0;
  7576. }
  7577. Entity* entity = ((Entity*)spawn);
  7578. switch (type) {
  7579. case IMMUNITY_TYPE_AOE:
  7580. entity->AddAOEImmunity(spell);
  7581. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7582. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7583. break;
  7584. case IMMUNITY_TYPE_STUN:
  7585. entity->AddStunImmunity(spell);
  7586. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7587. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7588. break;
  7589. case IMMUNITY_TYPE_ROOT:
  7590. entity->AddRootImmunity(spell);
  7591. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7592. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7593. break;
  7594. case IMMUNITY_TYPE_DAZE:
  7595. entity->AddDazeImmunity(spell);
  7596. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7597. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7598. break;
  7599. case IMMUNITY_TYPE_FEAR:
  7600. entity->AddFearImmunity(spell);
  7601. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7602. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7603. break;
  7604. case IMMUNITY_TYPE_MEZ:
  7605. entity->AddMezImmunity(spell);
  7606. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7607. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7608. break;
  7609. case IMMUNITY_TYPE_STIFLE:
  7610. entity->AddStifleImmunity(spell);
  7611. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7612. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7613. break;
  7614. default:
  7615. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7616. }
  7617. }
  7618. else {
  7619. bool should_break = false;
  7620. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7621. for (int8 i = 0; i < spell->targets.size(); i++) {
  7622. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7623. if (!spawn || !spawn->IsEntity())
  7624. continue;
  7625. Entity* entity = ((Entity*)spawn);
  7626. switch (type) {
  7627. case IMMUNITY_TYPE_AOE:
  7628. entity->AddAOEImmunity(spell);
  7629. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7630. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7631. break;
  7632. case IMMUNITY_TYPE_STUN:
  7633. entity->AddStunImmunity(spell);
  7634. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7635. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7636. break;
  7637. case IMMUNITY_TYPE_ROOT:
  7638. entity->AddRootImmunity(spell);
  7639. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7640. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7641. break;
  7642. case IMMUNITY_TYPE_DAZE:
  7643. entity->AddDazeImmunity(spell);
  7644. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7645. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7646. break;
  7647. case IMMUNITY_TYPE_FEAR:
  7648. entity->AddFearImmunity(spell);
  7649. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7650. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7651. break;
  7652. case IMMUNITY_TYPE_MEZ:
  7653. entity->AddMezImmunity(spell);
  7654. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7655. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7656. break;
  7657. case IMMUNITY_TYPE_STIFLE:
  7658. entity->AddStifleImmunity(spell);
  7659. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7660. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7661. break;
  7662. default:
  7663. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7664. should_break = true;
  7665. }
  7666. if (should_break)
  7667. break;
  7668. }
  7669. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7670. }
  7671. return 0;
  7672. }
  7673. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7674. if (!lua_interface)
  7675. return 0;
  7676. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7677. int8 type = lua_interface->GetInt8Value(state);
  7678. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7679. if (!spell) {
  7680. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (spawn) {
  7684. if (!spawn->IsEntity()) {
  7685. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. Entity* entity = ((Entity*)spawn);
  7689. switch (type) {
  7690. case IMMUNITY_TYPE_AOE:
  7691. entity->RemoveAOEImmunity(spell);
  7692. break;
  7693. case IMMUNITY_TYPE_STUN:
  7694. entity->RemoveStunImmunity(spell);
  7695. break;
  7696. case IMMUNITY_TYPE_ROOT:
  7697. entity->RemoveRootImmunity(spell);
  7698. break;
  7699. case IMMUNITY_TYPE_DAZE:
  7700. entity->RemoveDazeImmunity(spell);
  7701. break;
  7702. case IMMUNITY_TYPE_FEAR:
  7703. entity->RemoveFearImmunity(spell);
  7704. break;
  7705. case IMMUNITY_TYPE_MEZ:
  7706. entity->RemoveMezImmunity(spell);
  7707. break;
  7708. case IMMUNITY_TYPE_STIFLE:
  7709. entity->RemoveStifleImmunity(spell);
  7710. break;
  7711. default:
  7712. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7713. }
  7714. }
  7715. else {
  7716. bool should_break = false;
  7717. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7718. for (int8 i = 0; i < spell->targets.size(); i++) {
  7719. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7720. if (!spawn || !spawn->IsEntity())
  7721. continue;
  7722. Entity* entity = ((Entity*)spawn);
  7723. switch (type) {
  7724. case IMMUNITY_TYPE_AOE:
  7725. entity->RemoveAOEImmunity(spell);
  7726. break;
  7727. case IMMUNITY_TYPE_STUN:
  7728. entity->RemoveStunImmunity(spell);
  7729. break;
  7730. case IMMUNITY_TYPE_ROOT:
  7731. entity->RemoveRootImmunity(spell);
  7732. break;
  7733. case IMMUNITY_TYPE_DAZE:
  7734. entity->RemoveDazeImmunity(spell);
  7735. break;
  7736. case IMMUNITY_TYPE_FEAR:
  7737. entity->RemoveFearImmunity(spell);
  7738. break;
  7739. case IMMUNITY_TYPE_MEZ:
  7740. entity->RemoveMezImmunity(spell);
  7741. break;
  7742. case IMMUNITY_TYPE_STIFLE:
  7743. entity->RemoveStifleImmunity(spell);
  7744. break;
  7745. default:
  7746. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7747. should_break = true;
  7748. }
  7749. if (should_break)
  7750. break;
  7751. }
  7752. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7753. }
  7754. return 0;
  7755. }
  7756. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7757. if (!lua_interface)
  7758. return 0;
  7759. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7760. if (!spell) {
  7761. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7762. return 0;
  7763. }
  7764. float snare = lua_interface->GetFloatValue(state);
  7765. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7766. // convert the val to the speed multipler value (100 - val)
  7767. float val = 100.0 - snare;
  7768. val /= 100.0;
  7769. if (spawn) {
  7770. if (!spawn->IsEntity()) {
  7771. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7772. return 0;
  7773. }
  7774. ((Entity*)spawn)->SetSnareValue(spell, val);
  7775. }
  7776. else {
  7777. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7778. for (int8 i = 0; i < spell->targets.size(); i++) {
  7779. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7780. if (!spawn || !spawn->IsEntity())
  7781. continue;
  7782. ((Entity*)spawn)->SetSnareValue(spell, val);
  7783. }
  7784. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7785. }
  7786. return 0;
  7787. }
  7788. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7789. if (!lua_interface)
  7790. return 0;
  7791. Spawn* spawn = lua_interface->GetSpawn(state);
  7792. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7793. if (!spawn) {
  7794. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. if (race_id == 0) {
  7798. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7802. return 1;
  7803. }
  7804. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7805. if (!lua_interface)
  7806. return 0;
  7807. Spawn* spawn = lua_interface->GetSpawn(state);
  7808. if (!spawn) {
  7809. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7813. return 1;
  7814. }
  7815. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7816. if (!lua_interface)
  7817. return 0;
  7818. Spawn* spawn = lua_interface->GetSpawn(state);
  7819. if (!spawn) {
  7820. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7821. return 0;
  7822. }
  7823. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7824. return 1;
  7825. }
  7826. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7827. if (!lua_interface)
  7828. return 0;
  7829. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7830. if (!spell) {
  7831. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. lua_interface->SetStringValue(state, spell->spell->GetName());
  7835. return 1;
  7836. }
  7837. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7838. if (!lua_interface)
  7839. return 0;
  7840. Quest* quest = lua_interface->GetQuest(state);
  7841. if (!quest) {
  7842. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7846. return 1;
  7847. }
  7848. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7849. if (!lua_interface)
  7850. return 0;
  7851. Quest* quest = lua_interface->GetQuest(state);
  7852. int32 flags = lua_interface->GetInt32Value(state, 2);
  7853. if (!quest) {
  7854. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. quest->SetQuestFlags(flags);
  7858. return 0;
  7859. }
  7860. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7861. if (!lua_interface)
  7862. return 0;
  7863. Quest* quest = lua_interface->GetQuest(state);
  7864. Spawn* player = lua_interface->GetSpawn(state, 2);
  7865. int32 step = lua_interface->GetInt32Value(state, 3);
  7866. int32 duration = lua_interface->GetInt32Value(state, 4);
  7867. string action = lua_interface->GetStringValue(state, 5);
  7868. if (!quest) {
  7869. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7870. return 0;
  7871. }
  7872. if (!player) {
  7873. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7874. return 0;
  7875. }
  7876. if (!player->IsPlayer()) {
  7877. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. if (step == 0) {
  7881. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. if (duration == 0) {
  7885. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. if (action.length() == 0) {
  7889. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7890. return 0;
  7891. }
  7892. Client* client = player->GetZone()->GetClientBySpawn(player);
  7893. if (!client) {
  7894. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7895. return 0;
  7896. }
  7897. quest->SetTimerStep(step);
  7898. quest->AddFailedAction(step, action);
  7899. quest->SetStepTimer(duration);
  7900. client->AddQuestTimer(quest->GetQuestID());
  7901. return 0;
  7902. }
  7903. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7904. if (!lua_interface)
  7905. return 0;
  7906. Quest* quest = lua_interface->GetQuest(state);
  7907. Spawn* player = lua_interface->GetSpawn(state, 2);
  7908. if (!quest) {
  7909. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. if (!player) {
  7913. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7914. return 0;
  7915. }
  7916. if (!player->IsPlayer()) {
  7917. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7918. return 0;
  7919. }
  7920. Client* client = player->GetZone()->GetClientBySpawn(player);
  7921. if (!client) {
  7922. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. quest->SetTimerStep(0);
  7926. quest->SetStepTimer(0);
  7927. client->RemoveQuestTimer(quest->GetQuestID());
  7928. return 0;
  7929. }
  7930. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7931. if (!lua_interface)
  7932. return 0;
  7933. Spawn* player = lua_interface->GetSpawn(state);
  7934. Quest* quest = lua_interface->GetQuest(state, 2);
  7935. int32 step = lua_interface->GetInt32Value(state, 3);
  7936. if (!player) {
  7937. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7938. return 0;
  7939. }
  7940. if (!player->IsPlayer()) {
  7941. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7942. return 0;
  7943. }
  7944. if (!quest) {
  7945. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7946. return 0;
  7947. }
  7948. if (step == 0) {
  7949. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. Client* client = player->GetZone()->GetClientBySpawn(player);
  7953. if (!client) {
  7954. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (quest->RemoveQuestStep(step, client)) {
  7958. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7959. client->GetCurrentZone()->SendQuestUpdates(client);
  7960. }
  7961. else
  7962. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7963. return 0;
  7964. }
  7965. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7966. if (!lua_interface)
  7967. return 0;
  7968. Quest* quest = lua_interface->GetQuest(state, 1);
  7969. int32 step = lua_interface->GetInt32Value(state, 2);
  7970. string desc = lua_interface->GetStringValue(state, 3);
  7971. string task_group = lua_interface->GetStringValue(state, 4);
  7972. if (!quest) {
  7973. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. if (step == 0) {
  7977. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. QuestStep* quest_step = quest->GetQuestStep(step);
  7981. if (!quest_step) {
  7982. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7983. return 0;
  7984. }
  7985. quest_step->SetStepProgress(0);
  7986. quest_step->SetTaskGroup(task_group);
  7987. quest_step->SetDescription(desc);
  7988. return 0;
  7989. }
  7990. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7991. if (!lua_interface)
  7992. return 0;
  7993. Quest* quest = lua_interface->GetQuest(state);
  7994. int32 step = lua_interface->GetInt32Value(state, 2);
  7995. string action = lua_interface->GetStringValue(state, 3);
  7996. if (!quest) {
  7997. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. if (step == 0) {
  8001. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. if (action.length() == 0) {
  8005. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8006. return 0;
  8007. }
  8008. quest->AddFailedAction(step, action);
  8009. return 0;
  8010. }
  8011. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8012. if (!lua_interface)
  8013. return 0;
  8014. Spawn* player = lua_interface->GetSpawn(state);
  8015. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8016. int32 step = lua_interface->GetInt32Value(state, 3);
  8017. if (!player) {
  8018. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!player->IsPlayer()) {
  8022. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. if (quest_id == 0) {
  8026. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. if (step == 0) {
  8030. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8034. if (!quest) {
  8035. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8036. return 0;
  8037. }
  8038. quest->StepFailed(step);
  8039. return 0;
  8040. }
  8041. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8042. if (!lua_interface)
  8043. return 0;
  8044. Spawn* player = lua_interface->GetSpawn(state);
  8045. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8046. if (!player) {
  8047. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. if (!player->IsPlayer()) {
  8051. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8052. return 0;
  8053. }
  8054. if (quest_id == 0) {
  8055. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8059. if (!quest) {
  8060. lua_interface->SetInt32Value(state, 0);
  8061. return 1;
  8062. }
  8063. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8064. return 1;
  8065. }
  8066. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8067. if (!lua_interface)
  8068. return 0;
  8069. string name = lua_interface->GetStringValue(state);
  8070. string value = lua_interface->GetStringValue(state, 2);
  8071. string comment = lua_interface->GetStringValue(state, 3);
  8072. if (name.length() == 0) {
  8073. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. if (value.length() == 0) {
  8077. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8078. return 0;
  8079. }
  8080. string varname = string("lua_").append(name);
  8081. Variable* var = variables.FindVariable(varname);
  8082. if (var)
  8083. var->SetValue(value.c_str());
  8084. else {
  8085. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8086. variables.AddVariable(var);
  8087. }
  8088. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8089. return 0;
  8090. }
  8091. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8092. if (!lua_interface)
  8093. return 0;
  8094. string name = lua_interface->GetStringValue(state);
  8095. if (name.length() == 0) {
  8096. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. string varname = string("lua_").append(name);
  8100. Variable* var = variables.FindVariable(varname);
  8101. if (var)
  8102. lua_interface->SetStringValue(state, var->GetValue());
  8103. else
  8104. lua_interface->SetStringValue(state, "NULL");
  8105. return 1;
  8106. }
  8107. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8108. if (!lua_interface)
  8109. return 0;
  8110. Spawn* player = lua_interface->GetSpawn(state);
  8111. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8112. if (!player) {
  8113. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8114. return 0;
  8115. }
  8116. if (!player->IsPlayer()) {
  8117. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8118. return 0;
  8119. }
  8120. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8121. return 1;
  8122. }
  8123. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8124. if (!lua_interface)
  8125. return 0;
  8126. Spawn* player = lua_interface->GetSpawn(state);
  8127. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8128. if (!player) {
  8129. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. if (!player->IsPlayer()) {
  8133. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. Language* language = master_languages_list.GetLanguage(language_id);
  8137. if (language)
  8138. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8139. return 0;
  8140. }
  8141. int EQ2Emu_lua_IsNight(lua_State* state) {
  8142. if (!lua_interface)
  8143. return 0;
  8144. ZoneServer* zone = lua_interface->GetZone(state);
  8145. if (!zone) {
  8146. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8150. return 1;
  8151. }
  8152. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8153. if (!lua_interface)
  8154. return 0;
  8155. Spawn* spawn = lua_interface->GetSpawn(state);
  8156. if (!spawn) {
  8157. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (!spawn->IsWidget()) {
  8161. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8162. return 0;
  8163. }
  8164. ((Widget*)spawn)->SetMultiFloorLift(true);
  8165. if (spawn->GetZone())
  8166. spawn->GetZone()->AddTransportSpawn(spawn);
  8167. return 0;
  8168. }
  8169. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8170. if (!lua_interface)
  8171. return 0;
  8172. Spawn* player = lua_interface->GetSpawn(state);
  8173. int32 path = lua_interface->GetInt32Value(state, 2);
  8174. if (!player) {
  8175. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8176. return 0;
  8177. }
  8178. if (!player->IsPlayer()) {
  8179. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. if (path == 0) {
  8183. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. Client* client = player->GetZone()->GetClientBySpawn(player);
  8187. if (!client) {
  8188. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. client->SendFlightAutoMount(path);
  8192. return 0;
  8193. }
  8194. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8195. if (!lua_interface)
  8196. return 0;
  8197. Spawn* player = lua_interface->GetSpawn(state);
  8198. if (!player) {
  8199. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. if (!player->IsPlayer()) {
  8203. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. Client* client = player->GetZone()->GetClientBySpawn(player);
  8207. if (!client) {
  8208. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8209. return 0;
  8210. }
  8211. client->EndAutoMount();
  8212. return 0;
  8213. }
  8214. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8215. if (!lua_interface)
  8216. return 0;
  8217. Spawn* player = lua_interface->GetSpawn(state);
  8218. if (!player) {
  8219. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8220. return 0;
  8221. }
  8222. if (!player->IsPlayer()) {
  8223. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. Client* client = player->GetZone()->GetClientBySpawn(player);
  8227. if (!client) {
  8228. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8232. return 1;
  8233. }
  8234. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8235. if (!lua_interface)
  8236. return 0;
  8237. Spawn* player = lua_interface->GetSpawn(state);
  8238. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8239. int32 value = lua_interface->GetInt32Value(state, 3);
  8240. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8241. if (!player) {
  8242. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. if (!player->IsPlayer()) {
  8246. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8250. return 0;
  8251. }
  8252. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8253. if (!lua_interface)
  8254. return 0;
  8255. Spawn* player = lua_interface->GetSpawn(state);
  8256. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8257. if (!player) {
  8258. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. if (!player->IsPlayer()) {
  8262. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8263. return 0;
  8264. }
  8265. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8266. if (!hd)
  8267. return 0;
  8268. lua_interface->SetInt32Value(state, hd->Value);
  8269. lua_interface->SetInt32Value(state, hd->Value2);
  8270. return 2;
  8271. }
  8272. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8273. if (!lua_interface)
  8274. return 0;
  8275. Spawn* spawn = lua_interface->GetSpawn(state);
  8276. int32 grid = lua_interface->GetInt32Value(state, 2);
  8277. if (!spawn) {
  8278. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. if (grid == 0) {
  8282. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8286. return 0;
  8287. }
  8288. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8289. if (!lua_interface)
  8290. return 0;
  8291. Spawn* spawn = lua_interface->GetSpawn(state);
  8292. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8293. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8294. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8295. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8296. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8297. if (!spawn) {
  8298. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. //Add this quest to the list of required quests for this spawn
  8302. spawn->SetRequiredHistory(event_id, value1, value2);
  8303. //If private spawn value set
  8304. if (private_spawn) {
  8305. //Set the spawn to be private when not granted access via history
  8306. spawn->AddAllowAccessSpawn(spawn);
  8307. spawn->SetPrivateQuestSpawn(true);
  8308. }
  8309. //This value will override vis_flags in the vis packet
  8310. if (flag_override > 0)
  8311. spawn->SetQuestsRequiredOverride(flag_override);
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* player = lua_interface->GetSpawn(state);
  8318. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8319. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8320. if (!player) {
  8321. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!player->IsPlayer()) {
  8325. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8329. return 1;
  8330. }
  8331. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8332. if (!lua_interface)
  8333. return 0;
  8334. Spawn* player = lua_interface->GetSpawn(state);
  8335. int8 level = lua_interface->GetInt8Value(state, 2);
  8336. if (!player) {
  8337. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. if (!player->IsPlayer()) {
  8341. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. if (level == 0) {
  8345. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8346. return 0;
  8347. }
  8348. Client* client = player->GetZone()->GetClientBySpawn(player);
  8349. if (!client) {
  8350. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8351. return 0;
  8352. }
  8353. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. Spawn* player = lua_interface->GetSpawn(state);
  8360. int32 amount = lua_interface->GetInt32Value(state, 2);
  8361. if (!player) {
  8362. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. if (!player->IsPlayer()) {
  8366. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. if (amount == 0) {
  8370. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. ((Player*)player)->AddCoins(amount);
  8374. return 0;
  8375. }
  8376. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8377. if (!lua_interface)
  8378. return 0;
  8379. Spawn* player = lua_interface->GetSpawn(state);
  8380. int32 amount = lua_interface->GetInt32Value(state, 2);
  8381. if (!player) {
  8382. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (!player->IsPlayer()) {
  8386. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (amount == 0) {
  8390. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8394. return 1;
  8395. }
  8396. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8397. if (!lua_interface)
  8398. return 0;
  8399. ZoneServer* zone = lua_interface->GetZone(state);
  8400. if (!zone) {
  8401. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. vector<Entity*> players = zone->GetPlayers();
  8405. if (players.size() == 0)
  8406. return 0;
  8407. lua_createtable(state, players.size(), 0);
  8408. int newTable = lua_gettop(state);
  8409. for (int32 i = 0; i < players.size(); i++) {
  8410. lua_interface->SetSpawnValue(state, players.at(i));
  8411. lua_rawseti(state, newTable, i + 1);
  8412. }
  8413. return 1;
  8414. }
  8415. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8416. if (!lua_interface)
  8417. return 0;
  8418. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8419. if (!zone) {
  8420. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8421. return 0;
  8422. }
  8423. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8424. //Map of <placement_id, location_id>
  8425. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8426. map<int32, int32>::iterator itr;
  8427. vector<Spawn*> group;
  8428. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8429. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8430. if (!location) {
  8431. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8432. return 0;
  8433. }
  8434. Spawn* spawn = 0;
  8435. if (location->entities[0]) {
  8436. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8437. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8438. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8439. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8440. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8441. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8442. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8443. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8444. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8445. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8446. if (spawn) {
  8447. const char* script = 0;
  8448. for (int x = 0; x < 3; x++) {
  8449. switch (x) {
  8450. case 0:
  8451. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8452. break;
  8453. case 1:
  8454. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8455. break;
  8456. case 2:
  8457. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8458. break;
  8459. }
  8460. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8461. spawn->SetSpawnScript(string(script));
  8462. break;
  8463. }
  8464. }
  8465. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8466. lua_interface->SetSpawnValue(state, spawn);
  8467. group.push_back(spawn);
  8468. }
  8469. else {
  8470. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8471. safe_delete(spawn);
  8472. }
  8473. }
  8474. }
  8475. if (!group.empty()) {
  8476. lua_createtable(state, group.size(), 0);
  8477. int newTable = lua_gettop(state);
  8478. for (int32 i = 0; i < group.size(); i++) {
  8479. lua_interface->SetSpawnValue(state, group[i]);
  8480. lua_rawseti(state, newTable, i + 1);
  8481. }
  8482. }
  8483. else
  8484. lua_pushnil(state);
  8485. return 1;
  8486. }
  8487. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8488. if (!lua_interface)
  8489. return 0;
  8490. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8491. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8492. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8493. if (!spawn) {
  8494. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (anim_id == 0) {
  8498. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (leeway == 0)
  8502. leeway = 5000;
  8503. spawn->SetSpawnAnim(anim_id);
  8504. spawn->SetSpawnAnimLeeway(leeway);
  8505. return 0;
  8506. }
  8507. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8508. if (!lua_interface)
  8509. return 0;
  8510. Spawn* player = lua_interface->GetSpawn(state);
  8511. if (!player) {
  8512. return 0;
  8513. }
  8514. Client* client = player->GetZone()->GetClientBySpawn(player);
  8515. if (!client) {
  8516. return 0;
  8517. }
  8518. lua_interface->SetInt32Value(state, client->GetVersion());
  8519. return 1;
  8520. }
  8521. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. Item* item = lua_interface->GetItem(state);
  8525. if (!item) {
  8526. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. lua_interface->SetInt32Value(state, item->details.item_id);
  8530. return 1;
  8531. }
  8532. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8533. if (!lua_interface)
  8534. return 0;
  8535. Spawn* spawn = lua_interface->GetSpawn(state);
  8536. if (!spawn) {
  8537. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8538. return 0;
  8539. }
  8540. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8541. return 1;
  8542. }
  8543. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8544. if (!lua_interface)
  8545. return 0;
  8546. Spawn* spawn = lua_interface->GetSpawn(state);
  8547. if (!spawn) {
  8548. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8552. return 1;
  8553. }
  8554. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8555. if (!lua_interface)
  8556. return 0;
  8557. Spawn* spawn = lua_interface->GetSpawn(state);
  8558. if (!spawn) {
  8559. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8563. return 1;
  8564. }
  8565. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8566. if (!lua_interface)
  8567. return 0;
  8568. Spawn* spawn = lua_interface->GetSpawn(state);
  8569. if (!spawn) {
  8570. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8571. return 0;
  8572. }
  8573. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8574. return 1;
  8575. }
  8576. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8577. if (!lua_interface)
  8578. return 0;
  8579. Spawn* spawn = lua_interface->GetSpawn(state);
  8580. float pct = lua_interface->GetFloatValue(state, 2);
  8581. if (!spawn) {
  8582. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8583. return 0;
  8584. }
  8585. if (pct == 0) {
  8586. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8590. lua_interface->SetInt32Value(state, amount);
  8591. return 1;
  8592. }
  8593. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. Spawn* spawn = lua_interface->GetSpawn(state);
  8597. float pct = lua_interface->GetFloatValue(state, 2);
  8598. if (!spawn) {
  8599. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. if (pct == 0) {
  8603. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8607. lua_interface->SetInt32Value(state, amount);
  8608. return 1;
  8609. }
  8610. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8611. if (!lua_interface)
  8612. return 0;
  8613. Spawn* spawn = lua_interface->GetSpawn(state);
  8614. if (!spawn) {
  8615. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. if (!spawn->IsPlayer()) {
  8619. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8620. return 0;
  8621. }
  8622. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8623. return 1;
  8624. }
  8625. int EQ2Emu_lua_Evac(lua_State* state) {
  8626. if (!lua_interface)
  8627. return 0;
  8628. Spawn* target = lua_interface->GetSpawn(state);
  8629. if (target) {
  8630. float x = target->GetZone()->GetSafeX();
  8631. float y = target->GetZone()->GetSafeY();
  8632. float z = target->GetZone()->GetSafeZ();
  8633. float h = target->GetZone()->GetSafeHeading();
  8634. target->SetX(x);
  8635. target->SetY(y);
  8636. target->SetZ(z);
  8637. target->SetHeading(h);
  8638. target->SetSpawnOrigX(target->GetX());
  8639. target->SetSpawnOrigY(target->GetY());
  8640. target->SetSpawnOrigZ(target->GetZ());
  8641. target->SetSpawnOrigHeading(target->GetHeading());
  8642. if (target->IsPlayer()) {
  8643. Client* client = target->GetZone()->GetClientBySpawn(target);
  8644. if (client) {
  8645. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8646. if (packet)
  8647. {
  8648. packet->setDataByName("x", x);
  8649. packet->setDataByName("y", y);
  8650. packet->setDataByName("z", z);
  8651. client->QueuePacket(packet->serialize());
  8652. safe_delete(packet);
  8653. }
  8654. }
  8655. }
  8656. }
  8657. else {
  8658. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8659. ZoneServer* zone = spell->caster->GetZone();
  8660. float x = spell->caster->GetZone()->GetSafeX();
  8661. float y = spell->caster->GetZone()->GetSafeY();
  8662. float z = spell->caster->GetZone()->GetSafeZ();
  8663. float h = spell->caster->GetZone()->GetSafeHeading();
  8664. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8665. for (int32 i = 0; i < spell->targets.size(); i++) {
  8666. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8667. if (!target2)
  8668. continue;
  8669. target2->SetX(x);
  8670. target2->SetY(y);
  8671. target2->SetZ(z);
  8672. target2->SetHeading(h);
  8673. target2->SetSpawnOrigX(target2->GetX());
  8674. target2->SetSpawnOrigY(target2->GetY());
  8675. target2->SetSpawnOrigZ(target2->GetZ());
  8676. target2->SetSpawnOrigHeading(target2->GetHeading());
  8677. if (target2->IsPlayer()) {
  8678. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8679. if (client) {
  8680. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8681. if (packet)
  8682. {
  8683. packet->setDataByName("x", x);
  8684. packet->setDataByName("y", y);
  8685. packet->setDataByName("z", z);
  8686. client->QueuePacket(packet->serialize());
  8687. safe_delete(packet);
  8688. }
  8689. }
  8690. }
  8691. }
  8692. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8693. }
  8694. return 0;
  8695. }
  8696. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8700. if (!luaspell) {
  8701. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. int8 tier = luaspell->spell->GetSpellTier();
  8705. lua_interface->SetInt32Value(state, tier);
  8706. return 1;
  8707. }
  8708. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8709. if (!lua_interface)
  8710. return 0;
  8711. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8712. if (!luaspell) {
  8713. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. int32 spell_id = luaspell->spell->GetSpellID();
  8717. lua_interface->SetInt32Value(state, spell_id);
  8718. return 1;
  8719. }
  8720. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8721. if (!lua_interface)
  8722. return 0;
  8723. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8724. if (!spawn) {
  8725. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. if (!spawn->IsPlayer()) {
  8729. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. ZoneServer* zone = spawn->GetZone();
  8733. if (!zone) {
  8734. return 0;
  8735. }
  8736. Client* client = zone->GetClientBySpawn(spawn);
  8737. if (!client) {
  8738. return 0;
  8739. }
  8740. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8741. return 0;
  8742. }
  8743. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8744. if (!lua_interface)
  8745. return 0;
  8746. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8747. if (!spawn) {
  8748. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8749. return 0;
  8750. }
  8751. if (!spawn->IsPlayer()) {
  8752. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8753. return 0;
  8754. }
  8755. ZoneServer* zone = spawn->GetZone();
  8756. if (!zone) {
  8757. return 0;
  8758. }
  8759. Client* client = zone->GetClientBySpawn(spawn);
  8760. if (!client) {
  8761. return 0;
  8762. }
  8763. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8764. return 0;
  8765. }
  8766. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* caster = lua_interface->GetSpawn(state);
  8770. Spawn* target = lua_interface->GetSpawn(state, 2);
  8771. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8772. string spell_name = lua_interface->GetStringValue(state, 4);
  8773. if (!caster) {
  8774. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8775. return 0;
  8776. }
  8777. if (!caster->IsEntity()) {
  8778. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8779. return 0;
  8780. }
  8781. if (!target) {
  8782. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. if (!target->IsEntity()) {
  8786. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8790. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8791. return 0;
  8792. }
  8793. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8794. if (!lua_interface)
  8795. return 0;
  8796. Spawn* object = lua_interface->GetSpawn(state);
  8797. Spawn* player = lua_interface->GetSpawn(state, 2);
  8798. if (object && player && player->IsPlayer()) {
  8799. int32 coins = lua_interface->GetInt32Value(state, 3);
  8800. vector<Item*>* items = 0;
  8801. int i = 0;
  8802. int32 item_id = 0;
  8803. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8804. if (items == 0)
  8805. items = new vector<Item*>;
  8806. if (master_item_list.GetItem(item_id))
  8807. items->push_back(master_item_list.GetItem(item_id));
  8808. i++;
  8809. }
  8810. Client* client = 0;
  8811. client = object->GetZone()->GetClientBySpawn(player);
  8812. if (client) {
  8813. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8814. }
  8815. safe_delete(items);
  8816. }
  8817. return 0;
  8818. }
  8819. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Spawn* player = lua_interface->GetSpawn(state);
  8823. int32 amount = lua_interface->GetInt32Value(state, 2);
  8824. if (player && player->IsPlayer() && amount > 0) {
  8825. ((Player*)player)->AddXP(amount);
  8826. ((Player*)player)->SetCharSheetChanged(true);
  8827. Client* client = player->GetZone()->GetClientBySpawn(player);
  8828. if (client) {
  8829. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8830. }
  8831. }
  8832. return 0;
  8833. }
  8834. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8835. if (!lua_interface)
  8836. return 0;
  8837. Spawn* player = lua_interface->GetSpawn(state);
  8838. int8 type = lua_interface->GetInt8Value(state, 2);
  8839. string text = lua_interface->GetStringValue(state, 3);
  8840. Client* client = 0;
  8841. if (player && player->IsPlayer())
  8842. client = player->GetZone()->GetClientBySpawn(player);
  8843. if (!client || text.length() == 0) {
  8844. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8845. return 0;
  8846. }
  8847. client->SimpleMessage(type, text.c_str());
  8848. return 0;
  8849. }
  8850. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8851. if (!lua_interface)
  8852. return 0;
  8853. Spawn* player = lua_interface->GetSpawn(state);
  8854. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8855. Client* client = 0;
  8856. if (player && player->IsPlayer())
  8857. client = player->GetZone()->GetClientBySpawn(player);
  8858. if (!client || !spawn) {
  8859. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8860. return 0;
  8861. }
  8862. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8863. if (!items) {
  8864. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. client->Loot(spawn->GetLootCoins(), items, spawn);
  8868. return 0;
  8869. }
  8870. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8871. if (!lua_interface)
  8872. return 0;
  8873. Spawn* spawnref = lua_interface->GetSpawn(state);
  8874. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8875. if (spawn_id > 0 && spawnref) {
  8876. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8877. if (spawns.size() == 0) {
  8878. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. Spawn* spawn = 0;
  8882. int16 index = MakeRandomInt(0, spawns.size());
  8883. if (index >= spawns.size() || index < 0)
  8884. index = 0;
  8885. spawn = spawns[index];
  8886. lua_interface->SetSpawnValue(state, spawn);
  8887. return 1;
  8888. }
  8889. else {
  8890. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8891. }
  8892. return 0;
  8893. }
  8894. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8895. Spawn* player = lua_interface->GetSpawn(state);
  8896. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8897. string name = lua_interface->GetStringValue(state, 3);
  8898. float distance = lua_interface->GetFloatValue(state, 4);
  8899. string command = lua_interface->GetStringValue(state, 5);
  8900. string error_text = lua_interface->GetStringValue(state, 6);
  8901. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8902. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8903. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8904. if (distance == 0)
  8905. distance = 10.0f;
  8906. if (command.length() == 0)
  8907. command = name;
  8908. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8909. if (spawns.size() == 0) {
  8910. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. Spawn* spawn = 0;
  8914. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8915. spawn = *itr;
  8916. if (spawn) {
  8917. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8918. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8919. }
  8920. }
  8921. }
  8922. return 0;
  8923. }
  8924. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8925. if (!lua_interface)
  8926. return 0;
  8927. Client* client = 0;
  8928. Spawn* player = lua_interface->GetSpawn(state);
  8929. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8930. if (player && player->IsPlayer() && player->GetZone())
  8931. client = player->GetZone()->GetClientBySpawn(player);
  8932. else{
  8933. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8934. return 0;
  8935. }
  8936. if (client) {
  8937. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8938. if (packet) {
  8939. packet->setDataByName("goal_num", goal_num);
  8940. client->QueuePacket(packet->serialize());
  8941. safe_delete(packet);
  8942. }
  8943. }
  8944. return 0;
  8945. }
  8946. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8947. if (!lua_interface)
  8948. return 0;
  8949. Client* client = 0;
  8950. Spawn* player = lua_interface->GetSpawn(state);
  8951. if (player && player->IsPlayer() && player->GetZone())
  8952. client = player->GetZone()->GetClientBySpawn(player);
  8953. else {
  8954. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8955. return 0;
  8956. }
  8957. if (client) {
  8958. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8959. }
  8960. return 0;
  8961. }
  8962. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8963. if (!lua_interface)
  8964. return 0;
  8965. Client* client = 0;
  8966. Spawn* player = lua_interface->GetSpawn(state);
  8967. float duration = lua_interface->GetFloatValue(state, 2);
  8968. string text = lua_interface->GetStringValue(state, 3);
  8969. string voice = lua_interface->GetStringValue(state, 4);
  8970. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8971. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8972. string signal = lua_interface->GetStringValue(state, 7);
  8973. string goal1 = lua_interface->GetStringValue(state, 8);
  8974. string task1 = lua_interface->GetStringValue(state, 9);
  8975. string goal2 = lua_interface->GetStringValue(state, 10);
  8976. string task2 = lua_interface->GetStringValue(state, 11);
  8977. string goal3 = lua_interface->GetStringValue(state, 12);
  8978. string task3 = lua_interface->GetStringValue(state, 13);
  8979. string goal4 = lua_interface->GetStringValue(state, 14);
  8980. string task4 = lua_interface->GetStringValue(state, 15);
  8981. if (!player) {
  8982. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8983. return 0;
  8984. }
  8985. if (!player->IsPlayer()) {
  8986. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8987. return 0;
  8988. }
  8989. else
  8990. client = ((Player*)player)->GetClient();
  8991. if (!client) {
  8992. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8993. return 0;
  8994. }
  8995. if (text.length() == 0) {
  8996. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8997. return 0;
  8998. }
  8999. if (duration >= 0 && duration < 2)
  9000. duration = 2;
  9001. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9002. if (packet) {
  9003. packet->setDataByName("open_seconds_max", duration);
  9004. packet->setDataByName("text", text.c_str());
  9005. packet->setDataByName("voice", voice.c_str());
  9006. int8 num_goals = 1;
  9007. if (task2.length() > 0)
  9008. num_goals++;
  9009. if (task3.length() > 0)
  9010. num_goals++;
  9011. if (task4.length() > 0)
  9012. num_goals++;
  9013. packet->setArrayLengthByName("num_goals", num_goals);
  9014. for (int8 i = 0; i < num_goals; i++) {
  9015. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9016. }
  9017. if (goal1.length() > 0)
  9018. packet->setArrayDataByName("goal_text", goal1.c_str());
  9019. if (goal2.length() > 0)
  9020. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9021. if (goal3.length() > 0)
  9022. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9023. if (goal4.length() > 0)
  9024. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9025. packet->setSubArrayDataByName("task_text", task1.c_str());
  9026. if (task2.length() > 0)
  9027. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9028. if (task3.length() > 0)
  9029. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9030. if (task4.length() > 0)
  9031. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9032. packet->setDataByName("complete_sound", "click");
  9033. packet->setDataByName("signal", signal.c_str());
  9034. packet->setDataByName("voice_key1", voice_key1);
  9035. packet->setDataByName("voice_key2", voice_key2);
  9036. client->QueuePacket(packet->serialize());
  9037. safe_delete(packet);
  9038. }
  9039. return 0;
  9040. }
  9041. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9042. if (!lua_interface)
  9043. return 0;
  9044. Client* client = 0;
  9045. Spawn* player = lua_interface->GetSpawn(state);
  9046. string window = lua_interface->GetStringValue(state, 2);
  9047. int8 show = lua_interface->GetInt8Value(state, 3);
  9048. if (!player) {
  9049. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9050. return 0;
  9051. }
  9052. if (!player->IsPlayer()) {
  9053. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9054. return 0;
  9055. }
  9056. else
  9057. client = ((Player*)player)->GetClient();
  9058. if (!client) {
  9059. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9060. return 0;
  9061. }
  9062. if (window.length() == 0) {
  9063. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9064. return 0;
  9065. }
  9066. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9067. if (packet) {
  9068. packet->setDataByName("window", window.c_str());
  9069. packet->setDataByName("show", show);
  9070. client->QueuePacket(packet->serialize());
  9071. safe_delete(packet);
  9072. }
  9073. return 0;
  9074. }
  9075. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9076. //See GameEvents.txt for options that can be used for this function
  9077. if (!lua_interface)
  9078. return 0;
  9079. Client* client = 0;
  9080. Spawn* player = lua_interface->GetSpawn(state);
  9081. string event_name = lua_interface->GetStringValue(state, 2);
  9082. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9083. if (!player || !player->IsPlayer()) {
  9084. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9085. return 0;
  9086. }
  9087. if (player->GetZone())
  9088. client = player->GetZone()->GetClientBySpawn(player);
  9089. if (!client) {
  9090. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9091. return 0;
  9092. }
  9093. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9094. if (packet) {
  9095. packet->setDataByName("event_name", event_name.c_str());
  9096. packet->setDataByName("enabled", enabled);
  9097. client->QueuePacket(packet->serialize());
  9098. safe_delete(packet);
  9099. }
  9100. return 0;
  9101. }
  9102. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Spawn* player = lua_interface->GetSpawn(state);
  9106. if (player && player->IsPlayer()) {
  9107. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9108. return 1;
  9109. }
  9110. return 0;
  9111. }
  9112. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Spawn* player = lua_interface->GetSpawn(state);
  9116. int8 step = lua_interface->GetInt8Value(state, 2);
  9117. if (player && player->IsPlayer() && step > 0) {
  9118. ((Player*)player)->SetTutorialStep(step);
  9119. }
  9120. return 0;
  9121. }
  9122. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9123. if (!lua_interface)
  9124. return 0;
  9125. Client* client = 0;
  9126. Spawn* player = lua_interface->GetSpawn(state);
  9127. string window = lua_interface->GetStringValue(state, 2);
  9128. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9129. if (!player) {
  9130. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9131. return 0;
  9132. }
  9133. if (!player->IsPlayer()) {
  9134. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9135. return 0;
  9136. }
  9137. else
  9138. client = ((Player*)player)->GetClient();
  9139. if (!client) {
  9140. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9141. return 0;
  9142. }
  9143. if (window.length() == 0) {
  9144. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9145. return 0;
  9146. }
  9147. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9148. if (packet) {
  9149. packet->setDataByName("window", window.c_str());
  9150. packet->setDataByName("flash_seconds", flash_seconds);
  9151. client->QueuePacket(packet->serialize());
  9152. safe_delete(packet);
  9153. }
  9154. return 0;
  9155. }
  9156. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9157. if (!lua_interface)
  9158. return 0;
  9159. Spawn* spawn = lua_interface->GetSpawn(state);
  9160. Spawn* target = lua_interface->GetSpawn(state, 2);
  9161. if (spawn && target)
  9162. return spawn->CheckLoS(target);
  9163. return 0;
  9164. }
  9165. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9166. if (!lua_interface)
  9167. return 0;
  9168. Spawn* spawn = lua_interface->GetSpawn(state);
  9169. float x = lua_interface->GetFloatValue(state, 2);
  9170. float y = lua_interface->GetFloatValue(state, 3);
  9171. float z = lua_interface->GetFloatValue(state, 4);
  9172. if (spawn)
  9173. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9174. return 0;
  9175. }
  9176. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9177. if (!lua_interface)
  9178. return 0;
  9179. ZoneServer* zone = lua_interface->GetZone(state);
  9180. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9181. if (zone)
  9182. zone->SetExpansionFlag(xpackFlag);
  9183. return 0;
  9184. }
  9185. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9186. if (!lua_interface)
  9187. return 0;
  9188. ZoneServer* zone = lua_interface->GetZone(state);
  9189. if (zone) {
  9190. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9191. return 1;
  9192. }
  9193. return 0;
  9194. }
  9195. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9196. if (!lua_interface)
  9197. return 0;
  9198. ZoneServer* zone = lua_interface->GetZone(state);
  9199. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9200. if (zone)
  9201. zone->SetHolidayFlag(holidayFlag);
  9202. return 0;
  9203. }
  9204. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9205. if (!lua_interface)
  9206. return 0;
  9207. ZoneServer* zone = lua_interface->GetZone(state);
  9208. if (zone) {
  9209. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9210. return 1;
  9211. }
  9212. return 0;
  9213. }
  9214. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9215. if (!lua_interface)
  9216. return 0;
  9217. Spawn* spawn = lua_interface->GetSpawn(state);
  9218. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9219. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9220. float distance = lua_interface->GetFloatValue(state, 4);
  9221. string in_range_function = lua_interface->GetStringValue(state, 5);
  9222. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9223. if (spawn && distance > 0 && in_range_function.length() > 0)
  9224. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9225. return 0;
  9226. }
  9227. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9228. if (!lua_interface)
  9229. return 0;
  9230. Spawn* spawn = lua_interface->GetSpawn(state);
  9231. Spawn* target = lua_interface->GetSpawn(state, 2);
  9232. if (spawn && target)
  9233. {
  9234. if (spawn->IsPlayer() && target->IsEntity())
  9235. {
  9236. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9237. return 1;
  9238. }
  9239. else if (spawn->IsEntity() && target->IsEntity())
  9240. {
  9241. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9242. return 1;
  9243. }
  9244. }
  9245. return 0;
  9246. }
  9247. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9248. if (!lua_interface)
  9249. return 0;
  9250. Spawn* spawn = lua_interface->GetSpawn(state);
  9251. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9252. if (spawn && spawn->IsEntity())
  9253. {
  9254. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9255. if (spawn->IsPlayer())
  9256. {
  9257. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9258. if (client)
  9259. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9260. }
  9261. }
  9262. return 0;
  9263. }
  9264. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9265. if (!lua_interface)
  9266. return 0;
  9267. Spawn* spawn = lua_interface->GetSpawn(state);
  9268. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9269. if (spawn && spawn->IsEntity())
  9270. {
  9271. ((Entity*)spawn)->SetSeeHideSpell(val);
  9272. if (spawn->IsPlayer())
  9273. {
  9274. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9275. if (client)
  9276. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9277. }
  9278. }
  9279. return 0;
  9280. }
  9281. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9282. {
  9283. if (!lua_interface)
  9284. return 0;
  9285. Spawn* player = lua_interface->GetSpawn(state);
  9286. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9287. string command = lua_interface->GetStringValue(state, 3);
  9288. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9289. if (spawn && player && player->IsPlayer())
  9290. {
  9291. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9292. bool res = false;
  9293. if (cmd)
  9294. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9295. lua_interface->SetBooleanValue(state, res);
  9296. return 1;
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9301. {
  9302. if (!lua_interface)
  9303. return 0;
  9304. Spawn* spawn = lua_interface->GetSpawn(state);
  9305. string command = lua_interface->GetStringValue(state, 2);
  9306. if (spawn && command.length() > 0)
  9307. spawn->RemovePrimaryEntityCommand(command.c_str());
  9308. return 0;
  9309. }
  9310. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9311. if (!lua_interface)
  9312. return 0;
  9313. Spawn* spawn = lua_interface->GetSpawn(state);
  9314. float distance = lua_interface->GetFloatValue(state, 2);
  9315. string command = lua_interface->GetStringValue(state, 3);
  9316. Spawn* player = lua_interface->GetSpawn(state, 4);
  9317. if (spawn) {
  9318. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9319. }
  9320. return 0;
  9321. }
  9322. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9323. if (!lua_interface)
  9324. return 0;
  9325. Spawn* spawn = lua_interface->GetSpawn(state);
  9326. Spawn* player = lua_interface->GetSpawn(state, 2);
  9327. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9328. if (spawn && player && transport_id && player->IsPlayer()) {
  9329. Client* client = 0;
  9330. if (player && player->IsPlayer())
  9331. client = player->GetZone()->GetClientBySpawn(player);
  9332. if (!client)
  9333. return 0;
  9334. vector<TransportDestination*> destinations;
  9335. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9336. if (destinations.size())
  9337. {
  9338. client->SetTemporaryTransportID(transport_id);
  9339. client->ProcessTeleport(spawn, &destinations, transport_id);
  9340. }
  9341. else
  9342. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9343. }
  9344. return 0;
  9345. }
  9346. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9347. if (!lua_interface)
  9348. return 0;
  9349. Spawn* player = lua_interface->GetSpawn(state);
  9350. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9351. if (player && player->IsPlayer()) {
  9352. Client* client = 0;
  9353. if (player && player->IsPlayer())
  9354. client = player->GetZone()->GetClientBySpawn(player);
  9355. if (!client)
  9356. return 0;
  9357. client->SetTemporaryTransportID(transport_id);
  9358. }
  9359. return 0;
  9360. }
  9361. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9362. if (!lua_interface)
  9363. return 0;
  9364. Spawn* player = lua_interface->GetSpawn(state);
  9365. if (player && player->IsPlayer()) {
  9366. Client* client = 0;
  9367. if (player && player->IsPlayer())
  9368. client = player->GetZone()->GetClientBySpawn(player);
  9369. if (!client)
  9370. return 0;
  9371. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9372. return 1;
  9373. }
  9374. return 0;
  9375. }
  9376. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9377. if (!lua_interface)
  9378. return 0;
  9379. Spawn* spawn = lua_interface->GetSpawn(state);
  9380. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9381. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9382. if (!spawn) {
  9383. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9384. return 0;
  9385. }
  9386. if (!spawn->IsEntity()) {
  9387. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9388. return 0;
  9389. }
  9390. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9391. {
  9392. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  9393. return 0;
  9394. }
  9395. if (spell && spell->targets.size() > 0) {
  9396. ZoneServer* zone = spell->caster->GetZone();
  9397. for (int8 i = 0; i < spell->targets.size(); i++) {
  9398. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9399. if (target->IsEntity()) {
  9400. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9401. if (target->IsPlayer())
  9402. ((Player*)target)->SetCharSheetChanged(true);
  9403. }
  9404. }
  9405. }
  9406. else {
  9407. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9408. if (spawn->IsPlayer())
  9409. ((Player*)spawn)->SetCharSheetChanged(true);
  9410. }
  9411. return 0;
  9412. }
  9413. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9414. if (!lua_interface)
  9415. return 0;
  9416. Spawn* spawn = lua_interface->GetSpawn(state);
  9417. if (!spawn) {
  9418. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9419. return 0;
  9420. }
  9421. if (!spawn->IsEntity()) {
  9422. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9423. return 0;
  9424. }
  9425. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9426. return 1;
  9427. }
  9428. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. int32 spell_id = lua_interface->GetInt32Value(state);
  9432. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9433. if (spell_id > 0) {
  9434. if (spell_tier == 0)
  9435. spell_tier = 1;
  9436. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9437. LuaSpell* lua_spell = 0;
  9438. if (lua_interface)
  9439. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9440. if (!lua_spell)
  9441. return 0;
  9442. lua_spell->spell = new Spell(spell);
  9443. lua_interface->AddCustomSpell(lua_spell);
  9444. lua_interface->SetSpellValue(state, lua_spell);
  9445. return 1;
  9446. }
  9447. return 0;
  9448. }
  9449. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9450. if (!lua_interface)
  9451. return 0;
  9452. LuaSpell* spell = lua_interface->GetSpell(state);
  9453. string field = lua_interface->GetStringValue(state, 2);
  9454. if (!spell) {
  9455. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9456. return 0;
  9457. }
  9458. if (!spell->spell || !spell->spell->GetSpellData()) {
  9459. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9460. return 0;
  9461. }
  9462. boost::to_lower(field);
  9463. return spell->spell->GetSpellData(state, field);
  9464. }
  9465. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9466. if (!lua_interface)
  9467. return 0;
  9468. LuaSpell* spell = lua_interface->GetSpell(state);
  9469. string field = lua_interface->GetStringValue(state, 2);
  9470. int8 fieldArg = 3; // field value after the initial set
  9471. if (!spell) {
  9472. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9473. return 0;
  9474. }
  9475. if (!spell->spell || !spell->spell->GetSpellData()) {
  9476. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9477. return 0;
  9478. }
  9479. boost::to_lower(field);
  9480. bool valSet = false;
  9481. spell->spell->SetSpellData(state, field, fieldArg);
  9482. return valSet;
  9483. }
  9484. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9485. if (!lua_interface)
  9486. return 0;
  9487. LuaSpell* spell = lua_interface->GetSpell(state);
  9488. int8 idx = lua_interface->GetInt32Value(state, 2);
  9489. if (!spell) {
  9490. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9491. return 0;
  9492. }
  9493. if (!spell->spell || !spell->spell->GetSpellData()) {
  9494. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9495. return 0;
  9496. }
  9497. if (spell->spell->lua_data.size() <= idx)
  9498. {
  9499. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9500. return 0;
  9501. }
  9502. bool setVal = true;
  9503. LUAData* data = spell->spell->lua_data[idx];
  9504. switch (data->type)
  9505. {
  9506. case 0:
  9507. {
  9508. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9509. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9510. data->int_value = value;
  9511. data->int_value2 = value2;
  9512. break;
  9513. }
  9514. case 1:
  9515. {
  9516. float value = lua_interface->GetFloatValue(state, 3);
  9517. float value2 = lua_interface->GetFloatValue(state, 4);
  9518. data->float_value = value;
  9519. data->float_value2 = value2;
  9520. break;
  9521. }
  9522. case 2:
  9523. {
  9524. bool value = lua_interface->GetBooleanValue(state, 3);
  9525. data->bool_value = value;
  9526. break;
  9527. }
  9528. case 3:
  9529. {
  9530. string value = lua_interface->GetStringValue(state, 3);
  9531. string value2 = lua_interface->GetStringValue(state, 4);
  9532. data->string_value = value;
  9533. data->string_value2 = value2;
  9534. break;
  9535. }
  9536. default:
  9537. setVal = false;
  9538. }
  9539. return setVal;
  9540. }
  9541. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9542. if (!lua_interface)
  9543. return 0;
  9544. LuaSpell* spell = lua_interface->GetSpell(state);
  9545. int8 idx = lua_interface->GetInt32Value(state, 2);
  9546. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9547. if (!spell) {
  9548. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9549. return 0;
  9550. }
  9551. if (!spell->spell || !spell->spell->GetSpellData()) {
  9552. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9553. return 0;
  9554. }
  9555. if (spell->spell->lua_data.size() <= idx)
  9556. {
  9557. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9558. return 0;
  9559. }
  9560. bool setVal = true;
  9561. LUAData* data = spell->spell->lua_data[idx];
  9562. switch (data->type)
  9563. {
  9564. case 0:
  9565. {
  9566. if(!secondfield)
  9567. lua_interface->SetSInt32Value(state, data->int_value);
  9568. else
  9569. lua_interface->SetSInt32Value(state, data->int_value2);
  9570. break;
  9571. }
  9572. case 1:
  9573. {
  9574. if (!secondfield)
  9575. lua_interface->SetFloatValue(state, data->float_value);
  9576. else
  9577. lua_interface->SetFloatValue(state, data->float_value2);
  9578. break;
  9579. }
  9580. case 2:
  9581. {
  9582. lua_interface->SetBooleanValue(state, data->bool_value);
  9583. break;
  9584. }
  9585. case 3:
  9586. {
  9587. if (!secondfield)
  9588. lua_interface->SetStringValue(state, data->string_value.c_str());
  9589. else
  9590. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9591. break;
  9592. }
  9593. default:
  9594. setVal = false;
  9595. }
  9596. return setVal;
  9597. }
  9598. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9599. if (!lua_interface)
  9600. return 0;
  9601. LuaSpell* spell = lua_interface->GetSpell(state);
  9602. int8 idx = lua_interface->GetInt32Value(state, 2);
  9603. string field = lua_interface->GetStringValue(state, 3);
  9604. boost::to_lower(field);
  9605. if (!spell) {
  9606. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9607. return 0;
  9608. }
  9609. if (!spell->spell || !spell->spell->GetSpellData()) {
  9610. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9611. return 0;
  9612. }
  9613. if (spell->spell->effects.size() <= idx)
  9614. {
  9615. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9616. return 0;
  9617. }
  9618. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9619. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9620. if (field == "description")
  9621. effect->description = string(lua_interface->GetStringValue(state, 4));
  9622. else if (field == "bullet")
  9623. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9624. else if (field == "percentage")
  9625. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9626. else // no match
  9627. return 0;
  9628. return 1;
  9629. }
  9630. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9631. if (!lua_interface)
  9632. return 0;
  9633. LuaSpell* spell = lua_interface->GetSpell(state);
  9634. int8 idx = lua_interface->GetInt32Value(state, 2);
  9635. string field = lua_interface->GetStringValue(state, 3);
  9636. boost::to_lower(field);
  9637. if (!spell) {
  9638. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9639. return 0;
  9640. }
  9641. if (!spell->spell || !spell->spell->GetSpellData()) {
  9642. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9643. return 0;
  9644. }
  9645. if (spell->spell->effects.size() <= idx)
  9646. {
  9647. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9648. return 0;
  9649. }
  9650. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9651. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9652. if (field == "description")
  9653. lua_interface->SetStringValue(state, effect->description.c_str());
  9654. else if (field == "bullet")
  9655. lua_interface->SetInt32Value(state, effect->subbullet);
  9656. else if (field == "percentage")
  9657. lua_interface->SetInt32Value(state, effect->percentage);
  9658. else // no match
  9659. return 0;
  9660. return 1;
  9661. }
  9662. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9663. if (!lua_interface)
  9664. return 0;
  9665. LuaSpell* spell = lua_interface->GetSpell(state);
  9666. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9667. Spawn* target = lua_interface->GetSpawn(state, 3);
  9668. if (!target) {
  9669. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9670. return 0;
  9671. }
  9672. if (!target->IsEntity()) {
  9673. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9674. return 0;
  9675. }
  9676. if (!spell) {
  9677. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9678. return 0;
  9679. }
  9680. if (caster && !caster->IsEntity()) {
  9681. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9682. return 0;
  9683. }
  9684. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9685. return 0;
  9686. }
  9687. int EQ2Emu_lua_InWater(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. Spawn* spawn = lua_interface->GetSpawn(state);
  9691. if (spawn) {
  9692. lua_interface->SetBooleanValue(state, spawn->InWater());
  9693. return 1;
  9694. }
  9695. return 0;
  9696. }
  9697. int EQ2Emu_lua_InLava(lua_State* state) {
  9698. if (!lua_interface)
  9699. return 0;
  9700. Spawn* spawn = lua_interface->GetSpawn(state);
  9701. if (spawn) {
  9702. lua_interface->SetBooleanValue(state, spawn->InLava());
  9703. return 1;
  9704. }
  9705. return 0;
  9706. }
  9707. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9708. if (!lua_interface)
  9709. return 0;
  9710. Spawn* attacker = lua_interface->GetSpawn(state);
  9711. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9712. int8 type = lua_interface->GetInt8Value(state, 3);
  9713. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9714. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9715. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9716. string spell_name = lua_interface->GetStringValue(state, 7);
  9717. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9718. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9719. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9720. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9721. if (!attacker) {
  9722. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9723. return 0;
  9724. }
  9725. if (!attacker->IsEntity()) {
  9726. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9727. return 0;
  9728. }
  9729. if (!victim) {
  9730. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. if (!victim->IsEntity()) {
  9734. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9735. return 0;
  9736. }
  9737. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9738. return 0;
  9739. }
  9740. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9741. if (!lua_interface)
  9742. return 0;
  9743. Spawn* spawn = lua_interface->GetSpawn(state);
  9744. if (spawn) {
  9745. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9746. return 1;
  9747. }
  9748. return 0;
  9749. }
  9750. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9751. if (!lua_interface)
  9752. return 0;
  9753. Spawn* spawn = lua_interface->GetSpawn(state);
  9754. bool invul = lua_interface->GetBooleanValue(state, 2);
  9755. if (spawn) {
  9756. spawn->SetInvulnerable(invul);
  9757. }
  9758. return 0;
  9759. }
  9760. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9761. if (!lua_interface)
  9762. return 0;
  9763. string category = lua_interface->GetStringValue(state);
  9764. string name = lua_interface->GetStringValue(state, 2);
  9765. Rule *ret = 0;
  9766. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9767. lua_interface->SetInt32Value(state, ret->GetInt32());
  9768. return 1;
  9769. }
  9770. lua_interface->LogError("%s: LUA GetRuleFlag Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9771. return 0;
  9772. }
  9773. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9774. if (!lua_interface)
  9775. return 0;
  9776. Spawn* spawn = lua_interface->GetSpawn(state);
  9777. string type = lua_interface->GetStringValue(state, 2);
  9778. if (spawn) {
  9779. int res = 1;
  9780. boost::to_lower(type);
  9781. if(type == "assigned_aa")
  9782. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9783. else if ( type == "unassigned_aa")
  9784. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9785. else if ( type == "assigned_tradeskill_aa")
  9786. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9787. else if ( type == "unassigned_tradeskill_aa")
  9788. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9789. else if ( type == "assigned_prestige_aa")
  9790. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9791. else if ( type == "unassigned_prestige_aa")
  9792. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9793. else if ( type == "assigned_tradeskill_prestige_aa")
  9794. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9795. else if ( type == "unassigned_tradeskill_prestige_aa")
  9796. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9797. else
  9798. res = 0;
  9799. return res;
  9800. }
  9801. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9802. return 0;
  9803. }
  9804. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9805. if (!lua_interface)
  9806. return 0;
  9807. Spawn* spawn = lua_interface->GetSpawn(state);
  9808. string type = lua_interface->GetStringValue(state, 2);
  9809. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9810. if (spawn) {
  9811. boost::to_lower(type);
  9812. if(type == "assigned_aa")
  9813. spawn->SetAssignedAA((sint16)value);
  9814. else if ( type == "unassigned_aa")
  9815. spawn->SetUnassignedAA((sint16)value);
  9816. else if ( type == "assigned_tradeskill_aa")
  9817. spawn->SetTradeskillAA((sint16)value);
  9818. else if ( type == "unassigned_tradeskill_aa")
  9819. spawn->SetUnassignedTradeskillAA((sint16)value);
  9820. else if ( type == "assigned_prestige_aa")
  9821. spawn->SetPrestigeAA((sint16)value);
  9822. else if ( type == "unassigned_prestige_aa")
  9823. spawn->SetUnassignedPrestigeAA((sint16)value);
  9824. else if ( type == "assigned_tradeskill_prestige_aa")
  9825. spawn->SetTradeskillPrestigeAA((sint16)value);
  9826. else if ( type == "unassigned_tradeskill_prestige_aa")
  9827. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  9828. if(spawn->IsPlayer())
  9829. ((Player*)spawn)->SetCharSheetChanged(true);
  9830. }
  9831. return 0;
  9832. }