LuaFunctions.cpp 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374
  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. #include <sstream>
  36. extern MasterFactionList master_faction_list;
  37. extern WorldDatabase database;
  38. extern LuaInterface* lua_interface;
  39. extern ConfigReader configReader;
  40. extern MasterQuestList master_quest_list;
  41. extern MasterItemList master_item_list;
  42. extern MasterSpellList master_spell_list;
  43. extern World world;
  44. extern Commands commands;
  45. extern ZoneList zone_list;
  46. extern Races races;
  47. extern Classes classes;
  48. extern Variables variables;
  49. extern MasterSkillList master_skill_list;
  50. extern MasterHeroicOPList master_ho_list;
  51. extern MasterRaceTypeList race_types_list;
  52. extern MasterLanguagesList master_languages_list;
  53. vector<string> ParseString(string strVal, char delim) {
  54. stringstream ss(strVal);
  55. vector<string> ret;
  56. while (ss.good())
  57. {
  58. string substr;
  59. getline(ss, substr, delim);
  60. ret.push_back(substr);
  61. }
  62. return ret;
  63. }
  64. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  65. stringstream ss(strVal);
  66. vector<unsigned int> ret;
  67. while (ss.good())
  68. {
  69. string substr;
  70. getline(ss, substr, delim);
  71. stringstream valss(substr);
  72. unsigned int val = 0;
  73. valss >> val;
  74. ret.push_back(val);
  75. }
  76. return ret;
  77. }
  78. map<string, signed int> ParseStringMap(string strVal, char delim) {
  79. vector<string> pairs = ParseString(strVal, delim);
  80. vector<string>::iterator itr;
  81. map<string, signed int> ret;
  82. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  83. vector<string> keyvaluepair = ParseString(*itr, ':');
  84. if (keyvaluepair.size() == 2) {
  85. stringstream valss(keyvaluepair[1]);
  86. int32 val = 0;
  87. valss >> val;
  88. ret[keyvaluepair[0]] = val;
  89. }
  90. }
  91. return ret;
  92. }
  93. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  94. vector<string> pairs = ParseString(strVal, delim);
  95. vector<string>::iterator itr;
  96. map<unsigned int, unsigned short> ret;
  97. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  98. vector<string> keyvaluepair = ParseString(*itr, ':');
  99. int32 key = 0;
  100. if (keyvaluepair.size() > 0) {
  101. stringstream keyss(keyvaluepair[0]);
  102. keyss >> key;
  103. }
  104. if (keyvaluepair.size() == 1) {
  105. ret[key] = 1;
  106. }
  107. else if (keyvaluepair.size() == 2) {
  108. stringstream valss(keyvaluepair[1]);
  109. unsigned short val = 0;
  110. valss >> val;
  111. ret[key] = val;
  112. }
  113. }
  114. return ret;
  115. }
  116. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  117. vector<string> pairs = ParseString(strVal, delim);
  118. vector<string>::iterator itr;
  119. map<unsigned int, signed int> ret;
  120. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  121. vector<string> keyvaluepair = ParseString(*itr, ':');
  122. int32 key = 0;
  123. if (keyvaluepair.size() > 0) {
  124. stringstream keyss(keyvaluepair[0]);
  125. keyss >> key;
  126. }
  127. if (keyvaluepair.size() == 1) {
  128. ret[key] = 1;
  129. }
  130. else if (keyvaluepair.size() == 2) {
  131. stringstream valss(keyvaluepair[1]);
  132. signed int val = 0;
  133. valss >> val;
  134. ret[key] = val;
  135. }
  136. }
  137. return ret;
  138. }
  139. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  140. if (!lua_interface)
  141. return 0;
  142. Spawn* spawn = lua_interface->GetSpawn(state);
  143. string mp3_string = lua_interface->GetStringValue(state, 2);
  144. string text_string = lua_interface->GetStringValue(state, 3);
  145. string emote_string = lua_interface->GetStringValue(state, 4);
  146. int32 key1 = lua_interface->GetInt32Value(state, 5);
  147. int32 key2 = lua_interface->GetInt32Value(state, 6);
  148. Spawn* player = lua_interface->GetSpawn(state, 7);
  149. int8 language = lua_interface->GetInt8Value(state, 8);
  150. if (spawn) {
  151. const char* mp3 = 0;
  152. const char* text = 0;
  153. const char* emote = 0;
  154. if (mp3_string.length() > 0)
  155. mp3 = mp3_string.c_str();
  156. if (text_string.length() > 0)
  157. text = text_string.c_str();
  158. if (emote_string.length() > 0)
  159. emote = emote_string.c_str();
  160. Client* client = 0;
  161. if (player && player->IsPlayer())
  162. client = spawn->GetZone()->GetClientBySpawn(player);
  163. if (client) {
  164. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  165. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  166. }
  167. else
  168. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  169. }
  170. return 0;
  171. }
  172. int EQ2Emu_lua_PlaySound(lua_State* state) {
  173. if (!lua_interface)
  174. return 0;
  175. Spawn* spawn = lua_interface->GetSpawn(state);
  176. string sound_string = lua_interface->GetStringValue(state, 2);
  177. float x = lua_interface->GetFloatValue(state, 3);
  178. float y = lua_interface->GetFloatValue(state, 4);
  179. float z = lua_interface->GetFloatValue(state, 5);
  180. Spawn* player = lua_interface->GetSpawn(state, 6);
  181. if (spawn && sound_string.length() > 0) {
  182. Client* client = 0;
  183. if (player && player->IsPlayer())
  184. client = spawn->GetZone()->GetClientBySpawn(player);
  185. if (client)
  186. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  187. else
  188. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  189. }
  190. return 0;
  191. }
  192. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  193. if (!lua_interface)
  194. return 0;
  195. Spawn* spawn = lua_interface->GetSpawn(state);
  196. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  197. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  198. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  199. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  200. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  201. if (!spawn) {
  202. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  203. return 0;
  204. }
  205. if (quest_id > 0) {
  206. //Add this quest to the list of required quests for this spawn
  207. spawn->SetQuestsRequired(quest_id, quest_step);
  208. //If private spawn value set
  209. if (private_spawn) {
  210. //Set the spawn to be private when not granted access through this quest
  211. spawn->AddAllowAccessSpawn(spawn);
  212. spawn->SetPrivateQuestSpawn(true);
  213. }
  214. //This value allows access after a quest step, or the whole quest has been completed
  215. if (continued_access)
  216. spawn->SetQuestsRequiredContinuedAccess(true);
  217. //This value will override vis_flags in the vis packet
  218. if (flag_override > 0)
  219. spawn->SetQuestsRequiredOverride(flag_override);
  220. }
  221. return 0;
  222. }
  223. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  224. if (!lua_interface)
  225. return 0;
  226. Spawn* spawn = lua_interface->GetSpawn(state);
  227. float max_distance = lua_interface->GetFloatValue(state, 2);
  228. string variable = lua_interface->GetStringValue(state, 3);
  229. string value = lua_interface->GetStringValue(state, 4);
  230. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  231. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  232. return 0;
  233. }
  234. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  235. if (!lua_interface)
  236. return 0;
  237. Client* client = 0;
  238. Spawn* player = lua_interface->GetSpawn(state);
  239. if (!player) {
  240. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  241. return 0;
  242. }
  243. if (!player->IsPlayer()) {
  244. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  245. return 0;
  246. }
  247. if (player->GetZone())
  248. client = player->GetZone()->GetClientBySpawn(player);
  249. if (!client) {
  250. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  251. return 0;
  252. }
  253. float intensity = lua_interface->GetFloatValue(state, 2);
  254. int8 direction = lua_interface->GetInt8Value(state, 3);
  255. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  256. if (packet) {
  257. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  258. v1 = *(float *)(a1 + 4);
  259. if ( v1 > 0.0 )
  260. v2 = fminf(v1, 1.0);
  261. else
  262. v2 = 0.1;
  263. */
  264. packet->setDataByName("intensity", intensity);
  265. if ( client->GetVersion() > 546 )
  266. packet->setDataByName("direction", direction);
  267. client->QueuePacket(packet->serialize());
  268. safe_delete(packet);
  269. }
  270. return 0;
  271. }
  272. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  273. if (!lua_interface)
  274. return 0;
  275. Spawn* dead = lua_interface->GetSpawn(state);
  276. Spawn* killer = lua_interface->GetSpawn(state, 2);
  277. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  278. if (dead && dead->Alive() && dead->GetZone())
  279. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* spawn = lua_interface->GetSpawn(state);
  286. float max_distance = lua_interface->GetFloatValue(state, 2);
  287. bool include_players = lua_interface->GetInt8Value(state, 3);
  288. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  289. if (max_distance > 0 && spawn && spawn->GetZone())
  290. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_Despawn(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. int32 delay = lua_interface->GetInt32Value(state, 2);
  298. if (spawn && spawn->GetZone())
  299. spawn->GetZone()->Despawn(spawn, delay);
  300. return 0;
  301. }
  302. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  303. if (!lua_interface)
  304. return 0;
  305. Spawn* spawn = lua_interface->GetSpawn(state);
  306. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  307. if (spawn) {
  308. spawn->info_changed = true;
  309. spawn->SetShowHandIcon(displayHandIcon);
  310. }
  311. return 0;
  312. }
  313. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  314. if (!lua_interface)
  315. return 0;
  316. Spawn* spawn = lua_interface->GetSpawn(state);
  317. int32 new_state = lua_interface->GetInt32Value(state, 2);
  318. if (spawn) {
  319. spawn->GetZone()->SendStateCommand(spawn, new_state);
  320. }
  321. return 0;
  322. }
  323. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  324. if (!lua_interface)
  325. return 0;
  326. Spawn* spawn = lua_interface->GetSpawn(state);
  327. string variable = lua_interface->GetStringValue(state, 2);
  328. string value = lua_interface->GetStringValue(state, 3);
  329. int32 type = commands.GetSpawnSetType(variable);
  330. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  331. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  332. return 0;
  333. }
  334. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  335. if (!lua_interface)
  336. return 0;
  337. Spawn* spawn = lua_interface->GetSpawn(state);
  338. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  339. if (spawn && spawn_id > 0) {
  340. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  341. if (closest_spawn) {
  342. lua_interface->SetSpawnValue(state, closest_spawn);
  343. return 1;
  344. }
  345. }
  346. return 0;
  347. }
  348. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  349. if (!lua_interface)
  350. return 0;
  351. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  352. int32 position = lua_interface->GetInt32Value(state, 2);
  353. if (spawnList) {
  354. if (spawnList->size() > position) {
  355. lua_interface->SetSpawnValue(state, spawnList->at(position));
  356. return 1;
  357. }
  358. else {
  359. return 0;
  360. }
  361. return spawnList->size();
  362. }
  363. return 0;
  364. }
  365. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  366. if (!lua_interface)
  367. return 0;
  368. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  369. if (spawnList) {
  370. return spawnList->size();
  371. }
  372. return 0;
  373. }
  374. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  375. if (!lua_interface)
  376. return 0;
  377. vector<Spawn*>* spawnList = new vector<Spawn*>();
  378. lua_interface->SetSpawnListValue(state, spawnList);
  379. return 1;
  380. }
  381. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  382. if (!lua_interface)
  383. return 0;
  384. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  385. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  386. if (spawnList) {
  387. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  388. if (it == spawnList->end())
  389. spawnList->push_back(spawn);
  390. }
  391. return 0;
  392. }
  393. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  394. if (!lua_interface)
  395. return 0;
  396. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  397. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  398. if (spawnList) {
  399. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  400. if(it != spawnList->end())
  401. spawnList->erase(it);
  402. }
  403. return 0;
  404. }
  405. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  406. if (!lua_interface)
  407. return 0;
  408. Spawn* spawn = lua_interface->GetSpawn(state);
  409. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  410. if (spawn) {
  411. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  412. if (spawns.size() > 0) {
  413. vector<Spawn*>* spawnList = new vector<Spawn*>();
  414. vector<Spawn*>::iterator itr;
  415. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  416. spawnList->push_back(*itr);
  417. }
  418. lua_interface->SetSpawnListValue(state, spawnList);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. string variable_name = lua_interface->GetStringValue(state);
  428. Variable* var = variables.FindVariable(variable_name);
  429. if (var) {
  430. lua_interface->SetStringValue(state, var->GetValue());
  431. return 1;
  432. }
  433. return 0;
  434. }
  435. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  436. if (!lua_interface)
  437. return 0;
  438. int32 total_coins = lua_interface->GetInt32Value(state);
  439. if (total_coins == 0) {
  440. lua_interface->SetStringValue(state, "0 copper");
  441. return 1;
  442. }
  443. char tmp[64] = { 0 };
  444. string message = "";
  445. int32 val = 0;
  446. if (total_coins >= 1000000) {
  447. val = total_coins / 1000000;
  448. total_coins -= 1000000 * val;
  449. sprintf(tmp, " %u Platinum", val);
  450. message.append(tmp);
  451. memset(tmp, 0, 64);
  452. }
  453. if (total_coins >= 10000) {
  454. val = total_coins / 10000;
  455. total_coins -= 10000 * val;
  456. sprintf(tmp, " %u Gold", val);
  457. message.append(tmp);
  458. memset(tmp, 0, 64);
  459. }
  460. if (total_coins >= 100) {
  461. val = total_coins / 100;
  462. total_coins -= 100 * val;
  463. sprintf(tmp, " %u Silver", val);
  464. message.append(tmp);
  465. memset(tmp, 0, 64);
  466. }
  467. if (total_coins > 0) {
  468. sprintf(tmp, " %u Copper", (int32)total_coins);
  469. message.append(tmp);
  470. }
  471. lua_interface->SetStringValue(state, message.c_str());
  472. return 1;
  473. }
  474. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  475. ZoneServer* zone = lua_interface->GetZone(state);
  476. int32 group_id = lua_interface->GetInt32Value(state, 2);
  477. if (zone) {
  478. Spawn* spawn = zone->GetSpawnGroup(group_id);
  479. if (spawn) {
  480. lua_interface->SetSpawnValue(state, spawn);
  481. return 1;
  482. }
  483. }
  484. return 0;
  485. }
  486. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  487. ZoneServer* zone = lua_interface->GetZone(state);
  488. int32 location_id = lua_interface->GetInt32Value(state, 2);
  489. if (zone) {
  490. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  491. if (spawn) {
  492. lua_interface->SetSpawnValue(state, spawn);
  493. return 1;
  494. }
  495. }
  496. return 0;
  497. }
  498. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  499. Spawn* spawn = lua_interface->GetSpawn(state);
  500. if (spawn) {
  501. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  502. return 1;
  503. }
  504. return 0;
  505. }
  506. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  507. Spawn* spawn = lua_interface->GetSpawn(state);
  508. if (spawn) {
  509. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  510. return 1;
  511. }
  512. return 0;
  513. }
  514. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  515. Spawn* spawn = lua_interface->GetSpawn(state);
  516. if (spawn) {
  517. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  518. return 1;
  519. }
  520. return 0;
  521. }
  522. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  523. Spawn* spawn = lua_interface->GetSpawn(state);
  524. if (spawn) {
  525. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  526. return 1;
  527. }
  528. return 0;
  529. }
  530. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  531. Player* player = (Player*)lua_interface->GetSpawn(state);
  532. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  533. if (player && player->IsPlayer() && faction_id > 0) {
  534. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  535. return 1;
  536. }
  537. return 0;
  538. }
  539. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  540. if (!lua_interface)
  541. return 0;
  542. Spawn* spawn = lua_interface->GetSpawn(state);
  543. int32 value = lua_interface->GetInt32Value(state, 2);
  544. if (spawn) {
  545. spawn->SetFactionID(value);
  546. }
  547. return 0;
  548. }
  549. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  550. Spawn* spawn = lua_interface->GetSpawn(state);
  551. if (spawn) {
  552. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  553. return 1;
  554. }
  555. return 0;
  556. }
  557. int EQ2Emu_lua_GetGender(lua_State* state) {
  558. Spawn* spawn = lua_interface->GetSpawn(state);
  559. if (spawn) {
  560. lua_interface->SetInt32Value(state, spawn->GetGender());
  561. return 1;
  562. }
  563. return 0;
  564. }
  565. int EQ2Emu_lua_GetTarget(lua_State* state) {
  566. Spawn* spawn = lua_interface->GetSpawn(state);
  567. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  568. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  569. return 1;
  570. }
  571. return 0;
  572. }
  573. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  574. if (!lua_interface)
  575. return 0;
  576. Spawn* spawn = lua_interface->GetSpawn(state);
  577. string mp3_string = lua_interface->GetStringValue(state, 2);
  578. int32 key1 = lua_interface->GetInt32Value(state, 3);
  579. int32 key2 = lua_interface->GetInt32Value(state, 4);
  580. Spawn* player = lua_interface->GetSpawn(state, 5);
  581. if (spawn && mp3_string.length() > 0) {
  582. Client* client = 0;
  583. if (player && player->IsPlayer())
  584. client = spawn->GetZone()->GetClientBySpawn(player);
  585. if (client) {
  586. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  587. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  588. }
  589. else
  590. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  595. if (!lua_interface)
  596. return 0;
  597. Spawn* spawn = lua_interface->GetSpawn(state);
  598. if (spawn) {
  599. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  600. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  601. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  602. return 3;
  603. }
  604. return 0;
  605. }
  606. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  607. if (!lua_interface)
  608. return 0;
  609. Spawn* spawn = lua_interface->GetSpawn(state);
  610. if (spawn) {
  611. int32 item_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  613. return 1;
  614. }
  615. return 0;
  616. }
  617. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  618. if (!lua_interface)
  619. return 0;
  620. Spawn* spawn = lua_interface->GetSpawn(state);
  621. if (spawn && spawn->IsEntity()) {
  622. int32 item_id = lua_interface->GetInt32Value(state, 2);
  623. int16 charges = lua_interface->GetInt16Value(state, 3);
  624. if (charges == 0)
  625. charges = 1;
  626. ((Entity*)spawn)->AddLootItem(item_id, charges);
  627. }
  628. return 0;
  629. }
  630. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  631. if (!lua_interface)
  632. return 0;
  633. Spawn* spawn = lua_interface->GetSpawn(state);
  634. if (spawn && spawn->IsEntity()) {
  635. int32 item_id = lua_interface->GetInt32Value(state, 2);
  636. spawn->LootItem(item_id);
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. if (spawn) {
  645. int32 val = lua_interface->GetInt32Value(state, 2);
  646. spawn->AddLootCoins(val);
  647. }
  648. return 0;
  649. }
  650. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  651. if (!lua_interface)
  652. return 0;
  653. Spawn* entity = lua_interface->GetSpawn(state);
  654. Spawn* player = lua_interface->GetSpawn(state, 2);
  655. if (entity && player && player->IsPlayer()) {
  656. int32 coins = lua_interface->GetInt32Value(state, 3);
  657. vector<Item*>* items = 0;
  658. int i = 0;
  659. int32 item_id = 0;
  660. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  661. if (items == 0)
  662. items = new vector<Item*>;
  663. if (master_item_list.GetItem(item_id))
  664. items->push_back(master_item_list.GetItem(item_id));
  665. i++;
  666. }
  667. Client* client = 0;
  668. client = player->GetZone()->GetClientBySpawn(player);
  669. if (client)
  670. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  671. if(coins > 0)
  672. entity->AddLootCoins(coins);
  673. safe_delete(items);
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* entity = lua_interface->GetSpawn(state);
  681. Spawn* player = lua_interface->GetSpawn(state, 2);
  682. int32 item_id = lua_interface->GetInt32Value(state, 3);
  683. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  684. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  685. return 1;
  686. }
  687. return 0;
  688. }
  689. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  690. if (!lua_interface)
  691. return 0;
  692. Spawn* entity = lua_interface->GetSpawn(state);
  693. Spawn* player = lua_interface->GetSpawn(state, 2);
  694. if (entity && player && player->IsPlayer()) {
  695. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  701. if (!lua_interface)
  702. return 0;
  703. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  704. safe_delete(conversation);
  705. conversation = new vector<ConversationOption>();
  706. lua_interface->SetConversationValue(state, conversation);
  707. return 1;
  708. }
  709. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  710. if (!lua_interface)
  711. return 0;
  712. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  713. if (conversation) {
  714. ConversationOption conv_option;
  715. conv_option.option = lua_interface->GetStringValue(state, 2);
  716. conv_option.function = lua_interface->GetStringValue(state, 3);
  717. if (conv_option.option.length() > 0)
  718. conversation->push_back(conv_option);
  719. }
  720. return 0;
  721. }
  722. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  723. if (!lua_interface)
  724. return 0;
  725. Spawn* npc = lua_interface->GetSpawn(state);
  726. Spawn* player = lua_interface->GetSpawn(state, 2);
  727. if (npc && player && player->IsPlayer() && player->GetZone()) {
  728. Client* client = player->GetZone()->GetClientBySpawn(player);
  729. if (client) {
  730. int32 conversation_id = client->GetConversationID(npc, 0);
  731. client->CloseDialog(conversation_id);
  732. }
  733. }
  734. return 0;
  735. }
  736. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  737. if (!lua_interface)
  738. return 0;
  739. Item* item = lua_interface->GetItem(state);
  740. Spawn* player = lua_interface->GetSpawn(state, 2);
  741. if (item && player && player->IsPlayer() && player->GetZone()) {
  742. Client* client = player->GetZone()->GetClientBySpawn(player);
  743. if (client) {
  744. int32 conversation_id = client->GetConversationID(0, item);
  745. client->CloseDialog(conversation_id);
  746. }
  747. }
  748. return 0;
  749. }
  750. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  751. if (!lua_interface)
  752. return 0;
  753. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  754. Spawn* spawn = 0;
  755. Item* item = 0;
  756. int8 type = lua_interface->GetInt8Value(state, 2);
  757. if (type == 1 || type == 3)
  758. spawn = lua_interface->GetSpawn(state, 3);
  759. else if (type == 2 || type == 4)
  760. item = lua_interface->GetItem(state, 3);
  761. Spawn* player = lua_interface->GetSpawn(state, 4);
  762. string text = lua_interface->GetStringValue(state, 5);
  763. string mp3 = lua_interface->GetStringValue(state, 6);
  764. int32 key1 = lua_interface->GetInt32Value(state, 7);
  765. int32 key2 = lua_interface->GetInt32Value(state, 8);
  766. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  767. Client* client = player->GetZone()->GetClientBySpawn(player);
  768. if (client) {
  769. if (spawn) {
  770. // Need to do this so the function works the same as it did before
  771. if (type == 1)
  772. type++;
  773. if (mp3.length() > 0)
  774. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  775. else
  776. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  777. }
  778. else {
  779. if (mp3.length() > 0)
  780. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  781. else
  782. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  783. }
  784. }
  785. }
  786. safe_delete(conversation);
  787. lua_interface->SetConversationValue(state, NULL);
  788. return 0;
  789. }
  790. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  791. if(!lua_interface)
  792. return 0;
  793. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  794. Item* item = lua_interface->GetItem(state, 2);
  795. Spawn* player = lua_interface->GetSpawn(state, 3);
  796. string text = lua_interface->GetStringValue(state, 4);
  797. string mp3 = lua_interface->GetStringValue(state, 5);
  798. int32 key1 = lua_interface->GetInt32Value(state, 6);
  799. int32 key2 = lua_interface->GetInt32Value(state, 7);
  800. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  801. Client* client = player->GetZone()->GetClientBySpawn(player);
  802. if(client){
  803. if(mp3.length() > 0)
  804. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  805. else
  806. client->DisplayConversation(item, conversation, (char*)text.c_str());
  807. }
  808. safe_delete(conversation);
  809. }
  810. return 0;
  811. }*/
  812. int EQ2Emu_lua_StartConversation(lua_State* state) {
  813. if (!lua_interface)
  814. return 0;
  815. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  816. Spawn* npc = lua_interface->GetSpawn(state, 2);
  817. Spawn* player = lua_interface->GetSpawn(state, 3);
  818. string text = lua_interface->GetStringValue(state, 4);
  819. string mp3 = lua_interface->GetStringValue(state, 5);
  820. int32 key1 = lua_interface->GetInt32Value(state, 6);
  821. int32 key2 = lua_interface->GetInt32Value(state, 7);
  822. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  823. Client* client = npc->GetZone()->GetClientBySpawn(player);
  824. if (mp3.length() > 0)
  825. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  826. else
  827. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  828. safe_delete(conversation);
  829. lua_interface->SetConversationValue(state, NULL);
  830. }
  831. else
  832. 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);
  833. return 0;
  834. }
  835. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  836. if (!lua_interface)
  837. return 0;
  838. Spawn* spawn = lua_interface->GetSpawn(state);
  839. float distance = lua_interface->GetFloatValue(state, 2);
  840. string in_range_function = lua_interface->GetStringValue(state, 3);
  841. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  842. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  843. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  844. return 0;
  845. }
  846. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  847. ZoneServer* zone = lua_interface->GetZone(state);
  848. float x = lua_interface->GetFloatValue(state, 2);
  849. float y = lua_interface->GetFloatValue(state, 3);
  850. float z = lua_interface->GetFloatValue(state, 4);
  851. float max_variation = lua_interface->GetFloatValue(state, 5);
  852. string in_range_function = lua_interface->GetStringValue(state, 6);
  853. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  854. if (zone && in_range_function.length() > 0)
  855. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  856. return 0;
  857. }
  858. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  859. if (!lua_interface)
  860. return 0;
  861. Spawn* spawn = lua_interface->GetSpawn(state);
  862. if (spawn && spawn->IsEntity()) {
  863. int32 val = lua_interface->GetInt32Value(state, 2);
  864. ((Entity*)spawn)->SetLootCoins(val);
  865. }
  866. return 0;
  867. }
  868. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  869. if (!lua_interface)
  870. return 0;
  871. Spawn* spawn = lua_interface->GetSpawn(state);
  872. if (spawn && spawn->IsEntity()) {
  873. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  874. return 1;
  875. }
  876. return 0;
  877. }
  878. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  879. if (!lua_interface)
  880. return 0;
  881. Spawn* spawn = lua_interface->GetSpawn(state);
  882. float x = lua_interface->GetFloatValue(state, 2);
  883. float y = lua_interface->GetFloatValue(state, 3);
  884. float z = lua_interface->GetFloatValue(state, 4);
  885. float speed = lua_interface->GetFloatValue(state, 5);
  886. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  887. string function = lua_interface->GetStringValue(state, 7);
  888. if (spawn) {
  889. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  890. spawn->GetZone()->AddMovementNPC(spawn);
  891. }
  892. lua_interface->ResetFunctionStack(state);
  893. return 0;
  894. }
  895. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  896. if (!lua_interface)
  897. return 0;
  898. Spawn* spawn = lua_interface->GetSpawn(state);
  899. if (spawn) {
  900. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  901. return 1;
  902. }
  903. return 0;
  904. }
  905. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  906. if (!lua_interface)
  907. return 0;
  908. Spawn* spawn = lua_interface->GetSpawn(state);
  909. Spawn* target = lua_interface->GetSpawn(state, 2);
  910. if (spawn && target) {
  911. if (spawn->IsEntity())
  912. // ((Entity*)spawn)->FaceTarget(target);
  913. static_cast<Entity*>(spawn)->FaceTarget(target);
  914. }
  915. lua_interface->ResetFunctionStack(state);
  916. return 0;
  917. }
  918. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  919. if (!lua_interface)
  920. return 0;
  921. Spawn* spawn = lua_interface->GetSpawn(state);
  922. float x = lua_interface->GetFloatValue(state, 2);
  923. float y = lua_interface->GetFloatValue(state, 3);
  924. float z = lua_interface->GetFloatValue(state, 4);
  925. float speed = lua_interface->GetFloatValue(state, 5);
  926. string lua_function = lua_interface->GetStringValue(state, 6);
  927. bool more_points = lua_interface->GetBooleanValue(state, 7);
  928. if (spawn) {
  929. if (speed == 0)
  930. speed = spawn->GetSpeed();
  931. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  932. }
  933. lua_interface->ResetFunctionStack(state);
  934. return 0;
  935. }
  936. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Spawn* spawn = lua_interface->GetSpawn(state);
  940. if (spawn) {
  941. spawn->ClearRunningLocations();
  942. }
  943. return 0;
  944. }
  945. int EQ2Emu_lua_Say(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. string message = lua_interface->GetStringValue(state, 2);
  950. Spawn* player = lua_interface->GetSpawn(state, 3);
  951. int32 language = lua_interface->GetInt32Value(state, 4);
  952. if (spawn && message.length() > 0) {
  953. Client* client = 0;
  954. if (player && player->IsPlayer())
  955. client = spawn->GetZone()->GetClientBySpawn(player);
  956. if (client)
  957. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  958. else
  959. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  960. }
  961. lua_interface->ResetFunctionStack(state);
  962. return 0;
  963. }
  964. int EQ2Emu_lua_Shout(lua_State* state) {
  965. if (!lua_interface)
  966. return 0;
  967. Spawn* spawn = lua_interface->GetSpawn(state);
  968. string message = lua_interface->GetStringValue(state, 2);
  969. Spawn* player = lua_interface->GetSpawn(state, 3);
  970. if (spawn && message.length() > 0) {
  971. Client* client = 0;
  972. if (player && player->IsPlayer())
  973. client = spawn->GetZone()->GetClientBySpawn(player);
  974. if (client)
  975. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  976. else
  977. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  978. }
  979. lua_interface->ResetFunctionStack(state);
  980. return 0;
  981. }
  982. int EQ2Emu_lua_SayOOC(lua_State* state) {
  983. if (!lua_interface)
  984. return 0;
  985. Spawn* spawn = lua_interface->GetSpawn(state);
  986. string message = lua_interface->GetStringValue(state, 2);
  987. Spawn* player = lua_interface->GetSpawn(state, 3);
  988. if (spawn && message.length() > 0) {
  989. Client* client = 0;
  990. if (player && player->IsPlayer())
  991. client = spawn->GetZone()->GetClientBySpawn(player);
  992. if (client)
  993. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  994. else
  995. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  996. }
  997. lua_interface->ResetFunctionStack(state);
  998. return 0;
  999. }
  1000. int EQ2Emu_lua_Emote(lua_State* state) {
  1001. if (!lua_interface)
  1002. return 0;
  1003. Spawn* spawn = lua_interface->GetSpawn(state);
  1004. string message = lua_interface->GetStringValue(state, 2);
  1005. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1006. Spawn* player = lua_interface->GetSpawn(state, 4);
  1007. char* to = 0;
  1008. if (spawn2)
  1009. to = spawn2->GetName();
  1010. if (spawn && message.length() > 0) {
  1011. Client* client = 0;
  1012. if (player && player->IsPlayer())
  1013. client = spawn->GetZone()->GetClientBySpawn(player);
  1014. if (client)
  1015. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1016. else
  1017. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1018. }
  1019. lua_interface->ResetFunctionStack(state);
  1020. return 0;
  1021. }
  1022. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1023. if (!lua_interface)
  1024. return 0;
  1025. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1026. if (!luaspell)
  1027. return 0;
  1028. Spawn* caster = luaspell->caster;
  1029. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1030. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1031. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1032. Spawn* target = lua_interface->GetSpawn(state, 4);
  1033. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1034. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1035. lua_interface->ResetFunctionStack(state);
  1036. if (caster && caster->IsEntity()) {
  1037. bool success = false;
  1038. luaspell->resisted = false;
  1039. if (target) {
  1040. float distance = caster->GetDistance(target, true);
  1041. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  1042. success = true;
  1043. }
  1044. if (luaspell->targets.size() > 0) {
  1045. Spawn* target = 0;
  1046. ZoneServer* zone = luaspell->caster->GetZone();
  1047. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1048. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1049. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1050. float distance = caster->GetDistance(target, true);
  1051. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  1052. }
  1053. }
  1054. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1055. success = true;
  1056. }
  1057. if (success) {
  1058. if (caster->GetZone())
  1059. caster->GetZone()->TriggerCharSheetTimer();
  1060. }
  1061. }
  1062. return 0;
  1063. }
  1064. int EQ2Emu_lua_AddItem(lua_State* state) {
  1065. if (!lua_interface)
  1066. return 0;
  1067. Spawn* spawn = lua_interface->GetSpawn(state);
  1068. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1069. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1070. // default of 1 quantity to add
  1071. if (quantity == 0)
  1072. quantity = 1;
  1073. if (spawn && spawn->IsPlayer()) {
  1074. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1075. if (client && item_id > 0) {
  1076. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1077. return 1;
  1078. }
  1079. }
  1080. lua_interface->SetBooleanValue(state, false);
  1081. return 1;
  1082. }
  1083. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1084. if (!lua_interface)
  1085. return 0;
  1086. Spawn* spawn = lua_interface->GetSpawn(state);
  1087. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1088. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1089. string location = lua_interface->GetStringValue(state, 4);
  1090. if (spawn && spawn->IsPlayer()) {
  1091. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1092. if (client && item_id > 0) {
  1093. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1094. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1095. else
  1096. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1097. if (send_messages) {
  1098. Item* item = master_item_list.GetItem(item_id);
  1099. if (item) {
  1100. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1101. string popup_text = "You receive " + item->name;
  1102. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1103. }
  1104. }
  1105. return 1;
  1106. }
  1107. }
  1108. lua_interface->SetBooleanValue(state, false);
  1109. return 1;
  1110. }
  1111. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1112. Spawn* spawn = lua_interface->GetSpawn(state);
  1113. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1114. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1115. // default of 1 to remove
  1116. if (quantity == 0)
  1117. quantity = 1;
  1118. Client* client;
  1119. Item* item;
  1120. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1121. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1122. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1123. if (client->RemoveItem(item, quantity)) {
  1124. lua_interface->SetBooleanValue(state, true);
  1125. return 1;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. lua_interface->SetBooleanValue(state, false);
  1131. return 1;
  1132. }
  1133. int EQ2Emu_lua_HasItem(lua_State* state) {
  1134. Spawn* player = lua_interface->GetSpawn(state);
  1135. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1136. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1137. if (player && player->IsPlayer()) {
  1138. bool hasItem = false;
  1139. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1140. if (!hasItem)
  1141. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1142. lua_interface->SetBooleanValue(state, hasItem);
  1143. return 1;
  1144. }
  1145. lua_interface->SetBooleanValue(state, false);
  1146. return 1;
  1147. }
  1148. int EQ2Emu_lua_Spawn(lua_State* state) {
  1149. if (!lua_interface)
  1150. return 0;
  1151. ZoneServer* zone = lua_interface->GetZone(state);
  1152. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1153. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1154. float x = lua_interface->GetFloatValue(state, 4);
  1155. float y = lua_interface->GetFloatValue(state, 5);
  1156. float z = lua_interface->GetFloatValue(state, 6);
  1157. float heading = lua_interface->GetFloatValue(state, 7);
  1158. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1159. Spawn* spawn = zone->GetSpawn(spawn_id);
  1160. if (!spawn)
  1161. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1162. else {
  1163. spawn->SetX(x);
  1164. spawn->SetZ(z);
  1165. spawn->SetY(y,true,true);
  1166. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1167. spawn->SetHeading(heading);
  1168. if (restricted_npc)
  1169. spawn->AddAllowAccessSpawn(spawn);
  1170. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1171. bool scriptActive = false;
  1172. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1173. scriptActive = true;
  1174. spawn->SetSpawnScript(string(spawn_script));
  1175. }
  1176. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1177. zone->AddSpawn(spawn);
  1178. if (scriptActive) {
  1179. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1180. }
  1181. lua_interface->SetSpawnValue(state, spawn);
  1182. return 1;
  1183. }
  1184. }
  1185. else {
  1186. string output = "Invalid paramaters to LUA Spawn command: \n";
  1187. if (!zone)
  1188. output = output.append("\t").append("Missing zone reference. \n");
  1189. if (spawn_id == 0)
  1190. output = output.append("\t").append("Missing spawn_id.");
  1191. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1192. }
  1193. return 0;
  1194. }
  1195. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1196. if (!lua_interface)
  1197. return 0;
  1198. ZoneServer* zone = lua_interface->GetZone(state);
  1199. if (zone) {
  1200. lua_interface->SetStringValue(state, zone->GetZoneName());
  1201. return 1;
  1202. }
  1203. return 0;
  1204. }
  1205. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1206. if (!lua_interface)
  1207. return 0;
  1208. ZoneServer* zone = lua_interface->GetZone(state);
  1209. if (zone) {
  1210. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1211. return 1;
  1212. }
  1213. return 0;
  1214. }
  1215. int EQ2Emu_lua_GetZone(lua_State* state) {
  1216. if (!lua_interface)
  1217. return 0;
  1218. int32 zone_id = lua_interface->GetInt32Value(state);
  1219. ZoneServer* zone = 0;
  1220. if (zone_id > 0)
  1221. zone = zone_list.Get(zone_id);
  1222. else {
  1223. string zone_name = lua_interface->GetStringValue(state);
  1224. if (zone_name.length() > 0) {
  1225. zone = zone_list.Get(zone_name.c_str());
  1226. }
  1227. else {
  1228. Spawn* spawn = lua_interface->GetSpawn(state);
  1229. if (spawn)
  1230. zone = spawn->GetZone();
  1231. }
  1232. }
  1233. if (zone) {
  1234. lua_interface->SetZoneValue(state, zone);
  1235. return 1;
  1236. }
  1237. return 0;
  1238. }
  1239. int EQ2Emu_lua_AddHate(lua_State* state) {
  1240. Spawn* entity = lua_interface->GetSpawn(state);
  1241. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1242. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1243. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if (entity && entity->IsEntity() && amount != 0) {
  1246. if (luaspell) {
  1247. ZoneServer* zone = luaspell->caster->GetZone();
  1248. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1249. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1250. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1251. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1252. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1253. if (send_packet)
  1254. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1255. }
  1256. }
  1257. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1258. }
  1259. else if (npc && npc->IsNPC() && npc->GetZone())
  1260. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1261. }
  1262. return 0;
  1263. }
  1264. int EQ2Emu_lua_Zone(lua_State* state) {
  1265. if (!lua_interface)
  1266. return 0;
  1267. ZoneServer* zone = lua_interface->GetZone(state);
  1268. Spawn* player = lua_interface->GetSpawn(state, 2);
  1269. Client* client = 0;
  1270. if (player && player->IsPlayer())
  1271. client = player->GetZone()->GetClientBySpawn(player);
  1272. float x = lua_interface->GetFloatValue(state, 3);
  1273. float y = lua_interface->GetFloatValue(state, 4);
  1274. float z = lua_interface->GetFloatValue(state, 5);
  1275. float heading = lua_interface->GetFloatValue(state, 6);
  1276. if (zone && client) {
  1277. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1278. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1279. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1280. {
  1281. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1282. return 0;
  1283. }
  1284. if (x != 0 || y != 0 || z != 0) {
  1285. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1286. player->SetX(x);
  1287. player->SetY(y);
  1288. player->SetZ(z);
  1289. player->SetHeading(heading);
  1290. client->Zone(zone->GetZoneName(), false);
  1291. }
  1292. else
  1293. client->Zone(zone->GetZoneName());
  1294. }
  1295. else
  1296. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1297. return 0;
  1298. }
  1299. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1300. if (!lua_interface)
  1301. return 0;
  1302. Spawn* spawn = lua_interface->GetSpawn(state);
  1303. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1304. if (spawn && spawn2)
  1305. spawn->AddAllowAccessSpawn(spawn2);
  1306. return 0;
  1307. }
  1308. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1309. if (!lua_interface)
  1310. return 0;
  1311. Spawn* target = lua_interface->GetSpawn(state);
  1312. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1313. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1314. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1315. if (!target) {
  1316. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1317. return 0;
  1318. }
  1319. if (!target->IsEntity()) {
  1320. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1321. return 0;
  1322. }
  1323. if (spell_id <= 0) {
  1324. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1325. return 0;
  1326. }
  1327. if (caster && !caster->IsEntity()) {
  1328. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1329. return 0;
  1330. }
  1331. if (spell_tier == 0)
  1332. spell_tier = 1;
  1333. if (!caster)
  1334. caster = target;
  1335. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1336. return 0;
  1337. }
  1338. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1339. if (!lua_interface)
  1340. return 0;
  1341. Spawn* target = lua_interface->GetSpawn(state);
  1342. int32 target_id = 0;
  1343. if (target)
  1344. target_id = target->GetID();
  1345. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1346. if (!luaspell)
  1347. return 0;
  1348. Spawn* caster = luaspell->caster;
  1349. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1350. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1351. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1352. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1353. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1354. //lua_interface->ResetFunctionStack(state);
  1355. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1356. vector<int16> faction_req;
  1357. vector<int16> race_req;
  1358. int32 class_req = 0;
  1359. int32 i = 0;
  1360. int8 f = 0;
  1361. int8 r = 0;
  1362. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1363. if (class_id < 100) {
  1364. class_req += pow(2.0, double(class_id - 1));
  1365. }
  1366. else if (class_id > 100 && class_id < 1000) {
  1367. race_req.push_back(class_id);
  1368. r++;
  1369. }
  1370. else {
  1371. faction_req.push_back(class_id);
  1372. f++;
  1373. }
  1374. i++;
  1375. }
  1376. if (caster && caster->IsEntity()) {
  1377. bool race_match = false;
  1378. bool success = false;
  1379. luaspell->resisted = false;
  1380. if (luaspell->initial_target == target_id) {
  1381. int xxx = 0;
  1382. }
  1383. if (luaspell->targets.size() > 0) {
  1384. ZoneServer* zone = luaspell->caster->GetZone();
  1385. Spawn* target = 0;
  1386. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1387. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1388. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1389. if (race_req.size() > 0) {
  1390. for (int8 i = 0; i < race_req.size(); i++) {
  1391. int32 xxx = target->GetLuaRaceId();
  1392. if (target->GetLuaRaceId() == race_req[i]) {
  1393. race_match = true;
  1394. }
  1395. }
  1396. }
  1397. else
  1398. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1399. if (race_match == true) {
  1400. float distance = caster->GetDistance(target, true);
  1401. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1402. }
  1403. }
  1404. }
  1405. success = true;
  1406. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1407. }
  1408. else if (target) {
  1409. //check class and race/faction here
  1410. if (race_req.size() > 0) {
  1411. for (int8 i = 0; i < race_req.size(); i++) {
  1412. if (target->GetLuaRaceId() == race_req[i]) {
  1413. race_match = true;
  1414. }
  1415. }
  1416. }
  1417. else
  1418. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1419. if (race_match == true) {
  1420. float distance = caster->GetDistance(target, true);
  1421. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1422. success = true;
  1423. }
  1424. }
  1425. if (success) {
  1426. Spell* spell = luaspell->spell;
  1427. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1428. ((Player*)caster)->InCombat(true);
  1429. if (caster->GetZone())
  1430. caster->GetZone()->TriggerCharSheetTimer();
  1431. }
  1432. }
  1433. }
  1434. return 0;
  1435. }
  1436. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1437. if (!lua_interface)
  1438. return 0;
  1439. Spawn* spawn = lua_interface->GetSpawn(state);
  1440. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1441. lua_interface->ResetFunctionStack(state);
  1442. if (spawn && value != 0) {
  1443. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1444. spawn->SetPower(spawn->GetTotalPower());
  1445. else
  1446. spawn->SetPower(spawn->GetPower() + value);
  1447. }
  1448. return 0;
  1449. }
  1450. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1451. if (!lua_interface)
  1452. return 0;
  1453. Spawn* spawn = lua_interface->GetSpawn(state);
  1454. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1455. lua_interface->ResetFunctionStack(state);
  1456. if (spawn && value != 0) {
  1457. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1458. spawn->SetHP(spawn->GetTotalHP());
  1459. else
  1460. spawn->SetHP(spawn->GetHP() + value);
  1461. }
  1462. return 0;
  1463. }
  1464. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1465. if (!lua_interface)
  1466. return 0;
  1467. Spawn* spawn = lua_interface->GetSpawn(state);
  1468. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1469. lua_interface->ResetFunctionStack(state);
  1470. if (spawn && value != 0) {
  1471. spawn->SetPower(spawn->GetPower() + value);
  1472. if (value > spawn->GetTotalHPBase())
  1473. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1474. }
  1475. return 0;
  1476. }
  1477. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1478. if (!lua_interface)
  1479. return 0;
  1480. Spawn* spawn = lua_interface->GetSpawn(state);
  1481. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1482. lua_interface->ResetFunctionStack(state);
  1483. if (spawn && value != 0) {
  1484. spawn->SetHP(spawn->GetHP() + value);
  1485. if (value > spawn->GetTotalHPBase())
  1486. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1487. }
  1488. return 0;
  1489. }
  1490. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1491. if (!lua_interface)
  1492. return 0;
  1493. Spawn* spawn = lua_interface->GetSpawn(state);
  1494. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1495. lua_interface->ResetFunctionStack(state);
  1496. if (spawn && value > 0) {
  1497. spawn->SetHP(value);
  1498. if (value > spawn->GetTotalHPBase())
  1499. spawn->SetTotalHP(value);
  1500. }
  1501. return 0;
  1502. }
  1503. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1504. if (!lua_interface)
  1505. return 0;
  1506. Spawn* spawn = lua_interface->GetSpawn(state);
  1507. float value = lua_interface->GetFloatValue(state, 2);
  1508. lua_interface->ResetFunctionStack(state);
  1509. if (spawn && spawn->IsEntity() && value > 0)
  1510. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1511. if (spawn->IsPlayer())
  1512. ((Player*)spawn)->SetCharSheetChanged(true);
  1513. return 0;
  1514. }
  1515. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1516. if (!lua_interface)
  1517. return 0;
  1518. Spawn* spawn = lua_interface->GetSpawn(state);
  1519. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1520. lua_interface->ResetFunctionStack(state);
  1521. if (spawn && spawn->IsEntity() && value > 0)
  1522. ((Entity*)spawn)->SetTotalHPBase(value);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. Spawn* spawn = lua_interface->GetSpawn(state);
  1529. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1530. lua_interface->ResetFunctionStack(state);
  1531. if (spawn && value > 0) {
  1532. spawn->SetPower(value);
  1533. if (value > spawn->GetTotalPowerBase())
  1534. spawn->SetTotalPower(value);
  1535. }
  1536. return 0;
  1537. }
  1538. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1539. if (!lua_interface)
  1540. return 0;
  1541. Spawn* spawn = lua_interface->GetSpawn(state);
  1542. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1543. lua_interface->ResetFunctionStack(state);
  1544. if (spawn && spawn->IsEntity() && value > 0)
  1545. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1546. return 0;
  1547. }
  1548. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1549. if (!lua_interface)
  1550. return 0;
  1551. Spawn* spawn = lua_interface->GetSpawn(state);
  1552. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1553. lua_interface->ResetFunctionStack(state);
  1554. if (spawn && spawn->IsEntity() && value > 0)
  1555. ((Entity*)spawn)->SetTotalPowerBase(value);
  1556. return 0;
  1557. }
  1558. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1559. if (!lua_interface)
  1560. return 0;
  1561. Spawn* spawn = lua_interface->GetSpawn(state);
  1562. float x = lua_interface->GetFloatValue(state, 2);
  1563. float y = lua_interface->GetFloatValue(state, 3);
  1564. float z = lua_interface->GetFloatValue(state, 4);
  1565. float heading = lua_interface->GetFloatValue(state, 5);
  1566. lua_interface->ResetFunctionStack(state);
  1567. if (spawn) {
  1568. spawn->SetX(x);
  1569. spawn->SetY(y);
  1570. spawn->SetZ(z);
  1571. if (heading != 0)
  1572. spawn->SetHeading(heading);
  1573. spawn->SetSpawnOrigX(spawn->GetX());
  1574. spawn->SetSpawnOrigY(spawn->GetY());
  1575. spawn->SetSpawnOrigZ(spawn->GetZ());
  1576. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1577. if (spawn->IsPlayer()) {
  1578. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1579. if (client) {
  1580. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1581. client->QueuePacket(packet);
  1582. }
  1583. }
  1584. }
  1585. return 0;
  1586. }
  1587. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1588. if (!lua_interface)
  1589. return 0;
  1590. Spawn* spawn = lua_interface->GetSpawn(state);
  1591. float value = lua_interface->GetFloatValue(state, 2);
  1592. lua_interface->ResetFunctionStack(state);
  1593. if (spawn) {
  1594. spawn->SetHeading(value);
  1595. if (spawn->IsPlayer()) {
  1596. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1597. if (client) {
  1598. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1599. client->QueuePacket(packet);
  1600. }
  1601. }
  1602. }
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. Spawn* spawn = lua_interface->GetSpawn(state);
  1609. int16 value = lua_interface->GetInt16Value(state, 2);
  1610. lua_interface->ResetFunctionStack(state);
  1611. if (spawn)
  1612. spawn->SetModelType(value);
  1613. return 0;
  1614. }
  1615. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1616. if (!lua_interface)
  1617. return 0;
  1618. Spawn* spawn = lua_interface->GetSpawn(state);
  1619. int8 value = lua_interface->GetInt8Value(state, 2);
  1620. lua_interface->ResetFunctionStack(state);
  1621. if (spawn) {
  1622. if (spawn->IsPlayer())
  1623. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1624. else
  1625. spawn->SetAdventureClass(value);
  1626. }
  1627. return 0;
  1628. }
  1629. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1630. if (!lua_interface)
  1631. return 0;
  1632. Spawn* spawn = lua_interface->GetSpawn(state);
  1633. int8 value = lua_interface->GetInt8Value(state, 2);
  1634. lua_interface->ResetFunctionStack(state);
  1635. if (spawn) {
  1636. spawn->SetTradeskillClass(value);
  1637. if (spawn->IsEntity()) {
  1638. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1639. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1640. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1641. }
  1642. if (spawn->IsPlayer())
  1643. ((Player*)spawn)->SetCharSheetChanged(true);
  1644. }
  1645. return 0;
  1646. }
  1647. int EQ2Emu_lua_SetMount(lua_State* state) {
  1648. if (!lua_interface)
  1649. return 0;
  1650. Spawn* spawn = lua_interface->GetSpawn(state);
  1651. int16 value = lua_interface->GetInt16Value(state, 2);
  1652. if (spawn && spawn->IsEntity()) {
  1653. ((Entity*)spawn)->SetMount(value);
  1654. EQ2_Color color;
  1655. color.red = 255;
  1656. color.green = 255;
  1657. color.blue = 255;
  1658. ((Entity*)spawn)->SetMountColor(&color);
  1659. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1660. }
  1661. return 0;
  1662. }
  1663. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1664. if (!lua_interface)
  1665. return 0;
  1666. Spawn* spawn = lua_interface->GetSpawn(state);
  1667. EQ2_Color mount_color;
  1668. EQ2_Color saddle_color;
  1669. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1670. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1671. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1672. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1673. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1674. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1675. if (spawn && spawn->IsEntity()) {
  1676. ((Entity*)spawn)->SetMountColor(&mount_color);
  1677. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1678. }
  1679. return 0;
  1680. }
  1681. int EQ2Emu_lua_GetMount(lua_State* state) {
  1682. if (!lua_interface)
  1683. return 0;
  1684. Spawn* spawn = lua_interface->GetSpawn(state);
  1685. if (spawn && spawn->IsEntity()) {
  1686. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1687. return 1;
  1688. }
  1689. return 0;
  1690. }
  1691. int EQ2Emu_lua_GetRace(lua_State* state) {
  1692. if (!lua_interface)
  1693. return 0;
  1694. Spawn* spawn = lua_interface->GetSpawn(state);
  1695. if (spawn)
  1696. {
  1697. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1698. lua_interface->SetInt32Value(state, spawn->GetRace());
  1699. return 1;
  1700. }
  1701. return 0;
  1702. }
  1703. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1704. if (!lua_interface)
  1705. return 0;
  1706. Spawn* spawn = lua_interface->GetSpawn(state);
  1707. if (spawn) {
  1708. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1709. return 1;
  1710. }
  1711. return 0;
  1712. }
  1713. int EQ2Emu_lua_GetClass(lua_State* state) {
  1714. Spawn* spawn = lua_interface->GetSpawn(state);
  1715. if (spawn) {
  1716. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1717. return 1;
  1718. }
  1719. return 0;
  1720. }
  1721. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. if (spawn) {
  1724. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1725. return 1;
  1726. }
  1727. return 0;
  1728. }
  1729. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1730. if (!lua_interface)
  1731. return 0;
  1732. Spawn* spawn = lua_interface->GetSpawn(state);
  1733. float value = lua_interface->GetFloatValue(state, 2);
  1734. lua_interface->ResetFunctionStack(state);
  1735. if (spawn) {
  1736. spawn->SetSpeed(value);
  1737. ((Entity*)spawn)->SetSpeed(value);
  1738. if (spawn->IsPlayer()) {
  1739. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1740. if (client) {
  1741. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1742. if (packet) {
  1743. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1744. packet->setDataByName("speed", value);
  1745. packet->setDataByName("size", 0.51);
  1746. EQ2Packet* app = packet->serialize();
  1747. client->QueuePacket(app);
  1748. safe_delete(packet);
  1749. }
  1750. }
  1751. }
  1752. }
  1753. return 0;
  1754. }
  1755. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1756. if (!lua_interface)
  1757. return 0;
  1758. Spawn* spawn = lua_interface->GetSpawn(state);
  1759. const int16 type = lua_interface->GetInt16Value(state, 2);
  1760. const float value = lua_interface->GetFloatValue(state, 3);
  1761. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1762. int64 class_req = 0;
  1763. int32 class_id = 0;
  1764. vector<int16> faction_req;
  1765. vector<int16> race_req;
  1766. int32 i = 0;
  1767. int8 f = 0;
  1768. int8 r = 0;
  1769. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1770. if (class_id < 100) {
  1771. class_req += pow(2.0, double(class_id - 1));
  1772. }
  1773. else if (class_id > 100 && class_id < 1000) {
  1774. race_req.push_back(class_id);
  1775. r++;
  1776. }
  1777. else {
  1778. faction_req.push_back(class_id);
  1779. f++;
  1780. }
  1781. i++;
  1782. }
  1783. if (value != 0 && type >= 0) {
  1784. if (luaspell && luaspell->spell && luaspell->caster) {
  1785. ZoneServer* zone = luaspell->caster->GetZone();
  1786. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1787. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1788. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1789. if (target) {
  1790. if (target->IsPlayer()) {
  1791. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1792. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1793. if (((Player*)target)->GetGroupMemberInfo())
  1794. ((Player*)target)->UpdateGroupMemberInfo();
  1795. ((Player*)target)->SetCharSheetChanged(true);
  1796. }
  1797. else if (target->IsNPC())
  1798. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1799. else
  1800. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1801. }
  1802. }
  1803. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1804. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1805. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1806. }
  1807. else if (spawn && spawn->IsEntity()) {
  1808. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1809. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1810. if (spawn->IsPlayer())
  1811. ((Player*)spawn)->SetCharSheetChanged(true);
  1812. }
  1813. else
  1814. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1815. }
  1816. else
  1817. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1818. return 0;
  1819. }
  1820. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1821. if (!lua_interface)
  1822. return 0;
  1823. Spawn* spawn = lua_interface->GetSpawn(state);
  1824. int16 type = lua_interface->GetInt16Value(state, 2);
  1825. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1826. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1827. if (!spawn) {
  1828. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1829. return 0;
  1830. }
  1831. if (!spawn->IsEntity()) {
  1832. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1833. return 0;
  1834. }
  1835. if (value == 0) {
  1836. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1837. return 0;
  1838. }
  1839. if (!luaspell || !luaspell->spell) {
  1840. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1841. return 0;
  1842. }
  1843. int32 class_req = 0;
  1844. vector<int16> faction_req;
  1845. vector<int16> race_req;
  1846. int32 class_id = 0;
  1847. int32 i = 0;
  1848. int8 f = 0;
  1849. int8 r = 0;
  1850. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1851. if (class_id < 100) {
  1852. class_req += pow(2.0, double(class_id - 1));
  1853. }
  1854. else if (class_id > 100 && class_id < 1000) {
  1855. race_req.push_back(class_id);
  1856. r++;
  1857. }
  1858. else {
  1859. faction_req.push_back(class_id);
  1860. f++;
  1861. }
  1862. i++;
  1863. }
  1864. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1865. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1866. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1867. if (spawn->IsPlayer())
  1868. ((Player*)spawn)->SetCharSheetChanged(true);
  1869. return 0;
  1870. }
  1871. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1872. if (!lua_interface)
  1873. return 0;
  1874. Spawn* spawn = lua_interface->GetSpawn(state);
  1875. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1876. if (luaspell && luaspell->spell) {
  1877. ZoneServer* zone = luaspell->caster->GetZone();
  1878. Spawn* target = 0;
  1879. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1880. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1881. target = zone->GetSpawnByID(luaspell->targets[i]);
  1882. if (target && target->IsEntity()) {
  1883. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1884. if (target->IsPlayer())
  1885. ((Player*)target)->SetCharSheetChanged(true);
  1886. }
  1887. }
  1888. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1889. }
  1890. else if (spawn && spawn->IsEntity()) {
  1891. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1892. if (spawn->IsPlayer())
  1893. ((Player*)spawn)->SetCharSheetChanged(true);
  1894. }
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1902. float value = lua_interface->GetFloatValue(state, 3);
  1903. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1904. if (value != 0) {
  1905. int32 spell_id = 0;
  1906. if (luaspell && luaspell->spell && luaspell->caster) {
  1907. spell_id = luaspell->spell->GetSpellID();
  1908. ZoneServer* zone = luaspell->caster->GetZone();
  1909. Spawn* target = 0;
  1910. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1911. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1912. target = zone->GetSpawnByID(luaspell->targets[i]);
  1913. if (target && target->Alive()) {
  1914. if (target->IsPlayer()) {
  1915. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1916. Client* client = target->GetZone()->GetClientBySpawn(target);
  1917. if (client) {
  1918. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1919. if (packet)
  1920. client->QueuePacket(packet);
  1921. }
  1922. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1923. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1924. }
  1925. else if (target->IsNPC()) {
  1926. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1927. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1928. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1929. }
  1930. else
  1931. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1932. }
  1933. }
  1934. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1935. }
  1936. else if (spawn) {
  1937. if (spawn->IsPlayer()) {
  1938. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1939. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1940. if (client) {
  1941. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1942. if (packet)
  1943. client->QueuePacket(packet);
  1944. }
  1945. }
  1946. else if (spawn->IsNPC())
  1947. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1948. else
  1949. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1950. }
  1951. }
  1952. else
  1953. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1954. return 0;
  1955. }
  1956. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1957. if (!lua_interface)
  1958. return 0;
  1959. Spawn* spawn = lua_interface->GetSpawn(state);
  1960. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1961. if (spawn && spawn->IsPlayer()) {
  1962. int32 spell_id = 0;
  1963. if (luaspell && luaspell->spell) {
  1964. spell_id = luaspell->spell->GetSpellID();
  1965. ZoneServer* zone = luaspell->caster->GetZone();
  1966. Spawn* target = 0;
  1967. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1968. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1969. target = zone->GetSpawnByID(luaspell->targets[i]);
  1970. if (target) {
  1971. if (target->IsPlayer()) {
  1972. ((Player*)target)->RemoveSkillBonus(spell_id);
  1973. Client* client = target->GetZone()->GetClientBySpawn(target);
  1974. if (client) {
  1975. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1976. if (packet)
  1977. client->QueuePacket(packet);
  1978. }
  1979. }
  1980. else if (target->IsNPC())
  1981. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1982. else
  1983. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1984. }
  1985. }
  1986. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1987. }
  1988. else if (spawn) {
  1989. if (spawn->IsPlayer()) {
  1990. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1991. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1992. if (client) {
  1993. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1994. if (packet)
  1995. client->QueuePacket(packet);
  1996. }
  1997. }
  1998. else if (spawn->IsNPC())
  1999. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2000. else
  2001. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2002. }
  2003. }
  2004. return 0;
  2005. }
  2006. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2007. if (!lua_interface)
  2008. return 0;
  2009. Spawn* spawn = lua_interface->GetSpawn(state);
  2010. int8 type = lua_interface->GetInt32Value(state, 2);
  2011. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2012. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2013. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2014. ZoneServer* zone = luaspell->caster->GetZone();
  2015. Spawn* target = 0;
  2016. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2017. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2018. target = zone->GetSpawnByID(luaspell->targets[i]);
  2019. if (target && target->IsEntity()) {
  2020. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2021. ((Entity*)target)->AddMezSpell(luaspell);
  2022. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2023. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2024. if (target->IsNPC())
  2025. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2026. }
  2027. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2028. ((Entity*)target)->AddStifleSpell(luaspell);
  2029. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2030. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2031. if (target->IsNPC())
  2032. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2033. }
  2034. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2035. ((Entity*)target)->AddDazeSpell(luaspell);
  2036. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2037. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2038. if (target->IsNPC())
  2039. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2040. }
  2041. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2042. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2043. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2044. ((Entity*)target)->AddStunSpell(luaspell);
  2045. if (target->IsNPC())
  2046. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2047. }
  2048. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2049. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2050. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2051. ((Entity*)target)->AddRootSpell(luaspell);
  2052. if (target->IsNPC())
  2053. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2054. }
  2055. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2056. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2057. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2058. ((Entity*)target)->AddFearSpell(luaspell);
  2059. if (target->IsNPC())
  2060. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2061. }
  2062. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2063. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2064. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2065. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2066. }
  2067. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2068. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2071. }
  2072. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2073. ((Entity*)target)->AddSnareSpell(luaspell);
  2074. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2075. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2076. if (target->IsNPC())
  2077. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2078. }
  2079. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2080. ((Entity*)target)->AddFlightSpell(luaspell);
  2081. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2082. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2083. }
  2084. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2085. ((Entity*)target)->AddGlideSpell(luaspell);
  2086. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2087. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2088. }
  2089. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2090. ((Entity*)target)->AddSafefallSpell(luaspell);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2093. }
  2094. else
  2095. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2096. }
  2097. else
  2098. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2099. }
  2100. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2101. }
  2102. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2103. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2104. ((Entity*)spawn)->AddMezSpell(luaspell);
  2105. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2106. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2107. }
  2108. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2109. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2110. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2111. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2112. }
  2113. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2114. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2115. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2116. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2117. }
  2118. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2119. ((Entity*)spawn)->AddStunSpell(luaspell);
  2120. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2121. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2122. }
  2123. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2124. ((Entity*)spawn)->AddRootSpell(luaspell);
  2125. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2126. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2127. }
  2128. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2129. ((Entity*)spawn)->AddFearSpell(luaspell);
  2130. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2131. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2132. }
  2133. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2134. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2135. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2136. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2137. }
  2138. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2139. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2140. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2141. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2142. }
  2143. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2144. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2145. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2146. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2147. }
  2148. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2149. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2150. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2151. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2152. }
  2153. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2154. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2155. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2156. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2157. }
  2158. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2159. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2160. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2161. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2162. }
  2163. else
  2164. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. int8 type = lua_interface->GetInt8Value(state, 2);
  2175. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2176. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2177. if (spawn && spawn->IsEntity()) {
  2178. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2179. ZoneServer* zone = luaspell->caster->GetZone();
  2180. Spawn* target = 0;
  2181. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2182. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2183. target = zone->GetSpawnByID(luaspell->targets[i]);
  2184. if (target) {
  2185. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2186. ((Entity*)target)->RemoveMezSpell(luaspell);
  2187. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2188. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2189. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2190. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2191. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2192. ((Entity*)target)->RemoveStunSpell(luaspell);
  2193. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2194. ((Entity*)target)->RemoveRootSpell(luaspell);
  2195. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2196. ((Entity*)target)->RemoveFearSpell(luaspell);
  2197. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2198. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2199. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2200. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2201. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2202. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2203. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2204. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2205. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2206. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2207. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2208. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2209. else
  2210. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2211. }
  2212. }
  2213. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2214. }
  2215. else if (only_remove_spawn) {
  2216. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2217. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2219. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2221. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2223. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2225. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2227. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2229. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2231. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2233. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2235. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2236. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2237. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2238. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2239. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2240. else
  2241. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2242. }
  2243. }
  2244. return 0;
  2245. }
  2246. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2247. if (!lua_interface)
  2248. return 0;
  2249. Spawn* spawn = lua_interface->GetSpawn(state);
  2250. int16 value = lua_interface->GetInt16Value(state, 2);
  2251. if (spawn && spawn->IsEntity()) {
  2252. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2253. if (spawn->IsPlayer())
  2254. ((Player*)spawn)->SetCharSheetChanged(true);
  2255. }
  2256. return 0;
  2257. }
  2258. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2259. if (!lua_interface)
  2260. return 0;
  2261. Spawn* spawn = lua_interface->GetSpawn(state);
  2262. int16 value = lua_interface->GetInt16Value(state, 2);
  2263. if (spawn && spawn->IsEntity()) {
  2264. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2265. if (spawn->IsPlayer())
  2266. ((Player*)spawn)->SetCharSheetChanged(true);
  2267. }
  2268. return 0;
  2269. }
  2270. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2271. if (!lua_interface)
  2272. return 0;
  2273. Spawn* spawn = lua_interface->GetSpawn(state);
  2274. int16 value = lua_interface->GetInt16Value(state, 2);
  2275. if (spawn && spawn->IsEntity()) {
  2276. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2277. if (spawn->IsPlayer())
  2278. ((Player*)spawn)->SetCharSheetChanged(true);
  2279. }
  2280. return 0;
  2281. }
  2282. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2283. if (!lua_interface)
  2284. return 0;
  2285. Spawn* spawn = lua_interface->GetSpawn(state);
  2286. int16 value = lua_interface->GetInt16Value(state, 2);
  2287. if (spawn && spawn->IsEntity()) {
  2288. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2289. if (spawn->IsPlayer())
  2290. ((Player*)spawn)->SetCharSheetChanged(true);
  2291. }
  2292. return 0;
  2293. }
  2294. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2295. if (!lua_interface)
  2296. return 0;
  2297. Spawn* spawn = lua_interface->GetSpawn(state);
  2298. int16 value = lua_interface->GetInt16Value(state, 2);
  2299. if (spawn && spawn->IsEntity()) {
  2300. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2301. if (spawn->IsPlayer())
  2302. ((Player*)spawn)->SetCharSheetChanged(true);
  2303. }
  2304. return 0;
  2305. }
  2306. int EQ2Emu_lua_SetInt(lua_State* state) {
  2307. if (!lua_interface)
  2308. return 0;
  2309. Spawn* spawn = lua_interface->GetSpawn(state);
  2310. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2311. if (spawn && spawn->IsEntity()) {
  2312. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2313. if (spawn->IsPlayer())
  2314. ((Player*)spawn)->SetCharSheetChanged(true);
  2315. }
  2316. return 0;
  2317. }
  2318. int EQ2Emu_lua_SetWis(lua_State* state) {
  2319. if (!lua_interface)
  2320. return 0;
  2321. Spawn* spawn = lua_interface->GetSpawn(state);
  2322. float value = lua_interface->GetFloatValue(state, 2);
  2323. if (spawn && spawn->IsEntity()) {
  2324. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2325. if (spawn->IsPlayer())
  2326. ((Player*)spawn)->SetCharSheetChanged(true);
  2327. }
  2328. return 0;
  2329. }
  2330. int EQ2Emu_lua_SetSta(lua_State* state) {
  2331. if (!lua_interface)
  2332. return 0;
  2333. Spawn* spawn = lua_interface->GetSpawn(state);
  2334. float value = lua_interface->GetFloatValue(state, 2);
  2335. if (spawn && spawn->IsEntity()) {
  2336. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2337. if (spawn->IsPlayer())
  2338. ((Player*)spawn)->SetCharSheetChanged(true);
  2339. }
  2340. return 0;
  2341. }
  2342. int EQ2Emu_lua_SetStr(lua_State* state) {
  2343. if (!lua_interface)
  2344. return 0;
  2345. Spawn* spawn = lua_interface->GetSpawn(state);
  2346. float value = lua_interface->GetFloatValue(state, 2);
  2347. if (spawn && spawn->IsEntity()) {
  2348. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2349. if (spawn->IsPlayer())
  2350. ((Player*)spawn)->SetCharSheetChanged(true);
  2351. }
  2352. return 0;
  2353. }
  2354. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2355. if (!lua_interface)
  2356. return 0;
  2357. Spawn* spawn = lua_interface->GetSpawn(state);
  2358. float value = lua_interface->GetFloatValue(state, 2);
  2359. if (spawn && spawn->IsEntity()) {
  2360. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2361. if (spawn->IsPlayer())
  2362. ((Player*)spawn)->SetCharSheetChanged(true);
  2363. }
  2364. return 0;
  2365. }
  2366. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2367. if (!lua_interface)
  2368. return 0;
  2369. Spawn* spawn = lua_interface->GetSpawn(state);
  2370. if (spawn) {
  2371. lua_interface->SetInt32Value(state, spawn->GetHP());
  2372. return 1;
  2373. }
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2377. if (!lua_interface)
  2378. return 0;
  2379. Spawn* spawn = lua_interface->GetSpawn(state);
  2380. if (spawn) {
  2381. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2382. return 1;
  2383. }
  2384. return 0;
  2385. }
  2386. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2387. if (!lua_interface)
  2388. return 0;
  2389. Spawn* spawn = lua_interface->GetSpawn(state);
  2390. if (spawn) {
  2391. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2392. return 1;
  2393. }
  2394. return 0;
  2395. }
  2396. int EQ2Emu_lua_GetName(lua_State* state) {
  2397. if (!lua_interface)
  2398. return 0;
  2399. Spawn* spawn = lua_interface->GetSpawn(state);
  2400. if (spawn) {
  2401. lua_interface->SetStringValue(state, spawn->GetName());
  2402. return 1;
  2403. }
  2404. return 0;
  2405. }
  2406. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2407. Spawn* spawn = lua_interface->GetSpawn(state);
  2408. if (spawn) {
  2409. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2410. return 1;
  2411. }
  2412. return 0;
  2413. }
  2414. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2415. if (!lua_interface)
  2416. return 0;
  2417. Spawn* spawn = lua_interface->GetSpawn(state);
  2418. if (spawn) {
  2419. lua_interface->SetInt32Value(state, spawn->GetPower());
  2420. return 1;
  2421. }
  2422. return 0;
  2423. }
  2424. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2425. if (!lua_interface)
  2426. return 0;
  2427. Spawn* spawn = lua_interface->GetSpawn(state);
  2428. if (spawn) {
  2429. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2430. return 1;
  2431. }
  2432. return 0;
  2433. }
  2434. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2435. if (!lua_interface)
  2436. return 0;
  2437. Spawn* spawn = lua_interface->GetSpawn(state);
  2438. if (spawn) {
  2439. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2440. return 1;
  2441. }
  2442. return 0;
  2443. }
  2444. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2445. if (!lua_interface)
  2446. return 0;
  2447. Spawn* spawn = lua_interface->GetSpawn(state);
  2448. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2449. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2450. if (spawn && spawn2) {
  2451. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2452. lua_interface->SetFloatValue(state, distance);
  2453. return 1;
  2454. }
  2455. return 0;
  2456. }
  2457. int EQ2Emu_lua_GetX(lua_State* state) {
  2458. if (!lua_interface)
  2459. return 0;
  2460. Spawn* spawn = lua_interface->GetSpawn(state);
  2461. if (spawn) {
  2462. lua_interface->SetFloatValue(state, spawn->GetX());
  2463. return 1;
  2464. }
  2465. return 0;
  2466. }
  2467. int EQ2Emu_lua_GetY(lua_State* state) {
  2468. if (!lua_interface)
  2469. return 0;
  2470. Spawn* spawn = lua_interface->GetSpawn(state);
  2471. if (spawn) {
  2472. lua_interface->SetFloatValue(state, spawn->GetY());
  2473. return 1;
  2474. }
  2475. return 0;
  2476. }
  2477. int EQ2Emu_lua_GetZ(lua_State* state) {
  2478. if (!lua_interface)
  2479. return 0;
  2480. Spawn* spawn = lua_interface->GetSpawn(state);
  2481. if (spawn) {
  2482. lua_interface->SetFloatValue(state, spawn->GetZ());
  2483. return 1;
  2484. }
  2485. return 0;
  2486. }
  2487. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2488. if (!lua_interface)
  2489. return 0;
  2490. Spawn* spawn = lua_interface->GetSpawn(state);
  2491. if (spawn) {
  2492. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2493. return 1;
  2494. }
  2495. return 0;
  2496. }
  2497. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2498. if (!lua_interface)
  2499. return 0;
  2500. Spawn* spawn = lua_interface->GetSpawn(state);
  2501. if (spawn) {
  2502. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2503. return 1;
  2504. }
  2505. return 0;
  2506. }
  2507. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2508. if (!lua_interface)
  2509. return 0;
  2510. Spawn* spawn = lua_interface->GetSpawn(state);
  2511. if (spawn) {
  2512. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2513. return 1;
  2514. }
  2515. return 0;
  2516. }
  2517. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2518. if (!lua_interface)
  2519. return 0;
  2520. Spawn* spawn = lua_interface->GetSpawn(state);
  2521. if (spawn && spawn->IsEntity()) {
  2522. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2523. return 1;
  2524. }
  2525. return 0;
  2526. }
  2527. int EQ2Emu_lua_GetInt(lua_State* state) {
  2528. if (!lua_interface)
  2529. return 0;
  2530. Spawn* spawn = lua_interface->GetSpawn(state);
  2531. if (spawn && spawn->IsEntity()) {
  2532. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2533. return 1;
  2534. }
  2535. return 0;
  2536. }
  2537. int EQ2Emu_lua_GetWis(lua_State* state) {
  2538. if (!lua_interface)
  2539. return 0;
  2540. Spawn* spawn = lua_interface->GetSpawn(state);
  2541. if (spawn && spawn->IsEntity()) {
  2542. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2543. return 1;
  2544. }
  2545. return 0;
  2546. }
  2547. int EQ2Emu_lua_GetSta(lua_State* state) {
  2548. if (!lua_interface)
  2549. return 0;
  2550. Spawn* spawn = lua_interface->GetSpawn(state);
  2551. if (spawn && spawn->IsEntity()) {
  2552. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2553. return 1;
  2554. }
  2555. return 0;
  2556. }
  2557. int EQ2Emu_lua_GetStr(lua_State* state) {
  2558. if (!lua_interface)
  2559. return 0;
  2560. Spawn* spawn = lua_interface->GetSpawn(state);
  2561. if (spawn && spawn->IsEntity()) {
  2562. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2563. return 1;
  2564. }
  2565. return 0;
  2566. }
  2567. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2568. if (!lua_interface)
  2569. return 0;
  2570. Spawn* spawn = lua_interface->GetSpawn(state);
  2571. if (spawn && spawn->IsEntity()) {
  2572. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2573. return 1;
  2574. }
  2575. return 0;
  2576. }
  2577. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2578. if (!lua_interface)
  2579. return 0;
  2580. Spawn* spawn = lua_interface->GetSpawn(state);
  2581. if (spawn && spawn->IsEntity()) {
  2582. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2583. return 1;
  2584. }
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. if (spawn && spawn->IsEntity()) {
  2592. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2593. return 1;
  2594. }
  2595. return 0;
  2596. }
  2597. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2598. if (!lua_interface)
  2599. return 0;
  2600. Spawn* spawn = lua_interface->GetSpawn(state);
  2601. if (spawn && spawn->IsEntity()) {
  2602. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2603. return 1;
  2604. }
  2605. return 0;
  2606. }
  2607. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2608. if (!lua_interface)
  2609. return 0;
  2610. Spawn* spawn = lua_interface->GetSpawn(state);
  2611. if (spawn && spawn->IsEntity()) {
  2612. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2613. return 1;
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* spawn = lua_interface->GetSpawn(state);
  2621. if (spawn && spawn->IsEntity()) {
  2622. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2623. return 1;
  2624. }
  2625. return 0;
  2626. }
  2627. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2628. if (!lua_interface)
  2629. return 0;
  2630. Spawn* player = lua_interface->GetSpawn(state);
  2631. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2632. int32 step = lua_interface->GetInt32Value(state, 3);
  2633. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2634. Client* client = player->GetZone()->GetClientBySpawn(player);
  2635. if (client)
  2636. client->AddPendingQuestUpdate(quest_id, step);
  2637. }
  2638. return 0;
  2639. }
  2640. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2641. Spawn* player = lua_interface->GetSpawn(state);
  2642. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2643. int32 step = lua_interface->GetInt32Value(state, 3);
  2644. int32 progress = lua_interface->GetInt32Value(state, 4);
  2645. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2646. Client* client = player->GetZone()->GetClientBySpawn(player);
  2647. if (client)
  2648. client->AddPendingQuestUpdate(quest_id, step, progress);
  2649. }
  2650. return 0;
  2651. }
  2652. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2653. if (!lua_interface)
  2654. return 0;
  2655. Spawn* player = lua_interface->GetSpawn(state);
  2656. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2657. if (player && player->IsPlayer() && quest_id > 0) {
  2658. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2659. return 1;
  2660. }
  2661. return 0;
  2662. }
  2663. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2664. if (!lua_interface)
  2665. return 0;
  2666. Spawn* player = lua_interface->GetSpawn(state);
  2667. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2668. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2669. if (player && player->IsPlayer() && quest_id > 0) {
  2670. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2671. return 1;
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Spawn* player = lua_interface->GetSpawn(state);
  2679. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2680. if (player && player->IsPlayer() && quest_id > 0) {
  2681. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2682. return 1;
  2683. }
  2684. return 0;
  2685. }
  2686. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2687. if (!lua_interface)
  2688. return 0;
  2689. Quest* quest = lua_interface->GetQuest(state);
  2690. string name = lua_interface->GetStringValue(state, 2);
  2691. string type = lua_interface->GetStringValue(state, 3);
  2692. string zone = lua_interface->GetStringValue(state, 4);
  2693. int16 level = lua_interface->GetInt16Value(state, 5);
  2694. string description = lua_interface->GetStringValue(state, 6);
  2695. bool load = true;
  2696. if (!quest) {
  2697. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2698. load = false;
  2699. }
  2700. if (load && name.length() == 0) {
  2701. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2702. load = false;
  2703. }
  2704. if (load && type.length() == 0) {
  2705. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2706. load = false;
  2707. }
  2708. if (load && zone.length() == 0) {
  2709. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2710. load = false;
  2711. }
  2712. if (load && description.length() == 0) {
  2713. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2714. load = false;
  2715. }
  2716. if (load && level == 0) {
  2717. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2718. load = false;
  2719. }
  2720. if (load)
  2721. quest->RegisterQuest(name, type, zone, level, description);
  2722. return 0;
  2723. }
  2724. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2725. if (!lua_interface)
  2726. return 0;
  2727. Quest* quest = lua_interface->GetQuest(state);
  2728. if (quest) {
  2729. int8 level = lua_interface->GetInt16Value(state, 2);
  2730. quest->SetPrereqLevel(level);
  2731. }
  2732. return 0;
  2733. }
  2734. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2735. if (!lua_interface)
  2736. return 0;
  2737. Quest* quest = lua_interface->GetQuest(state);
  2738. if (quest) {
  2739. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2740. quest->AddPrereqQuest(quest_id);
  2741. }
  2742. return 0;
  2743. }
  2744. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2745. if (!lua_interface)
  2746. return 0;
  2747. Quest* quest = lua_interface->GetQuest(state);
  2748. if (quest) {
  2749. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2750. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2751. if (quantity == 0)
  2752. quantity = 1;
  2753. Item* master_item = master_item_list.GetItem(item_id);
  2754. if (master_item) {
  2755. Item* item = new Item(master_item);
  2756. item->details.count = quantity;
  2757. quest->AddPrereqItem(item);
  2758. }
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Spawn* player = lua_interface->GetSpawn(state);
  2766. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2767. if (player && player->IsPlayer() && quest_id > 0) {
  2768. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2769. return 1;
  2770. }
  2771. return 0;
  2772. }
  2773. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2774. if (!lua_interface)
  2775. return 0;
  2776. Quest* quest = lua_interface->GetQuest(state);
  2777. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2778. if (quest && spawn_id > 0)
  2779. quest->SetQuestReturnNPC(spawn_id);
  2780. return 0;
  2781. }
  2782. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2783. if (!lua_interface)
  2784. return 0;
  2785. Spawn* spawn = lua_interface->GetSpawn(state);
  2786. if (!spawn) {
  2787. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2788. return 0;
  2789. }
  2790. int32 time = lua_interface->GetInt32Value(state, 2);
  2791. if (time <= 0) {
  2792. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2793. return 0;
  2794. }
  2795. string function = lua_interface->GetStringValue(state, 3);
  2796. if (function.length() == 0) {
  2797. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2798. return 0;
  2799. }
  2800. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2801. Spawn* player = lua_interface->GetSpawn(state, 5);
  2802. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2803. timer->timer = Timer::GetCurrentTime2() + time;
  2804. timer->function = function;
  2805. timer->spawn = spawn->GetID();
  2806. timer->player = player ? player->GetID() : 0;
  2807. if (max_count == 0)
  2808. max_count = 1;
  2809. timer->max_count = max_count;
  2810. timer->current_count = 0;
  2811. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2812. return 0;
  2813. }
  2814. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2815. if (!lua_interface)
  2816. return 0;
  2817. Spawn* player = lua_interface->GetSpawn(state);
  2818. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2819. if (player && player->IsPlayer() && quest_id > 0) {
  2820. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2821. return 1;
  2822. }
  2823. return 0;
  2824. }
  2825. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2826. if (!lua_interface)
  2827. return 0;
  2828. Spawn* player = lua_interface->GetSpawn(state);
  2829. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2830. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2831. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2832. if (quest)
  2833. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* player = lua_interface->GetSpawn(state);
  2842. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2843. if (player && player->IsPlayer() && quest_id > 0) {
  2844. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* npc = lua_interface->GetSpawn(state);
  2853. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2854. if (npc && !npc->IsPlayer() && quest_id > 0)
  2855. npc->AddProvidedQuest(quest_id);
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* npc = lua_interface->GetSpawn(state);
  2862. Spawn* player = lua_interface->GetSpawn(state, 2);
  2863. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2864. bool forced = lua_interface->GetBooleanValue(state, 4);
  2865. /* NPC is allowed to be null */
  2866. if (player && player->IsPlayer() && quest_id > 0) {
  2867. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2868. if (master_quest) {
  2869. Client* client = player->GetZone()->GetClientBySpawn(player);
  2870. Quest* quest = new Quest(master_quest);
  2871. if (client && quest) {
  2872. if (npc)
  2873. quest->SetQuestGiver(npc->GetDatabaseID());
  2874. else
  2875. quest->SetQuestGiver(0);
  2876. client->AddPendingQuest(quest, forced);
  2877. }
  2878. }
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Quest* quest = lua_interface->GetQuest(state);
  2886. if (quest) {
  2887. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2888. quest->AddPrereqClass(class_id);
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Quest* quest = lua_interface->GetQuest(state);
  2896. if (quest) {
  2897. int8 race = lua_interface->GetInt8Value(state, 2);
  2898. quest->AddPrereqRace(race);
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Quest* quest = lua_interface->GetQuest(state);
  2906. if (quest) {
  2907. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2908. quest->AddPrereqModelType(model_type);
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Quest* quest = lua_interface->GetQuest(state);
  2916. if (!quest) {
  2917. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2918. return 0;
  2919. }
  2920. int8 level = lua_interface->GetInt8Value(state, 2);
  2921. quest->SetPrereqTSLevel(level);
  2922. return 0;
  2923. }
  2924. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2925. if (!lua_interface)
  2926. return 0;
  2927. Quest* quest = lua_interface->GetQuest(state);
  2928. if (!quest) {
  2929. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2930. return 0;
  2931. }
  2932. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2933. quest->AddPrereqTradeskillClass(class_id);
  2934. return 0;
  2935. }
  2936. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2937. if (!lua_interface)
  2938. return 0;
  2939. Quest* quest = lua_interface->GetQuest(state);
  2940. if (quest) {
  2941. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2942. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2943. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2944. quest->AddPrereqFaction(faction_id, min, max);
  2945. }
  2946. return 0;
  2947. }
  2948. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2949. if (!lua_interface)
  2950. return 0;
  2951. Quest* quest = lua_interface->GetQuest(state);
  2952. if (quest) {
  2953. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2954. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2955. if (quantity == 0)
  2956. quantity = 1;
  2957. Item* master_item = master_item_list.GetItem(item_id);
  2958. if (master_item) {
  2959. Item* item = new Item(master_item);
  2960. item->details.count = quantity;
  2961. quest->AddSelectableRewardItem(item);
  2962. }
  2963. }
  2964. return 0;
  2965. }
  2966. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2967. if (!lua_interface)
  2968. return 0;
  2969. Quest* quest = lua_interface->GetQuest(state);
  2970. if (quest) {
  2971. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2972. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2973. if (quantity == 0)
  2974. quantity = 1;
  2975. Item* master_item = master_item_list.GetItem(item_id);
  2976. if (master_item) {
  2977. Item* item = new Item(master_item);
  2978. item->details.count = quantity;
  2979. quest->AddRewardItem(item);
  2980. }
  2981. }
  2982. return 0;
  2983. }
  2984. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2985. if (!lua_interface)
  2986. return 0;
  2987. Quest* quest = lua_interface->GetQuest(state);
  2988. if (quest) {
  2989. int32 copper = lua_interface->GetInt32Value(state, 2);
  2990. int32 silver = lua_interface->GetInt32Value(state, 3);
  2991. int32 gold = lua_interface->GetInt32Value(state, 4);
  2992. int32 plat = lua_interface->GetInt32Value(state, 5);
  2993. quest->AddRewardCoins(copper, silver, gold, plat);
  2994. }
  2995. return 0;
  2996. }
  2997. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2998. if (!lua_interface)
  2999. return 0;
  3000. Quest* quest = lua_interface->GetQuest(state);
  3001. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3002. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3003. if (quest && faction_id > 0 && amount != 0)
  3004. quest->AddRewardFaction(faction_id, amount);
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Quest* quest = lua_interface->GetQuest(state);
  3011. if (quest) {
  3012. int32 status = lua_interface->GetInt32Value(state, 2);
  3013. quest->SetRewardStatus(status);
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Quest* quest = lua_interface->GetQuest(state);
  3021. if (quest) {
  3022. string comment = lua_interface->GetStringValue(state, 2);
  3023. quest->SetRewardComment(comment);
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Quest* quest = lua_interface->GetQuest(state);
  3031. if (quest) {
  3032. int32 exp = lua_interface->GetInt32Value(state, 2);
  3033. quest->SetRewardXP(exp);
  3034. }
  3035. return 0;
  3036. }
  3037. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3038. Quest* quest = lua_interface->GetQuest(state);
  3039. if (quest) {
  3040. int32 step = lua_interface->GetInt32Value(state, 2);
  3041. string description = lua_interface->GetStringValue(state, 3);
  3042. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3043. float percentage = lua_interface->GetFloatValue(state, 5);
  3044. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3045. int16 icon = lua_interface->GetInt16Value(state, 7);
  3046. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3047. const char* taskgroup = 0;
  3048. if (str_taskgroup.length() > 0)
  3049. taskgroup = str_taskgroup.c_str();
  3050. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3051. if (quest_step && icon && quantity > 0)
  3052. quest_step->SetIcon(icon);
  3053. }
  3054. return 0;
  3055. }
  3056. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3057. if (!lua_interface)
  3058. return 0;
  3059. Quest* quest = lua_interface->GetQuest(state);
  3060. if (quest) {
  3061. int32 step = lua_interface->GetInt32Value(state, 2);
  3062. string description = lua_interface->GetStringValue(state, 3);
  3063. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3064. float percentage = lua_interface->GetFloatValue(state, 5);
  3065. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3066. int16 icon = lua_interface->GetInt16Value(state, 7);
  3067. const char* taskgroup = 0;
  3068. if (str_taskgroup.length() > 0)
  3069. taskgroup = str_taskgroup.c_str();
  3070. int32 npc_id = 0;
  3071. vector<int32>* ids = 0;
  3072. Spawn* spawn = nullptr;
  3073. int i = 0;
  3074. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3075. if (ids == 0)
  3076. ids = new vector<int32>;
  3077. ids->push_back(npc_id);
  3078. i++;
  3079. }
  3080. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3081. if (quest_step && icon > 0 && quantity > 0)
  3082. quest_step->SetIcon(icon);
  3083. if (quest->GetPlayer()) {
  3084. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3085. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3086. }
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Quest* quest = lua_interface->GetQuest(state);
  3094. if (quest) {
  3095. int32 step = lua_interface->GetInt32Value(state, 2);
  3096. string description = lua_interface->GetStringValue(state, 3);
  3097. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3098. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3099. int16 icon = lua_interface->GetInt16Value(state, 6);
  3100. const char* taskgroup = 0;
  3101. if (str_taskgroup.length() > 0)
  3102. taskgroup = str_taskgroup.c_str();
  3103. int32 npc_id = 0;
  3104. vector<int32>* ids = 0;
  3105. int i = 0;
  3106. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3107. if (ids == 0)
  3108. ids = new vector<int32>;
  3109. ids->push_back(npc_id);
  3110. i++;
  3111. }
  3112. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3113. if (quest_step && icon > 0)
  3114. quest_step->SetIcon(icon);
  3115. if (quest->GetPlayer()) {
  3116. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3117. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3118. }
  3119. }
  3120. return 0;
  3121. }
  3122. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3123. if (!lua_interface)
  3124. return 0;
  3125. Quest* quest = lua_interface->GetQuest(state);
  3126. if (quest) {
  3127. int32 step = lua_interface->GetInt32Value(state, 2);
  3128. string description = lua_interface->GetStringValue(state, 3);
  3129. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3130. float percentage = lua_interface->GetFloatValue(state, 5);
  3131. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3132. int16 icon = lua_interface->GetInt16Value(state, 7);
  3133. const char* taskgroup = 0;
  3134. if (str_taskgroup.length() > 0)
  3135. taskgroup = str_taskgroup.c_str();
  3136. int32 item_id = 0;
  3137. vector<int32>* ids = 0;
  3138. int i = 0;
  3139. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3140. if (ids == 0)
  3141. ids = new vector<int32>;
  3142. ids->push_back(item_id);
  3143. i++;
  3144. }
  3145. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3146. if (quest_step && icon > 0 && quantity > 0)
  3147. quest_step->SetIcon(icon);
  3148. if (quest->GetPlayer()) {
  3149. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3150. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3151. }
  3152. }
  3153. return 0;
  3154. }
  3155. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3156. if (!lua_interface)
  3157. return 0;
  3158. Quest* quest = lua_interface->GetQuest(state);
  3159. if (quest) {
  3160. int32 step = lua_interface->GetInt32Value(state, 2);
  3161. string description = lua_interface->GetStringValue(state, 3);
  3162. float max_variation = lua_interface->GetFloatValue(state, 4);
  3163. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3164. int16 icon = lua_interface->GetInt16Value(state, 6);
  3165. const char* taskgroup = 0;
  3166. if (str_taskgroup.length() > 0)
  3167. taskgroup = str_taskgroup.c_str();
  3168. vector<Location>* locations = 0;
  3169. int i = 7;
  3170. while (true) {
  3171. Location loc;
  3172. loc.x = lua_interface->GetFloatValue(state, i);
  3173. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3174. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3175. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3176. break;
  3177. if (locations == 0)
  3178. locations = new vector<Location>;
  3179. locations->push_back(loc);
  3180. i += 3;
  3181. }
  3182. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3183. if (quest_step && icon > 0)
  3184. quest_step->SetIcon(icon);
  3185. if (quest->GetPlayer()) {
  3186. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3187. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3188. }
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. if (quest) {
  3197. int32 step = lua_interface->GetInt32Value(state, 2);
  3198. string description = lua_interface->GetStringValue(state, 3);
  3199. float max_variation = lua_interface->GetFloatValue(state, 4);
  3200. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3201. int16 icon = lua_interface->GetInt16Value(state, 6);
  3202. const char* taskgroup = 0;
  3203. if (str_taskgroup.length() > 0)
  3204. taskgroup = str_taskgroup.c_str();
  3205. vector<Location>* locations = 0;
  3206. int i = 7;
  3207. while (true) {
  3208. Location loc;
  3209. loc.x = lua_interface->GetFloatValue(state, i);
  3210. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3211. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3212. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3213. break;
  3214. if (locations == 0)
  3215. locations = new vector<Location>;
  3216. locations->push_back(loc);
  3217. i += 3;
  3218. }
  3219. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3220. if (quest_step && icon > 0)
  3221. quest_step->SetIcon(icon);
  3222. if (quest->GetPlayer()) {
  3223. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3224. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3225. }
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3230. Quest* quest = lua_interface->GetQuest(state);
  3231. if (quest) {
  3232. int32 step = lua_interface->GetInt32Value(state, 2);
  3233. string description = lua_interface->GetStringValue(state, 3);
  3234. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3235. float percentage = lua_interface->GetFloatValue(state, 5);
  3236. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3237. int16 icon = lua_interface->GetInt16Value(state, 7);
  3238. const char* taskgroup = 0;
  3239. if (str_taskgroup.length() > 0)
  3240. taskgroup = str_taskgroup.c_str();
  3241. int32 spell_id = 0;
  3242. vector<int32>* ids = 0;
  3243. int i = 0;
  3244. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3245. if (ids == 0)
  3246. ids = new vector<int32>;
  3247. ids->push_back(spell_id);
  3248. i++;
  3249. }
  3250. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3251. if (quest_step && icon > 0 && quantity > 0)
  3252. quest_step->SetIcon(icon);
  3253. if (quest->GetPlayer()) {
  3254. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3255. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3256. }
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3261. if (!lua_interface)
  3262. return 0;
  3263. Quest* quest = lua_interface->GetQuest(state);
  3264. if (quest) {
  3265. int32 step = lua_interface->GetInt32Value(state, 2);
  3266. string description = lua_interface->GetStringValue(state, 3);
  3267. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3268. float percentage = lua_interface->GetFloatValue(state, 5);
  3269. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3270. int16 icon = lua_interface->GetInt16Value(state, 7);
  3271. const char* taskgroup = 0;
  3272. if (str_taskgroup.length() > 0)
  3273. taskgroup = str_taskgroup.c_str();
  3274. int32 item_id = 0;
  3275. vector<int32>* ids = 0;
  3276. int i = 0;
  3277. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3278. if (ids == 0)
  3279. ids = new vector<int32>;
  3280. ids->push_back(item_id);
  3281. i++;
  3282. }
  3283. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3284. if (quest_step && icon > 0 && quantity > 0)
  3285. quest_step->SetIcon(icon);
  3286. if (quest->GetPlayer()) {
  3287. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3288. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3289. }
  3290. }
  3291. return 0;
  3292. }
  3293. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3294. if (!lua_interface)
  3295. return 0;
  3296. Quest* quest = lua_interface->GetQuest(state);
  3297. if (quest) {
  3298. int32 step = lua_interface->GetInt32Value(state, 2);
  3299. string description = lua_interface->GetStringValue(state, 3);
  3300. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3301. float percentage = lua_interface->GetFloatValue(state, 5);
  3302. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3303. int16 icon = lua_interface->GetInt16Value(state, 7);
  3304. const char* taskgroup = 0;
  3305. if (str_taskgroup.length() > 0)
  3306. taskgroup = str_taskgroup.c_str();
  3307. int32 item_id = 0;
  3308. vector<int32>* ids = 0;
  3309. int i = 0;
  3310. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3311. if (ids == 0)
  3312. ids = new vector<int32>;
  3313. ids->push_back(item_id);
  3314. i++;
  3315. }
  3316. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3317. if (quest_step && icon > 0 && quantity > 0)
  3318. quest_step->SetIcon(icon);
  3319. if (quest->GetPlayer()) {
  3320. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3321. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3322. }
  3323. }
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Quest* quest = lua_interface->GetQuest(state);
  3330. if (quest) {
  3331. string action = lua_interface->GetStringValue(state, 2);
  3332. if (action.length() > 0)
  3333. quest->SetCompleteAction(action);
  3334. }
  3335. return 0;
  3336. }
  3337. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3338. if (!lua_interface)
  3339. return 0;
  3340. Quest* quest = lua_interface->GetQuest(state);
  3341. if (quest) {
  3342. int32 step = lua_interface->GetInt32Value(state, 2);
  3343. string action = lua_interface->GetStringValue(state, 3);
  3344. if (step > 0 && action.length() > 0)
  3345. quest->AddCompleteAction(step, action);
  3346. }
  3347. return 0;
  3348. }
  3349. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3350. if (!lua_interface)
  3351. return 0;
  3352. Quest* quest = lua_interface->GetQuest(state);
  3353. if (quest) {
  3354. int32 step = lua_interface->GetInt32Value(state, 2);
  3355. string action = lua_interface->GetStringValue(state, 3);
  3356. if (step > 0 && action.length() > 0)
  3357. quest->AddProgressAction(step, action);
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. string description = lua_interface->GetStringValue(state, 2);
  3366. if (quest && description.length() > 0)
  3367. quest->SetDescription(description);
  3368. return 0;
  3369. }
  3370. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3371. if (!lua_interface)
  3372. return 0;
  3373. Quest* quest = lua_interface->GetQuest(state);
  3374. string description = lua_interface->GetStringValue(state, 2);
  3375. if (quest && description.length() > 0)
  3376. quest->SetCompletedDescription(description);
  3377. return 0;
  3378. }
  3379. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3380. if (!lua_interface)
  3381. return 0;
  3382. Quest* quest = lua_interface->GetQuest(state);
  3383. int32 step = lua_interface->GetInt32Value(state, 2);
  3384. string description = lua_interface->GetStringValue(state, 3);
  3385. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3386. if (quest && step > 0 && description.length() > 0) {
  3387. quest->SetTaskGroupDescription(step, description, display_bullets);
  3388. if (quest->GetPlayer()) {
  3389. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3390. if (client)
  3391. client->SendQuestUpdateStep(quest, step, false);
  3392. }
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3397. if (!lua_interface)
  3398. return 0;
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. int32 step = lua_interface->GetInt32Value(state, 2);
  3401. string description = lua_interface->GetStringValue(state, 3);
  3402. if (quest && step > 0 && description.length() > 0) {
  3403. quest->SetStepDescription(step, description);
  3404. if (quest->GetPlayer()) {
  3405. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3406. if (client)
  3407. client->SendQuestUpdateStepImmediately(quest, step);
  3408. }
  3409. }
  3410. return 0;
  3411. }
  3412. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3413. Quest* quest = lua_interface->GetQuest(state);
  3414. string zone = lua_interface->GetStringValue(state, 2);
  3415. if (quest && zone.length() > 0)
  3416. quest->SetZone(zone);
  3417. return 0;
  3418. }
  3419. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3420. if (!lua_interface)
  3421. return 0;
  3422. Quest* quest = lua_interface->GetQuest(state);
  3423. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3424. int32 coin = lua_interface->GetInt32Value(state, 3);
  3425. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3426. string rewards_str = lua_interface->GetStringValue(state, 5);
  3427. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3428. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3429. string text = lua_interface->GetStringValue(state, 8);
  3430. int32 source_id = 0;
  3431. if (quest)
  3432. source_id = quest->GetQuestID();
  3433. if (playerSpawn && playerSpawn->IsPlayer()) {
  3434. Player* player = (Player*)playerSpawn;
  3435. Client* client = player->GetZone()->GetClientBySpawn(player);
  3436. if (client) {
  3437. vector<Item*> reward_items;
  3438. vector<Item*> selectable_reward_items;
  3439. if (rewards_str.length() > 0) {
  3440. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3441. map<unsigned int, unsigned short>::iterator itr;
  3442. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3443. if (itr->first > 0) {
  3444. Item* item = new Item(master_item_list.GetItem(itr->first));
  3445. if (item) {
  3446. if (itr->second > 0)
  3447. item->stack_count = itr->second;
  3448. reward_items.push_back(item);
  3449. }
  3450. }
  3451. }
  3452. }
  3453. if (select_rewards_str.length() > 0) {
  3454. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3455. map<unsigned int, unsigned short>::iterator itr;
  3456. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3457. if (itr->first > 0) {
  3458. Item* item = new Item(master_item_list.GetItem(itr->first));
  3459. if (item) {
  3460. if (itr->second > 0)
  3461. item->stack_count = itr->second;
  3462. selectable_reward_items.push_back(item);
  3463. }
  3464. }
  3465. }
  3466. }
  3467. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3468. const char* reward_type = "Quest Reward!";
  3469. if (!quest)
  3470. reward_type = "Reward!";
  3471. client->DisplayQuestRewards(0, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3472. }
  3473. }
  3474. /*PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", client->GetVersion());
  3475. if (packet2) {
  3476. player->AddCoins(coin);
  3477. client->PlaySound("coin_cha_ching");
  3478. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  3479. if(quest)
  3480. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  3481. else
  3482. packet2->setSubstructDataByName("reward_data", "reward", "Reward!");
  3483. packet2->setSubstructDataByName("reward_data", "coin", coin);
  3484. if (player->GetGuild()) {
  3485. player->GetInfoStruct()->status_points += status_points;
  3486. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  3487. }
  3488. if (rewards_str.length() > 0) {
  3489. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3490. vector<Item*> reward_items;
  3491. map<unsigned int, unsigned short>::iterator itr;
  3492. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3493. if (itr->first > 0) {
  3494. Item* item = new Item(master_item_list.GetItem(itr->first));
  3495. if (item) {
  3496. if (itr->second > 0)
  3497. item->stack_count = itr->second;
  3498. reward_items.push_back(item);
  3499. }
  3500. }
  3501. }
  3502. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", reward_items.size());
  3503. for (int i = 0; i < reward_items.size(); i++) {
  3504. Item* item = reward_items[i];
  3505. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  3506. packet2->setItemArrayDataByName("item", item, client->GetPlayer(), i, 0, -1);
  3507. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  3508. }
  3509. }
  3510. if (select_rewards_str.length() > 0) {
  3511. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3512. vector<Item*> reward_items;
  3513. map<unsigned int, unsigned short>::iterator itr;
  3514. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3515. if (itr->first > 0) {
  3516. Item* item = new Item(master_item_list.GetItem(itr->first));
  3517. if (item) {
  3518. if (itr->second > 0)
  3519. item->stack_count = itr->second;
  3520. reward_items.push_back(item);
  3521. }
  3522. }
  3523. }
  3524. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", reward_items.size());
  3525. for (int i = 0; i < reward_items.size(); i++) {
  3526. Item* item = reward_items[i];
  3527. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  3528. packet2->setItemArrayDataByName("select_item", item, client->GetPlayer(), i, 0, -1);
  3529. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  3530. }
  3531. }
  3532. if (factions_map_str.length() > 0) {
  3533. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3534. map<unsigned int, signed int>::iterator itr;
  3535. map<Faction*, signed int> factions;
  3536. for (itr = faction_rewards.begin(); itr != faction_rewards.end(); itr++) {
  3537. Faction* faction = master_faction_list.GetFaction(itr->first);
  3538. if (faction)
  3539. factions[faction] = itr->second;
  3540. }
  3541. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions.size());
  3542. map<Faction*, signed int>::iterator faction_itr;
  3543. int8 i = 0;
  3544. for (faction_itr = factions.begin(); faction_itr != factions.end(); faction_itr++) {
  3545. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  3546. sint32 amount = faction_itr->second;
  3547. packet2->setArrayDataByName("amount", amount, i);
  3548. if (amount > 0)
  3549. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  3550. else
  3551. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  3552. i++;
  3553. }
  3554. }
  3555. client->QueuePacket(packet2->serialize());
  3556. safe_delete(packet2);
  3557. }*/
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3565. if (quest && spawn) {
  3566. if (spawn->IsPlayer()) {
  3567. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3568. if (client)
  3569. client->AddPendingQuestReward(quest);
  3570. }
  3571. }
  3572. return 0;
  3573. }
  3574. int EQ2Emu_lua_Harvest(lua_State* state) {
  3575. if (!lua_interface)
  3576. return 0;
  3577. Spawn* player = lua_interface->GetSpawn(state);
  3578. Spawn* node = lua_interface->GetSpawn(state, 2);
  3579. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3580. Client* client = player->GetZone()->GetClientBySpawn(player);
  3581. if (client) {
  3582. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3583. ((GroundSpawn*)node)->ProcessHarvest(client);
  3584. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3585. player->GetZone()->RemoveSpawn(true, node, true);
  3586. }
  3587. }
  3588. else if (player && player->IsPlayer()) {
  3589. Client* client = player->GetZone()->GetClientBySpawn(player);
  3590. if (client)
  3591. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3592. }
  3593. return 0;
  3594. }
  3595. int EQ2Emu_lua_Bind(lua_State* state) {
  3596. if (!lua_interface)
  3597. return 0;
  3598. Spawn* spawn = lua_interface->GetSpawn(state);
  3599. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3600. float x = lua_interface->GetFloatValue(state, 3);
  3601. float y = lua_interface->GetFloatValue(state, 4);
  3602. float z = lua_interface->GetFloatValue(state, 5);
  3603. float h = lua_interface->GetFloatValue(state, 6);
  3604. if (!spawn) {
  3605. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3606. return 0;
  3607. }
  3608. if (!spawn->IsPlayer()) {
  3609. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3610. return 0;
  3611. }
  3612. if (zone_id == 0) {
  3613. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3614. if (!client) {
  3615. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3616. return 0;
  3617. }
  3618. if (!client->Bind())
  3619. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3620. }
  3621. else {
  3622. Player* player = (Player*)spawn;
  3623. player->GetPlayerInfo()->SetBindZone(zone_id);
  3624. player->GetPlayerInfo()->SetBindX(x);
  3625. player->GetPlayerInfo()->SetBindY(y);
  3626. player->GetPlayerInfo()->SetBindZ(z);
  3627. player->GetPlayerInfo()->SetBindHeading(h);
  3628. }
  3629. return 0;
  3630. }
  3631. int EQ2Emu_lua_Gate(lua_State* state) {
  3632. if (!lua_interface)
  3633. return 0;
  3634. Spawn* spawn = lua_interface->GetSpawn(state);
  3635. if (spawn) {
  3636. if (spawn->IsPlayer()) {
  3637. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3638. if (client) {
  3639. if (!client->Gate())
  3640. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3641. }
  3642. }
  3643. }
  3644. return 0;
  3645. }
  3646. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3647. if (!lua_interface)
  3648. return 0;
  3649. bool ret = false;
  3650. Spawn* spawn = lua_interface->GetSpawn(state);
  3651. if (spawn) {
  3652. if (spawn->IsPlayer()) {
  3653. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3654. if (client)
  3655. ret = client->BindAllowed();
  3656. }
  3657. }
  3658. lua_interface->SetBooleanValue(state, ret);
  3659. return 1;
  3660. }
  3661. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3662. if (!lua_interface)
  3663. return 0;
  3664. bool ret = false;
  3665. Spawn* spawn = lua_interface->GetSpawn(state);
  3666. if (spawn) {
  3667. if (spawn->IsPlayer()) {
  3668. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3669. if (client)
  3670. ret = client->GateAllowed();
  3671. }
  3672. }
  3673. lua_interface->SetBooleanValue(state, ret);
  3674. return 1;
  3675. }
  3676. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3677. Spawn* spawn = lua_interface->GetSpawn(state);
  3678. if (spawn) {
  3679. lua_interface->SetBooleanValue(state, spawn->Alive());
  3680. return 1;
  3681. }
  3682. return 0;
  3683. }
  3684. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3685. if (!lua_interface)
  3686. return 0;
  3687. Spawn* spawn = lua_interface->GetSpawn(state);
  3688. if (spawn && spawn->IsEntity()) {
  3689. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3690. return 1;
  3691. }
  3692. return 0;
  3693. }
  3694. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3695. Spawn* spawn = lua_interface->GetSpawn(state);
  3696. string message = lua_interface->GetStringValue(state, 2);
  3697. string color_str = lua_interface->GetStringValue(state, 3);
  3698. int8 color = CHANNEL_NARRATIVE;
  3699. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3700. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3701. if (client) {
  3702. if (color_str.length() > 0) {
  3703. // leave for backwards compat, but all future should just use the number
  3704. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3705. color = CHANNEL_COLOR_RED;
  3706. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3707. color = CHANNEL_COLOR_YELLOW;
  3708. else
  3709. {
  3710. // use a number to specify the channel as per Commands/Commands.h defines
  3711. color = (int8)atoul(color_str.c_str());
  3712. }
  3713. }
  3714. client->SimpleMessage(color, message.c_str());
  3715. }
  3716. }
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3720. Spawn* spawn = lua_interface->GetSpawn(state);
  3721. string message = lua_interface->GetStringValue(state, 2);
  3722. int8 red = lua_interface->GetInt8Value(state, 3);
  3723. int8 green = lua_interface->GetInt8Value(state, 4);
  3724. int8 blue = lua_interface->GetInt8Value(state, 5);
  3725. if (!spawn) {
  3726. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3727. return 0;
  3728. }
  3729. int32 words = ::CountWordsInString(message.c_str());
  3730. if (words < 5)
  3731. words = 5;
  3732. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3733. if (client)
  3734. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3735. return 0;
  3736. }
  3737. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3738. Spawn* spawn = lua_interface->GetSpawn(state);
  3739. int8 param = lua_interface->GetInt8Value(state, 2);
  3740. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3741. int8 value = lua_interface->GetInt8Value(state, 4);
  3742. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3743. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3744. if (client) {
  3745. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3746. switch (param) {
  3747. case 1: {
  3748. packet->setDataByName("parameter1", param_value);
  3749. break;
  3750. }
  3751. case 2: {
  3752. packet->setDataByName("parameter2", param_value);
  3753. break;
  3754. }
  3755. case 3: {
  3756. packet->setDataByName("parameter3", param_value);
  3757. break;
  3758. }
  3759. case 4: {
  3760. packet->setDataByName("parameter4", param_value);
  3761. break;
  3762. }
  3763. case 5: {
  3764. packet->setDataByName("parameter5", param_value);
  3765. break;
  3766. }
  3767. }
  3768. packet->setDataByName("value", value);
  3769. client->QueuePacket(packet->serialize());
  3770. safe_delete(packet);
  3771. }
  3772. }
  3773. return 0;
  3774. }
  3775. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3776. Spawn* spawn = lua_interface->GetSpawn(state);
  3777. if (spawn && spawn->IsPlayer()) {
  3778. if (((Player*)spawn)->GetIsTracking())
  3779. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3780. else
  3781. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3782. }
  3783. return 0;
  3784. }
  3785. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3786. Spawn* player = lua_interface->GetSpawn(state);
  3787. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3788. string name = lua_interface->GetStringValue(state, 3);
  3789. float distance = lua_interface->GetFloatValue(state, 4);
  3790. string command = lua_interface->GetStringValue(state, 5);
  3791. string error_text = lua_interface->GetStringValue(state, 6);
  3792. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3793. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3794. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3795. if (spawn) {
  3796. if (distance == 0)
  3797. distance = 10.0f;
  3798. if (command.length() == 0)
  3799. command = name;
  3800. if (command.length() < 1 && name.length() < 1)
  3801. {
  3802. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3803. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3804. spawn->RemovePrimaryCommands();
  3805. }
  3806. else
  3807. {
  3808. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3809. }
  3810. }
  3811. return 0;
  3812. }
  3813. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3814. if (!lua_interface)
  3815. return 0;
  3816. Spawn* player = lua_interface->GetSpawn(state);
  3817. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3818. int16 tier = lua_interface->GetInt16Value(state, 3);
  3819. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3820. if (player && spell && player->IsPlayer()) {
  3821. Client* client = player->GetZone()->GetClientBySpawn(player);
  3822. if (client) {
  3823. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3824. {
  3825. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3826. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3827. client->GetPlayer()->UnlockSpell(spell);
  3828. client->SendSpellUpdate(spell);
  3829. }
  3830. else
  3831. {
  3832. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3833. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3834. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3835. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3836. client->GetPlayer()->UnlockSpell(spell);
  3837. client->SendSpellUpdate(spell);
  3838. }
  3839. //if (client ) {
  3840. // ((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);
  3841. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3842. if (outapp)
  3843. client->QueuePacket(outapp);
  3844. }
  3845. }
  3846. return 0;
  3847. }
  3848. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3849. if (!lua_interface)
  3850. return 0;
  3851. Spawn* player = lua_interface->GetSpawn(state);
  3852. if (player && player->IsPlayer()) {
  3853. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3854. return 1;
  3855. }
  3856. return 0;
  3857. }
  3858. int EQ2Emu_lua_Attack(lua_State* state) {
  3859. if (lua_interface) {
  3860. Spawn* npc = lua_interface->GetSpawn(state);
  3861. Spawn* player = lua_interface->GetSpawn(state, 2);
  3862. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3863. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3864. }
  3865. return 0;
  3866. }
  3867. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3868. if (lua_interface) {
  3869. Spawn* target = lua_interface->GetSpawn(state);
  3870. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3871. if (target && target->GetZone())
  3872. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3873. }
  3874. return 0;
  3875. }
  3876. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3877. Spawn* player;
  3878. if (lua_interface) {
  3879. player = lua_interface->GetSpawn(state);
  3880. if (player && player->IsPlayer()) {
  3881. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3882. return 1;
  3883. }
  3884. }
  3885. return 0;
  3886. }
  3887. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3888. Spawn* player;
  3889. Client* client;
  3890. if (lua_interface) {
  3891. player = lua_interface->GetSpawn(state);
  3892. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3893. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3894. client->HandInCollections();
  3895. }
  3896. return 0;
  3897. }
  3898. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3899. Spawn* widget;
  3900. if (lua_interface) {
  3901. widget = lua_interface->GetSpawn(state);
  3902. if (widget && widget->IsWidget())
  3903. ((Widget*)widget)->HandleUse(NULL, "");
  3904. }
  3905. return 0;
  3906. }
  3907. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3908. Spawn* spawn = 0;
  3909. int32 primary_list = 0;
  3910. int32 secondary_list = 0;
  3911. if (lua_interface) {
  3912. spawn = lua_interface->GetSpawn(state);
  3913. primary_list = lua_interface->GetInt32Value(state, 2);
  3914. secondary_list = lua_interface->GetInt32Value(state, 3);
  3915. if (!spawn->IsNPC()) {
  3916. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3917. return 0;
  3918. }
  3919. NPC* npc = (NPC*)spawn;
  3920. npc->SetPrimarySpellList(primary_list);
  3921. npc->SetSecondarySpellList(secondary_list);
  3922. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3923. }
  3924. return 0;
  3925. }
  3926. int EQ2Emu_lua_GetPet(lua_State* state) {
  3927. if (!lua_interface)
  3928. return 0;
  3929. Spawn* spawn = lua_interface->GetSpawn(state);
  3930. if (spawn) {
  3931. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3932. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3933. return 1;
  3934. }
  3935. }
  3936. return 0;
  3937. }
  3938. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3939. if (!lua_interface)
  3940. return 0;
  3941. Spawn* spawn = lua_interface->GetSpawn(state);
  3942. if (spawn) {
  3943. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3944. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3945. return 1;
  3946. }
  3947. }
  3948. return 0;
  3949. }
  3950. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3951. if (!lua_interface)
  3952. return 0;
  3953. Spawn* spawn = lua_interface->GetSpawn(state);
  3954. if (spawn) {
  3955. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3956. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3957. return 1;
  3958. }
  3959. }
  3960. return 0;
  3961. }
  3962. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3963. if (!lua_interface)
  3964. return 0;
  3965. Spawn* spawn = lua_interface->GetSpawn(state);
  3966. if (spawn) {
  3967. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3968. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3969. return 1;
  3970. }
  3971. }
  3972. return 0;
  3973. }
  3974. int EQ2Emu_lua_Charm(lua_State* state) {
  3975. if (!lua_interface)
  3976. return 0;
  3977. Spawn* owner = lua_interface->GetSpawn(state);
  3978. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3979. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3980. if (!luaspell) {
  3981. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  3982. return 0;
  3983. }
  3984. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3985. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3986. pet->SetPet(true);
  3987. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3988. ((NPC*)pet)->SetOwner((Entity*)owner);
  3989. // If owner is player and player does not have a summoned pet set the players charsheet
  3990. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3991. Player* player = (Player*)owner;
  3992. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3993. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3994. player->GetInfoStruct()->pet_movement = 2;
  3995. player->GetInfoStruct()->pet_behavior = 3;
  3996. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3997. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3998. // Make sure the values get sent to the client
  3999. player->SetCharSheetChanged(true);
  4000. }
  4001. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4002. pet->SetSpawnScript("");
  4003. // Set faction to the same as the owner
  4004. pet->SetFactionID(owner->GetFactionID());
  4005. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4006. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4007. // Clear hate list
  4008. ((NPC*)pet)->Brain()->ClearHate();
  4009. // Set the brain to a pet brain
  4010. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4011. }
  4012. return 0;
  4013. }
  4014. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4015. if (!lua_interface)
  4016. return 0;
  4017. Spawn* spawn = lua_interface->GetSpawn(state);
  4018. if (!spawn) {
  4019. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4020. return 0;
  4021. }
  4022. vector<Spawn*> groupMembers;
  4023. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4024. groupMembers = *spawn->GetSpawnGroup();
  4025. }
  4026. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4027. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4028. deque<GroupMemberInfo*>::iterator itr;
  4029. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4030. if (group)
  4031. {
  4032. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4033. deque<GroupMemberInfo*>* members = group->GetMembers();
  4034. GroupMemberInfo* info = 0;
  4035. for (itr = members->begin(); itr != members->end(); itr++) {
  4036. info = *itr;
  4037. if (info->client)
  4038. groupMembers.push_back(info->client->GetPlayer());
  4039. }
  4040. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4041. }
  4042. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4043. }
  4044. else
  4045. return 0;
  4046. lua_createtable(state, groupMembers.size(), 0);
  4047. int newTable = lua_gettop(state);
  4048. for (int32 i = 0; i < groupMembers.size(); i++) {
  4049. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4050. lua_rawseti(state, newTable, i + 1);
  4051. }
  4052. return 1;
  4053. }
  4054. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4055. if (!lua_interface)
  4056. return 0;
  4057. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4058. lua_interface->SetOptionWindowValue(state, option_window);
  4059. return 1;
  4060. }
  4061. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4065. if (option_window) {
  4066. OptionWindowOption option_window_option;
  4067. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4068. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4069. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4070. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4071. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4072. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4073. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4074. option_window->push_back(option_window_option);
  4075. }
  4076. return 0;
  4077. }
  4078. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4079. if (!lua_interface)
  4080. return 0;
  4081. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4082. Spawn* player = lua_interface->GetSpawn(state, 2);
  4083. string window_title = lua_interface->GetStringValue(state, 3);
  4084. string cancel_command = lua_interface->GetStringValue(state, 4);
  4085. Client* client = player->GetZone()->GetClientBySpawn(player);
  4086. if (option_window && window_title.length() > 0 && client) {
  4087. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4088. if (!packet)
  4089. return 0;
  4090. packet->setDataByName("title_text", window_title.c_str());
  4091. if (cancel_command.length() > 0)
  4092. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4093. packet->setArrayLengthByName("num_selections", option_window->size());
  4094. vector<OptionWindowOption>::iterator itr;
  4095. int8 i = 0;
  4096. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4097. OptionWindowOption opt = *itr;
  4098. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4099. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4100. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4101. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4102. if (opt.optionCommand.length() > 0)
  4103. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4104. if (opt.optionConfirmTitle.length() > 0)
  4105. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4106. i++;
  4107. }
  4108. client->QueuePacket(packet->serialize());
  4109. safe_delete(option_window);
  4110. safe_delete(packet);
  4111. }
  4112. return 0;
  4113. }
  4114. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4115. if (!lua_interface)
  4116. return 0;
  4117. Spawn* spawn = lua_interface->GetSpawn(state);
  4118. if (spawn) {
  4119. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4120. return 1;
  4121. }
  4122. else
  4123. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4124. return 0;
  4125. }
  4126. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4127. if (!lua_interface)
  4128. return 0;
  4129. Spawn* spawn = lua_interface->GetSpawn(state);
  4130. if (spawn) {
  4131. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4132. return 1;
  4133. }
  4134. else
  4135. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4136. return 0;
  4137. }
  4138. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4139. if (!lua_interface)
  4140. return 0;
  4141. Spawn* spawn = lua_interface->GetSpawn(state);
  4142. if (spawn) {
  4143. int8 class_id = spawn->GetTradeskillClass();
  4144. // Need to add 42 for the offset in the array
  4145. class_id += 44;
  4146. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4147. return 1;
  4148. }
  4149. else
  4150. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4151. return 0;
  4152. }
  4153. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4154. if (!lua_interface)
  4155. return 0;
  4156. Spawn* spawn = lua_interface->GetSpawn(state);
  4157. int16 level = lua_interface->GetInt8Value(state, 2);
  4158. if (spawn) {
  4159. if (spawn->IsPlayer())
  4160. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4161. else
  4162. spawn->SetTSLevel(level);
  4163. }
  4164. else
  4165. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. Spawn* spawn = lua_interface->GetSpawn(state);
  4172. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4173. if (spawn) {
  4174. spawn->SetAttackable(attackable);
  4175. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4180. // Check to see if we have a valid lua_interface
  4181. if (!lua_interface)
  4182. return 0;
  4183. // Get the spawn that is getting the pet
  4184. Spawn* spawn = lua_interface->GetSpawn(state);
  4185. // Get the DB ID of the pet
  4186. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4187. // The max level the pet can gain
  4188. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4189. // Get the spell that this command was called from
  4190. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4191. // Check to make sure the spawn pointer is valid
  4192. if (!spawn) {
  4193. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4194. return 0;
  4195. }
  4196. // Check to make sure the spawn is an entity
  4197. if (!spawn->IsEntity()) {
  4198. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4199. return 0;
  4200. }
  4201. // Check to make sure the spawn doesn't already have a pet of this type
  4202. if (((Entity*)spawn)->GetPet()) {
  4203. if (spawn->IsPlayer()) {
  4204. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4205. if (client)
  4206. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4207. }
  4208. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4209. return 0;
  4210. }
  4211. // Check to see if the DB ID for the pet is set
  4212. if (pet_id == 0) {
  4213. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4214. return 0;
  4215. }
  4216. // Check to see if the pointer to the spell is valid
  4217. if (!luaspell) {
  4218. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4219. return 0;
  4220. }
  4221. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4222. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4223. if (!pet) {
  4224. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4225. return 0;
  4226. }
  4227. // Check to make sure the pet is an npc
  4228. if (!pet->IsNPC()) {
  4229. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4230. return 0;
  4231. }
  4232. // Spawn the pet at the same location as the owner
  4233. pet->SetX(spawn->GetX());
  4234. pet->SetY(spawn->GetY());
  4235. pet->SetZ(spawn->GetZ());
  4236. pet->SetLocation(spawn->GetLocation());
  4237. pet->SetHeading(spawn->GetHeading());
  4238. spawn->GetZone()->AddSpawn(pet);
  4239. /*
  4240. const char* spawn_script = world.GetSpawnScript(pet_id);
  4241. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4242. spawn->SetSpawnScript(string(spawn_script));
  4243. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4244. }*/
  4245. // Get a random pet name
  4246. string random_pet_name;
  4247. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4248. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4249. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4250. // If player set various values for the char sheet (pet window)
  4251. if (spawn->IsPlayer()) {
  4252. Player* player = (Player*)spawn;
  4253. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4254. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4255. player->GetInfoStruct()->pet_movement = 2;
  4256. player->GetInfoStruct()->pet_behavior = 3;
  4257. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4258. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4259. // Make sure the values get sent to the client
  4260. player->SetCharSheetChanged(true);
  4261. }
  4262. // Set the pets name
  4263. pet->SetName(random_pet_name.c_str());
  4264. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4265. if (max_level > 0)
  4266. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4267. else
  4268. pet->SetLevel(spawn->GetLevel());
  4269. // Set the max level this pet can reach
  4270. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4271. // Set the faction of the pet to the same faction as the owner
  4272. pet->SetFactionID(spawn->GetFactionID());
  4273. // Set the spawn as a pet
  4274. pet->SetPet(true);
  4275. // Give a pointer of the owner to the pet
  4276. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4277. // Give a pointer of the pet to the owner
  4278. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4279. // Set the pet type
  4280. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4281. // Set the spell id used to create this pet
  4282. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4283. // Set the spell tier used to create this pet
  4284. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4285. // Set the pets spawn type to 6
  4286. pet->SetSpawnType(6);
  4287. // Set the pets brain
  4288. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4289. // Check to see if the pet has a subtitle
  4290. if (strlen(pet->GetSubTitle()) > 0) {
  4291. // Add the players name to the front of the sub title
  4292. string pet_subtitle;
  4293. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4294. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4295. // Set the pets subtitle to the new one
  4296. pet->SetSubTitle(pet_subtitle.c_str());
  4297. }
  4298. // Add the "Pet Options" entity command to the pet
  4299. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4300. // Set the pet as the return value for this function
  4301. lua_interface->SetSpawnValue(state, pet);
  4302. return 1;
  4303. }
  4304. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4305. if (!lua_interface)
  4306. return 0;
  4307. Spawn* spawn = lua_interface->GetSpawn(state);
  4308. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4309. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4310. if (!spawn) {
  4311. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4312. return 0;
  4313. }
  4314. if (!spawn->IsEntity()) {
  4315. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4316. return 0;
  4317. }
  4318. if (((Entity*)spawn)->GetDeityPet()) {
  4319. if (spawn->IsPlayer()) {
  4320. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4321. if (client)
  4322. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4323. }
  4324. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4325. return 0;
  4326. }
  4327. if (pet_id == 0) {
  4328. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4329. return 0;
  4330. }
  4331. if (!luaspell) {
  4332. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4333. return 0;
  4334. }
  4335. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4336. if (!pet) {
  4337. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4338. return 0;
  4339. }
  4340. if (!pet->IsNPC()) {
  4341. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4342. return 0;
  4343. }
  4344. pet->SetX(spawn->GetX());
  4345. pet->SetY(spawn->GetY());
  4346. pet->SetZ(spawn->GetZ());
  4347. pet->SetLocation(spawn->GetLocation());
  4348. pet->SetHeading(spawn->GetHeading());
  4349. spawn->GetZone()->AddSpawn(pet);
  4350. string random_pet_name;
  4351. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4352. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4353. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4354. pet->SetName(random_pet_name.c_str());
  4355. pet->SetLevel(spawn->GetLevel());
  4356. pet->SetFactionID(spawn->GetFactionID());
  4357. pet->SetPet(true);
  4358. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4359. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4360. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4361. pet->SetSpawnType(6);
  4362. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4363. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4364. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4365. if (strlen(pet->GetSubTitle()) > 0) {
  4366. string pet_subtitle;
  4367. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4368. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4369. pet->SetSubTitle(pet_subtitle.c_str());
  4370. }
  4371. // deity and cosmetic pets are not attackable
  4372. pet->SetAttackable(false);
  4373. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4374. lua_interface->SetSpawnValue(state, pet);
  4375. return 1;
  4376. }
  4377. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4378. if (!lua_interface)
  4379. return 0;
  4380. Spawn* spawn = lua_interface->GetSpawn(state);
  4381. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4382. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4383. if (!spawn) {
  4384. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4385. return 0;
  4386. }
  4387. if (!spawn->IsEntity()) {
  4388. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4389. return 0;
  4390. }
  4391. if (((Entity*)spawn)->GetCosmeticPet()) {
  4392. if (spawn->IsPlayer()) {
  4393. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4394. if (client)
  4395. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4396. }
  4397. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4398. return 0;
  4399. }
  4400. if (pet_id == 0) {
  4401. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4402. return 0;
  4403. }
  4404. if (!luaspell) {
  4405. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4406. return 0;
  4407. }
  4408. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4409. if (!pet) {
  4410. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4411. return 0;
  4412. }
  4413. if (!pet->IsNPC()) {
  4414. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4415. return 0;
  4416. }
  4417. pet->SetX(spawn->GetX());
  4418. pet->SetY(spawn->GetY());
  4419. pet->SetZ(spawn->GetZ());
  4420. pet->SetLocation(spawn->GetLocation());
  4421. pet->SetHeading(spawn->GetHeading());
  4422. spawn->GetZone()->AddSpawn(pet);
  4423. string random_pet_name;
  4424. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4425. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4426. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4427. pet->SetName(random_pet_name.c_str());
  4428. pet->SetLevel(spawn->GetLevel());
  4429. pet->SetFactionID(spawn->GetFactionID());
  4430. pet->SetPet(true);
  4431. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4432. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4433. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4434. pet->SetSpawnType(6);
  4435. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4436. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4437. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4438. if (strlen(pet->GetSubTitle()) > 0) {
  4439. string pet_subtitle;
  4440. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4441. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4442. pet->SetSubTitle(pet_subtitle.c_str());
  4443. }
  4444. pet->SetAttackable(false);
  4445. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4446. lua_interface->SetSpawnValue(state, pet);
  4447. return 1;
  4448. }
  4449. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4450. if (!lua_interface)
  4451. return 0;
  4452. Spawn* spawn = lua_interface->GetSpawn(state);
  4453. if (!spawn) {
  4454. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4455. return 0;
  4456. }
  4457. if (!spawn->IsPet()) {
  4458. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4459. return 0;
  4460. }
  4461. if (!((NPC*)spawn)->IsDismissing())
  4462. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4466. if (!lua_interface)
  4467. return 0;
  4468. Quest* quest = lua_interface->GetQuest(state);
  4469. if (!quest) {
  4470. 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));
  4471. return 0;
  4472. }
  4473. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4474. if (feather_color > 0)
  4475. quest->SetFeatherColor(feather_color);
  4476. return 0;
  4477. }
  4478. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4483. if (!spawn) {
  4484. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4485. return 0;
  4486. }
  4487. if (!spawn2) {
  4488. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4489. return 0;
  4490. }
  4491. spawn->RemoveSpawnAccess(spawn2);
  4492. return 0;
  4493. }
  4494. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4495. if (!lua_interface)
  4496. return 0;
  4497. ZoneServer* zone = lua_interface->GetZone(state);
  4498. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4499. if (!zone) {
  4500. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4501. return 0;
  4502. }
  4503. if (location_id == 0) {
  4504. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4505. return 0;
  4506. }
  4507. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4508. if (!location) {
  4509. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4510. return 0;
  4511. }
  4512. Spawn* spawn = 0;
  4513. if (location->entities[0]) {
  4514. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4515. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4516. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4517. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4518. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4519. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4520. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4521. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4522. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4523. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4524. if (spawn) {
  4525. const char* script = 0;
  4526. for (int x = 0; x < 3; x++) {
  4527. switch (x) {
  4528. case 0:
  4529. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4530. break;
  4531. case 1:
  4532. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4533. break;
  4534. case 2:
  4535. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4536. break;
  4537. }
  4538. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4539. spawn->SetSpawnScript(string(script));
  4540. break;
  4541. }
  4542. }
  4543. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4544. lua_interface->SetSpawnValue(state, spawn);
  4545. return 1;
  4546. }
  4547. else {
  4548. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4549. safe_delete(spawn);
  4550. }
  4551. }
  4552. return 0;
  4553. }
  4554. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4555. if (!lua_interface)
  4556. return 0;
  4557. Spawn* caster = lua_interface->GetSpawn(state);
  4558. Spawn* target = lua_interface->GetSpawn(state, 2);
  4559. int32 id = lua_interface->GetInt32Value(state, 3);
  4560. string command = lua_interface->GetStringValue(state, 4);
  4561. if (!caster) {
  4562. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4563. return 0;
  4564. }
  4565. if (!target) {
  4566. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4567. return 0;
  4568. }
  4569. if (!caster->IsPlayer()) {
  4570. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4571. return 0;
  4572. }
  4573. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4574. if (!entity_command) {
  4575. 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());
  4576. return 0;
  4577. }
  4578. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4579. if (!client) {
  4580. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4581. return 0;
  4582. }
  4583. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4584. return 0;
  4585. }
  4586. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4587. if (!lua_interface)
  4588. return 0;
  4589. Spawn* spawn = lua_interface->GetSpawn(state);
  4590. if (!spawn) {
  4591. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4592. return 0;
  4593. }
  4594. if (!spawn->IsNPC()) {
  4595. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4596. return 0;
  4597. }
  4598. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4599. return 0;
  4600. }
  4601. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4602. if (!lua_interface)
  4603. return 0;
  4604. Spawn* spawn = lua_interface->GetSpawn(state);
  4605. int16 tick = lua_interface->GetInt16Value(state, 2);
  4606. if (!spawn) {
  4607. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4608. return 0;
  4609. }
  4610. if (!spawn->IsNPC()) {
  4611. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4612. return 0;
  4613. }
  4614. if (tick < 20) {
  4615. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4616. return 0;
  4617. }
  4618. ((NPC*)spawn)->Brain()->SetTick(tick);
  4619. return 0;
  4620. }
  4621. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4622. if (!lua_interface)
  4623. return 0;
  4624. Spawn* spawn = lua_interface->GetSpawn(state);
  4625. Spawn* target = lua_interface->GetSpawn(state, 2);
  4626. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4627. if (!spawn) {
  4628. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4629. return 0;
  4630. }
  4631. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4632. spawn->SetFollowTarget(target, follow_distance);
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4636. if (!lua_interface)
  4637. return 0;
  4638. Spawn* spawn = lua_interface->GetSpawn(state);
  4639. if (!spawn) {
  4640. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4641. return 0;
  4642. }
  4643. Spawn* target = spawn->GetFollowTarget();
  4644. if (target) {
  4645. lua_interface->SetSpawnValue(state, target);
  4646. return 1;
  4647. }
  4648. return 0;
  4649. }
  4650. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4651. if (!lua_interface)
  4652. return 0;
  4653. Spawn* spawn = lua_interface->GetSpawn(state);
  4654. if (!spawn) {
  4655. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4656. return 0;
  4657. }
  4658. if (spawn->following)
  4659. spawn->following = false;
  4660. else
  4661. spawn->following = true;
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4665. if (!lua_interface)
  4666. return 0;
  4667. Spawn* spawn = lua_interface->GetSpawn(state);
  4668. if (!spawn) {
  4669. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. lua_interface->SetBooleanValue(state, spawn->following);
  4673. return 1;
  4674. }
  4675. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4676. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4677. // I will attempt to explain how this function works for future refrence
  4678. // Fist lets make sure lua_interface is valid, if not return out
  4679. if (!lua_interface)
  4680. return 0;
  4681. // Next we grab the first 2 params same as we usually would
  4682. Spawn* spawn = lua_interface->GetSpawn(state);
  4683. string var = lua_interface->GetStringValue(state, 2);
  4684. // 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
  4685. // 1 = Spawn
  4686. // 2 = Zone
  4687. // 3 = Item
  4688. // 4 = Quest
  4689. // 5 = String
  4690. // 6 = nil (null)
  4691. int8 dataType = 0;
  4692. // Define pointers for each potential type
  4693. Spawn* spawnVal = 0;
  4694. ZoneServer* zone = 0;
  4695. Item* item = 0;
  4696. Quest* quest = 0;
  4697. string val;
  4698. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4699. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4700. // options window are also light user data be we do not handle those.
  4701. // We check with lua_islightuserdata(lua_State*, index)
  4702. if (lua_islightuserdata(state, 3)) {
  4703. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4704. // and convert it to LUAUserData*
  4705. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4706. // Check to make sure the data we got is valid, if not give an error
  4707. if (!data || !data->IsCorrectlyInitialized()) {
  4708. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4709. }
  4710. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4711. else if (data->IsSpawn()) {
  4712. spawnVal = data->spawn;
  4713. dataType = 1;
  4714. }
  4715. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4716. else if (data->IsZone()) {
  4717. zone = data->zone;
  4718. dataType = 2;
  4719. }
  4720. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4721. else if (data->IsItem()) {
  4722. item = data->item;
  4723. dataType = 3;
  4724. }
  4725. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4726. else if (data->IsQuest()) {
  4727. quest = data->quest;
  4728. dataType = 4;
  4729. }
  4730. }
  4731. // Wasn't light user data, check if it is nil(null)
  4732. else if (lua_isnil(state, 3)) {
  4733. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4734. dataType = 6;
  4735. }
  4736. // Wasn't light user data or nil (null), must be a string
  4737. else {
  4738. // Set the string and dataType variable
  4739. val = lua_interface->GetStringValue(state, 3);
  4740. dataType = 5;
  4741. }
  4742. // We now have all the params, lets check to make sure they are valid
  4743. if (!spawn) {
  4744. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4745. return 0;
  4746. }
  4747. if (var.length() == 0) {
  4748. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4749. return 0;
  4750. }
  4751. if (dataType == 0) {
  4752. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4756. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4757. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4758. switch (dataType) {
  4759. case 1:
  4760. // 1 = Spawn
  4761. spawn->AddTempVariable(var, spawnVal);
  4762. break;
  4763. case 2:
  4764. // 2 = Zone
  4765. spawn->AddTempVariable(var, zone);
  4766. break;
  4767. case 3:
  4768. // 3 = Item
  4769. spawn->AddTempVariable(var, item);
  4770. break;
  4771. case 4:
  4772. // 4 = Quest
  4773. spawn->AddTempVariable(var, quest);
  4774. break;
  4775. case 5:
  4776. // 5 = String
  4777. spawn->AddTempVariable(var, val);
  4778. break;
  4779. case 6:
  4780. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4781. spawn->DeleteTempVariable(var);
  4782. break;
  4783. }
  4784. // And we are done so return out
  4785. return 0;
  4786. }
  4787. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4788. if (!lua_interface)
  4789. return 0;
  4790. Spawn* spawn = lua_interface->GetSpawn(state);
  4791. string var = lua_interface->GetStringValue(state, 2);
  4792. if (!spawn) {
  4793. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4794. return 0;
  4795. }
  4796. if (var.length() == 0) {
  4797. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4801. int8 type = spawn->GetTempVariableType(var);
  4802. Spawn* spawn2 = 0;
  4803. ZoneServer* zone = 0;
  4804. Item* item = 0;
  4805. Quest* quest = 0;
  4806. // Set the lua function return value based on the type of data the variable contains
  4807. switch (type) {
  4808. case 1:
  4809. spawn2 = spawn->GetTempVariableSpawn(var);
  4810. if (!spawn2)
  4811. return 0;
  4812. lua_interface->SetSpawnValue(state, spawn2);
  4813. break;
  4814. case 2:
  4815. zone = spawn->GetTempVariableZone(var);
  4816. if (!zone)
  4817. return 0;
  4818. lua_interface->SetZoneValue(state, zone);
  4819. break;
  4820. case 3:
  4821. item = spawn->GetTempVariableItem(var);
  4822. if (!item)
  4823. return 0;
  4824. lua_interface->SetItemValue(state, item);
  4825. break;
  4826. case 4:
  4827. quest = spawn->GetTempVariableQuest(var);
  4828. if (!quest)
  4829. return 0;
  4830. lua_interface->SetQuestValue(state, quest);
  4831. break;
  4832. case 5:
  4833. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4834. break;
  4835. default:
  4836. // Not a valid type then the variable was not set so return out
  4837. return 0;
  4838. }
  4839. // Return value was set so return out
  4840. return 1;
  4841. }
  4842. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4843. {
  4844. if (!lua_interface)
  4845. return 0;
  4846. Quest* quest = lua_interface->GetQuest(state);
  4847. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4848. string description = lua_interface->GetStringValue(state, 3);
  4849. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4850. if (!quest) {
  4851. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4852. lua_interface->SetBooleanValue(state, false);
  4853. return 1;
  4854. }
  4855. if (!spawn) {
  4856. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4857. lua_interface->SetBooleanValue(state, false);
  4858. return 1;
  4859. }
  4860. if (!spawn->IsPlayer()) {
  4861. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4862. lua_interface->SetBooleanValue(state, false);
  4863. return 1;
  4864. }
  4865. if (item_id == 0) {
  4866. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4867. lua_interface->SetBooleanValue(state, false);
  4868. return 1;
  4869. }
  4870. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4871. if (!client) {
  4872. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4873. lua_interface->SetBooleanValue(state, false);
  4874. return 1;
  4875. }
  4876. Item* item = master_item_list.GetItem(item_id);
  4877. if (!item) {
  4878. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4879. lua_interface->SetBooleanValue(state, false);
  4880. return 1;
  4881. }
  4882. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4883. if (packet) {
  4884. packet->setDataByName("title", "Quest Reward!");
  4885. packet->setDataByName("name", quest->GetName());
  4886. packet->setDataByName("description", description.c_str());
  4887. packet->setDataByName("level", quest->GetLevel());
  4888. packet->setArrayLengthByName("num_rewards", 1);
  4889. packet->setArrayDataByName("reward_id", item->details.item_id);
  4890. if (client->GetVersion() < 860)
  4891. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4892. else if (client->GetVersion() < 1193)
  4893. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4894. else
  4895. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4896. client->QueuePacket(packet->serialize());
  4897. safe_delete(packet);
  4898. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4899. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  4900. return 1;
  4901. }
  4902. lua_interface->SetBooleanValue(state, false);
  4903. return 1;
  4904. }
  4905. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4906. if (!lua_interface)
  4907. return 0;
  4908. Quest* quest = lua_interface->GetQuest(state);
  4909. if (!quest) {
  4910. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4911. return 0;
  4912. }
  4913. quest->SetRepeatable(true);
  4914. return 0;
  4915. }
  4916. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4917. if (!lua_interface)
  4918. return 0;
  4919. Spawn* spawn = lua_interface->GetSpawn(state);
  4920. if (!spawn) {
  4921. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4922. return 0;
  4923. }
  4924. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4925. string ret = classes.GetClassNameCase(base_class);
  4926. if (ret.length() > 0) {
  4927. lua_interface->SetStringValue(state, ret.c_str());
  4928. return 1;
  4929. }
  4930. return 0;
  4931. }
  4932. int EQ2Emu_lua_AddWard(lua_State* state) {
  4933. if (!lua_interface)
  4934. return 0;
  4935. int32 damage = lua_interface->GetInt32Value(state);
  4936. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4937. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4938. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4939. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  4940. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  4941. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  4942. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  4943. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4944. bool ward_was_added = false;
  4945. ZoneServer* zone = spell->caster->GetZone();
  4946. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4947. for (int32 i = 0; i < spell->targets.size(); i++) {
  4948. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4949. if (!target)
  4950. continue;
  4951. if (target->IsEntity()) {
  4952. // If the ward is already active remove it
  4953. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4954. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4955. // Create new ward info
  4956. WardInfo* ward = new WardInfo;
  4957. ward->Spell = spell;
  4958. ward->BaseDamage = damage;
  4959. ward->DamageLeft = damage;
  4960. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  4961. ward->keepWard = keepWard;
  4962. ward->WardType = wardType;
  4963. if (damageAbsorptionPercent > 100)
  4964. damageAbsorptionPercent = 100;
  4965. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  4966. if (damageAbsorptionMaxHealthPercent > 100)
  4967. damageAbsorptionMaxHealthPercent = 100;
  4968. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  4969. ward->RedirectDamagePercent = redirectDamagePercent;
  4970. ward->LastRedirectDamage = 0;
  4971. ward->LastAbsorbedDamage = 0;
  4972. ward->HitCount = 0;
  4973. spell->num_triggers = maxHitCount;
  4974. spell->had_triggers = true;
  4975. spell->cancel_after_all_triggers = false;
  4976. ward->MaxHitCount = maxHitCount;
  4977. if (wardType == WARD_TYPE_MAGICAL)
  4978. ward->DamageType = damageTypes;
  4979. // Add the ward to the entity
  4980. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4981. ward_was_added = true;
  4982. }
  4983. }
  4984. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4985. if (ward_was_added && spell->caster->IsPlayer()) {
  4986. spell->had_dmg_remaining = true;
  4987. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4988. }
  4989. return 0;
  4990. }
  4991. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4992. if (!lua_interface)
  4993. return 0;
  4994. int32 amount = lua_interface->GetInt32Value(state);
  4995. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4996. WardInfo* ward = 0;
  4997. ZoneServer* zone = spell->caster->GetZone();
  4998. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4999. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5000. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5001. ward = target->GetWard(spell->spell->GetSpellID());
  5002. if (ward) {
  5003. ward->DamageLeft += amount;
  5004. if (ward->DamageLeft > ward->BaseDamage)
  5005. ward->DamageLeft = ward->BaseDamage;
  5006. for (int32 i = 0; i < spell->targets.size(); i++) {
  5007. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5008. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5009. }
  5010. }
  5011. }
  5012. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5013. if (ward && spell->caster->IsPlayer())
  5014. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5015. return 0;
  5016. }
  5017. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5018. if (!lua_interface)
  5019. return 0;
  5020. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5021. if (!spell) {
  5022. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5026. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5027. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5028. if (ward) {
  5029. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5030. return 1;
  5031. }
  5032. }
  5033. return 0;
  5034. }
  5035. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5036. if (!lua_interface)
  5037. return 0;
  5038. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5039. if (!spell) {
  5040. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5041. return 0;
  5042. }
  5043. string type = lua_interface->GetStringValue(state, 2);
  5044. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5045. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5046. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5047. if (ward) {
  5048. if (boost::iequals(type, "damageleft"))
  5049. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5050. else if (boost::iequals(type, "basedamage"))
  5051. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5052. else if (boost::iequals(type, "keepward"))
  5053. lua_interface->SetBooleanValue(state, ward->keepWard);
  5054. else if (boost::iequals(type, "wardtype"))
  5055. lua_interface->SetInt32Value(state, ward->WardType);
  5056. else if (boost::iequals(type, "dmgabsorptionpct"))
  5057. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5058. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5059. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5060. else if (boost::iequals(type, "redirectdamagepercent"))
  5061. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5062. else if (boost::iequals(type, "lastredirectdamage"))
  5063. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5064. else if (boost::iequals(type, "lastabsorbeddamage"))
  5065. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5066. else if (boost::iequals(type, "hitcount"))
  5067. lua_interface->SetInt32Value(state, ward->HitCount);
  5068. else if (boost::iequals(type, "maxhitcount"))
  5069. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5070. else
  5071. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5072. return 1;
  5073. }
  5074. }
  5075. return 0;
  5076. }
  5077. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5078. if (!lua_interface)
  5079. return 0;
  5080. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5081. ZoneServer* zone = spell->caster->GetZone();
  5082. Spawn* target = 0;
  5083. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5084. for (int32 i = 0; i < spell->targets.size(); i++) {
  5085. target = zone->GetSpawnByID(spell->targets.at(i));
  5086. if (target && target->IsEntity()) {
  5087. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5088. }
  5089. }
  5090. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5091. return 0;
  5092. }
  5093. int EQ2Emu_lua_Interrupt(lua_State* state)
  5094. {
  5095. if (!lua_interface)
  5096. return 0;
  5097. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5098. Spawn* target = lua_interface->GetSpawn(state, 2);
  5099. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5100. if (!caster)
  5101. {
  5102. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5103. return 0;
  5104. }
  5105. if (!target)
  5106. {
  5107. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5108. return 0;
  5109. }
  5110. if (!spell) {
  5111. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. if (!target->IsEntity() && !spell)
  5115. {
  5116. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. if (!target && spell) {
  5120. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5121. for (int8 i = 0; i < spell->targets.size(); i++) {
  5122. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5123. if (!target || !target->IsEntity())
  5124. continue;
  5125. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5126. }
  5127. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5128. }
  5129. else
  5130. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5131. return 0;
  5132. }
  5133. int EQ2Emu_lua_Stealth(lua_State* state) {
  5134. if (!lua_interface)
  5135. return 0;
  5136. int8 type = lua_interface->GetInt8Value(state);
  5137. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5138. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5139. if (!spell) {
  5140. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. ZoneServer* zone = spell->caster->GetZone();
  5144. if (spawn) {
  5145. if (spawn->IsEntity()) {
  5146. if (type == 1) {
  5147. ((Entity*)spawn)->AddStealthSpell(spell);
  5148. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5149. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5150. }
  5151. else if (type == 2) {
  5152. ((Entity*)spawn)->AddInvisSpell(spell);
  5153. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5154. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5155. }
  5156. return 0;
  5157. }
  5158. else {
  5159. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5160. return 0;
  5161. }
  5162. }
  5163. else {
  5164. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5165. for (int32 i = 0; i < spell->targets.size(); i++) {
  5166. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5167. if (!spawn || !spawn->IsEntity())
  5168. continue;
  5169. if (type == 1) {
  5170. ((Entity*)spawn)->AddStealthSpell(spell);
  5171. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5172. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5173. }
  5174. else if (type == 2) {
  5175. ((Entity*)spawn)->AddInvisSpell(spell);
  5176. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5177. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5178. }
  5179. else {
  5180. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5181. break;
  5182. }
  5183. }
  5184. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5185. }
  5186. return 0;
  5187. }
  5188. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5189. if (!lua_interface)
  5190. return 0;
  5191. Spawn* spawn = lua_interface->GetSpawn(state);
  5192. if (!spawn) {
  5193. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. if (spawn->IsEntity()) {
  5197. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5198. return 1;
  5199. }
  5200. else
  5201. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5205. if (!lua_interface)
  5206. return 0;
  5207. Spawn* spawn = lua_interface->GetSpawn(state);
  5208. if (!spawn) {
  5209. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. if (spawn->IsEntity()) {
  5213. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5214. return 1;
  5215. }
  5216. else
  5217. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5218. return 0;
  5219. }
  5220. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5221. if (!lua_interface)
  5222. return 0;
  5223. Spawn* player = lua_interface->GetSpawn(state);
  5224. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5225. if (!player->IsPlayer()) {
  5226. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5227. return 0;
  5228. }
  5229. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5230. return 1;
  5231. }
  5232. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5233. if (!lua_interface)
  5234. return 0;
  5235. Spawn* player = lua_interface->GetSpawn(state);
  5236. int8 slot = lua_interface->GetInt8Value(state, 2);
  5237. if (!player) {
  5238. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5239. return 0;
  5240. }
  5241. if (!player->IsPlayer()) {
  5242. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5243. return 0;
  5244. }
  5245. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5246. if (!item) {
  5247. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5248. return 0;
  5249. }
  5250. lua_interface->SetItemValue(state, item);
  5251. return 1;
  5252. }
  5253. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5254. if (!lua_interface)
  5255. return 0;
  5256. Spawn* player = lua_interface->GetSpawn(state);
  5257. int32 id = lua_interface->GetInt32Value(state, 2);
  5258. if (!player) {
  5259. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5260. return 0;
  5261. }
  5262. if (!player->IsPlayer()) {
  5263. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5264. return 0;
  5265. }
  5266. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5267. if (!item) {
  5268. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5269. return 0;
  5270. }
  5271. lua_interface->SetItemValue(state, item);
  5272. return 1;
  5273. }
  5274. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5275. if (!lua_interface)
  5276. return 0;
  5277. Spawn* player = lua_interface->GetSpawn(state);
  5278. int32 id = lua_interface->GetInt32Value(state, 2);
  5279. int8 count = lua_interface->GetInt8Value(state, 3);
  5280. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5281. if (!player) {
  5282. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. if (!player->IsPlayer()) {
  5286. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5287. return 0;
  5288. }
  5289. if (!count)
  5290. count = 1;
  5291. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5292. if (!item) {
  5293. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5294. return 0;
  5295. }
  5296. lua_interface->SetItemValue(state, item);
  5297. return 1;
  5298. }
  5299. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5300. if (!lua_interface)
  5301. return 0;
  5302. Spawn* spawn = lua_interface->GetSpawn(state);
  5303. int32 anim = lua_interface->GetInt32Value(state, 2);
  5304. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5305. int8 type = lua_interface->GetInt8Value(state, 4);
  5306. if (!spawn) {
  5307. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5308. return 0;
  5309. }
  5310. if (spawn2) {
  5311. if (spawn2->IsPlayer()) {
  5312. if (type != 1 && type != 2)
  5313. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5314. else
  5315. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5316. return 0;
  5317. }
  5318. else {
  5319. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5320. return 0;
  5321. }
  5322. }
  5323. else
  5324. spawn->GetZone()->PlayAnimation(spawn, anim);
  5325. return 0;
  5326. }
  5327. int EQ2Emu_lua_IsPet(lua_State* state) {
  5328. if (!lua_interface)
  5329. return 0;
  5330. Spawn* spawn = lua_interface->GetSpawn(state);
  5331. if (!spawn) {
  5332. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5333. return 0;
  5334. }
  5335. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5336. return 1;
  5337. }
  5338. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5339. if (!lua_interface)
  5340. return 0;
  5341. Spawn* spawn = lua_interface->GetSpawn(state);
  5342. if (!spawn) {
  5343. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5344. return 0;
  5345. }
  5346. if (!spawn->IsNPC()) {
  5347. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5348. return 0;
  5349. }
  5350. if (((NPC*)spawn)->GetOwner()) {
  5351. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5352. return 1;
  5353. }
  5354. return 0;
  5355. }
  5356. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5357. if (!lua_interface)
  5358. return 0;
  5359. Spawn* spawn = lua_interface->GetSpawn(state);
  5360. Spawn* target = lua_interface->GetSpawn(state, 2);
  5361. if (!spawn) {
  5362. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. if (!spawn) {
  5366. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5367. return 0;
  5368. }
  5369. spawn->SetTarget(target);
  5370. return 0;
  5371. }
  5372. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5373. if (!lua_interface)
  5374. return 0;
  5375. Spawn* spawn = lua_interface->GetSpawn(state);
  5376. bool val = lua_interface->GetBooleanValue(state, 2);
  5377. if (!spawn) {
  5378. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. if (!spawn->IsEntity()) {
  5382. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. ((Entity*)spawn)->InCombat(val);
  5386. if (val) {
  5387. spawn->ClearRunningLocations();
  5388. spawn->CalculateRunningLocation(true);
  5389. }
  5390. return 0;
  5391. }
  5392. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5393. if (!lua_interface)
  5394. return 0;
  5395. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5396. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5397. if (!spawn1) {
  5398. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5399. return 0;
  5400. }
  5401. if (!spawn2) {
  5402. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5406. return 1;
  5407. }
  5408. int EQ2Emu_lua_Runback(lua_State* state) {
  5409. if (!lua_interface)
  5410. return 0;
  5411. Spawn* spawn = lua_interface->GetSpawn(state);
  5412. if (!spawn) {
  5413. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5414. return 0;
  5415. }
  5416. if (!spawn->IsNPC()) {
  5417. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5418. return 0;
  5419. }
  5420. ((NPC*)spawn)->Runback();
  5421. return 0;
  5422. }
  5423. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5424. if (!lua_interface)
  5425. return 0;
  5426. Spawn* spawn = lua_interface->GetSpawn(state);
  5427. if (!spawn) {
  5428. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5429. return 0;
  5430. }
  5431. if (!spawn->IsNPC()) {
  5432. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5436. return 1;
  5437. }
  5438. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5439. if (!lua_interface)
  5440. return 0;
  5441. Spawn* spawn = lua_interface->GetSpawn(state);
  5442. if (!spawn) {
  5443. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5444. return 0;
  5445. }
  5446. if (!spawn->IsEntity()) {
  5447. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5448. return 0;
  5449. }
  5450. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5451. return 1;
  5452. }
  5453. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5454. if (!lua_interface)
  5455. return 0;
  5456. Spawn* spawn = lua_interface->GetSpawn(state);
  5457. if (!spawn) {
  5458. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5459. return 0;
  5460. }
  5461. if (!spawn->IsEntity()) {
  5462. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5463. return 0;
  5464. }
  5465. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5466. return 1;
  5467. }
  5468. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5469. if (!lua_interface)
  5470. return 0;
  5471. Spawn* spawn = lua_interface->GetSpawn(state);
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. if (!spawn->IsEntity()) {
  5477. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5481. return 1;
  5482. }
  5483. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (!spawn->IsEntity()) {
  5492. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5493. return 0;
  5494. }
  5495. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5496. return 1;
  5497. }
  5498. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5499. if (!lua_interface)
  5500. return 0;
  5501. Spawn* spawn = lua_interface->GetSpawn(state);
  5502. Spawn* target = lua_interface->GetSpawn(state, 2);
  5503. float distance = lua_interface->GetFloatValue(state, 3);
  5504. if (!spawn) {
  5505. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5506. return 0;
  5507. }
  5508. if (!target) {
  5509. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5510. return 0;
  5511. }
  5512. if (!spawn->IsNPC()) {
  5513. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5514. return 0;
  5515. }
  5516. if (!target->IsEntity()) {
  5517. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5518. return 0;
  5519. }
  5520. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5521. return 1;
  5522. }
  5523. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5524. if (!lua_interface)
  5525. return 0;
  5526. Spawn* spawn = lua_interface->GetSpawn(state);
  5527. Spawn* target = lua_interface->GetSpawn(state, 2);
  5528. float distance = lua_interface->GetFloatValue(state, 3);
  5529. if (!spawn) {
  5530. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5531. return 0;
  5532. }
  5533. if (!target) {
  5534. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5535. return 0;
  5536. }
  5537. if (!spawn->IsNPC()) {
  5538. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5539. return 0;
  5540. }
  5541. if (!target->IsEntity()) {
  5542. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5546. return 0;
  5547. }
  5548. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5549. if (!lua_interface)
  5550. return 0;
  5551. Spawn* spawn = lua_interface->GetSpawn(state);
  5552. if (!spawn) {
  5553. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5554. return 0;
  5555. }
  5556. if (!spawn->IsNPC()) {
  5557. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5558. return 0;
  5559. }
  5560. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5561. return 1;
  5562. }
  5563. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5564. if (!lua_interface)
  5565. return 0;
  5566. Spawn* spawn = lua_interface->GetSpawn(state);
  5567. if (!spawn) {
  5568. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5569. return 0;
  5570. }
  5571. if (!spawn->IsNPC()) {
  5572. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5573. return 0;
  5574. }
  5575. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5576. return 1;
  5577. }
  5578. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5579. if (!lua_interface)
  5580. return 0;
  5581. Spawn* spawn = lua_interface->GetSpawn(state);
  5582. if (!spawn) {
  5583. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5584. return 0;
  5585. }
  5586. if (!spawn->IsNPC()) {
  5587. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5588. return 0;
  5589. }
  5590. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5591. if (hated) {
  5592. lua_interface->SetSpawnValue(state, hated);
  5593. return 1;
  5594. }
  5595. return 0;
  5596. }
  5597. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5598. if (!lua_interface)
  5599. return 0;
  5600. Spawn* spawn = lua_interface->GetSpawn(state);
  5601. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5602. if (!spawn) {
  5603. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. if (!spawn->IsNPC()) {
  5607. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5608. return 0;
  5609. }
  5610. if (!hated) {
  5611. ((NPC*)spawn)->Brain()->ClearHate();
  5612. return 0;
  5613. }
  5614. else
  5615. {
  5616. if (!hated->IsEntity()) {
  5617. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5618. return 0;
  5619. }
  5620. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5621. return 0;
  5622. }
  5623. return 0;
  5624. }
  5625. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5626. if (!lua_interface)
  5627. return 0;
  5628. Spawn* spawn = lua_interface->GetSpawn(state);
  5629. if (!spawn) {
  5630. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. if (!spawn->IsNPC()) {
  5634. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5635. return 0;
  5636. }
  5637. ((NPC*)spawn)->Brain()->ClearEncounter();
  5638. return 0;
  5639. }
  5640. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5641. if (!lua_interface)
  5642. return 0;
  5643. Spawn* spawn = lua_interface->GetSpawn(state);
  5644. if (!spawn) {
  5645. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. if (!spawn->IsNPC()) {
  5649. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5650. return 0;
  5651. }
  5652. // Temp list to store hate list
  5653. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5654. if (encounterList->size() == 0) {
  5655. safe_delete(encounterList);
  5656. return 0;
  5657. }
  5658. lua_createtable(state, encounterList->size(), 0);
  5659. int newTable = lua_gettop(state);
  5660. for (int32 i = 0; i < encounterList->size(); i++) {
  5661. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5662. if (temp)
  5663. lua_interface->SetSpawnValue(state, temp);
  5664. lua_rawseti(state, newTable, i + 1);
  5665. }
  5666. safe_delete(encounterList);
  5667. return 1;
  5668. }
  5669. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5670. if (!lua_interface)
  5671. return 0;
  5672. Spawn* spawn = lua_interface->GetSpawn(state);
  5673. if (!spawn) {
  5674. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5675. return 0;
  5676. }
  5677. if (!spawn->IsNPC()) {
  5678. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5679. return 0;
  5680. }
  5681. // Temp list to store hate list
  5682. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5683. if (hateList->size() == 0) {
  5684. safe_delete(hateList);
  5685. return 0;
  5686. }
  5687. lua_createtable(state, hateList->size(), 0);
  5688. int newTable = lua_gettop(state);
  5689. for (int32 i = 0; i < hateList->size(); i++) {
  5690. lua_interface->SetSpawnValue(state, hateList->at(i));
  5691. lua_rawseti(state, newTable, i + 1);
  5692. }
  5693. safe_delete(hateList);
  5694. return 1;
  5695. }
  5696. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5697. if (!lua_interface)
  5698. return 0;
  5699. Spawn* spawn = lua_interface->GetSpawn(state);
  5700. if (!spawn) {
  5701. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5702. return 0;
  5703. }
  5704. if (spawn->IsPlayer()) {
  5705. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5706. lua_interface->SetBooleanValue(state, true);
  5707. else
  5708. lua_interface->SetBooleanValue(state, false);
  5709. return 1;
  5710. }
  5711. else {
  5712. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5713. return 1;
  5714. }
  5715. }
  5716. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5717. if (!lua_interface)
  5718. return 0;
  5719. Quest* quest = lua_interface->GetQuest(state);
  5720. if (!quest) {
  5721. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. quest->SetCompletedFlag(true);
  5725. return 0;
  5726. }
  5727. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5728. if (!lua_interface)
  5729. return 0;
  5730. Spawn* spawn = lua_interface->GetSpawn(state);
  5731. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5732. int8 tier = lua_interface->GetInt8Value(state, 3);
  5733. if (!spawn) {
  5734. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5735. return 0;
  5736. }
  5737. if (!spawn->IsEntity()) {
  5738. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5739. return 0;
  5740. }
  5741. if (spellID == 0) {
  5742. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5746. if (effect) {
  5747. if (tier > 0) {
  5748. // If a tier was passed chec to see if it is the same as the effect
  5749. if (tier == effect->tier)
  5750. lua_interface->SetBooleanValue(state, true);
  5751. else
  5752. lua_interface->SetBooleanValue(state, false);
  5753. return 1;
  5754. }
  5755. else {
  5756. // Have an effect but no tier was passed so return true
  5757. lua_interface->SetBooleanValue(state, true);
  5758. }
  5759. return 1;
  5760. }
  5761. // no effect so return false
  5762. lua_interface->SetBooleanValue(state, false);
  5763. return 1;
  5764. }
  5765. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5766. if (!lua_interface)
  5767. return 0;
  5768. Spawn* spawn = lua_interface->GetSpawn(state);
  5769. int32 id = lua_interface->GetInt32Value(state, 2);
  5770. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5771. Spawn* spawn2 = 0;
  5772. vector<Spawn*> list;
  5773. if (!spawn) {
  5774. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5775. return 0;
  5776. }
  5777. //If zone not provided, use spawn's zone
  5778. if (!zone)
  5779. zone = spawn->GetZone();
  5780. list = zone->GetSpawnsByID(id);
  5781. if (list.size() == 0) {
  5782. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5783. return 0;
  5784. }
  5785. vector<Spawn*>::iterator itr = list.begin();
  5786. for (int8 i = 0; i < list.size(); i++) {
  5787. spawn2 = itr[i];
  5788. if (spawn2)
  5789. spawn2->AddAllowAccessSpawn(spawn);
  5790. }
  5791. return 0;
  5792. }
  5793. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5794. if (!lua_interface)
  5795. return 0;
  5796. Spawn* spawn = lua_interface->GetSpawn(state);
  5797. int32 id = lua_interface->GetInt32Value(state, 2);
  5798. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5799. Spawn* spawn2 = 0;
  5800. if (!spawn) {
  5801. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5802. return 0;
  5803. }
  5804. //If zone not provided, use spawn's zone
  5805. if (!zone)
  5806. zone = spawn->GetZone();
  5807. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5808. vector<Spawn*>::iterator itr = list.begin();
  5809. if (list.size() == 0) {
  5810. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5811. return 0;
  5812. }
  5813. for (int8 i = 0; i < list.size(); i++) {
  5814. spawn2 = itr[i];
  5815. if (spawn2)
  5816. spawn2->RemoveSpawnAccess(spawn);
  5817. }
  5818. return 0;
  5819. }
  5820. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5821. if (!lua_interface)
  5822. return 0;
  5823. Quest* quest = lua_interface->GetQuest(state);
  5824. if (!quest) {
  5825. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5826. return 0;
  5827. }
  5828. quest->SetYellowName(true);
  5829. return 0;
  5830. }
  5831. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5832. if (!lua_interface)
  5833. return 0;
  5834. Spawn* spawn = lua_interface->GetSpawn(state);
  5835. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5836. if (!spawn) {
  5837. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. if (!spawn->IsPlayer()) {
  5841. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5842. return 0;
  5843. }
  5844. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5845. return 1;
  5846. }
  5847. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* spawn = lua_interface->GetSpawn(state);
  5851. if (!spawn) {
  5852. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5853. return 0;
  5854. }
  5855. if (!spawn->IsPlayer()) {
  5856. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5857. return 0;
  5858. }
  5859. ZoneServer* zone = spawn->GetZone();
  5860. if (!zone) {
  5861. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5862. return 0;
  5863. }
  5864. Instance_Type iType = zone->GetInstanceType();
  5865. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5866. iType == GROUP_LOCKOUT_INSTANCE ||
  5867. iType == RAID_LOCKOUT_INSTANCE ||
  5868. iType == SOLO_PERSIST_INSTANCE ||
  5869. iType == GROUP_PERSIST_INSTANCE ||
  5870. iType == RAID_PERSIST_INSTANCE) {
  5871. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5872. if (data) {
  5873. // Check to see if the timer has already been set, if it has return out.
  5874. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5875. return 0;
  5876. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5877. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5878. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5879. if (client) {
  5880. string time_msg = "";
  5881. int32 time = data->success_lockout_time;
  5882. int16 hour;
  5883. int8 min;
  5884. int8 sec;
  5885. hour = time / 3600;
  5886. time = time % 3600;
  5887. min = time / 60;
  5888. time = time % 60;
  5889. sec = time;
  5890. if (hour > 0) {
  5891. char temp[10];
  5892. sprintf(temp, " %i", hour);
  5893. time_msg.append(temp);
  5894. time_msg.append(" hour");
  5895. time_msg.append((hour > 1) ? "s" : "");
  5896. }
  5897. if (min > 0) {
  5898. char temp[5];
  5899. sprintf(temp, " %i", min);
  5900. time_msg.append(temp);
  5901. time_msg.append(" minute");
  5902. time_msg.append((min > 1) ? "s" : "");
  5903. }
  5904. // Only add seconds if minutes and hours are 0
  5905. if (hour == 0 && min == 0 && sec > 0) {
  5906. char temp[5];
  5907. sprintf(temp, " %i", sec);
  5908. time_msg.append(temp);
  5909. time_msg.append(" second");
  5910. time_msg.append((sec > 1) ? "s" : "");
  5911. }
  5912. 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());
  5913. }
  5914. }
  5915. else
  5916. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5917. }
  5918. else
  5919. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5923. if (!lua_interface)
  5924. return 0;
  5925. Spawn* spawn = lua_interface->GetSpawn(state);
  5926. if (!spawn) {
  5927. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. if (!spawn->IsPlayer()) {
  5931. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. ZoneServer* zone = spawn->GetZone();
  5935. if (!zone) {
  5936. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. Instance_Type iType = zone->GetInstanceType();
  5940. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5941. iType == GROUP_LOCKOUT_INSTANCE ||
  5942. iType == RAID_LOCKOUT_INSTANCE ||
  5943. iType == SOLO_PERSIST_INSTANCE ||
  5944. iType == GROUP_PERSIST_INSTANCE ||
  5945. iType == RAID_PERSIST_INSTANCE) {
  5946. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5947. if (data) {
  5948. // Check to see if the timer has already been set, if it has return out.
  5949. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5950. return 0;
  5951. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5952. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5953. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5954. if (client) {
  5955. string time_msg = "";
  5956. int32 time = data->failure_lockout_time;
  5957. int16 hour;
  5958. int8 min;
  5959. int8 sec;
  5960. hour = time / 3600;
  5961. time = time % 3600;
  5962. min = time / 60;
  5963. time = time % 60;
  5964. sec = time;
  5965. if (hour > 0) {
  5966. char temp[10];
  5967. sprintf(temp, " %i", hour);
  5968. time_msg.append(temp);
  5969. time_msg.append(" hour");
  5970. time_msg.append((hour > 1) ? "s" : "");
  5971. }
  5972. if (min > 0) {
  5973. char temp[5];
  5974. sprintf(temp, " %i", min);
  5975. time_msg.append(temp);
  5976. time_msg.append(" minute");
  5977. time_msg.append((min > 1) ? "s" : "");
  5978. }
  5979. // Only add seconds if minutes and hours are 0
  5980. if (hour == 0 && min == 0 && sec > 0) {
  5981. char temp[5];
  5982. sprintf(temp, " %i", sec);
  5983. time_msg.append(temp);
  5984. time_msg.append(" second");
  5985. time_msg.append((sec > 1) ? "s" : "");
  5986. }
  5987. 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());
  5988. }
  5989. }
  5990. else
  5991. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5992. }
  5993. else
  5994. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5998. if (!lua_interface)
  5999. return 0;
  6000. Spawn* spawn = lua_interface->GetSpawn(state);
  6001. if (!spawn) {
  6002. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6006. return 1;
  6007. }
  6008. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6009. if (!lua_interface)
  6010. return 0;
  6011. Spawn* player = lua_interface->GetSpawn(state);
  6012. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6013. if (!player) {
  6014. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6015. return 0;
  6016. }
  6017. if (!player->IsPlayer()) {
  6018. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6019. return 0;
  6020. }
  6021. if (!ground) {
  6022. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. if (!ground->IsGroundSpawn()) {
  6026. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6030. if (!groundspawn_entries) {
  6031. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6032. return 0;
  6033. }
  6034. Skill* skill = 0;
  6035. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6036. if (collection_skill == "Collecting")
  6037. skill = ((Player*)player)->GetSkillByName("Gathering");
  6038. else
  6039. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6040. if (!skill) {
  6041. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6042. return 0;
  6043. }
  6044. vector<GroundSpawnEntry*>::iterator itr;
  6045. GroundSpawnEntry* entry = 0;
  6046. bool can_harvest = false;
  6047. sint32 min_skill = -1;
  6048. // first, iterate through groundspawn_entries, discard tables player cannot use
  6049. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6050. {
  6051. entry = *itr;
  6052. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6053. min_skill = entry->min_skill_level;
  6054. // if player lacks skill, skip table
  6055. if (entry->min_skill_level > skill->current_val)
  6056. continue;
  6057. // if bonus, but player lacks level, skip table
  6058. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6059. continue;
  6060. can_harvest = true;
  6061. break;
  6062. }
  6063. lua_interface->SetBooleanValue(state, can_harvest);
  6064. // If false, send the message to the client
  6065. if (!can_harvest) {
  6066. Client* client = player->GetZone()->GetClientBySpawn(player);
  6067. if (client) {
  6068. string msg = "You do not have enough skill to ";
  6069. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6070. msg.append("gather");
  6071. else if (collection_skill == "Mining")
  6072. msg.append("mine");
  6073. else if (collection_skill == "Trapping")
  6074. msg.append("trap");
  6075. else if (collection_skill == "Foresting")
  6076. msg.append("forest");
  6077. else if (collection_skill == "Fishing")
  6078. msg.append("catch");
  6079. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6080. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6081. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6082. }
  6083. }
  6084. return 1;
  6085. }
  6086. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6087. if (!lua_interface)
  6088. return 0;
  6089. Spawn* player = lua_interface->GetSpawn(state);
  6090. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6091. if (!player) {
  6092. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. if (!player->IsPlayer()) {
  6096. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6097. return 0;
  6098. }
  6099. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6100. lua_interface->SetBooleanValue(state, ret);
  6101. return 1;
  6102. }
  6103. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6104. // Check to see if we have a valid lua_interface
  6105. if (!lua_interface)
  6106. return 0;
  6107. // Get the spawn that is getting the pet
  6108. Spawn* spawn = lua_interface->GetSpawn(state);
  6109. Spawn* target = lua_interface->GetSpawn(state, 2);
  6110. // Get the DB ID of the pet
  6111. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6112. float x = lua_interface->GetFloatValue(state, 4);
  6113. float y = lua_interface->GetFloatValue(state, 5);
  6114. float z = lua_interface->GetFloatValue(state, 6);
  6115. // Get the spell that this command was called from
  6116. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6117. // Check to make sure the spawn pointer is valid
  6118. if (!spawn) {
  6119. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. // Check to make sure the spawn is an entity
  6123. if (!spawn->IsEntity()) {
  6124. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. if (!target) {
  6128. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6129. return 0;
  6130. }
  6131. if (!target->IsEntity()) {
  6132. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6133. return 0;
  6134. }
  6135. // Check to see if the DB ID for the pet is set
  6136. if (pet_id == 0) {
  6137. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. // Check to see if the pointer to the spell is valid
  6141. if (!luaspell) {
  6142. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6143. return 0;
  6144. }
  6145. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6146. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6147. if (!pet) {
  6148. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6149. return 0;
  6150. }
  6151. // Check to make sure the pet is an npc
  6152. if (!pet->IsNPC()) {
  6153. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6154. return 0;
  6155. }
  6156. if (x == 0)
  6157. x = spawn->GetX();
  6158. if (y == 0)
  6159. y = spawn->GetY();
  6160. if (z == 0)
  6161. z = spawn->GetZ();
  6162. // Spawn the pet at the same location as the owner
  6163. pet->SetX(x);
  6164. pet->SetY(y);
  6165. pet->SetZ(z);
  6166. pet->SetLocation(spawn->GetLocation());
  6167. pet->SetHeading(spawn->GetHeading());
  6168. spawn->GetZone()->AddSpawn(pet);
  6169. /*
  6170. const char* spawn_script = world.GetSpawnScript(pet_id);
  6171. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6172. spawn->SetSpawnScript(string(spawn_script));
  6173. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6174. }*/
  6175. // Get a random pet name
  6176. string random_pet_name;
  6177. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6178. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6179. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6180. // Set the pets name
  6181. pet->SetName(random_pet_name.c_str());
  6182. // Set the level of the pet to the owners level
  6183. pet->SetLevel(spawn->GetLevel());
  6184. // Set the faction of the pet to the same faction as the owner
  6185. pet->SetFactionID(spawn->GetFactionID());
  6186. // Set the spawn as a pet
  6187. pet->SetPet(true);
  6188. // Give a pointer of the owner to the pet
  6189. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6190. // Set the pet type
  6191. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6192. // Set the spell id used to create this pet
  6193. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6194. // Set the spell tier used to create this pet
  6195. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6196. // Set the pets spawn type to 6
  6197. pet->SetSpawnType(6);
  6198. // Set the pets brain
  6199. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6200. // Check to see if the pet has a subtitle
  6201. if (strlen(pet->GetSubTitle()) > 0) {
  6202. // Add the players name to the front of the sub title
  6203. string pet_subtitle;
  6204. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6205. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6206. // Set the pets subtitle to the new one
  6207. pet->SetSubTitle(pet_subtitle.c_str());
  6208. }
  6209. // Set the pet as the return value for this function
  6210. lua_interface->SetSpawnValue(state, pet);
  6211. return 1;
  6212. }
  6213. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6214. if (!lua_interface)
  6215. return 0;
  6216. Spawn* spawn = lua_interface->GetSpawn(state);
  6217. Spawn* player = lua_interface->GetSpawn(state, 2);
  6218. float max_distance = lua_interface->GetFloatValue(state, 3);
  6219. string type = lua_interface->GetStringValue(state, 4);
  6220. if (!spawn || (spawn && spawn->IsPlayer())) {
  6221. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!player || (player && !player->IsPlayer())) {
  6225. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. Client* client = 0;
  6229. if (player->GetZone())
  6230. client = player->GetZone()->GetClientBySpawn(player);
  6231. if (!client) {
  6232. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6233. return 0;
  6234. }
  6235. //Set max_distance to default if not set or not proper value
  6236. if (max_distance <= 0)
  6237. max_distance = 500;
  6238. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6239. if (packet) {
  6240. float unknown2_3 = 0;
  6241. int8 placement_mode = 0;
  6242. if (type == "wall") {
  6243. placement_mode = 2;
  6244. unknown2_3 = 150;
  6245. }
  6246. else if (type == "ceiling")
  6247. placement_mode = 1;
  6248. packet->setDataByName("placement_mode", placement_mode);
  6249. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6250. packet->setDataByName("model_type", spawn->GetModelType());
  6251. packet->setDataByName("unknown", 1); //size
  6252. packet->setDataByName("unknown2", 1); //size 2
  6253. packet->setDataByName("unknown2", .5, 1); //size 3
  6254. packet->setDataByName("unknown2", 3, 2);
  6255. packet->setDataByName("unknown2", unknown2_3, 3);
  6256. packet->setDataByName("max_distance", max_distance);
  6257. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6258. client->QueuePacket(packet->serialize());
  6259. safe_delete(packet);
  6260. }
  6261. return 0;
  6262. }
  6263. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6264. if (!lua_interface)
  6265. return 0;
  6266. Item* item = lua_interface->GetItem(state);
  6267. if (!item) {
  6268. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6272. return 1;
  6273. }
  6274. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6275. if (!lua_interface)
  6276. return 0;
  6277. Spawn* spawn = lua_interface->GetSpawn(state);
  6278. if (!spawn) {
  6279. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6280. return 0;
  6281. }
  6282. if (spawn->GetZone())
  6283. spawn->GetZone()->AddTransportSpawn(spawn);
  6284. return 0;
  6285. }
  6286. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6287. if (!lua_interface)
  6288. return 0;
  6289. Skill* skill = lua_interface->GetSkill(state);
  6290. if (!skill) {
  6291. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6292. return 0;
  6293. }
  6294. lua_interface->SetInt32Value(state, skill->current_val);
  6295. return 1;
  6296. }
  6297. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6298. if (!lua_interface)
  6299. return 0;
  6300. Skill* skill = lua_interface->GetSkill(state);
  6301. if (!skill) {
  6302. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. lua_interface->SetInt32Value(state, skill->max_val);
  6306. return 1;
  6307. }
  6308. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6309. if (!lua_interface)
  6310. return 0;
  6311. Skill* skill = lua_interface->GetSkill(state);
  6312. if (!skill) {
  6313. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6314. return 0;
  6315. }
  6316. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6317. return 1;
  6318. }
  6319. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6320. if (!lua_interface)
  6321. return 0;
  6322. Skill* skill = lua_interface->GetSkill(state);
  6323. int16 value = lua_interface->GetInt16Value(state, 2);
  6324. if (!skill) {
  6325. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6326. return 0;
  6327. }
  6328. skill->max_val = value;
  6329. if (skill->max_val < skill->current_val)
  6330. skill->current_val = skill->max_val;
  6331. return 0;
  6332. }
  6333. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6334. if (!lua_interface)
  6335. return 0;
  6336. Skill* skill = lua_interface->GetSkill(state);
  6337. int16 value = lua_interface->GetInt16Value(state, 2);
  6338. if (!skill) {
  6339. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. if (value > skill->max_val)
  6343. skill->current_val = skill->max_val;
  6344. else
  6345. skill->current_val = value;
  6346. return 0;
  6347. }
  6348. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6349. if (!lua_interface)
  6350. return 0;
  6351. Spawn* spawn = lua_interface->GetSpawn(state);
  6352. string name = lua_interface->GetStringValue(state, 2);
  6353. if (!spawn) {
  6354. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6355. return 0;
  6356. }
  6357. if (!spawn->IsEntity()) {
  6358. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6359. return 0;
  6360. }
  6361. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6362. if (skill) {
  6363. lua_interface->SetSkillValue(state, skill);
  6364. return 1;
  6365. }
  6366. return 0;
  6367. }
  6368. int EQ2Emu_lua_AddProc(lua_State* state) {
  6369. if (!lua_interface)
  6370. return 0;
  6371. Spawn* spawn = lua_interface->GetSpawn(state);
  6372. int8 type = lua_interface->GetInt8Value(state, 2);
  6373. float chance = lua_interface->GetFloatValue(state, 3);
  6374. Item* item = lua_interface->GetItem(state, 4);
  6375. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6376. LuaSpell* spell = 0;
  6377. if (!spawn && (!spell || !use_all_spelltargets)) {
  6378. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6379. return 0;
  6380. }
  6381. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6382. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. if (!item)
  6386. spell = lua_interface->GetCurrentSpell(state);
  6387. if (!item && !spell) {
  6388. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (spell && use_all_spelltargets) {
  6392. Spawn* target;
  6393. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6394. for (int8 i = 0; i < spell->targets.size(); i++) {
  6395. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6396. if (!target || !target->IsEntity())
  6397. continue;
  6398. ((Entity*)target)->AddProc(type, chance, item, spell);
  6399. }
  6400. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6401. }
  6402. else
  6403. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6404. return 0;
  6405. }
  6406. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Spawn* spawn = lua_interface->GetSpawn(state);
  6410. Item* item = lua_interface->GetItem(state, 2);
  6411. LuaSpell* spell = 0;
  6412. if (!spawn) {
  6413. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6414. return 0;
  6415. }
  6416. if (!spawn->IsEntity()) {
  6417. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. if (!item)
  6421. spell = lua_interface->GetCurrentSpell(state);
  6422. if (!item && !spell) {
  6423. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6424. return 0;
  6425. }
  6426. if (spell) {
  6427. Spawn* target;
  6428. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6429. for (int8 i = 0; i < spell->targets.size(); i++) {
  6430. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6431. if (!target || !target->IsEntity())
  6432. continue;
  6433. ((Entity*)target)->RemoveProc(item, spell);
  6434. }
  6435. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6436. spell->caster->RemoveProc(item, spell);
  6437. }
  6438. else
  6439. ((Entity*)spawn)->RemoveProc(item, spell);
  6440. return 0;
  6441. }
  6442. int EQ2Emu_lua_Knockback(lua_State* state) {
  6443. if (!lua_interface)
  6444. return 0;
  6445. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6446. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6447. int32 duration = lua_interface->GetInt32Value(state, 3);
  6448. float vertical = lua_interface->GetFloatValue(state, 4);
  6449. float horizontal = lua_interface->GetFloatValue(state, 5);
  6450. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6451. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6452. if (!target_spawn) {
  6453. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. if (!spawn) {
  6457. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6458. return 0;
  6459. }
  6460. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6461. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6462. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6463. if (packet) {
  6464. packet->setDataByName("target_x", target_spawn->GetX());
  6465. packet->setDataByName("target_y", target_spawn->GetY());
  6466. packet->setDataByName("target_z", target_spawn->GetZ());
  6467. packet->setDataByName("vertical_movement", vertical);
  6468. packet->setDataByName("horizontal_movement", horizontal);
  6469. if (use_heading)
  6470. packet->setDataByName("use_player_heading", 1);
  6471. client->QueuePacket(packet->serialize());
  6472. }
  6473. safe_delete(packet);
  6474. }
  6475. return 0;
  6476. }
  6477. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6478. if (!lua_interface)
  6479. return 0;
  6480. Spawn* spawn = lua_interface->GetSpawn(state);
  6481. if (!spawn) {
  6482. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6486. return 1;
  6487. }
  6488. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6489. if (!lua_interface)
  6490. return 0;
  6491. Spawn* caster = lua_interface->GetSpawn(state);
  6492. Spawn* target = lua_interface->GetSpawn(state, 2);
  6493. string name = lua_interface->GetStringValue(state, 3);
  6494. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6495. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6496. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6497. string success_msg = lua_interface->GetStringValue(state, 7);
  6498. string effect_msg = lua_interface->GetStringValue(state, 8);
  6499. if (!caster) {
  6500. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6501. return 0;
  6502. }
  6503. if (!caster->IsEntity()) {
  6504. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!target) {
  6508. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. if (!target->IsEntity()) {
  6512. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. if (name.length() == 0) {
  6516. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6517. return 0;
  6518. }
  6519. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6520. return 0;
  6521. }
  6522. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6523. if (!lua_interface)
  6524. return 0;
  6525. string name = lua_interface->GetStringValue(state);
  6526. if (name.length() == 0) {
  6527. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6531. if (!skill) {
  6532. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6533. return 0;
  6534. }
  6535. lua_interface->SetInt32Value(state, skill->skill_id);
  6536. return 1;
  6537. }
  6538. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6539. if (!lua_interface)
  6540. return 0;
  6541. Spawn* spawn = lua_interface->GetSpawn(state);
  6542. if (!spawn) {
  6543. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6547. return 1;
  6548. }
  6549. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6550. if (!lua_interface)
  6551. return 0;
  6552. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6553. if (!luaspell) {
  6554. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6558. return 1;
  6559. }
  6560. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6561. if (!lua_interface)
  6562. return 0;
  6563. Spawn* spawn = lua_interface->GetSpawn(state);
  6564. Spawn* target = lua_interface->GetSpawn(state, 2);
  6565. if (!spawn) {
  6566. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6567. return 0;
  6568. }
  6569. if (!spawn->IsEntity()) {
  6570. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. if (!target) {
  6574. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6575. return 0;
  6576. }
  6577. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6578. return 1;
  6579. }
  6580. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6581. if (!lua_interface)
  6582. return 0;
  6583. Spawn* spawn = lua_interface->GetSpawn(state);
  6584. Spawn* target = lua_interface->GetSpawn(state, 2);
  6585. if (!spawn) {
  6586. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6587. return 0;
  6588. }
  6589. if (!spawn->IsEntity()) {
  6590. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6591. return 0;
  6592. }
  6593. if (!target) {
  6594. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6595. return 0;
  6596. }
  6597. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6598. return 1;
  6599. }
  6600. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6601. if (!lua_interface)
  6602. return 0;
  6603. Item* item = lua_interface->GetItem(state);
  6604. if (!item) {
  6605. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. lua_interface->SetInt32Value(state, item->details.count);
  6609. return 1;
  6610. }
  6611. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6612. if (!lua_interface)
  6613. return 0;
  6614. Item* item = lua_interface->GetItem(state);
  6615. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6616. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6617. if (!item) {
  6618. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6619. return 0;
  6620. }
  6621. if (!owner) {
  6622. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6623. return 0;
  6624. }
  6625. if (!owner->IsPlayer()) {
  6626. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6627. return 0;
  6628. }
  6629. if (item->stack_count < new_count) {
  6630. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6631. return 0;
  6632. }
  6633. if (new_count > 0) {
  6634. item->details.count = new_count;
  6635. item->save_needed = true;
  6636. }
  6637. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6638. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6639. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6640. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6641. else
  6642. {
  6643. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6647. if (!client)
  6648. return 0;
  6649. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6650. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6651. if (app)
  6652. client->QueuePacket(app);
  6653. return 0;
  6654. }
  6655. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6656. if (!lua_interface)
  6657. return 0;
  6658. int32 time = lua_interface->GetInt32Value(state);
  6659. string function = lua_interface->GetStringValue(state, 2);
  6660. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6661. Spawn* target = lua_interface->GetSpawn(state, 4);
  6662. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6663. if (time == 0) {
  6664. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6665. return 0;
  6666. }
  6667. if (function.length() == 0) {
  6668. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6669. return 0;
  6670. }
  6671. if (!spell) {
  6672. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6673. return 0;
  6674. }
  6675. SpellScriptTimer* timer = new SpellScriptTimer;
  6676. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6677. #ifdef WIN32
  6678. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6679. #else
  6680. bzero(timer, sizeof(SpellScriptTimer));
  6681. #endif*/
  6682. timer->caster = 0;
  6683. timer->deleteWhenDone = false;
  6684. timer->target = 0;
  6685. timer->time = Timer::GetCurrentTime2() + time;
  6686. timer->customFunction = function;
  6687. timer->spell = spell;
  6688. if (caster)
  6689. timer->caster = caster->GetID();
  6690. if (target)
  6691. timer->target = target->GetID();
  6692. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6693. return 0;
  6694. }
  6695. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6696. if (!lua_interface)
  6697. return 0;
  6698. float hp_perc = lua_interface->GetFloatValue(state);
  6699. float power_perc = lua_interface->GetFloatValue(state, 2);
  6700. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6701. Spawn* target = lua_interface->GetSpawn(state, 4);
  6702. string heal_name = lua_interface->GetStringValue(state, 5);
  6703. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6704. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6705. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6706. if (!spell) {
  6707. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. Entity* caster = spell->caster;
  6711. if (!caster) {
  6712. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. Client* client = 0;
  6716. PendingResurrection* rez = 0;
  6717. ZoneServer* zone = spell->caster->GetZone();
  6718. if (!target) {
  6719. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6720. if (spell->targets.size() > 0) {
  6721. vector<int32> spell_targets = spell->targets;
  6722. for (int8 i = 0; i < spell_targets.size(); i++) {
  6723. target = zone->GetSpawnByID(spell_targets.at(i));
  6724. if (!target)
  6725. continue;
  6726. if (!target->IsPlayer())
  6727. continue;
  6728. client = target->GetZone()->GetClientBySpawn(target);
  6729. if (!client)
  6730. continue;
  6731. rez = client->GetCurrentRez();
  6732. if (rez->active)
  6733. continue;
  6734. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6735. rez->active = true;
  6736. rez->caster = caster;
  6737. rez->expire_timer = new Timer;
  6738. int32 duration = spell->spell->GetSpellDuration();
  6739. rez->expire_timer->Start(duration * 100);
  6740. rez->hp_perc = hp_perc;
  6741. rez->mp_perc = power_perc;
  6742. rez->range = spell->spell->GetSpellData()->range;
  6743. rez->spell_name = spell->spell->GetName();
  6744. if (heal_name.length() > 0)
  6745. rez->heal_name = heal_name;
  6746. else
  6747. rez->heal_name = rez->spell_name;
  6748. rez->no_calcs = no_calcs;
  6749. rez->crit_mod = crit_mod;
  6750. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6751. if (send_window)
  6752. client->SendResurrectionWindow();
  6753. else {
  6754. target->GetZone()->ResurrectSpawn(target, client);
  6755. rez->should_delete = true;
  6756. }
  6757. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6758. }
  6759. }
  6760. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6761. }
  6762. else {
  6763. client = target->GetZone()->GetClientBySpawn(target);
  6764. if (!client)
  6765. return 0;
  6766. rez = client->GetCurrentRez();
  6767. if (rez->active)
  6768. return 0;
  6769. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6770. rez->active = true;
  6771. rez->caster = caster;
  6772. rez->expire_timer = new Timer;
  6773. int32 duration = spell->spell->GetSpellDuration();
  6774. rez->expire_timer->Start(duration * 100);
  6775. rez->hp_perc = hp_perc;
  6776. rez->mp_perc = power_perc;
  6777. rez->range = spell->spell->GetSpellData()->range;
  6778. rez->spell_name = spell->spell->GetName();
  6779. if (heal_name.length() > 0)
  6780. rez->heal_name = heal_name;
  6781. else
  6782. rez->heal_name = rez->spell_name;
  6783. rez->no_calcs = no_calcs;
  6784. rez->crit_mod = crit_mod;
  6785. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6786. if (send_window)
  6787. client->SendResurrectionWindow();
  6788. else {
  6789. target->GetZone()->ResurrectSpawn(target, client);
  6790. rez->should_delete = true;
  6791. }
  6792. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6793. }
  6794. return 0;
  6795. }
  6796. int EQ2Emu_lua_SetVision(lua_State* state) {
  6797. if (!lua_interface)
  6798. return 0;
  6799. Spawn* spawn = lua_interface->GetSpawn(state);
  6800. int8 vision = lua_interface->GetInt8Value(state, 2);
  6801. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6802. if (!spawn) {
  6803. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6804. return 0;
  6805. }
  6806. if (!spawn->IsEntity()) {
  6807. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6808. return 0;
  6809. }
  6810. if (spell && spell->targets.size() > 0) {
  6811. ZoneServer* zone = spell->caster->GetZone();
  6812. for (int8 i = 0; i < spell->targets.size(); i++) {
  6813. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6814. if (target->IsEntity()) {
  6815. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6816. if (target->IsPlayer())
  6817. ((Player*)target)->SetCharSheetChanged(true);
  6818. }
  6819. }
  6820. }
  6821. else {
  6822. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6823. if (spawn->IsPlayer())
  6824. ((Player*)spawn)->SetCharSheetChanged(true);
  6825. }
  6826. return 0;
  6827. }
  6828. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6829. if (!lua_interface)
  6830. return 0;
  6831. Spawn* spawn = lua_interface->GetSpawn(state);
  6832. float intensity = lua_interface->GetFloatValue(state, 2);
  6833. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6834. if (!spawn) {
  6835. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. if (!spawn->IsEntity()) {
  6839. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. if (spell && spell->targets.size() > 0) {
  6843. ZoneServer* zone = spell->caster->GetZone();
  6844. for (int8 i = 0; i < spell->targets.size(); i++) {
  6845. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6846. if (target && target->IsEntity()) {
  6847. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6848. if (target->IsPlayer())
  6849. ((Player*)target)->SetCharSheetChanged(true);
  6850. }
  6851. }
  6852. }
  6853. else {
  6854. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6855. if (spawn->IsPlayer())
  6856. ((Player*)spawn)->SetCharSheetChanged(true);
  6857. }
  6858. return 0;
  6859. }
  6860. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6861. if (!lua_interface)
  6862. return 0;
  6863. Spawn* spawn = lua_interface->GetSpawn(state);
  6864. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6865. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6866. if (!spawn) {
  6867. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6868. return 0;
  6869. }
  6870. if (!spawn->IsEntity()) {
  6871. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6872. return 0;
  6873. }
  6874. if (spell && spell->targets.size() > 0) {
  6875. ZoneServer* zone = spell->caster->GetZone();
  6876. for (int8 i = 0; i < spell->targets.size(); i++) {
  6877. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6878. if (target->IsEntity()) {
  6879. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6880. if (target->IsPlayer())
  6881. ((Player*)target)->SetCharSheetChanged(true);
  6882. }
  6883. }
  6884. }
  6885. else {
  6886. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6887. if (spawn->IsPlayer())
  6888. ((Player*)spawn)->SetCharSheetChanged(true);
  6889. }
  6890. return 0;
  6891. }
  6892. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6893. if (!lua_interface)
  6894. return 0;
  6895. Item* item = lua_interface->GetItem(state);
  6896. int8 type = lua_interface->GetInt32Value(state, 2);
  6897. if (!item) {
  6898. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. if (type == 1)
  6902. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6903. else if (type == 2)
  6904. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6905. return 1;
  6906. }
  6907. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6908. if (!lua_interface)
  6909. return 0;
  6910. Spawn* target = lua_interface->GetSpawn(state);
  6911. float val = lua_interface->GetFloatValue(state, 2);
  6912. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6913. // Added from Gangrenous post
  6914. if (spell && spell->resisted)
  6915. return 0;
  6916. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6917. if (val > 1.0f)
  6918. val = 1.0f - (val / 100.0f);
  6919. if (spell && spell->spell && spell->targets.size() > 0) {
  6920. ZoneServer* zone = spell->caster->GetZone();
  6921. for (int32 i = 0; i != spell->targets.size(); i++) {
  6922. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6923. if (spawn && spawn->IsEntity()) {
  6924. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6925. if (spawn->IsPlayer())
  6926. ((Player*)spawn)->SetCharSheetChanged(true);
  6927. }
  6928. }
  6929. }
  6930. else {
  6931. if (target && target->IsEntity()) {
  6932. ((Entity*)target)->SetSpeedMultiplier(val);
  6933. if (target->IsPlayer())
  6934. ((Player*)target)->SetCharSheetChanged(true);
  6935. }
  6936. }
  6937. return 0;
  6938. }
  6939. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6940. if (!lua_interface)
  6941. return 0;
  6942. Spawn* spawn = lua_interface->GetSpawn(state);
  6943. int16 model = lua_interface->GetInt16Value(state, 2);
  6944. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6945. if (spell && spell->spell && spell->targets.size() > 0) {
  6946. ZoneServer* zone = spell->caster->GetZone();
  6947. for (int32 i = 0; i < spell->targets.size(); i++) {
  6948. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6949. if (target)
  6950. target->SetIllusionModel(model);
  6951. }
  6952. }
  6953. else {
  6954. if (!spawn) {
  6955. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6956. return 0;
  6957. }
  6958. spawn->SetIllusionModel(model);
  6959. }
  6960. return 0;
  6961. }
  6962. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6963. if (!lua_interface)
  6964. return 0;
  6965. Spawn* spawn = lua_interface->GetSpawn(state);
  6966. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6967. if (spell && spell->spell && spell->targets.size() > 0) {
  6968. ZoneServer* zone = spell->caster->GetZone();
  6969. for (int32 i = 0; i < spell->targets.size(); i++) {
  6970. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6971. if (target)
  6972. target->SetIllusionModel(0);
  6973. }
  6974. }
  6975. else {
  6976. if (!spawn) {
  6977. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6978. return 0;
  6979. }
  6980. spawn->SetIllusionModel(0);
  6981. }
  6982. return 0;
  6983. }
  6984. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6985. if (!lua_interface)
  6986. return 0;
  6987. Spawn* caster = lua_interface->GetSpawn(state);
  6988. Spawn* target = lua_interface->GetSpawn(state, 2);
  6989. float chance = lua_interface->GetFloatValue(state, 3);
  6990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6991. if (!caster) {
  6992. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. if (!caster->IsEntity()) {
  6996. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  6997. return 0;
  6998. }
  6999. if (!target) {
  7000. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7001. return 0;
  7002. }
  7003. if (!target->IsEntity()) {
  7004. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7005. return 0;
  7006. }
  7007. if (chance <= 0) {
  7008. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7009. return 0;
  7010. }
  7011. if (!spell) {
  7012. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7013. return 0;
  7014. }
  7015. if (((Entity*)caster)->GetThreatTransfer()) {
  7016. return 0;
  7017. }
  7018. ThreatTransfer* transfer = new ThreatTransfer;
  7019. transfer->Target = target->GetID();
  7020. transfer->Amount = chance;
  7021. transfer->Spell = spell;
  7022. ((Entity*)caster)->SetThreatTransfer(transfer);
  7023. return 0;
  7024. }
  7025. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7026. if (!lua_interface)
  7027. return 0;
  7028. Spawn* spawn = lua_interface->GetSpawn(state);
  7029. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7030. if (!spawn) {
  7031. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. if (!spell) {
  7035. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7039. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7040. ((Entity*)spawn)->SetThreatTransfer(0);
  7041. safe_delete(transfer);
  7042. }
  7043. return 0;
  7044. }
  7045. int EQ2Emu_lua_CureByType(lua_State* state) {
  7046. if (!lua_interface)
  7047. return 0;
  7048. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7049. if (!spell) {
  7050. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. int8 cure_count = lua_interface->GetInt8Value(state);
  7054. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7055. string cure_name = lua_interface->GetStringValue(state, 3);
  7056. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7057. Spawn* target = lua_interface->GetSpawn(state, 5);
  7058. if (target) {
  7059. if (!target->IsEntity()) {
  7060. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7061. return 0;
  7062. }
  7063. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7064. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7065. }
  7066. else {
  7067. ZoneServer* zone = spell->caster->GetZone();
  7068. vector<int32> targets = spell->targets;
  7069. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7070. for (int8 i = 0; i < targets.size(); i++) {
  7071. target = zone->GetSpawnByID(targets.at(i));
  7072. if (!target || !target->IsEntity())
  7073. continue;
  7074. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7075. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7076. }
  7077. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7078. }
  7079. return 0;
  7080. }
  7081. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7082. if (!lua_interface)
  7083. return 0;
  7084. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7085. if (!spell) {
  7086. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7087. return 0;
  7088. }
  7089. int8 cure_count = lua_interface->GetInt8Value(state);
  7090. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7091. string cure_name = lua_interface->GetStringValue(state, 3);
  7092. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7093. Spawn* target = lua_interface->GetSpawn(state, 5);
  7094. if (target) {
  7095. if (!target->IsEntity()) {
  7096. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7097. return 0;
  7098. }
  7099. if (((Entity*)target)->GetDetCount() > 0)
  7100. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7101. }
  7102. else {
  7103. ZoneServer* zone = spell->caster->GetZone();
  7104. vector<int32> targets = spell->targets;
  7105. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7106. for (int8 i = 0; i < targets.size(); i++) {
  7107. target = zone->GetSpawnByID(targets.at(i));
  7108. if (!target || !target->IsEntity())
  7109. continue;
  7110. if (((Entity*)target)->GetDetCount() > 0)
  7111. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7112. }
  7113. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7114. }
  7115. return 0;
  7116. }
  7117. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7118. if (!lua_interface)
  7119. return 0;
  7120. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7121. if (!spell) {
  7122. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7123. return 0;
  7124. }
  7125. if (!spell->caster) {
  7126. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7127. return 0;
  7128. }
  7129. if (!spell->caster->GetZone()) {
  7130. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7131. return 0;
  7132. }
  7133. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7134. return 0;
  7135. }
  7136. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7137. if (!lua_interface)
  7138. return 0;
  7139. Spawn* spawn = lua_interface->GetSpawn(state);
  7140. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7141. if (!spell) {
  7142. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7143. return 0;
  7144. }
  7145. if (spawn && spawn->IsEntity())
  7146. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7147. else {
  7148. ZoneServer* zone = spell->caster->GetZone();
  7149. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7150. for (int32 i = 0; i < spell->targets.size(); i++) {
  7151. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7152. if (!spawn || !spawn->IsEntity())
  7153. continue;
  7154. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7155. }
  7156. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7157. }
  7158. return 0;
  7159. }
  7160. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7161. if (!lua_interface)
  7162. return 0;
  7163. Spawn* spawn = lua_interface->GetSpawn(state);
  7164. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7165. if (!spell) {
  7166. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7167. return 0;
  7168. }
  7169. if (spawn && spawn->IsEntity())
  7170. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7171. else {
  7172. ZoneServer* zone = spell->caster->GetZone();
  7173. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7174. for (int32 i = 0; i < spell->targets.size(); i++) {
  7175. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7176. if (!spawn || !spawn->IsEntity())
  7177. continue;
  7178. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7179. }
  7180. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7181. }
  7182. return 0;
  7183. }
  7184. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7185. if (!lua_interface)
  7186. return 0;
  7187. Spawn* caster = lua_interface->GetSpawn(state);
  7188. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7189. if (!caster) {
  7190. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7191. return 0;
  7192. }
  7193. if (!caster->IsPlayer()) {
  7194. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7195. return 0;
  7196. }
  7197. Spawn* target = caster->GetTarget();
  7198. if (!target) {
  7199. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7200. return 0;
  7201. }
  7202. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7203. if (!client) {
  7204. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7205. return 0;
  7206. }
  7207. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7208. if (ho) {
  7209. ho->SetTarget(target->GetID());
  7210. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7211. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7212. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7213. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7214. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7215. deque<GroupMemberInfo*>::iterator itr;
  7216. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7217. if (group)
  7218. {
  7219. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7220. deque<GroupMemberInfo*>* members = group->GetMembers();
  7221. for (itr = members->begin(); itr != members->end(); itr++) {
  7222. if ((*itr)->client)
  7223. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7224. }
  7225. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7226. }
  7227. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7228. }
  7229. else
  7230. safe_delete(ho);
  7231. }
  7232. else {
  7233. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7234. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7235. }
  7236. else
  7237. safe_delete(ho);
  7238. }
  7239. }
  7240. return 0;
  7241. }
  7242. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7243. if (!lua_interface)
  7244. return 0;
  7245. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7246. if (!spell) {
  7247. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. int16 triggerCount = lua_interface->GetInt16Value(state);
  7251. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7252. if (!triggerCount) {
  7253. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. spell->num_triggers = triggerCount;
  7257. spell->had_triggers = true;
  7258. spell->cancel_after_all_triggers = cancel_after_triggers;
  7259. return 0;
  7260. }
  7261. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7262. if (!lua_interface)
  7263. return 0;
  7264. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7265. if (!spell) {
  7266. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. lua_interface->SetInt32Value(state, spell->num_triggers);
  7270. return 1;
  7271. }
  7272. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7273. if (!lua_interface)
  7274. return 0;
  7275. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7276. if (!spell) {
  7277. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7278. return 0;
  7279. }
  7280. int16 remove_count = lua_interface->GetInt16Value(state);
  7281. if (!remove_count)
  7282. remove_count = 1;
  7283. if (remove_count >= spell->num_triggers) {
  7284. spell->num_triggers = 0;
  7285. if (spell->cancel_after_all_triggers)
  7286. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7287. }
  7288. else {
  7289. spell->num_triggers -= remove_count;
  7290. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7291. }
  7292. return 0;
  7293. }
  7294. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7295. if (!lua_interface)
  7296. return 0;
  7297. Spawn* spawn = lua_interface->GetSpawn(state);
  7298. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7299. if (!spawn) {
  7300. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. if (!copy_spawn) {
  7304. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7305. return 0;
  7306. }
  7307. spawn->CopySpawnAppearance(copy_spawn);
  7308. return 0;
  7309. }
  7310. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7311. if (!lua_interface)
  7312. return 0;
  7313. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7314. int8 type = lua_interface->GetInt8Value(state);
  7315. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7316. if (!spell) {
  7317. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7318. return 0;
  7319. }
  7320. if (spawn) {
  7321. if (!spawn->IsEntity()) {
  7322. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. Entity* entity = ((Entity*)spawn);
  7326. switch (type) {
  7327. case IMMUNITY_TYPE_AOE:
  7328. entity->AddAOEImmunity(spell);
  7329. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7330. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7331. break;
  7332. case IMMUNITY_TYPE_STUN:
  7333. entity->AddStunImmunity(spell);
  7334. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7335. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7336. break;
  7337. case IMMUNITY_TYPE_ROOT:
  7338. entity->AddRootImmunity(spell);
  7339. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7340. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7341. break;
  7342. case IMMUNITY_TYPE_DAZE:
  7343. entity->AddDazeImmunity(spell);
  7344. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7345. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7346. break;
  7347. case IMMUNITY_TYPE_FEAR:
  7348. entity->AddFearImmunity(spell);
  7349. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7350. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7351. break;
  7352. case IMMUNITY_TYPE_MEZ:
  7353. entity->AddMezImmunity(spell);
  7354. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7355. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7356. break;
  7357. case IMMUNITY_TYPE_STIFLE:
  7358. entity->AddStifleImmunity(spell);
  7359. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7360. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7361. break;
  7362. default:
  7363. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7364. }
  7365. }
  7366. else {
  7367. bool should_break = false;
  7368. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7369. for (int8 i = 0; i < spell->targets.size(); i++) {
  7370. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7371. if (!spawn || !spawn->IsEntity())
  7372. continue;
  7373. Entity* entity = ((Entity*)spawn);
  7374. switch (type) {
  7375. case IMMUNITY_TYPE_AOE:
  7376. entity->AddAOEImmunity(spell);
  7377. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7378. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7379. break;
  7380. case IMMUNITY_TYPE_STUN:
  7381. entity->AddStunImmunity(spell);
  7382. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7383. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7384. break;
  7385. case IMMUNITY_TYPE_ROOT:
  7386. entity->AddRootImmunity(spell);
  7387. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7388. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7389. break;
  7390. case IMMUNITY_TYPE_DAZE:
  7391. entity->AddDazeImmunity(spell);
  7392. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7393. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7394. break;
  7395. case IMMUNITY_TYPE_FEAR:
  7396. entity->AddFearImmunity(spell);
  7397. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7398. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7399. break;
  7400. case IMMUNITY_TYPE_MEZ:
  7401. entity->AddMezImmunity(spell);
  7402. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7403. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7404. break;
  7405. case IMMUNITY_TYPE_STIFLE:
  7406. entity->AddStifleImmunity(spell);
  7407. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7408. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7409. break;
  7410. default:
  7411. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7412. should_break = true;
  7413. }
  7414. if (should_break)
  7415. break;
  7416. }
  7417. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7418. }
  7419. return 0;
  7420. }
  7421. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7422. if (!lua_interface)
  7423. return 0;
  7424. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7425. int8 type = lua_interface->GetInt8Value(state);
  7426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7427. if (!spell) {
  7428. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7429. return 0;
  7430. }
  7431. if (spawn) {
  7432. if (!spawn->IsEntity()) {
  7433. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. Entity* entity = ((Entity*)spawn);
  7437. switch (type) {
  7438. case IMMUNITY_TYPE_AOE:
  7439. entity->RemoveAOEImmunity(spell);
  7440. break;
  7441. case IMMUNITY_TYPE_STUN:
  7442. entity->RemoveStunImmunity(spell);
  7443. break;
  7444. case IMMUNITY_TYPE_ROOT:
  7445. entity->RemoveRootImmunity(spell);
  7446. break;
  7447. case IMMUNITY_TYPE_DAZE:
  7448. entity->RemoveDazeImmunity(spell);
  7449. break;
  7450. case IMMUNITY_TYPE_FEAR:
  7451. entity->RemoveFearImmunity(spell);
  7452. break;
  7453. case IMMUNITY_TYPE_MEZ:
  7454. entity->RemoveMezImmunity(spell);
  7455. break;
  7456. case IMMUNITY_TYPE_STIFLE:
  7457. entity->RemoveStifleImmunity(spell);
  7458. break;
  7459. default:
  7460. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7461. }
  7462. }
  7463. else {
  7464. bool should_break = false;
  7465. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7466. for (int8 i = 0; i < spell->targets.size(); i++) {
  7467. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7468. if (!spawn || !spawn->IsEntity())
  7469. continue;
  7470. Entity* entity = ((Entity*)spawn);
  7471. switch (type) {
  7472. case IMMUNITY_TYPE_AOE:
  7473. entity->RemoveAOEImmunity(spell);
  7474. break;
  7475. case IMMUNITY_TYPE_STUN:
  7476. entity->RemoveStunImmunity(spell);
  7477. break;
  7478. case IMMUNITY_TYPE_ROOT:
  7479. entity->RemoveRootImmunity(spell);
  7480. break;
  7481. case IMMUNITY_TYPE_DAZE:
  7482. entity->RemoveDazeImmunity(spell);
  7483. break;
  7484. case IMMUNITY_TYPE_FEAR:
  7485. entity->RemoveFearImmunity(spell);
  7486. break;
  7487. case IMMUNITY_TYPE_MEZ:
  7488. entity->RemoveMezImmunity(spell);
  7489. break;
  7490. case IMMUNITY_TYPE_STIFLE:
  7491. entity->RemoveStifleImmunity(spell);
  7492. break;
  7493. default:
  7494. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7495. should_break = true;
  7496. }
  7497. if (should_break)
  7498. break;
  7499. }
  7500. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7501. }
  7502. return 0;
  7503. }
  7504. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7505. if (!lua_interface)
  7506. return 0;
  7507. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7508. if (!spell) {
  7509. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. float snare = lua_interface->GetFloatValue(state);
  7513. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7514. // convert the val to the speed multipler value (100 - val)
  7515. float val = 100.0 - snare;
  7516. val /= 100.0;
  7517. if (spawn) {
  7518. if (!spawn->IsEntity()) {
  7519. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. ((Entity*)spawn)->SetSnareValue(spell, val);
  7523. }
  7524. else {
  7525. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7526. for (int8 i = 0; i < spell->targets.size(); i++) {
  7527. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7528. if (!spawn || !spawn->IsEntity())
  7529. continue;
  7530. ((Entity*)spawn)->SetSnareValue(spell, val);
  7531. }
  7532. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7533. }
  7534. return 0;
  7535. }
  7536. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Spawn* spawn = lua_interface->GetSpawn(state);
  7540. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7541. if (!spawn) {
  7542. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. if (race_id == 0) {
  7546. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7547. return 0;
  7548. }
  7549. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7550. return 1;
  7551. }
  7552. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7553. if (!lua_interface)
  7554. return 0;
  7555. Spawn* spawn = lua_interface->GetSpawn(state);
  7556. if (!spawn) {
  7557. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7558. return 0;
  7559. }
  7560. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7561. return 1;
  7562. }
  7563. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7564. if (!lua_interface)
  7565. return 0;
  7566. Spawn* spawn = lua_interface->GetSpawn(state);
  7567. if (!spawn) {
  7568. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7572. return 1;
  7573. }
  7574. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7575. if (!lua_interface)
  7576. return 0;
  7577. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7578. if (!spell) {
  7579. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. lua_interface->SetStringValue(state, spell->spell->GetName());
  7583. return 1;
  7584. }
  7585. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7586. if (!lua_interface)
  7587. return 0;
  7588. Quest* quest = lua_interface->GetQuest(state);
  7589. if (!quest) {
  7590. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7591. return 0;
  7592. }
  7593. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7594. return 1;
  7595. }
  7596. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7597. if (!lua_interface)
  7598. return 0;
  7599. Quest* quest = lua_interface->GetQuest(state);
  7600. int32 flags = lua_interface->GetInt32Value(state, 2);
  7601. if (!quest) {
  7602. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7603. return 0;
  7604. }
  7605. quest->SetQuestFlags(flags);
  7606. return 0;
  7607. }
  7608. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7609. if (!lua_interface)
  7610. return 0;
  7611. Quest* quest = lua_interface->GetQuest(state);
  7612. Spawn* player = lua_interface->GetSpawn(state, 2);
  7613. int32 step = lua_interface->GetInt32Value(state, 3);
  7614. int32 duration = lua_interface->GetInt32Value(state, 4);
  7615. string action = lua_interface->GetStringValue(state, 5);
  7616. if (!quest) {
  7617. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (!player) {
  7621. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7622. return 0;
  7623. }
  7624. if (!player->IsPlayer()) {
  7625. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7626. return 0;
  7627. }
  7628. if (step == 0) {
  7629. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7630. return 0;
  7631. }
  7632. if (duration == 0) {
  7633. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7634. return 0;
  7635. }
  7636. if (action.length() == 0) {
  7637. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. Client* client = player->GetZone()->GetClientBySpawn(player);
  7641. if (!client) {
  7642. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. quest->SetTimerStep(step);
  7646. quest->AddFailedAction(step, action);
  7647. quest->SetStepTimer(duration);
  7648. client->AddQuestTimer(quest->GetQuestID());
  7649. return 0;
  7650. }
  7651. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7652. if (!lua_interface)
  7653. return 0;
  7654. Quest* quest = lua_interface->GetQuest(state);
  7655. Spawn* player = lua_interface->GetSpawn(state, 2);
  7656. if (!quest) {
  7657. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. if (!player) {
  7661. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. if (!player->IsPlayer()) {
  7665. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7666. return 0;
  7667. }
  7668. Client* client = player->GetZone()->GetClientBySpawn(player);
  7669. if (!client) {
  7670. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7671. return 0;
  7672. }
  7673. quest->SetTimerStep(0);
  7674. quest->SetStepTimer(0);
  7675. client->RemoveQuestTimer(quest->GetQuestID());
  7676. return 0;
  7677. }
  7678. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7679. if (!lua_interface)
  7680. return 0;
  7681. Spawn* player = lua_interface->GetSpawn(state);
  7682. Quest* quest = lua_interface->GetQuest(state, 2);
  7683. int32 step = lua_interface->GetInt32Value(state, 3);
  7684. if (!player) {
  7685. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (!player->IsPlayer()) {
  7689. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7690. return 0;
  7691. }
  7692. if (!quest) {
  7693. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. if (step == 0) {
  7697. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7698. return 0;
  7699. }
  7700. Client* client = player->GetZone()->GetClientBySpawn(player);
  7701. if (!client) {
  7702. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. if (quest->RemoveQuestStep(step, client)) {
  7706. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7707. client->GetCurrentZone()->SendQuestUpdates(client);
  7708. }
  7709. else
  7710. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7711. return 0;
  7712. }
  7713. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7714. if (!lua_interface)
  7715. return 0;
  7716. Quest* quest = lua_interface->GetQuest(state, 1);
  7717. int32 step = lua_interface->GetInt32Value(state, 2);
  7718. string desc = lua_interface->GetStringValue(state, 3);
  7719. string task_group = lua_interface->GetStringValue(state, 4);
  7720. if (!quest) {
  7721. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7722. return 0;
  7723. }
  7724. if (step == 0) {
  7725. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7726. return 0;
  7727. }
  7728. QuestStep* quest_step = quest->GetQuestStep(step);
  7729. if (!quest_step) {
  7730. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7731. return 0;
  7732. }
  7733. quest_step->SetStepProgress(0);
  7734. quest_step->SetTaskGroup(task_group);
  7735. quest_step->SetDescription(desc);
  7736. return 0;
  7737. }
  7738. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7739. if (!lua_interface)
  7740. return 0;
  7741. Quest* quest = lua_interface->GetQuest(state);
  7742. int32 step = lua_interface->GetInt32Value(state, 2);
  7743. string action = lua_interface->GetStringValue(state, 3);
  7744. if (!quest) {
  7745. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7746. return 0;
  7747. }
  7748. if (step == 0) {
  7749. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7750. return 0;
  7751. }
  7752. if (action.length() == 0) {
  7753. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7754. return 0;
  7755. }
  7756. quest->AddFailedAction(step, action);
  7757. return 0;
  7758. }
  7759. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7760. if (!lua_interface)
  7761. return 0;
  7762. Spawn* player = lua_interface->GetSpawn(state);
  7763. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7764. int32 step = lua_interface->GetInt32Value(state, 3);
  7765. if (!player) {
  7766. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7767. return 0;
  7768. }
  7769. if (!player->IsPlayer()) {
  7770. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7771. return 0;
  7772. }
  7773. if (quest_id == 0) {
  7774. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. if (step == 0) {
  7778. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7779. return 0;
  7780. }
  7781. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7782. if (!quest) {
  7783. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7784. return 0;
  7785. }
  7786. quest->StepFailed(step);
  7787. return 0;
  7788. }
  7789. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7790. if (!lua_interface)
  7791. return 0;
  7792. Spawn* player = lua_interface->GetSpawn(state);
  7793. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7794. if (!player) {
  7795. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. if (!player->IsPlayer()) {
  7799. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. if (quest_id == 0) {
  7803. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7804. return 0;
  7805. }
  7806. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7807. if (!quest) {
  7808. lua_interface->SetInt32Value(state, 0);
  7809. return 1;
  7810. }
  7811. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7812. return 1;
  7813. }
  7814. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7815. if (!lua_interface)
  7816. return 0;
  7817. string name = lua_interface->GetStringValue(state);
  7818. string value = lua_interface->GetStringValue(state, 2);
  7819. string comment = lua_interface->GetStringValue(state, 3);
  7820. if (name.length() == 0) {
  7821. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7822. return 0;
  7823. }
  7824. if (value.length() == 0) {
  7825. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7826. return 0;
  7827. }
  7828. string varname = string("lua_").append(name);
  7829. Variable* var = variables.FindVariable(varname);
  7830. if (var)
  7831. var->SetValue(value.c_str());
  7832. else {
  7833. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7834. variables.AddVariable(var);
  7835. }
  7836. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7837. return 0;
  7838. }
  7839. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7840. if (!lua_interface)
  7841. return 0;
  7842. string name = lua_interface->GetStringValue(state);
  7843. if (name.length() == 0) {
  7844. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7845. return 0;
  7846. }
  7847. string varname = string("lua_").append(name);
  7848. Variable* var = variables.FindVariable(varname);
  7849. if (var)
  7850. lua_interface->SetStringValue(state, var->GetValue());
  7851. else
  7852. lua_interface->SetStringValue(state, "NULL");
  7853. return 1;
  7854. }
  7855. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7856. if (!lua_interface)
  7857. return 0;
  7858. Spawn* player = lua_interface->GetSpawn(state);
  7859. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7860. if (!player) {
  7861. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7862. return 0;
  7863. }
  7864. if (!player->IsPlayer()) {
  7865. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7866. return 0;
  7867. }
  7868. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7869. return 1;
  7870. }
  7871. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7872. if (!lua_interface)
  7873. return 0;
  7874. Spawn* player = lua_interface->GetSpawn(state);
  7875. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7876. if (!player) {
  7877. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. if (!player->IsPlayer()) {
  7881. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. Language* language = master_languages_list.GetLanguage(language_id);
  7885. if (language)
  7886. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7887. return 0;
  7888. }
  7889. int EQ2Emu_lua_IsNight(lua_State* state) {
  7890. if (!lua_interface)
  7891. return 0;
  7892. ZoneServer* zone = lua_interface->GetZone(state);
  7893. if (!zone) {
  7894. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7895. return 0;
  7896. }
  7897. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7898. return 1;
  7899. }
  7900. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7901. if (!lua_interface)
  7902. return 0;
  7903. Spawn* spawn = lua_interface->GetSpawn(state);
  7904. if (!spawn) {
  7905. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. if (!spawn->IsWidget()) {
  7909. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. ((Widget*)spawn)->SetMultiFloorLift(true);
  7913. if (spawn->GetZone())
  7914. spawn->GetZone()->AddTransportSpawn(spawn);
  7915. return 0;
  7916. }
  7917. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7918. if (!lua_interface)
  7919. return 0;
  7920. Spawn* player = lua_interface->GetSpawn(state);
  7921. int32 path = lua_interface->GetInt32Value(state, 2);
  7922. if (!player) {
  7923. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. if (!player->IsPlayer()) {
  7927. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7928. return 0;
  7929. }
  7930. if (path == 0) {
  7931. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. Client* client = player->GetZone()->GetClientBySpawn(player);
  7935. if (!client) {
  7936. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. client->SendFlightAutoMount(path);
  7940. return 0;
  7941. }
  7942. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7943. if (!lua_interface)
  7944. return 0;
  7945. Spawn* player = lua_interface->GetSpawn(state);
  7946. if (!player) {
  7947. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. if (!player->IsPlayer()) {
  7951. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7952. return 0;
  7953. }
  7954. Client* client = player->GetZone()->GetClientBySpawn(player);
  7955. if (!client) {
  7956. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. client->EndAutoMount();
  7960. return 0;
  7961. }
  7962. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7963. if (!lua_interface)
  7964. return 0;
  7965. Spawn* player = lua_interface->GetSpawn(state);
  7966. if (!player) {
  7967. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  7968. return 0;
  7969. }
  7970. if (!player->IsPlayer()) {
  7971. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7972. return 0;
  7973. }
  7974. Client* client = player->GetZone()->GetClientBySpawn(player);
  7975. if (!client) {
  7976. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7977. return 0;
  7978. }
  7979. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7980. return 1;
  7981. }
  7982. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7983. if (!lua_interface)
  7984. return 0;
  7985. Spawn* player = lua_interface->GetSpawn(state);
  7986. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7987. int32 value = lua_interface->GetInt32Value(state, 3);
  7988. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7989. if (!player) {
  7990. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7991. return 0;
  7992. }
  7993. if (!player->IsPlayer()) {
  7994. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7998. return 0;
  7999. }
  8000. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8001. if (!lua_interface)
  8002. return 0;
  8003. Spawn* player = lua_interface->GetSpawn(state);
  8004. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8005. if (!player) {
  8006. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. if (!player->IsPlayer()) {
  8010. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8014. if (!hd)
  8015. return 0;
  8016. lua_interface->SetInt32Value(state, hd->Value);
  8017. lua_interface->SetInt32Value(state, hd->Value2);
  8018. return 2;
  8019. }
  8020. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8021. if (!lua_interface)
  8022. return 0;
  8023. Spawn* spawn = lua_interface->GetSpawn(state);
  8024. int32 grid = lua_interface->GetInt32Value(state, 2);
  8025. if (!spawn) {
  8026. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. if (grid == 0) {
  8030. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8034. return 0;
  8035. }
  8036. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8037. if (!lua_interface)
  8038. return 0;
  8039. Spawn* spawn = lua_interface->GetSpawn(state);
  8040. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8041. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8042. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8043. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8044. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8045. if (!spawn) {
  8046. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. //Add this quest to the list of required quests for this spawn
  8050. spawn->SetRequiredHistory(event_id, value1, value2);
  8051. //If private spawn value set
  8052. if (private_spawn) {
  8053. //Set the spawn to be private when not granted access via history
  8054. spawn->AddAllowAccessSpawn(spawn);
  8055. spawn->SetPrivateQuestSpawn(true);
  8056. }
  8057. //This value will override vis_flags in the vis packet
  8058. if (flag_override > 0)
  8059. spawn->SetQuestsRequiredOverride(flag_override);
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. Spawn* player = lua_interface->GetSpawn(state);
  8066. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8067. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8068. if (!player) {
  8069. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8070. return 0;
  8071. }
  8072. if (!player->IsPlayer()) {
  8073. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8077. return 1;
  8078. }
  8079. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8080. if (!lua_interface)
  8081. return 0;
  8082. Spawn* player = lua_interface->GetSpawn(state);
  8083. int8 level = lua_interface->GetInt8Value(state, 2);
  8084. if (!player) {
  8085. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8086. return 0;
  8087. }
  8088. if (!player->IsPlayer()) {
  8089. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8090. return 0;
  8091. }
  8092. if (level == 0) {
  8093. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. Client* client = player->GetZone()->GetClientBySpawn(player);
  8097. if (!client) {
  8098. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8102. client->GetPlayer()->SetXP(1);
  8103. client->GetPlayer()->SetNeededXP();
  8104. return 0;
  8105. }
  8106. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. Spawn* player = lua_interface->GetSpawn(state);
  8110. int32 amount = lua_interface->GetInt32Value(state, 2);
  8111. if (!player) {
  8112. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8113. return 0;
  8114. }
  8115. if (!player->IsPlayer()) {
  8116. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8117. return 0;
  8118. }
  8119. if (amount == 0) {
  8120. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8121. return 0;
  8122. }
  8123. ((Player*)player)->AddCoins(amount);
  8124. return 0;
  8125. }
  8126. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8127. if (!lua_interface)
  8128. return 0;
  8129. Spawn* player = lua_interface->GetSpawn(state);
  8130. int32 amount = lua_interface->GetInt32Value(state, 2);
  8131. if (!player) {
  8132. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8133. return 0;
  8134. }
  8135. if (!player->IsPlayer()) {
  8136. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8137. return 0;
  8138. }
  8139. if (amount == 0) {
  8140. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8141. return 0;
  8142. }
  8143. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8144. return 1;
  8145. }
  8146. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8147. if (!lua_interface)
  8148. return 0;
  8149. ZoneServer* zone = lua_interface->GetZone(state);
  8150. if (!zone) {
  8151. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8152. return 0;
  8153. }
  8154. vector<Entity*> players = zone->GetPlayers();
  8155. if (players.size() == 0)
  8156. return 0;
  8157. lua_createtable(state, players.size(), 0);
  8158. int newTable = lua_gettop(state);
  8159. for (int32 i = 0; i < players.size(); i++) {
  8160. lua_interface->SetSpawnValue(state, players.at(i));
  8161. lua_rawseti(state, newTable, i + 1);
  8162. }
  8163. return 1;
  8164. }
  8165. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8166. if (!lua_interface)
  8167. return 0;
  8168. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8169. if (!zone) {
  8170. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8171. return 0;
  8172. }
  8173. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8174. //Map of <placement_id, location_id>
  8175. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8176. map<int32, int32>::iterator itr;
  8177. vector<Spawn*> group;
  8178. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8179. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8180. if (!location) {
  8181. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8182. return 0;
  8183. }
  8184. Spawn* spawn = 0;
  8185. if (location->entities[0]) {
  8186. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8187. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8188. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8189. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8190. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8191. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8192. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8193. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8194. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8195. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8196. if (spawn) {
  8197. const char* script = 0;
  8198. for (int x = 0; x < 3; x++) {
  8199. switch (x) {
  8200. case 0:
  8201. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8202. break;
  8203. case 1:
  8204. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8205. break;
  8206. case 2:
  8207. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8208. break;
  8209. }
  8210. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8211. spawn->SetSpawnScript(string(script));
  8212. break;
  8213. }
  8214. }
  8215. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8216. lua_interface->SetSpawnValue(state, spawn);
  8217. group.push_back(spawn);
  8218. }
  8219. else {
  8220. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8221. safe_delete(spawn);
  8222. }
  8223. }
  8224. }
  8225. if (!group.empty()) {
  8226. lua_createtable(state, group.size(), 0);
  8227. int newTable = lua_gettop(state);
  8228. for (int32 i = 0; i < group.size(); i++) {
  8229. lua_interface->SetSpawnValue(state, group[i]);
  8230. lua_rawseti(state, newTable, i + 1);
  8231. }
  8232. }
  8233. else
  8234. lua_pushnil(state);
  8235. return 1;
  8236. }
  8237. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8238. if (!lua_interface)
  8239. return 0;
  8240. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8241. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8242. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8243. if (!spawn) {
  8244. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if (anim_id == 0) {
  8248. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8249. return 0;
  8250. }
  8251. if (leeway == 0)
  8252. leeway = 5000;
  8253. spawn->SetSpawnAnim(anim_id);
  8254. spawn->SetSpawnAnimLeeway(leeway);
  8255. return 0;
  8256. }
  8257. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8258. if (!lua_interface)
  8259. return 0;
  8260. Spawn* player = lua_interface->GetSpawn(state);
  8261. if (!player) {
  8262. return 0;
  8263. }
  8264. Client* client = player->GetZone()->GetClientBySpawn(player);
  8265. if (!client) {
  8266. return 0;
  8267. }
  8268. lua_interface->SetInt32Value(state, client->GetVersion());
  8269. return 1;
  8270. }
  8271. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8272. if (!lua_interface)
  8273. return 0;
  8274. Item* item = lua_interface->GetItem(state);
  8275. if (!item) {
  8276. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8277. return 0;
  8278. }
  8279. lua_interface->SetInt32Value(state, item->details.item_id);
  8280. return 1;
  8281. }
  8282. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8283. if (!lua_interface)
  8284. return 0;
  8285. Spawn* spawn = lua_interface->GetSpawn(state);
  8286. if (!spawn) {
  8287. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8288. return 0;
  8289. }
  8290. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8291. return 1;
  8292. }
  8293. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8294. if (!lua_interface)
  8295. return 0;
  8296. Spawn* spawn = lua_interface->GetSpawn(state);
  8297. if (!spawn) {
  8298. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8302. return 1;
  8303. }
  8304. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8305. if (!lua_interface)
  8306. return 0;
  8307. Spawn* spawn = lua_interface->GetSpawn(state);
  8308. if (!spawn) {
  8309. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8313. return 1;
  8314. }
  8315. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8316. if (!lua_interface)
  8317. return 0;
  8318. Spawn* spawn = lua_interface->GetSpawn(state);
  8319. if (!spawn) {
  8320. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8324. return 1;
  8325. }
  8326. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8327. if (!lua_interface)
  8328. return 0;
  8329. Spawn* spawn = lua_interface->GetSpawn(state);
  8330. float pct = lua_interface->GetFloatValue(state, 2);
  8331. if (!spawn) {
  8332. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. if (pct == 0) {
  8336. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8340. lua_interface->SetInt32Value(state, amount);
  8341. return 1;
  8342. }
  8343. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8344. if (!lua_interface)
  8345. return 0;
  8346. Spawn* spawn = lua_interface->GetSpawn(state);
  8347. float pct = lua_interface->GetFloatValue(state, 2);
  8348. if (!spawn) {
  8349. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8350. return 0;
  8351. }
  8352. if (pct == 0) {
  8353. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8354. return 0;
  8355. }
  8356. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8357. lua_interface->SetInt32Value(state, amount);
  8358. return 1;
  8359. }
  8360. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8361. if (!lua_interface)
  8362. return 0;
  8363. Spawn* spawn = lua_interface->GetSpawn(state);
  8364. if (!spawn) {
  8365. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8366. return 0;
  8367. }
  8368. if (!spawn->IsPlayer()) {
  8369. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8373. return 1;
  8374. }
  8375. int EQ2Emu_lua_Evac(lua_State* state) {
  8376. if (!lua_interface)
  8377. return 0;
  8378. Spawn* target = lua_interface->GetSpawn(state);
  8379. if (target) {
  8380. float x = target->GetZone()->GetSafeX();
  8381. float y = target->GetZone()->GetSafeY();
  8382. float z = target->GetZone()->GetSafeZ();
  8383. float h = target->GetZone()->GetSafeHeading();
  8384. target->SetX(x);
  8385. target->SetY(y);
  8386. target->SetZ(z);
  8387. target->SetHeading(h);
  8388. target->SetSpawnOrigX(target->GetX());
  8389. target->SetSpawnOrigY(target->GetY());
  8390. target->SetSpawnOrigZ(target->GetZ());
  8391. target->SetSpawnOrigHeading(target->GetHeading());
  8392. if (target->IsPlayer()) {
  8393. Client* client = target->GetZone()->GetClientBySpawn(target);
  8394. if (client) {
  8395. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8396. if (packet)
  8397. {
  8398. packet->setDataByName("x", x);
  8399. packet->setDataByName("y", y);
  8400. packet->setDataByName("z", z);
  8401. client->QueuePacket(packet->serialize());
  8402. safe_delete(packet);
  8403. }
  8404. }
  8405. }
  8406. }
  8407. else {
  8408. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8409. ZoneServer* zone = spell->caster->GetZone();
  8410. float x = spell->caster->GetZone()->GetSafeX();
  8411. float y = spell->caster->GetZone()->GetSafeY();
  8412. float z = spell->caster->GetZone()->GetSafeZ();
  8413. float h = spell->caster->GetZone()->GetSafeHeading();
  8414. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8415. for (int32 i = 0; i < spell->targets.size(); i++) {
  8416. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8417. if (!target2)
  8418. continue;
  8419. target2->SetX(x);
  8420. target2->SetY(y);
  8421. target2->SetZ(z);
  8422. target2->SetHeading(h);
  8423. target2->SetSpawnOrigX(target2->GetX());
  8424. target2->SetSpawnOrigY(target2->GetY());
  8425. target2->SetSpawnOrigZ(target2->GetZ());
  8426. target2->SetSpawnOrigHeading(target2->GetHeading());
  8427. if (target2->IsPlayer()) {
  8428. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8429. if (client) {
  8430. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8431. if (packet)
  8432. {
  8433. packet->setDataByName("x", x);
  8434. packet->setDataByName("y", y);
  8435. packet->setDataByName("z", z);
  8436. client->QueuePacket(packet->serialize());
  8437. safe_delete(packet);
  8438. }
  8439. }
  8440. }
  8441. }
  8442. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8443. }
  8444. return 0;
  8445. }
  8446. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8447. if (!lua_interface)
  8448. return 0;
  8449. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8450. if (!luaspell) {
  8451. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. int8 tier = luaspell->spell->GetSpellTier();
  8455. lua_interface->SetInt32Value(state, tier);
  8456. return 1;
  8457. }
  8458. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8459. if (!lua_interface)
  8460. return 0;
  8461. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8462. if (!luaspell) {
  8463. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8464. return 0;
  8465. }
  8466. int32 spell_id = luaspell->spell->GetSpellID();
  8467. lua_interface->SetInt32Value(state, spell_id);
  8468. return 1;
  8469. }
  8470. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8471. if (!lua_interface)
  8472. return 0;
  8473. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8474. if (!spawn) {
  8475. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (!spawn->IsPlayer()) {
  8479. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. ZoneServer* zone = spawn->GetZone();
  8483. if (!zone) {
  8484. return 0;
  8485. }
  8486. Client* client = zone->GetClientBySpawn(spawn);
  8487. if (!client) {
  8488. return 0;
  8489. }
  8490. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8491. return 0;
  8492. }
  8493. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8494. if (!lua_interface)
  8495. return 0;
  8496. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8497. if (!spawn) {
  8498. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (!spawn->IsPlayer()) {
  8502. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8503. return 0;
  8504. }
  8505. ZoneServer* zone = spawn->GetZone();
  8506. if (!zone) {
  8507. return 0;
  8508. }
  8509. Client* client = zone->GetClientBySpawn(spawn);
  8510. if (!client) {
  8511. return 0;
  8512. }
  8513. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8514. return 0;
  8515. }
  8516. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8517. if (!lua_interface)
  8518. return 0;
  8519. Spawn* caster = lua_interface->GetSpawn(state);
  8520. Spawn* target = lua_interface->GetSpawn(state, 2);
  8521. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8522. string spell_name = lua_interface->GetStringValue(state, 4);
  8523. if (!caster) {
  8524. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8525. return 0;
  8526. }
  8527. if (!caster->IsEntity()) {
  8528. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8529. return 0;
  8530. }
  8531. if (!target) {
  8532. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8533. return 0;
  8534. }
  8535. if (!target->IsEntity()) {
  8536. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8540. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8541. return 0;
  8542. }
  8543. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8544. if (!lua_interface)
  8545. return 0;
  8546. Spawn* object = lua_interface->GetSpawn(state);
  8547. Spawn* player = lua_interface->GetSpawn(state, 2);
  8548. if (object && player && player->IsPlayer()) {
  8549. int32 coins = lua_interface->GetInt32Value(state, 3);
  8550. vector<Item*>* items = 0;
  8551. int i = 0;
  8552. int32 item_id = 0;
  8553. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8554. if (items == 0)
  8555. items = new vector<Item*>;
  8556. if (master_item_list.GetItem(item_id))
  8557. items->push_back(master_item_list.GetItem(item_id));
  8558. i++;
  8559. }
  8560. Client* client = 0;
  8561. client = object->GetZone()->GetClientBySpawn(player);
  8562. if (client) {
  8563. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8564. }
  8565. safe_delete(items);
  8566. }
  8567. return 0;
  8568. }
  8569. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8570. if (!lua_interface)
  8571. return 0;
  8572. Spawn* player = lua_interface->GetSpawn(state);
  8573. int32 amount = lua_interface->GetInt32Value(state, 2);
  8574. if (player && player->IsPlayer() && amount > 0) {
  8575. ((Player*)player)->AddXP(amount);
  8576. ((Player*)player)->SetCharSheetChanged(true);
  8577. Client* client = player->GetZone()->GetClientBySpawn(player);
  8578. if (client) {
  8579. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8580. }
  8581. }
  8582. return 0;
  8583. }
  8584. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8585. if (!lua_interface)
  8586. return 0;
  8587. Spawn* player = lua_interface->GetSpawn(state);
  8588. int8 type = lua_interface->GetInt8Value(state, 2);
  8589. string text = lua_interface->GetStringValue(state, 3);
  8590. Client* client = 0;
  8591. if (player && player->IsPlayer())
  8592. client = player->GetZone()->GetClientBySpawn(player);
  8593. if (!client || text.length() == 0) {
  8594. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8595. return 0;
  8596. }
  8597. client->SimpleMessage(type, text.c_str());
  8598. return 0;
  8599. }
  8600. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8601. if (!lua_interface)
  8602. return 0;
  8603. Spawn* player = lua_interface->GetSpawn(state);
  8604. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8605. Client* client = 0;
  8606. if (player && player->IsPlayer())
  8607. client = player->GetZone()->GetClientBySpawn(player);
  8608. if (!client || !spawn) {
  8609. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8610. return 0;
  8611. }
  8612. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8613. if (!items) {
  8614. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8615. return 0;
  8616. }
  8617. client->Loot(spawn->GetLootCoins(), items, spawn);
  8618. return 0;
  8619. }
  8620. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8621. if (!lua_interface)
  8622. return 0;
  8623. Spawn* spawnref = lua_interface->GetSpawn(state);
  8624. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8625. if (spawn_id > 0 && spawnref) {
  8626. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8627. if (spawns.size() == 0) {
  8628. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8629. return 0;
  8630. }
  8631. Spawn* spawn = 0;
  8632. int16 index = MakeRandomInt(0, spawns.size());
  8633. if (index >= spawns.size() || index < 0)
  8634. index = 0;
  8635. spawn = spawns[index];
  8636. lua_interface->SetSpawnValue(state, spawn);
  8637. return 1;
  8638. }
  8639. else {
  8640. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8641. }
  8642. return 0;
  8643. }
  8644. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8645. Spawn* player = lua_interface->GetSpawn(state);
  8646. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8647. string name = lua_interface->GetStringValue(state, 3);
  8648. float distance = lua_interface->GetFloatValue(state, 4);
  8649. string command = lua_interface->GetStringValue(state, 5);
  8650. string error_text = lua_interface->GetStringValue(state, 6);
  8651. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8652. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8653. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8654. if (distance == 0)
  8655. distance = 10.0f;
  8656. if (command.length() == 0)
  8657. command = name;
  8658. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8659. if (spawns.size() == 0) {
  8660. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. Spawn* spawn = 0;
  8664. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8665. spawn = *itr;
  8666. if (spawn) {
  8667. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8668. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8669. }
  8670. }
  8671. }
  8672. return 0;
  8673. }
  8674. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. Client* client = 0;
  8678. Spawn* player = lua_interface->GetSpawn(state);
  8679. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8680. if (player && player->IsPlayer() && player->GetZone())
  8681. client = player->GetZone()->GetClientBySpawn(player);
  8682. else{
  8683. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8684. return 0;
  8685. }
  8686. if (client) {
  8687. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8688. if (packet) {
  8689. packet->setDataByName("goal_num", goal_num);
  8690. client->QueuePacket(packet->serialize());
  8691. safe_delete(packet);
  8692. }
  8693. }
  8694. return 0;
  8695. }
  8696. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. Client* client = 0;
  8700. Spawn* player = lua_interface->GetSpawn(state);
  8701. if (player && player->IsPlayer() && player->GetZone())
  8702. client = player->GetZone()->GetClientBySpawn(player);
  8703. else {
  8704. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8705. return 0;
  8706. }
  8707. if (client) {
  8708. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8709. }
  8710. return 0;
  8711. }
  8712. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8713. if (!lua_interface)
  8714. return 0;
  8715. Client* client = 0;
  8716. Spawn* player = lua_interface->GetSpawn(state);
  8717. float duration = lua_interface->GetFloatValue(state, 2);
  8718. string text = lua_interface->GetStringValue(state, 3);
  8719. string voice = lua_interface->GetStringValue(state, 4);
  8720. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8721. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8722. string signal = lua_interface->GetStringValue(state, 7);
  8723. string goal1 = lua_interface->GetStringValue(state, 8);
  8724. string task1 = lua_interface->GetStringValue(state, 9);
  8725. string goal2 = lua_interface->GetStringValue(state, 10);
  8726. string task2 = lua_interface->GetStringValue(state, 11);
  8727. string goal3 = lua_interface->GetStringValue(state, 12);
  8728. string task3 = lua_interface->GetStringValue(state, 13);
  8729. string goal4 = lua_interface->GetStringValue(state, 14);
  8730. string task4 = lua_interface->GetStringValue(state, 15);
  8731. if (!player) {
  8732. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8733. return 0;
  8734. }
  8735. if (!player->IsPlayer()) {
  8736. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8737. return 0;
  8738. }
  8739. else
  8740. client = ((Player*)player)->GetClient();
  8741. if (!client) {
  8742. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8743. return 0;
  8744. }
  8745. if (text.length() == 0 || task1.length() == 0 || signal.length() == 0) {
  8746. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8747. return 0;
  8748. }
  8749. if (duration >= 0 && duration < 2)
  8750. duration = 2;
  8751. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8752. if (packet) {
  8753. packet->setDataByName("open_seconds_max", duration);
  8754. packet->setDataByName("text", text.c_str());
  8755. packet->setDataByName("voice", voice.c_str());
  8756. int8 num_goals = 1;
  8757. if (task2.length() > 0)
  8758. num_goals++;
  8759. if (task3.length() > 0)
  8760. num_goals++;
  8761. if (task4.length() > 0)
  8762. num_goals++;
  8763. packet->setArrayLengthByName("num_goals", num_goals);
  8764. for (int8 i = 0; i < num_goals; i++) {
  8765. packet->setSubArrayLengthByName("num_tasks", 1, i);
  8766. }
  8767. if (goal1.length() > 0)
  8768. packet->setArrayDataByName("goal_text", goal1.c_str());
  8769. if (goal2.length() > 0)
  8770. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  8771. if (goal3.length() > 0)
  8772. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  8773. if (goal4.length() > 0)
  8774. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  8775. packet->setSubArrayDataByName("task_text", task1.c_str());
  8776. if (task2.length() > 0)
  8777. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  8778. if (task3.length() > 0)
  8779. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  8780. if (task4.length() > 0)
  8781. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  8782. packet->setDataByName("complete_sound", "click");
  8783. packet->setDataByName("signal", signal.c_str());
  8784. packet->setDataByName("voice_key1", voice_key1);
  8785. packet->setDataByName("voice_key2", voice_key2);
  8786. client->QueuePacket(packet->serialize());
  8787. safe_delete(packet);
  8788. }
  8789. return 0;
  8790. }
  8791. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  8792. if (!lua_interface)
  8793. return 0;
  8794. Client* client = 0;
  8795. Spawn* player = lua_interface->GetSpawn(state);
  8796. string window = lua_interface->GetStringValue(state, 2);
  8797. int8 show = lua_interface->GetInt8Value(state, 3);
  8798. if (!player) {
  8799. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  8800. return 0;
  8801. }
  8802. if (!player->IsPlayer()) {
  8803. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  8804. return 0;
  8805. }
  8806. else
  8807. client = ((Player*)player)->GetClient();
  8808. if (!client) {
  8809. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  8810. return 0;
  8811. }
  8812. if (window.length() == 0) {
  8813. lua_interface->LogError("LUA ShowWindow required parameters not given");
  8814. return 0;
  8815. }
  8816. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  8817. if (packet) {
  8818. packet->setDataByName("window", window.c_str());
  8819. packet->setDataByName("show", show);
  8820. client->QueuePacket(packet->serialize());
  8821. safe_delete(packet);
  8822. }
  8823. return 0;
  8824. }
  8825. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  8826. //See GameEvents.txt for options that can be used for this function
  8827. if (!lua_interface)
  8828. return 0;
  8829. Client* client = 0;
  8830. Spawn* player = lua_interface->GetSpawn(state);
  8831. string event_name = lua_interface->GetStringValue(state, 2);
  8832. int8 enabled = lua_interface->GetInt8Value(state, 3);
  8833. if (!player || !player->IsPlayer()) {
  8834. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  8835. return 0;
  8836. }
  8837. if (player->GetZone())
  8838. client = player->GetZone()->GetClientBySpawn(player);
  8839. if (!client) {
  8840. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  8841. return 0;
  8842. }
  8843. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  8844. if (packet) {
  8845. packet->setDataByName("event_name", event_name.c_str());
  8846. packet->setDataByName("enabled", enabled);
  8847. client->QueuePacket(packet->serialize());
  8848. safe_delete(packet);
  8849. }
  8850. return 0;
  8851. }
  8852. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  8853. if (!lua_interface)
  8854. return 0;
  8855. Spawn* player = lua_interface->GetSpawn(state);
  8856. if (player && player->IsPlayer()) {
  8857. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  8858. return 1;
  8859. }
  8860. return 0;
  8861. }
  8862. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  8863. if (!lua_interface)
  8864. return 0;
  8865. Spawn* player = lua_interface->GetSpawn(state);
  8866. int8 step = lua_interface->GetInt8Value(state, 2);
  8867. if (player && player->IsPlayer() && step > 0) {
  8868. ((Player*)player)->SetTutorialStep(step);
  8869. }
  8870. return 0;
  8871. }
  8872. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. Client* client = 0;
  8876. Spawn* player = lua_interface->GetSpawn(state);
  8877. string window = lua_interface->GetStringValue(state, 2);
  8878. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  8879. if (!player) {
  8880. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  8881. return 0;
  8882. }
  8883. if (!player->IsPlayer()) {
  8884. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  8885. return 0;
  8886. }
  8887. else
  8888. client = ((Player*)player)->GetClient();
  8889. if (!client) {
  8890. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  8891. return 0;
  8892. }
  8893. if (window.length() == 0) {
  8894. lua_interface->LogError("LUA FlashWindow required parameters not given");
  8895. return 0;
  8896. }
  8897. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  8898. if (packet) {
  8899. packet->setDataByName("window", window.c_str());
  8900. packet->setDataByName("flash_seconds", flash_seconds);
  8901. client->QueuePacket(packet->serialize());
  8902. safe_delete(packet);
  8903. }
  8904. return 0;
  8905. }
  8906. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8907. if (!lua_interface)
  8908. return 0;
  8909. Spawn* spawn = lua_interface->GetSpawn(state);
  8910. Spawn* target = lua_interface->GetSpawn(state, 2);
  8911. if (spawn && target)
  8912. return spawn->CheckLoS(target);
  8913. return 0;
  8914. }
  8915. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8916. if (!lua_interface)
  8917. return 0;
  8918. Spawn* spawn = lua_interface->GetSpawn(state);
  8919. float x = lua_interface->GetFloatValue(state, 2);
  8920. float y = lua_interface->GetFloatValue(state, 3);
  8921. float z = lua_interface->GetFloatValue(state, 4);
  8922. if (spawn)
  8923. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8924. return 0;
  8925. }
  8926. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8927. if (!lua_interface)
  8928. return 0;
  8929. ZoneServer* zone = lua_interface->GetZone(state);
  8930. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8931. if (zone)
  8932. zone->SetExpansionFlag(xpackFlag);
  8933. return 0;
  8934. }
  8935. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8936. if (!lua_interface)
  8937. return 0;
  8938. ZoneServer* zone = lua_interface->GetZone(state);
  8939. if (zone) {
  8940. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8941. return 1;
  8942. }
  8943. return 0;
  8944. }
  8945. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  8946. if (!lua_interface)
  8947. return 0;
  8948. ZoneServer* zone = lua_interface->GetZone(state);
  8949. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  8950. if (zone)
  8951. zone->SetHolidayFlag(holidayFlag);
  8952. return 0;
  8953. }
  8954. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  8955. if (!lua_interface)
  8956. return 0;
  8957. ZoneServer* zone = lua_interface->GetZone(state);
  8958. if (zone) {
  8959. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  8960. return 1;
  8961. }
  8962. return 0;
  8963. }
  8964. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  8965. if (!lua_interface)
  8966. return 0;
  8967. Spawn* spawn = lua_interface->GetSpawn(state);
  8968. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  8969. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  8970. float distance = lua_interface->GetFloatValue(state, 4);
  8971. string in_range_function = lua_interface->GetStringValue(state, 5);
  8972. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  8973. if (spawn && distance > 0 && in_range_function.length() > 0)
  8974. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  8975. return 0;
  8976. }
  8977. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  8978. if (!lua_interface)
  8979. return 0;
  8980. Spawn* spawn = lua_interface->GetSpawn(state);
  8981. Spawn* target = lua_interface->GetSpawn(state, 2);
  8982. if (spawn && target)
  8983. {
  8984. if (spawn->IsPlayer() && target->IsEntity())
  8985. {
  8986. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  8987. return 1;
  8988. }
  8989. else if (spawn->IsEntity() && target->IsEntity())
  8990. {
  8991. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  8992. return 1;
  8993. }
  8994. }
  8995. return 0;
  8996. }
  8997. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  8998. if (!lua_interface)
  8999. return 0;
  9000. Spawn* spawn = lua_interface->GetSpawn(state);
  9001. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9002. if (spawn && spawn->IsEntity())
  9003. {
  9004. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9005. if (spawn->IsPlayer())
  9006. {
  9007. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9008. if (client)
  9009. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9010. }
  9011. }
  9012. return 0;
  9013. }
  9014. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9015. if (!lua_interface)
  9016. return 0;
  9017. Spawn* spawn = lua_interface->GetSpawn(state);
  9018. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9019. if (spawn && spawn->IsEntity())
  9020. {
  9021. ((Entity*)spawn)->SetSeeHideSpell(val);
  9022. if (spawn->IsPlayer())
  9023. {
  9024. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9025. if (client)
  9026. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9027. }
  9028. }
  9029. return 0;
  9030. }
  9031. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9032. {
  9033. if (!lua_interface)
  9034. return 0;
  9035. Spawn* player = lua_interface->GetSpawn(state);
  9036. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9037. string command = lua_interface->GetStringValue(state, 3);
  9038. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9039. if (spawn && player && player->IsPlayer())
  9040. {
  9041. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9042. bool res = false;
  9043. if (cmd)
  9044. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9045. lua_interface->SetBooleanValue(state, res);
  9046. return 1;
  9047. }
  9048. return 0;
  9049. }
  9050. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9051. {
  9052. if (!lua_interface)
  9053. return 0;
  9054. Spawn* spawn = lua_interface->GetSpawn(state);
  9055. string command = lua_interface->GetStringValue(state, 2);
  9056. if (spawn && command.length() > 0)
  9057. spawn->RemovePrimaryEntityCommand(command.c_str());
  9058. return 0;
  9059. }
  9060. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Spawn* spawn = lua_interface->GetSpawn(state);
  9064. float distance = lua_interface->GetFloatValue(state, 2);
  9065. string command = lua_interface->GetStringValue(state, 3);
  9066. Spawn* player = lua_interface->GetSpawn(state, 4);
  9067. if (spawn) {
  9068. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9069. }
  9070. return 0;
  9071. }
  9072. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9073. if (!lua_interface)
  9074. return 0;
  9075. Spawn* spawn = lua_interface->GetSpawn(state);
  9076. Spawn* player = lua_interface->GetSpawn(state, 2);
  9077. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9078. if (spawn && player && transport_id && player->IsPlayer()) {
  9079. Client* client = 0;
  9080. if (player && player->IsPlayer())
  9081. client = player->GetZone()->GetClientBySpawn(player);
  9082. if (!client)
  9083. return 0;
  9084. vector<TransportDestination*> destinations;
  9085. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9086. if (destinations.size())
  9087. {
  9088. client->SetTemporaryTransportID(transport_id);
  9089. client->ProcessTeleport(spawn, &destinations, transport_id);
  9090. }
  9091. else
  9092. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9093. }
  9094. return 0;
  9095. }
  9096. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9097. if (!lua_interface)
  9098. return 0;
  9099. Spawn* player = lua_interface->GetSpawn(state);
  9100. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9101. if (player && player->IsPlayer()) {
  9102. Client* client = 0;
  9103. if (player && player->IsPlayer())
  9104. client = player->GetZone()->GetClientBySpawn(player);
  9105. if (!client)
  9106. return 0;
  9107. client->SetTemporaryTransportID(transport_id);
  9108. }
  9109. return 0;
  9110. }
  9111. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9112. if (!lua_interface)
  9113. return 0;
  9114. Spawn* player = lua_interface->GetSpawn(state);
  9115. if (player && player->IsPlayer()) {
  9116. Client* client = 0;
  9117. if (player && player->IsPlayer())
  9118. client = player->GetZone()->GetClientBySpawn(player);
  9119. if (!client)
  9120. return 0;
  9121. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9122. return 1;
  9123. }
  9124. return 0;
  9125. }