LuaFunctions.cpp 306 KB

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