LuaFunctions.cpp 281 KB

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